2015-10-20 50 views
1

我有一個簡單的自定義按鈕條紋結帳安裝在收費付款好的時刻,但我似乎無法讓客戶的電子郵件地址傳回給條紋。爲什麼客戶的電子郵件地址不發送給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> 

任何想法,我要去哪裏錯了?

+0

不清楚這一步是問題,或者你如何讓電子郵件發送給條紋創建令牌 – charlietfl

回答

0

你覆蓋,當你調用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(); 
}); 
+0

感謝@Ywain,我已經採取了這些覆蓋了,但現在出現以下錯誤...致命錯誤:未收集的異常'條紋\錯誤\卡'帶消息'無法向沒有活動卡的客戶收費' –

相關問題