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

407 - New Donation Flow PaymentIntent endpoints and flow #425

Merged
merged 17 commits into from
Feb 2, 2023

Conversation

dimitur2204
Copy link
Contributor

@dimitur2204 dimitur2204 commented Jan 29, 2023

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 frontend

Note: The two payment-intent endpoints are both POST, because of how the Stripe API is setup. We can change that though (https://stripe.com/docs/api/payment_intents)

@dimitur2204 dimitur2204 linked an issue Jan 29, 2023 that may be closed by this pull request
@dimitur2204 dimitur2204 self-assigned this Jan 29, 2023
@dimitur2204 dimitur2204 added the type: enhancement New feature or request label Jan 29, 2023
@dimitur2204 dimitur2204 marked this pull request as ready for review January 29, 2023 18:31
Comment on lines +122 to +126
async createInitialDonationFromIntent(
campaign: Campaign,
stripePaymentDto: CreateStripePaymentDto,
paymentIntent: Stripe.PaymentIntent,
): Promise<Donation> {
Copy link
Contributor Author

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({
Copy link
Contributor Author

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

@dimitur2204 dimitur2204 changed the title 407 payment intent endpoint 407 - New Donation Flow PaymentIntent endpoints and flow Jan 31, 2023
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
Copy link
Member

@kachar kachar Jan 31, 2023

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.

Copy link
Contributor Author

@dimitur2204 dimitur2204 Jan 31, 2023

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.

Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dimitur2204 dimitur2204 merged commit c5268f5 into master Feb 2, 2023
@dimitur2204 dimitur2204 deleted the 407-payment-intent-endpoint branch February 2, 2023 19:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

New Donation Flow - Payment Intent Donations Endpoints
2 participants