2017-07-25 118 views
0

我正在尝试Stripe API &函数,但我正在扭转这个问题 - 如何在(测试)付款成功后提交表单?条纹定制结帐 - 表单提交

这里是我当前的代码:

<script> 
    var handler = StripeCheckout.configure({ 
     key: 'pk_test_mykey', 
     image: 'https://stripe.com/img/documentation/checkout/marketplace.png', 
     locale: 'sv', 
     token: function(token) { 
      // You can access the token ID with `token.id`. 
      // Get the token ID to your server-side code for use. 
     } 
    }); 


    document.getElementById('customButton').addEventListener('click', function(e) { 
     stripe_spots = document.getElementById("spots").value; 
     stripe_total = (stripe_spots) * 70; 
     // Open Checkout with further options: 
     handler.open({ 
      name: 'Revy!', 
      description: stripe_spots + " platser", 
      zipCode: true, 
      currency: 'sek', 
      amount: stripe_total * 100 
     }); 

     e.preventDefault(); 
    }); 

    // Close Checkout on page navigation: 
    window.addEventListener('popstate', function() { 
     handler.close(); 
    }); 
</script> 

在哪时我应该提交表单?

谢谢!

回答

0

您使用令牌回调函数更新你的手柄,像这样提交表单

var handler = StripeCheckout.configure({ 
key: 'pk_test_mykey', 
image: 'https://stripe.com/img/documentation/checkout/marketplace.png', 
locale: 'sv', 
token: function (token) { 
    $.ajax({ 
     type: 'POST', 
     url: '/checkout.php', 
     data: {stripeToken: token.id, stripeEmail: token.email}, 
     success: function (data) { 
      //handle success response here 
     }, 
     error: function(data){ 
      //handle error response here 
     } 
    }); 
    } 
});