Advertisement
hmunoz-stripe

prbutton confirm

Oct 27th, 2021 (edited)
1,476
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. paymentRequest.on('paymentmethod', function(ev) {
  2.     console.log("Paymentrequest paymentMethod: ")
  3.     console.log(ev);
  4.     console.log(ev.paymentMethod);
  5.    
  6.     // I get clientSecret from an input field in my sample
  7.     var clientSecret = clientSecretInput.value;
  8.     paymentRequestConfirm(ev, clientSecret);
  9.   });
  10.  
  11.  
  12. function paymentRequestConfirm(ev, clientSecret) {
  13.     // Confirm the PaymentIntent without handling potential next actions (yet).
  14.     stripe.confirmCardPayment(
  15.       clientSecret,
  16.       {payment_method: ev.paymentMethod.id},
  17.       {handleActions: false}
  18.     ).then(function(confirmResult) {
  19.       console.log("first confirm result is");
  20.       console.log(confirmResult);
  21.       if (confirmResult.error) {
  22.         // Report to the browser that the payment failed, prompting it to
  23.         // re-show the payment interface, or show an error message and close
  24.         // the payment interface.
  25.         ev.complete('fail');
  26.       } else {
  27.         // Report to the browser that the confirmation was successful, prompting
  28.         // it to close the browser payment method collection interface.
  29.         ev.complete('success');
  30.         // Let Stripe.js handle the rest of the payment flow.
  31.         console.log(confirmResult.paymentIntent.status);
  32.         if (confirmResult.paymentIntent.status == "requires_action") {
  33.           stripe.confirmCardPayment(clientSecret).then(function(result) {
  34.             console.log("second confirm result is");
  35.             console.log(result);
  36.             if (result.error) {
  37.               // The payment failed -- ask your customer for a new payment method.
  38.             } else {
  39.               // The payment has succeeded.
  40.             }
  41.           });
  42.         }
  43.       }
  44.     });
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement