1
我試圖在以下問題stripe checkout custom button not charging中提供的條紋中使用自定義付款的方法。用戶輸入提交按鈕上顯示的金額值。條紋定製付款不充電
的index.php
<form action="charge.php" method="post">
<input class="form-control" type="number" id="donation-amount" placeholder="20.00" min="0" step="5.00"/>
<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>
<button id="customButton">Donate</button>
<script>
$('#customButton').click(function(){
var token = function(res){
var $input = $('<input type=hidden name=stripeToken />').val(res.id);
$('form').append($input).submit();
};
var amount = $("#donation-amount").val() * 100;
StripeCheckout.open({
key: 'pk_test_*************************',
address: false,
amount: amount,
currency: 'usd',
name: 'Test Customer',
description: 'Demo Description',
panelLabel: 'Checkout',
token: token
});
return false;
});
</script>
<input type="hidden" name="chargeamount" val=<?php amount ?>/>
</form>
提交按鈕顯示正確的量,但點擊提交按鈕白色屏幕不具有電荷發生時。
Charge.php
<?php
require_once(dirname(__FILE__) . '/config.php');
$token = $_POST['stripeToken'];
$amount = $_POST['chargeamount'];
$customer = Stripe_Customer::create(array(
'email' => '[email protected]',
'card' => $token
));
$charge = Stripe_Charge::create(array(
'customer' => $customer->id,
'amount' => $amount,
'currency' => 'usd'
));
echo '<h1>Successfully charged '. $amount. '!</h1>';
?>
的config.php
<?php
require_once('vendor/stripe/lib/Stripe.php');
$stripe = array(
"secret_key" => "sk_test_************************",
"publishable_key" => "pk_test_************************"
);
Stripe::setApiKey($stripe['secret_key']);
?>
$charge = Stripe_Charge::create(array(
'customer' => $customer->id,
'amount' => $amount
'currency' => 'usd'
));
echo '<h1>Successfully charged '. $amount .'!</h1>';
?>
我在想我的窗體底部我實施input
的有點沙基,考慮到如果我插入固定號碼到我的$amount
變量在charge.php中,它確實收取該付款。
任何援助將不勝感激。
我已對指定點進行了指定的更改。腳本必須包含在[docs](https://stripe.com/docs/checkout/v2)所述的表單元素中。 – 2014-11-07 02:49:33
@QuintonJasonJr對不起,我不熟悉Strip API。但是,我的指針仍然有效,只需在相關行中進行修改即可。 – Himal 2014-11-07 03:23:04