I'm transitioning a website from Google Wallet for Digital Goods to Stripe and I'm trying to duplicate the old flow of
Customer makes purchase and user_id
, product_id
, quantity
, and other arbitrary data are passed to Google Wallet
A postback is sent to my server including all that extra data and a secret key so I know it's not a customer spoofing a postback
My server assumes that means a legitimate purchase has taken place and finishes up various processing
For each purchase, my site obviously needs to know
charge.description
can't be used as a unique identifier)
I'm trying to integrate Checkout and don't see
charge
object (which the webhook is sending back to my server) that passes back arbitrary data.The customer object doesn't seem like the solution, since the API docs say "Customer objects allow you to perform recurring charges and track multiple charges that are associated with the same customer", neither of which apply to my situation.
I can do something like this,
var handler = StripeCheckout.configure({
token: function(token) {
var user_id = 123;
var product_id = 456;
var quantity = 2;
var arbitrary = 'data';
// fire off a POST call to http://example.com/hey_look_a_charge with the above data
}
});
But the Checkout example says that the token
callback gets invoked "when the Checkout process is complete", not just for successful charges. The token.id
could be stored along with the other data as a 'pending purchase' that becomes verified once the charge.succeeded
event fires a webhook, but that might introduce a race condition, sounds convoluted as hell, and token.id
isn't sent back with the webhook in the first place.
This seems like a really common requirement for payment processing, but I'm totally baffled how to practically pull it off with Stripe. Can anyone advise?
Stripe uses webhooks to notify your application when an event happens in your account. Webhooks are particularly useful for asynchronous events like when a customer's bank confirms a payment, a customer disputes a charge, a recurring payment succeeds, or when collecting subscription payments.
It is possible to manually resend webhook events. In the Stripe Dashboard, select Developers > Webhooks , then find the webhook your working with and press the little "resend" icon. Note that for events which succeeded, you can still resend them by clicking the ellipsis and then "Resend" (this is a newer feature).
Add a webhook endpointOpen the Webhooks page. Click Add endpoint. Add your webhook endpoint's HTTPS URL in Endpoint URL. If you have a Stripe Connect account, enter a description and select Listen to events on Connected accounts.
I think you're confused about how Stripe Checkout works. Getting the Stripe token is only the first step in the process of handling a payment. When using Stripe Checkout or Stripe.js you get a Stripe token back that you then need to send to your server where you then use the Create Charge API to create a charge and receive a payment.
So in your case you would be able to create the charge server-side and once the API call is made you don't need to wait for the charge.succeeded
event in your webhook. You get either a charge object back indicating success or an error indicating the charge failed. You would then be able to update your database at that point.
You can add a hidden input field to the form containing the stripe script tag.
<form action="/your-server-side-code" method="POST">
<input type="hidden" name="my_data" value="my_data_value">
<script
src="https://checkout.stripe.com/checkout.js" class="stripe-button"
data-key="pk_test_d2luBCpkXXuIVPKS7hBN43jR"
data-amount="999"
data-name="Demo Site"
data-description="Widget"
data-image="https://stripe.com/img/documentation/checkout/marketplace.png"
data-locale="auto">
</script>
</form>
then you can receive the value in the '/your-server-side-code' url.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With