【问题标题】:Why is the customers email address not sending to Stripe?为什么客户的电子邮件地址没有发送到 Stripe?
【发布时间】:2015-10-20 21:45:42
【问题描述】:

我现在有一个简单的自定义按钮 Stripe Checkout 设置,它可以收取付款,但我似乎无法让客户的电子邮件地址传回给 Stripe。

这是我当前的代码:

JS

var handler = StripeCheckout.configure({
    key: 'myPublicKey',
    image: '/images/RoadPreview.jpg',
    locale: 'auto',
    token: function(token, args){
        $form.append(jQuery('<input type="hidden" name="stripeToken" />').val(token.id));
        $form.append(jQuery('<input type="hidden" name="stripeEmail" />').val(token.email));
        $form.get(0).submit();
    }
});

jQuery('#roadFlow').on('click', function(e) {  
    var token = function(res){
        var $input = jQuery('<input type=hidden name=stripeToken />').val(res.id);
        jQuery('form').append($input).submit();
    };

    // Open Checkout with further options
    handler.open({
        name: 'Road Bike - Flow',
        description: 'Make a £500 deposit to Order Now',
        billingAddress: true,
        shippingAddress: true,
        currency: "gbp",
        amount: 50000,
        token: token
    });
    e.preventDefault();
});

jQuery(window).on('popstate', function() {
    handler.close();
});

PHP

<?php
    require_once('stripeConfig.php');

    \Stripe\Stripe::setApiKey("mySecretKey");
    $token  = $_POST['stripeToken'];
    $email = $_POST['stripeEmail'];

    $customer = \Stripe\Customer::create(array(
        'id' => $name,
        'email' => $email,
        'card'  => $token
    ));

    $charge = \Stripe\Charge::create(array(
        'customer' => $customer->id,
        'amount'   => 50000,
        'description' => "Dassi Road - Flow",
        "receipt_email" => $email,
        'currency' => 'gbp'
    ));
    echo '<h1>Successfully Paid!</h1>';
?>

按钮

<form action="charge.php" method="post"><button type="submit" id="roadFlow">Order Now</button>

关于我哪里出错了有什么想法吗?

【问题讨论】:

  • 不清楚哪一步有问题,或者你如何让电子邮件发送到条带以创建令牌

标签: php jquery stripe-payments


【解决方案1】:

当您调用handler.open() 时,您将覆盖在StripeCheckout.configure() 调用中定义的token 回调,并且覆盖函数不会添加stripeEmail 字段。

这应该可行:

var handler = StripeCheckout.configure({
    key: 'myPublicKey',
    image: '/images/RoadPreview.jpg',
    locale: 'auto',
    token: function(token, args){
        $form.append(jQuery('<input type="hidden" name="stripeToken" />').val(token.id));
        $form.append(jQuery('<input type="hidden" name="stripeEmail" />').val(token.email));
        $form.get(0).submit();
    }
});

jQuery('#roadFlow').on('click', function(e) {  
    // Open Checkout with further options
    handler.open({
        name: 'Road Bike - Flow',
        description: 'Make a £500 deposit to Order Now',
        billingAddress: true,
        shippingAddress: true,
        currency: "gbp",
        amount: 50000
    });
    e.preventDefault();
});

jQuery(window).on('popstate', function() {
    handler.close();
});

【讨论】:

  • 谢谢@Ywain,我已经取消了这些覆盖,但现在出现以下错误...活动卡'
猜你喜欢
  • 2014-12-01
  • 2022-07-30
  • 2021-08-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-06-11
  • 2021-12-28
相关资源
最近更新 更多