Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- paymentRequest.on('paymentmethod', function(ev) {
- console.log("Paymentrequest paymentMethod: ")
- console.log(ev);
- console.log(ev.paymentMethod);
- // I get clientSecret from an input field in my sample
- var clientSecret = clientSecretInput.value;
- paymentRequestConfirm(ev, clientSecret);
- });
- function paymentRequestConfirm(ev, clientSecret) {
- // Confirm the PaymentIntent without handling potential next actions (yet).
- stripe.confirmCardPayment(
- clientSecret,
- {payment_method: ev.paymentMethod.id},
- {handleActions: false}
- ).then(function(confirmResult) {
- console.log("first confirm result is");
- console.log(confirmResult);
- if (confirmResult.error) {
- // Report to the browser that the payment failed, prompting it to
- // re-show the payment interface, or show an error message and close
- // the payment interface.
- ev.complete('fail');
- } else {
- // Report to the browser that the confirmation was successful, prompting
- // it to close the browser payment method collection interface.
- ev.complete('success');
- // Let Stripe.js handle the rest of the payment flow.
- console.log(confirmResult.paymentIntent.status);
- if (confirmResult.paymentIntent.status == "requires_action") {
- stripe.confirmCardPayment(clientSecret).then(function(result) {
- console.log("second confirm result is");
- console.log(result);
- if (result.error) {
- // The payment failed -- ask your customer for a new payment method.
- } else {
- // The payment has succeeded.
- }
- });
- }
- }
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement