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

[Stripe] Implement Refund event listener in Stripe webhook #556

Merged
merged 16 commits into from
Oct 29, 2023

Conversation

Nnachevvv
Copy link
Member

@Nnachevvv Nnachevvv commented Oct 1, 2023

This PR ensures we will handle stripe refund event, so that in case of Refund request, the refunded amounts to be properly substracted.

The refund itself is by calling /api/v1/donation/refund-stripe-paymet/ endpoint or from billing Stripe Admin UI. After refund request is received Stripe sends a charge.refunded event: https://stripe.com/docs/api/refunds/object

After we receive this event, we will:

  • subtract the value from the vault
  • send an email to the end user
  • change the donation status to refund

Relates to podkrepi-bg/frontend#1635
Closes #518 and podkrepi-bg/frontend#1585

Test:

Created a donation:
Screenshot 2023-10-01 at 17 27 32

After refund button is clicked - donation is not present in the campaign tab:

Screenshot 2023-10-28 at 23 02 24 Screenshot 2023-10-28 at 23 02 40 Screenshot 2023-10-01 at 17 28 21

End user will receive the following mail:

Screenshot 2023-10-01 at 17 34 34

@github-actions
Copy link

github-actions bot commented Oct 1, 2023

✅ Tests will run for this PR. Once they succeed it can be merged.

@igoychev igoychev added the run tests Allows running the tests workflows for forked repos label Oct 2, 2023
@github-actions github-actions bot removed the run tests Allows running the tests workflows for forked repos label Oct 2, 2023
@igoychev igoychev added the run tests Allows running the tests workflows for forked repos label Oct 3, 2023
@github-actions github-actions bot removed the run tests Allows running the tests workflows for forked repos label Oct 3, 2023
@igoychev igoychev added the run tests Allows running the tests workflows for forked repos label Oct 29, 2023
@github-actions github-actions bot removed the run tests Allows running the tests workflows for forked repos label Oct 29, 2023
Copy link
Contributor

@igoychev igoychev left a comment

Choose a reason for hiding this comment

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

all great!
the logic is implemented on the right places and I especially like how you made the refactoring around Increment/Decrement to preserve readability and correctness.

my only request for change is the text in the email as per the comment

Comment on lines 50 to 51
Транзакцията ще отнеме от 5 до 10 дни и парите ви ще бъдат върнати по същия начин, по
който са били получени. <br /><br />
Copy link
Contributor

Choose a reason for hiding this comment

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

нека да променим текста за да е малко по-ясно:
"парите ще ви бъдат върнати към същата карта, с която сте превели дарението към Страйп."

Comment on lines +485 to +491
/**
* Refund a stipe payment donation
* https://stripe.com/docs/api/refunds/create
* @param inputDto Refund-stripe params
* @returns {Promise<Stripe.Response<Stripe.Refund>>}
*/
async refundStripePayment(paymentIntentId: string): Promise<Stripe.Response<Stripe.Refund>> {
Copy link
Contributor

Choose a reason for hiding this comment

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

great for including the reference to the docs!


return await this.stripeClient.refunds.create({
payment_intent: paymentIntentId,
reason: 'requested_by_customer',
Copy link
Contributor

Choose a reason for hiding this comment

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

[TODO] for next version, it would be good to allow several predefined reasons and a free text that can be selected/entered on the fronted from the Admin UI.
I will write a separate ticket for this

Comment on lines +192 to +195
await this.sendEmail.sendFromTemplate(mail, recepient, {
//Allow users to receive the mail, regardles of unsubscribes
bypassUnsubscribeManagement: { enable: true },
})
Copy link
Contributor

Choose a reason for hiding this comment

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

good call here!

@igoychev igoychev added the run tests Allows running the tests workflows for forked repos label Oct 29, 2023
@github-actions github-actions bot removed the run tests Allows running the tests workflows for forked repos label Oct 29, 2023
@igoychev igoychev merged commit 4a6e572 into podkrepi-bg:master Oct 29, 2023
11 of 12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Stripe] Implement Refund event listener in Stripe webhook
3 participants