简体   繁体   中英

Stripe payment using Google Apps Script

Trying to use this example code to create Stripe checkout and charges inside Google Apps Script.

HTML.html

 <!DOCTYPE html> <!-- modification of https://stripe.com/docs/checkout#integration-custom --> <button id="customButton">Purchase</button> <script src="https://checkout.stripe.com/checkout.js"></script> <script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script> <script> var handler = StripeCheckout.configure( { key: 'pk_test_UUbDY16wDCECOujIs0vQ2vTi', image: 'https://i.imgur.com/M0ku9HH.png', token: function(token) { // Use the token to create the charge with a server-side script. // You can access the token ID with `token.id` google.script.run.withSuccessHandler(chargeSuccess) google.script.run.withFailureHandler(chargeFailure) google.script.run.processCharge(token); } } ); $('#customButton').on('click', function(e) { // Open Checkout with further options handler.open( { name: 'ASD Anastasiya Ballet S.', description: 'Pagamento online' }); e.preventDefault(); }); function chargeSuccess(result) { // handle response code client side } function chargeFailure(error) { // client error handling } </script>

GS.gs
google.script.run.processCharge(token);

The form work fine but no charge is created since seems no token was created. Being not at all a JS expert I'm not sure if the function

token: function(token)

that calls

google.script.run.processCharge(token);

is executed correctly.

Your code is failing as you've commented out the custId - this has to be provided. There's no harm in leaving this in, it'll simply create a test customer. Otherwise create a customer in the Stripe control panel and copy the ID into custId.

You can always look in "View > Execution transcript" to get clues as to why the script is failing.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM