【发布时间】:2018-07-02 21:58:42
【问题描述】:
我有一个使用现在不受支持的“data-shipping-address="true"" 参数的条带结帐。当使用带有以下代码的简单条带结帐时,这可以按预期工作:
<script
src="https://checkout.stripe.com/checkout.js"
class="stripe-button"
data-key="<?php echo $stripe['publishable_key']; ?>"
data-amount="1000"
data-currency="gbp"
data-allow-remember-me="true"
data-shipping-address="true"
data-billing-address="true"
data-label="Proceed to payment details"
data-image=""
data-description="TrillShirts">
</script>
但如果我在 .js 文件中调用它,我无法让它发布从运输详细信息中获取的数据。这是我的代码:
var handler = StripeCheckout.configure({
key: 'pk_test_JfqHIgPSCG2oWOsJ54PWS0Nl',
image: 'https://stripe.com/img/documentation/checkout/marketplace.png',
locale: 'auto',
billingAddress: 'true',
shippingAddress: 'true',
token: function(token) {
console.log(token.id);
console.log(token.email);
// here I try to find the shippingAddress using cosole.log
console.log(token.shippingAddressLine1);
console.log(token.stripeShippingAddressLine1);
// When I eventually have the shipping address, I will insert it in the same way as below
$(".stripeToken").val(token.id);
$(".stripeEmail").val(token.email);
$(".stripe").submit();
}
});
document.getElementById('pay').addEventListener('click', function(e) {
// Open Checkout with further options:
handler.open({
name: 'TrillShirts',
description: 'Childcatcher Tee',
currency: 'gbp',
amount: 2000
});
});
});
以下两个都在控制台中返回 undefined,所以我无法弄清楚运输详细信息返回的格式。
console.log(token.shippingAddressLine1);
console.log(token.stripeShippingAddressLine1);
一旦我知道格式并获得了成功的控制台日志,我就可以在提交之前使用 jQuery 将数据插入到表单中。
谁能帮忙?
【问题讨论】:
标签: stripe-payments