How do you send extra data with a Stripe account that needs to be returned to webhook?

I’m navigating a website from Google Wallet for digital goods in a strip and I’m trying to duplicate an old stream

  • Customer makes a purchase and user_id , product_id , quantity and other arbitrary data are transferred to Google Wallet

  • A postback is sent to my server, including all this extra data and a secret key, so I know that this is not a client cheating on the postback

  • My server assumes that this means that a legitimate purchase has taken place and is completing various processing

For every purchase, my site obviously needs to know

  • Which product was purchased (and charge.description cannot be used as a unique identifier)
  • Which of the user accounts of your site was registered by the client when making a purchase.

I am trying to integrate Checkout and cannot see

Use client object?

The customer object does not look like a solution, as the API docs say: “Customer objects allow you to make recurring payments and track multiple charges associated with the same customer,” none of which apply to my situation.

Handle it in a local Javascript callback?

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 is called “when the verification process is complete”, and not just for successful collections. token.id can be saved along with other data in the form of a “pending purchase”, which will be checked after the charge.succeeded event triggers a web check, but this can lead to a race condition, a sound minimized as hell, and token.id isn’t sent back by webcam first.

This seems like a really common requirement for processing payments, but I'm completely puzzled by how to practically pull it out with Stripe. Can anyone advise?

+6
source share
2 answers

I think you are confused about how Stripe Checkout works. Obtaining a Stripe token is only the first step in the payment processing process. When using Stripe Checkout or Stripe.js, you receive and then you need to send it to your server, where you then use the Create Charge API to create a payment and receive a payment.

So, in your case, you can create a server board with a charge, and after calling the API you do not need to wait for the charge.succeeded event in your web host. You get either a charge object back, indicating success, or an error indicating that the failure was not completed. Then you can update your database at this point.

+2
source

You can add a hidden input field to the form containing the 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 get the value in the url '/ your-server-side-code'.

+3
source

Source: https://habr.com/ru/post/980480/


All Articles