-
Notifications
You must be signed in to change notification settings - Fork 43
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
Conversation
✅ Tests will run for this PR. Once they succeed it can be merged. |
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.
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
Транзакцията ще отнеме от 5 до 10 дни и парите ви ще бъдат върнати по същия начин, по | ||
който са били получени. <br /><br /> |
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.
нека да променим текста за да е малко по-ясно:
"парите ще ви бъдат върнати към същата карта, с която сте превели дарението към Страйп."
/** | ||
* 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>> { |
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.
great for including the reference to the docs!
|
||
return await this.stripeClient.refunds.create({ | ||
payment_intent: paymentIntentId, | ||
reason: 'requested_by_customer', |
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.
[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
await this.sendEmail.sendFromTemplate(mail, recepient, { | ||
//Allow users to receive the mail, regardles of unsubscribes | ||
bypassUnsubscribeManagement: { enable: true }, | ||
}) |
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.
good call here!
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:
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](https://private-user-images.githubusercontent.com/44066540/271834855-e5cd04e3-afff-4d70-91f0-a3a04628b64d.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjU1MTQwODYsIm5iZiI6MTcyNTUxMzc4NiwicGF0aCI6Ii80NDA2NjU0MC8yNzE4MzQ4NTUtZTVjZDA0ZTMtYWZmZi00ZDcwLTkxZjAtYTNhMDQ2MjhiNjRkLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA5MDUlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwOTA1VDA1MjMwNlomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTQzNmNhNTczNmRmMmZmNzkzNjRjNjc1MTlhMzlmYTRhOTAzNWYxYjljMDQ3YmQxMjlhZDRmNzhjYjExMDMyYzImWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.wqvqdqzKdvZll5tffuge9CZ_xOHkiQGtzvxh9_Dkqqk)
After refund button is clicked - donation is not present in the campaign tab:
End user will receive the following mail: