Stripe payments 获取客户电子邮件地址
我正在尝试使用stripecheckout.js创建订阅,然后使用PHP订阅客户。我的问题是获取他们的电子邮件地址。在文档中找不到任何有用的内容 此处的文档: 我所拥有的:Stripe payments 获取客户电子邮件地址,stripe-payments,Stripe Payments,我正在尝试使用stripecheckout.js创建订阅,然后使用PHP订阅客户。我的问题是获取他们的电子邮件地址。在文档中找不到任何有用的内容 此处的文档: 我所拥有的: <script src="https://checkout.stripe.com/checkout.js"></script> <button id="customButton">Purchase</button> <script> var handler =
<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
)
);
?>
购买
var handler=StripeCheckout.configure({
键:“pk_test_keyhere”,
图像:'/square image.png',
令牌:函数(令牌){
//使用令牌通过服务器端脚本创建费用。
//您可以使用`token.ID'访问令牌ID`
}
});
document.getElementById('customButton')。addEventListener('click',函数(e){
//打开带有更多选项的签出
handler.open({
名称:“test2”,
描述:“测试Des”,
金额:0001,
货币:英镑
});
e、 预防默认值();
});
如果您使用Checkout,将向您传递一个令牌,使用该令牌,您可以通过API调用获得电子邮件地址:
不确定为什么电子邮件没有列在下面,但我确实有一个电子邮件属性可供我使用。您还可以在条带日志下查看电子邮件。除了David的答案之外,您还可以通过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'
));