Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed handling of repeated charge.succeeded event #544

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions apps/api/src/campaign/campaign.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,10 @@ export class CampaignService {
})

//if donation is switching to successful, increment the vault amount and send notification
if (newDonationStatus === DonationStatus.succeeded) {
if (
donation.status != DonationStatus.succeeded &&
newDonationStatus === DonationStatus.succeeded
) {
await this.vaultService.incrementVaultAmount(
donation.targetVaultId,
paymentData.netAmount,
Expand Down Expand Up @@ -743,8 +746,15 @@ export class CampaignService {

async createDonationWish(wish: string, donationId: string, campaignId: string) {
const person = await this.prisma.donation.findUnique({ where: { id: donationId } }).person()
await this.prisma.donationWish.create({
data: {
await this.prisma.donationWish.upsert({
where: { donationId },
create: {
message: wish,
donationId,
campaignId,
personId: person?.id,
},
update: {
message: wish,
donationId,
campaignId,
Expand Down
6 changes: 3 additions & 3 deletions apps/api/src/donations/events/stripe-payment.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ export class StripePaymentService {
)

//updateDonationPayment will mark the campaign as completed if amount is reached
await this.checkForCompletedCampaign(metadata.campaignId)
await this.cancelSubscriptionsIfCompletedCampaign(metadata.campaignId)

//and finally save the donation wish
if (donationId && metadata?.wish) {
Expand Down Expand Up @@ -307,11 +307,11 @@ export class StripePaymentService {
)

//updateDonationPayment will mark the campaign as completed if amount is reached
await this.checkForCompletedCampaign(metadata.campaignId)
await this.cancelSubscriptionsIfCompletedCampaign(metadata.campaignId)
}

//if the campaign is finished, we need to stop all active subscriptions
async checkForCompletedCampaign(campaignId: string) {
async cancelSubscriptionsIfCompletedCampaign(campaignId: string) {
const updatedCampaign = await this.campaignService.getCampaignById(campaignId)
if (updatedCampaign.state === CampaignState.complete) {
const recurring =
Expand Down
12 changes: 7 additions & 5 deletions apps/api/src/prisma/prisma-client-exception.filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,13 @@ export class PrismaClientExceptionFilter extends BaseExceptionFilter {
return { property: el, children: [], constraints }
})

response.status(status).json({
statusCode: status,
message,
error: this.cleanUpException(exception),
})
if (response) {
response.status(status).json({
statusCode: status,
message,
error: this.cleanUpException(exception),
})
}
}

/**
Expand Down
Loading