douceng7070 2015-04-21 22:18
浏览 159

如何从Stripe Checkout返回电子邮件?

Using Stripe, I want to store a customer email address from the email they supplied in Checkout. Unfortunately, posting stripeEmail in my charge.php file returns null.

How can I return the email from checkout so I can use it to send a receipt?

Here's my form code:

<script src="https://checkout.stripe.com/v2/checkout.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.js"></script>
<form action="charge.php" method="post">
  <input type="hidden" id="amount" name="chargeAmount"/>
  <button data-charge-amount="300000" data-charge-name="Name" data-charge-description="Description">Select Pledge Level</button>
  <button data-charge-amount="123123" data-charge-name="Name2" data-charge-description="Description2">Donate</button>
</form>
<script>
  $('button').click(function(){
    var token = function(res){
      var $theToken = $('<input type=hidden name=stripeToken />').val(res.id);
      $('form').append($theToken).submit();
    };
    var amount = $(this).data("chargeAmount");
    var name = $(this).data("chargeName");
    var description = $(this).data("chargeDescription");
    $('input#amount').val(amount);
    StripeCheckout.open({
      key:         'pk_test_xxxxxxxxxxxxxxxxxxxxxxxx',
      address:     true,
      amount:      amount,
      currency:    'usd',
      name:        name,
      description: description,
      panelLabel:  'Pledge',
      token:       token,
    });
    return false;
  });
</script>

Here is my charge.php code:

<?php
require_once('./config.php');
$token  = $_POST['stripeToken'];
$amount = $_POST['chargeAmount'];
$customer = \Stripe\Customer::create(array(
    'email' => $email,
    'card'  => $token,
));
$charge = \Stripe\Charge::create(array(
  'customer' => $customer->id,
  'amount'   => $amount,
  'currency' => 'usd',
));
?> 

Here is my config.php code:

<?php
require_once('./stripe-php-2.1.2/init.php');

$stripe = array(
  "secret_key"      => "sk_test_xxxxxxxxxxxxxxxxxxxxxxxx",
  "publishable_key" => "pk_test_xxxxxxxxxxxxxxxxxxxxxxxx"
);

\Stripe\Stripe::setApiKey($stripe['secret_key']);
?>

Any help would be much appreciated.

THANKS!

  • 写回答

3条回答 默认 最新

  • dongre8505 2015-04-21 22:23
    关注

    The issue here is that you're using Custom Checkout which means that Checkout won't post the data to your server automatically but instead give it in the token callback. In your case you're only retrieving the token id here which is why you are not seeing the email.

    Update your code so that the token callback also retrieves the email and send it in the stripeEmail parameter:

    var token = function(res){
      var $theToken = $('<input type="hidden" name="stripeToken" />').val(res.id);
      var $theEmail = $('<input type="hidden" name="stripeEmail" />').val(res.email);
      $('form').append($theToken).append($theEmail).submit();
    };
    
    评论

报告相同问题?

悬赏问题

  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?
  • ¥15 乘性高斯噪声在深度学习网络中的应用
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集