条纹支付不起作用
Stripe payment won't work
在过去的两周里,我尝试使用 Stripe 制作自定义支付表格,它允许用户自己选择价格,然后在付款时从他们的卡中扣款。使 "token" 有效的表格显示在我的 Stripe 仪表板下的日志中,但问题是客户信用卡的收费不起作用。我正在通过将脚本上传到托管面板来测试脚本,我正在用于另一个网站,但是这样做时,我收到以下错误 "Internal Server Error",如下图所示。
我不知道错误是什么,我知道错误最有可能是在.php 为卡充电的脚本中,因为获取 "token" 没有问题来自 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();
函数中
- 您在
echo
上漏掉了结束分号
- (不是您问题的原因)但您将
"
放错了 text/javascript
您在金额字段中传递了令牌!以下是您的代码
$charge = \Stripe\Charge::create(array(
"amount" => $token, // amount in cents, again
"currency" => "usd",
"source" => $token,
"description" => "payinguser@example.com"));
在过去的两周里,我尝试使用 Stripe 制作自定义支付表格,它允许用户自己选择价格,然后在付款时从他们的卡中扣款。使 "token" 有效的表格显示在我的 Stripe 仪表板下的日志中,但问题是客户信用卡的收费不起作用。我正在通过将脚本上传到托管面板来测试脚本,我正在用于另一个网站,但是这样做时,我收到以下错误 "Internal Server Error",如下图所示。
我不知道错误是什么,我知道错误最有可能是在.php 为卡充电的脚本中,因为获取 "token" 没有问题来自 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();
函数中 - 您在
echo
上漏掉了结束分号
- (不是您问题的原因)但您将
"
放错了text/javascript
您在金额字段中传递了令牌!以下是您的代码
$charge = \Stripe\Charge::create(array(
"amount" => $token, // amount in cents, again
"currency" => "usd",
"source" => $token,
"description" => "payinguser@example.com"));