-
Notifications
You must be signed in to change notification settings - Fork 48
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
407 - New Donation Flow PaymentIntent endpoints and flow #425
Conversation
async createInitialDonationFromIntent( | ||
campaign: Campaign, | ||
stripePaymentDto: CreateStripePaymentDto, | ||
paymentIntent: Stripe.PaymentIntent, | ||
): Promise<Donation> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is basically a copy of createInitialDonationFromSession
adapted to work with the stripePaymentDto
and the new requests.
/** | ||
* Create or update initial donation object | ||
*/ | ||
const donation = await this.prisma.donation.upsert({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is an upsert call since I ran into 409 Conflict
errors, because when that method is called the payment_intent.create
hook had already created a donation with that extPaymentIntentId
and it should be unique for every donation.
Maybe it should be a straight update
call since the frontend will call the create-stripe-payment
always after the payment_intent.created
has been sent
extCustomerId: stripePaymentDto.personEmail ?? '', | ||
extPaymentIntentId: paymentIntent.id, | ||
extPaymentMethodId: 'card', | ||
billingEmail: stripePaymentDto.isAnonymous ? stripePaymentDto.personEmail : null, //set the personal mail to billing which is not public field |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we can add the billing email in all cases, not only when the user has selected anonymous donation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That would make sense.
It would actually make even more sense to not save the email if he has chosen isAnonymous
if the email is not required.
Then we might not be able to send the receipt though if this is the email that is used for that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As you said the billingEmail
is never exposed to the public, so it's always anonymous.
I'd suggest we keep the billing email so we can contact the person if there's a problem with the payments or other circumstances.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Closes #409
Motivation and context
This PR includes new endpoints needed for the new Donation Flow. Check out podkrepi-bg/frontend#1272.
There are changes on how the Stripe donation flow works for the checkout session and the new Payment Intent approach.
This is the guide that was followed when creating these new endpoints:
https://stripe.com/docs/payments/accept-a-payment?platform=web&ui=elements
Testing
No testing done currently.
Steps to test
Go to swagger at http://localhost:5010/swagger (they are public and you do not need a toke)
New endpoints
@Post('payment-intent')
- Creates a new stripe payment intent based and returns it@Post('payment-intent/:id')
- Updates a payment intent@Post('create-stripe-payment')
- Creates a donation based on the intent info and data provided by the user through the form on the frontendNote: The two
payment-intent
endpoints are bothPOST
, because of how the Stripe API is setup. We can change that though (https://stripe.com/docs/api/payment_intents)