为什么客户的电子邮件地址没有发送到Stripe?

时间:2015-10-20 10:56:07

标签: php jquery stripe-payments

我现在有一个简单的自定义按钮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>

关于我哪里出错的任何想法?

1 个答案:

答案 0 :(得分:0)

您在调用token时覆盖了在StripeCheckout.configure()来电中定义的handler.open()回调,并且覆盖功能未添加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();
});