是否可以检查客户端看到的金额以及服务器看到的金额是否相同?
在这里,我在客户端设置金额:
<script src="https://checkout.stripe.com/checkout.js"></script>
<button id="customButton">Purchase</button>
<script>
var handler = StripeCheckout.configure({
key: 'pk_test_1002UFB11gJ1sXBHcdDM8HPi',
image: '/square-image.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`
}
});
document.getElementById('customButton').addEventListener('click', function(e) {
// Open Checkout with further options
handler.open({
name: 'Demo Site',
description: '2 widgets ($20.00)',
amount: 2000
});
e.preventDefault();
});
// Close Checkout on page navigation
window.addEventListener('popstate', function() {
handler.close();
});
</script>
我将令牌从客户端条带回调发送到服务器:
<?php
require_once(dirname(__FILE__) . '/config.php');
$token = $_POST['stripeToken'];
$charge = Stripe_Charge::create(array(
'customer' => $customer->id,
'amount' => 1000000000000,
'currency' => 'usd'
'email' => '[email protected]',
'card' => $token
));
echo '<h1>Successfully charged $2!</h1>';
?>
客户端编号明显低于服务器端的数量,条带收取服务器端编号。
我们这样做的方法是让服务器检查它。
我们的流程是: