我一直在尝试实现Stripe,而不必担心运输成本非常简单,我的这段代码运行良好:
<form action="payment.php" method="POST">
<script src="https://checkout.stripe.com/checkout.js" class="stripe-button"
data-key="xxxxxxxxxxxxxxxxxxxxxxxxxxx"
data-amount="2500"
data-name="some name"
data-description="some description"
data-label="{{ order.button_name|e }}"
data-locale="auto"
data-zip-code="true"
data-billing-address="true"
data-shipping-address="true"
data-currency="aud">
</script>
</form>
现在,据我所知,我必须计算/或从Stripe 之前检索运输成本,然后填充此代码(或动态更新),以便可以考虑运输。
我一直在阅读有关Orders API的信息,看来您需要创建一个订单商品以:从Stripe取回税金和运输费用
因此,考虑到这一点,听起来好像需要在用户单击按钮进行付款之前完成,这样您才具有正确的运输费用以增加向其收取的费用-但我很困惑,不应将“订单”只能在他们实际上订购一个项目后的之后创建;但这似乎只是文档阅读方式的术语问题。
第二,为了能够计算运输成本,我需要从用户那里获取用户的运输地址,然后再让他们启动付款方式,所以这意味着我不会在付款方式中要求它-但是,在这种情况下,如果Stripe未在付款方式中输入地址信息,怎么知道呢?
听起来我会以某种方式将从订单API 返回的订单ID 通过结帐传递给Stripe?
因此,基本上,我对将Order API与Checkout结合使用时如何改变事物感到困惑。
返回 Order对象后的处理过程是什么,它与我上面正在使用的当前代码有何不同?服务器端代码与标准Checkout有何不同?似乎标准检查是“产生费用”,例如:
// Set your secret key: remember to change this to your live secret key in production
// See your keys here: https://dashboard.stripe.com/account/apikeys
\Stripe\Stripe::setApiKey("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
// Token is created using Checkout or Elements!
// Get the payment token ID submitted by the form:
$token = $_POST['stripeToken'];
$charge = \Stripe\Charge::create([
'amount' => 999,
'currency' => 'usd',
'description' => 'Example charge',
'source' => $token,
]);
...并且使用Order API,我们正在做一些不同的事情:
// Set your secret key: remember to change this to your live secret key in production
// See your keys here: https://dashboard.stripe.com/account/apikeys
\Stripe\Stripe::setApiKey("xxxxxxxxxxxxxxxxxxxxxxxxxxxx");
// Token is created using Checkout or Elements!
// Get the payment token ID submitted by the form:
$token = $_POST['stripeToken'];
$order = \Stripe\Order::retrieve('or_1D2jGkKFk4dvoSd9xVrShgsg');
$order->pay(['source' => $token]);
答案 0 :(得分:1)
不幸的是,Checkout和Orders之间没有完全集成。您将要做的是在显示站点的“结帐”页面时创建一个订单。您需要将用户要购买的商品以及用户的收货地址添加到订单中,以获取准确的运费和要显示的税收信息。无法从Stripe Checkout中获取运输信息 ,并将其传递回Order对象,因此您需要提前收集信息。然后,当您的用户选择一种送货方式时,您将使用该方式来设置Stripe Checkout以正确显示总数。
分别实现运输和税收逻辑并简单地为总金额创建费用可能更简单,这就是WooCommerce之类的软件与Stripe集成时的用途(而不是使用订单)。