gpt4 book ai didi

javascript - Stripe 结帐。查询客户金额

转载 作者:可可西里 更新时间:2023-11-01 12:38:12 25 4
gpt4 key购买 nike

是否可以检查客户端看到的数量和服务器看到的数量是否相同?

这里我在客户端设置金额:

<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>

我正在将 token 从客户端 strip 回调发送到服务器:

<?php
require_once(dirname(__FILE__) . '/config.php');

$token = $_POST['stripeToken'];

$charge = Stripe_Charge::create(array(
'customer' => $customer->id,

'amount' => 1000000000000,
'currency' => 'usd'
'email' => 'customer@example.com',
'card' => $token
));

echo '<h1>Successfully charged $2!</h1>';
?>

client端数明显低于server端数额,stripe按server端数收费。

最佳答案

我们这样做的方法是让服务器检查它。

我们的流程是:

  1. 客户端向后端发出 API 调用以获取它应该为产品收取的价格。
  2. 客户端调用stripe api获取token,并将步骤1的金额显示给客户端
  3. 客户获得 token 后,调用后端 API 以通过 token 和金额(我们称之为对帐金额)进行收费。
  4. 在后端,在调用 stripe create charge api 之前,我们首先通过比较客户在第 3 步中提供的金额与产品应有的金额(来自第 1 步)来核对金额。如果这些不匹配,我们不会继续并向客户端返回错误。

关于javascript - Stripe 结帐。查询客户金额,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27040942/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com