【问题标题】:Stripe get customer email addressStripe 获取客户电子邮件地址
【发布时间】:2014-12-01 04:44:02
【问题描述】:

我正在尝试使用 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
 )
);
?>

【问题讨论】:

    标签: stripe-payments


    【解决方案1】:

    添加到大卫的答案,您可以通过 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'
     ));
    

    我只需要做一些小改动就可以让我的代码正常工作。

    【讨论】:

      【解决方案2】:

      如果您使用 Checkout,您将获得一个令牌,使用该令牌您可以通过 API 调用获取电子邮件地址:https://stripe.com/docs/api#retrieve_token

      不知道为什么电子邮件没有在下面列出,但我确实有一个可用的电子邮件属性。您还可以在 Stripe 的日志下查看电子邮件。

      【讨论】:

      • 感谢您的回答。它帮助了我!
      猜你喜欢
      • 2021-12-28
      • 1970-01-01
      • 2016-06-11
      • 1970-01-01
      • 2020-10-31
      • 2021-04-09
      • 2014-12-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多