[英]Stripe payment won't work
在過去的兩周中,我嘗試使用Stripe制作自定義付款表格,該表格允許用戶自行選擇價格,然后用余款在付款時向其信用卡收取費用。 用於制作“令牌”的表單有效,並顯示在我的日志中的Stripe儀表板下,但是問題是客戶信用卡的費用無法使用。 我正在通過將腳本上傳到主機面板來測試腳本,我正在使用另一個網站,但是這樣做時,出現以下錯誤“內部服務器錯誤”,如下圖所示。
我無法弄清楚錯誤是什么,我知道錯誤很可能是在.php腳本中為卡充電的,因為從html / javascript表單獲取“令牌”沒有問題。
我的腳本html和javascript:
<!DOCTYPE html>
<html>
<head>
<!-- STRIPE PAYMENT JAVASCRIPT FUNCTIONS START -->
<script src="https://checkout.stripe.com/checkout.js"></script>
<script src="https://code.jquery.com/jquery-1.11.2.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
var handler = StripeCheckout.configure({
key: 'REMOVED FOR SAFETY BUT IS THERE IN THE REAL SCRIPT',
image: '/square-image.png',
token: function(token) {
// get the payment form
var $form = $('#payment-form');
// Use the token to create the charge with a server-side script.
// You can access the token ID with `token.id`
// Insert the token into the form so it gets submitted to the server
$form.append($('<input type="hidden" name="stripeToken" />').val(token.id));
// and re-submit
$form.get(0).submit();
}
});
$('#customButton').on('click', function(e) {
// get the amount from #amount, round to avoid funny issues
var amount = Math.round($("#amount").val()*100);
// Open Checkout with further options
handler.open({
name: 'Payment',
description: 'Payment',
amount: amount
});
e.preventDefault();
});
// Close Checkout on page navigation
$(window).on('popstate', function() {
handler.close();
});
});
</script>
<!-- STRIPE PAYMENT JAVASCRIPT FUNCTIONS ENDING -->
</head>
<body>
<!-- FORM FOR STRIPE PAYMENT START-->
<form id="payment-form" action="chargeCard.php" method="POST">
<input onkeypress="return isNumberKey(event)" type="text" name="amount" id="amount" />
<input type="image" src="BidButton1.png" id="customButton" value="pay" alt="button"/>
</form>
<script type="text/javascript">
function isNumberKey(evt)
{
var charCode = (evt.which) ? evt.which : event.keyCode
if (charCode > 31 && (charCode < 48 || charCode > 57))
return false;
return true;
}
</script>
<!--FORM FOR STRIPE PAYMENT ENDING-->
</body>
</html>
我的腳本php叫做chargeCard:
<?php
require_once('./init.php');
// Set your secret key: remember to change this to your live secret key in production
// See your keys here https://dashboard.stripe.com/account
\Stripe\Stripe::setApiKey("REMOVED FOR SAFETY");
// Get the credit card details submitted by the form
$token = $_POST['stripeToken'];
// Create the charge on Stripe's servers - this will charge the user's card
try {
$charge = \Stripe\Charge::create(array(
"amount" => $token, // amount in cents, again
"currency" => "usd",
"source" => $token,
"description" => "payinguser@example.com"));
echo '<script type="text/javascript">addOne();</script>"';
} catch(\Stripe\Error\Card $e) {
// The card has been declined
}
?>
看起來您的Create
函數和數組很混亂。
try {
$charge = \Stripe\Charge::create(array(
"amount" => $amount, // amount in cents, again
"currency" => "usd",
"source" => $token,
"description" => "payinguser@example.com"));
echo '<script type="text/javascript">addOne();</script>';
} catch(\Stripe\Error\Card $e) {
// The card has been declined
}
更新
這里有三個錯誤
echo
在您的Charge::create();
內部Charge::create();
功能 echo
結束分號 "
放到了text/javascript
您正在數量字段中傳遞令牌! 下面是你的代碼
$charge = \Stripe\Charge::create(array(
"amount" => $token, // amount in cents, again
"currency" => "usd",
"source" => $token,
"description" => "payinguser@example.com"));
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.