stripe-payments - Stripe 获取客户电子邮件地址

标签 stripe-payments

我正在尝试使用 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/

相关文章:

swift - Stripe 连接 IOS 集成

javascript - Cordova 应用程序中的 Stripe 重定向浏览器而不是加载结帐

javascript - 您不能接受使用此 API 的付款,因为印度不再支持它 Next js、Strapi、Stripe

javascript - Stripe webhooks 返回 400 响应

java - 如何使用 Java(Android) 在 Stripe 中为卡充值

php - Stripe Webhook 错误 500

javascript - 尝试连接到 Stripe 时我的脚本不会执行

php - 如何获取该月某一天的下一次出现情况

javascript - 编辑 Stripe 嵌入表单

javascript - 如何创建 Stripe 客户?