Skip to content

Commit

Permalink
fix: Stripe webhook crashing due to missing type (#637)
Browse files Browse the repository at this point in the history
  • Loading branch information
sashko9807 authored Jun 1, 2024
1 parent 4d44d38 commit 2ce887b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
1 change: 1 addition & 0 deletions apps/api/src/donations/dto/create-session.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export class CreateSessionDto {
@ApiProperty()
@Expose()
@IsEnum(DonationType)
@IsOptional()
public readonly type: DonationType

@ApiProperty()
Expand Down
8 changes: 4 additions & 4 deletions apps/api/src/donations/helpers/payment-intent-helpers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { PaymentProvider } from '@prisma/client'
import { DonationType, PaymentProvider } from '@prisma/client'
import Stripe from 'stripe'
import { getCountryRegion, stripeFeeCalculator } from './stripe-fee-calculator'
import { RecurringDonationStatus, Currency } from '@prisma/client'
Expand Down Expand Up @@ -56,7 +56,7 @@ export function getPaymentData(
billingEmail: charge?.billing_details?.email ?? paymentIntent.receipt_email ?? undefined,
paymentMethodId: getPaymentMethodId(paymentIntent),
stripeCustomerId: getPaymentCustomerId(paymentIntent),
type: paymentIntent.metadata.type,
type: paymentIntent.metadata.type ?? DonationType.donation,
personId: !isAnonymous ? paymentIntent.metadata.personId : undefined,
}
}
Expand All @@ -80,7 +80,7 @@ export function getPaymentDataFromCharge(charge: Stripe.Charge): PaymentData {
billingEmail: charge?.billing_details?.email ?? charge.receipt_email ?? undefined,
paymentMethodId: 'card',
stripeCustomerId: charge.billing_details?.email ?? undefined,
type: charge.metadata.type,
type: charge.metadata.type ?? DonationType.donation,
personId: !isAnonymous ? charge.metadata.personId : undefined,
}
}
Expand All @@ -96,7 +96,7 @@ export function getInvoiceData(invoice: Stripe.Invoice): PaymentData {
personId = line.metadata.personId
}
if (line.metadata.type) {
type = line.metadata.type
type = line.metadata.type ?? DonationType.donation
}
})

Expand Down

0 comments on commit 2ce887b

Please sign in to comment.