Skip to content

Commit

Permalink
fix: Connect non anonymous donation by personId (#678)
Browse files Browse the repository at this point in the history
* fix: Connect non anonymous donation by personId
It is not necessary for the billlingEmail to be the one of the registered user(e.g. company emails for billing)

* fix: Tests
  • Loading branch information
sashko9807 authored Nov 30, 2024
1 parent e43461a commit 46fe5b0
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 7 deletions.
8 changes: 5 additions & 3 deletions apps/api/src/donations/donations.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -914,7 +914,7 @@ export class DonationsService {
create: {
amount: paymentData.netAmount,
type: paymentData.type as DonationType,
person: paymentData.personId ? { connect: { email: paymentData.billingEmail } } : {},
person: paymentData.personId ? { connect: { id: paymentData.personId } } : {},
targetVault: targetVaultData,
},
},
Expand All @@ -928,7 +928,7 @@ export class DonationsService {
donation.amount,
tx,
)
this.notificationService.sendNotification('successfulDonation', donation)
this.notificationService.sendNotification('successfulDonation', donation.donations[0])
}

return donation
Expand Down Expand Up @@ -966,7 +966,9 @@ export class DonationsService {
},
include: { donations: true },
})
Logger.debug('Donation found by subscription: ', donation)
if (donation) {
Logger.debug('Donation found by subscription: ', donation)
}
}
return donation
}
Expand Down
3 changes: 2 additions & 1 deletion apps/api/src/sockets/notifications/notification.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ export const donationNotificationSelect = Prisma.validator<Prisma.PaymentSelect>
amount: true,
extPaymentMethodId: true,
createdAt: true,

donations: {
select: {
id: true,
targetVaultId: true,
createdAt: true,
amount: true,
person: {
select: {
firstName: true,
Expand Down
4 changes: 2 additions & 2 deletions apps/api/src/stripe/stripe.controller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ describe('StripeController', () => {
checkout: { sessions: { create: jest.fn() } },
paymentIntents: { retrieve: jest.fn() },
refunds: { create: jest.fn() },
setupIntents: { retrieve: jest.fn() },
setupIntents: { retrieve: jest.fn(), update: jest.fn() },
customers: { create: jest.fn(), list: jest.fn() },
paymentMethods: { attach: jest.fn() },
products: { search: jest.fn(), create: jest.fn() },
Expand Down Expand Up @@ -199,7 +199,7 @@ describe('StripeController', () => {
reason: 'requested_by_customer',
})
})
it(`should not call setupintents.update if campaign can't accept donations`, async () => {
it(`should not call setupintents.update if no campaignId is provided`, async () => {
prismaMock.campaign.findFirst.mockResolvedValue({
id: 'complete-campaign',
allowDonationOnComplete: false,
Expand Down
2 changes: 1 addition & 1 deletion apps/api/src/stripe/stripe.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export class StripeService {
): Promise<Stripe.Response<Stripe.SetupIntent>> {
if (!inputDto.metadata.campaignId)
throw new BadRequestException('campaignId is missing from metadata')
const campaign = await this.campaignService.validateCampaignId(
await this.campaignService.validateCampaignId(
inputDto.metadata.campaignId as string,
)
return await this.stripeClient.setupIntents.update(id, inputDto, { idempotencyKey })
Expand Down

0 comments on commit 46fe5b0

Please sign in to comment.