#Slush - webhooks
1 messages ยท Page 1 of 1 (latest)
Hi there! Yes, more details would be helpful. Are you running into any specific errors?
No no errors everything is working perfectly
I am using the example quickstart webhook guide
And everything is working perfectly
But I have a question on how to handle something if I run into it.
I have a call to my database to setup the users account after they purchase.
But if the database returns back an "error" then their account doesnt actually get setup.
But they have still paid for it and they still get redirected to a screen that says success.
What is the best way to handle this?
{
var paymentIntent = stripeEvent.Data.Object as PaymentIntent;
Console.WriteLine("A successful payment for {0} was made.", paymentIntent.Amount);
// Then define and call a method to handle the successful payment intent.
// handlePaymentIntentSucceeded(paymentIntent);
CloudConnection.dbconnect connection = new CloudConnection.dbconnect();
string tournyID = paymentIntent.Metadata["TournyID"];
string partnerID = paymentIntent.Metadata["PartnerID"];
string playerID = paymentIntent.Metadata["PlayerID"];
string result = connection.FinalEntranceCheck(tournyID, partnerID, playerID);
if(result == "true")
{
}
}```
Thats my code, as you can see if result == true then its good to go. If result == false then I need to refund them and let the user know that the payment actually failed.
Thanks for sharing this! If result == false this condition is still within the conditional for stripeEvent.Type == Events.PaymentIntentSucceeded , right?
Do you want your application to retry creating their account in your database if their payment was successful?
No I want to give them a refund and notify them that they have been refunded.
Hi there ๐ taking over for @vestal zealot as they needed to step away.
If the payment fails, then no refund is necessary (since that would mean the payment did not go through)
No
Thats not what Im saying
If the payment goes through I have a webhook setup so I can setup their account in my database
But if my database setup fails for whatever reason I want it to instantly refund the user.
Ah, okay. That's a pretty simple task: https://stripe.com/docs/refunds
Email confirmations for refunds are also covered in those docs
So if this code executes var options = new RefundCreateOptions { PaymentIntent = "pi_Aabcxyz01aDfoo" }; var service = new RefundService(); service.Create(options);"
Then the user will be refunded granted I put in the corresponding payment intent ID?
I don't recognize a lot of the methods in that code. Where is RefundService() coming from?
Its inthe guide you sent
Ah, apologies. I forgot you're in C#
No worries
So yea, that code will trigger a refund. If you want an email to be sent, then you'll want to confirm that each of these conditions are met:
- The original charge was created on a Customer object in your Stripe account
- The Customer object has a stored email address
- You have Email customers for refunds enabled (https://dashboard.stripe.com/account/emails)
Sign in to the Stripe Dashboard to manage business payments and operations in your account. Manage payments and refunds, respond to disputes and more.
So for the payment intent I need to have this parameter filled out ""receipt_email""
Is that correct?
No, you'll want customer.email to be filled out: https://stripe.com/docs/api/customers/update#update_customer-email
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
Hmm I dont see that here: { "id": "pi_1DsTgI2eZvKYlo2CAd7R4A03", "object": "payment_intent", "amount": 2000, "amount_capturable": 0, "amount_details": { "tip": {} }, "amount_received": 0, "application": null, "application_fee_amount": null, "automatic_payment_methods": null, "canceled_at": null, "cancellation_reason": null, "capture_method": "automatic", "charges": { "object": "list", "data": [], "has_more": false, "url": "/v1/charges?payment_intent=pi_1DsTgI2eZvKYlo2CAd7R4A03" }, "client_secret": "xxx", "confirmation_method": "automatic", "created": 1547465558, "currency": "usd", "customer": null, "description": null, "invoice": null, "last_payment_error": null, "livemode": false, "metadata": {}, "next_action": null, "on_behalf_of": null, "payment_method": null, "payment_method_options": { "card": { "installments": null, "mandate_options": null, "network": null, "request_three_d_secure": "automatic" } }, "payment_method_types": [ "card" ], "processing": null, "receipt_email": null, "review": null, "setup_future_usage": null, "shipping": null, "statement_descriptor": null, "statement_descriptor_suffix": null, "status": "requires_payment_method", "transfer_data": null, "transfer_group": null }