gpt4 book ai didi

javascript - Stripe支付无法使用

转载 作者:行者123 更新时间:2023-11-28 19:19:15 26 4
gpt4 key购买 nike

在过去的两周里,我尝试使用 Stripe 制作自定义付款表单,该表单允许用户自己选择价格,然后在付款时从他们的卡中扣款。用于制作“ token ”的表单有效,并且显示在 Stripe 仪表板下的我的日志中,但问题是客户信用卡的收费不起作用。我正在通过将脚本上传到托管面板来测试脚本,我正在使用另一个网站,但这样做时,我收到以下错误“内部服务器错误”,如下图所示。

enter image description here

我无法弄清楚错误是什么,我知道错误最有可能出现在用于卡收费的 .php 脚本中,因为从 html/javascript 表单获取“ token ”没有问题。

我的脚本 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
}

更新

这里有三个错误

  1. 您的 echo 位于您的 Charge::create(); 函数内
  2. 您错过了 echo 上的结束分号
  3. (不是问题的原因),但您将 " 放错了 text/javascript

关于javascript - Stripe支付无法使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29199035/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com