2017-08-14 179 views
1

我有一段代码在工作,我想知道是否有可能在结账过程的“成功代币”内进行分条付费?下面的所有代码都在工作,我只是想知道在哪里插入创建acctuall费用的代码。 使用JavaScript创建条纹费用

<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 With Card</button> 

    <script> 
    var handler = StripeCheckout.configure({ 
     key: 'mykeyhere', 
     image: 'https://stripe.com/img/documentation/checkout/marketplace.png', 
     locale: 'auto', 
     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("book-appointment-submit").style.display="block"; 
     document.getElementById("payment-button").style.display="none"; 
     } 
    }); 

    document.getElementById('payment-button').addEventListener('click', function(e) { 
     // Open Checkout with 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> 

回答

2

你不能在JS内部收费。使用Stripe为客户收费是一个两步骤的过程。

第1步:您通过Checkout收集客户的信用卡信息,然后发送给Stripe。你找回一个令牌。这就是你在上面的代码中所做的。

步骤2:您必须将此令牌传递给您的后端,然后通知Stripe对其进行收费,或将其保存至客户以便稍后进行收费。您需要在您的服务器上使用脚本(PHP,Ruby等)来处理此步骤。

第二步的一些短的例子在这里:https://stripe.com/docs/charges

内以最低的token: function(token) { }回调你要抢token.id,其追加到和.submit()一个<form></form>周围您的Checkout按钮。

如果您想要一些更复杂的东西,您可以通过AJAX请求将令牌ID传递给您的后端,然后将收费请求的成功或失败转交给用户。

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