Skip to content

Commit 2ce887b

Browse files
authored
fix: Stripe webhook crashing due to missing type (#637)
1 parent 4d44d38 commit 2ce887b

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

apps/api/src/donations/dto/create-session.dto.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export class CreateSessionDto {
2828
@ApiProperty()
2929
@Expose()
3030
@IsEnum(DonationType)
31+
@IsOptional()
3132
public readonly type: DonationType
3233

3334
@ApiProperty()

apps/api/src/donations/helpers/payment-intent-helpers.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { PaymentProvider } from '@prisma/client'
1+
import { DonationType, PaymentProvider } from '@prisma/client'
22
import Stripe from 'stripe'
33
import { getCountryRegion, stripeFeeCalculator } from './stripe-fee-calculator'
44
import { RecurringDonationStatus, Currency } from '@prisma/client'
@@ -56,7 +56,7 @@ export function getPaymentData(
5656
billingEmail: charge?.billing_details?.email ?? paymentIntent.receipt_email ?? undefined,
5757
paymentMethodId: getPaymentMethodId(paymentIntent),
5858
stripeCustomerId: getPaymentCustomerId(paymentIntent),
59-
type: paymentIntent.metadata.type,
59+
type: paymentIntent.metadata.type ?? DonationType.donation,
6060
personId: !isAnonymous ? paymentIntent.metadata.personId : undefined,
6161
}
6262
}
@@ -80,7 +80,7 @@ export function getPaymentDataFromCharge(charge: Stripe.Charge): PaymentData {
8080
billingEmail: charge?.billing_details?.email ?? charge.receipt_email ?? undefined,
8181
paymentMethodId: 'card',
8282
stripeCustomerId: charge.billing_details?.email ?? undefined,
83-
type: charge.metadata.type,
83+
type: charge.metadata.type ?? DonationType.donation,
8484
personId: !isAnonymous ? charge.metadata.personId : undefined,
8585
}
8686
}
@@ -96,7 +96,7 @@ export function getInvoiceData(invoice: Stripe.Invoice): PaymentData {
9696
personId = line.metadata.personId
9797
}
9898
if (line.metadata.type) {
99-
type = line.metadata.type
99+
type = line.metadata.type ?? DonationType.donation
100100
}
101101
})
102102

0 commit comments

Comments
 (0)