php - Creating a Stripe Charge with JavaScript -


i have working piece of code below, wondering if possible make stripe charge within "successful token" of checkout process? code below working, wondering insert code creates acctuall charge.

    <script src="https://checkout.stripe.com/checkout.js"></script>     <script src="https://js.stripe.com/v3/"</script>      <button id="payment-button" type="button" class="btn btn-success">pay card</button>      <script>     var handler = stripecheckout.configure({       key: 'mykeyhere',       image: 'https://stripe.com/img/documentation/checkout/marketplace.png',       locale: 'auto',       token: function(token) {         // can access token id `token.id`.         // token id server-side code use.         document.getelementbyid("book-appointment-submit").style.display="block";         document.getelementbyid("payment-button").style.display="none";       }     });      document.getelementbyid('payment-button').addeventlistener('click', function(e) {       // open checkout further options:       handler.open({         name: 'denchcodeltd',         description: '2 widgets',         zipcode: true,         currency: 'gbp',         amount: 2000       });       e.preventdefault();     });      // close checkout on page navigation:     window.addeventlistener('popstate', function() {       handler.close();     });     </script>  <!-- end of stripe payment -->  <button id="book-appointment-submit" type="button" class="btn btn-success" style="display:none">     <span class="glyphicon glyphicon-ok"></span>     <?php         echo (!$manage_mode) ? $this->lang->line('confirm')                 : $this->lang->line('update');     ?> </button> 

you can't make charge within js itself. charging customer stripe two-step process.

step 1: collect customer's credit card information checkout, sent stripe. token. that's you're doing in code above.

step 2: have take token , pass backend, tell stripe make charge it, or save customer charged later. need script on server (php, ruby, etc) handle step.

some short examples of second step here: https://stripe.com/docs/charges

inside token: function(token) { } callback @ minimum you'll want grab token.id, append , .submit() <form></form> surrounding checkout button.

if want little more complex, pass token id backend via ajax request , relay success or failure of charge request user.

https://stripe.com/docs/checkout#integration-custom


Comments

Popular posts from this blog

python Tkinter Capturing keyboard events save as one single string -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

javascript - Z-index in d3.js -