我正在尝试使用 Stripe checkout.js 订阅,然后使用 PHP 订阅客户。我的问题是获取他们的电子邮件地址。在文档中找不到任何有用的东西。
文档在这里:https://stripe.com/docs/guides/subscriptions#step-2-subscribe-customers
我拥有的:
<script src="https://checkout.stripe.com/checkout.js"></script>
<button id="customButton">Purchase</button>
<script>
var handler = StripeCheckout.configure({
key: 'pk_test_keyhere',
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: 'test2',
description: 'Test Des',
amount: 0001,
currency:'GBP'
});
e.preventDefault();
});
</script>
<?php
// Set your API key
Stripe::setApiKey("sk_test_keyhere");
$token = $_POST['stripeToken'];
$customer = Stripe_Customer::create(array(
"card" => $token,
"plan" => "test2",
"email" => $email
)
);
?>
最佳答案
添加到大卫的回答中,您可以通过 PHP 检索电子邮件地址,如下所示:
$stripeinfo =Stripe_Token::retrieve($_POST["token"]);
echo '<pre>',print_r($stripeinfo),'</pre>'; //show stripeObject info
$email = $stripeinfo->email;
为现在遇到此问题的人添加对此答案的小更新。
$token = $_POST['stripeToken'];
$stripeinfo = \Stripe\Token::retrieve($token);
$email = $stripeinfo->email;
$customer = \Stripe\Customer::create(array(
'email' => $email,
'source' => $token,
'description' => 'New Customer'
));
只是我必须进行一些小的更改才能使我的代码正常工作。
关于stripe-payments - Stripe 获取客户电子邮件地址,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26224438/