gpt4 book ai didi

javascript - Stripe API 错误 - 缺少必需的参数 : amount - PHP library

转载 作者:行者123 更新时间:2023-11-30 09:31:27 27 4
gpt4 key购买 nike

我已经实现了 Stripe 付款,但问题是我不断收到此错误:

{status: 500, error: "Missing required param: amount."}

从代码中可以看出,我已经有了所有参数,但我仍然不知道为什么会出现这个错误。这是我正在使用的代码:

public function process(){
try {
Stripe::setApiKey('sk_text_key');
$charge = Stripe_Charge::create(array(
"amount" => 2000,
"currency" => "USD",
"card" => $this->input->post('access_token'),
"description" => "Stripe Payment"
));
} catch (Stripe_InvalidRequestError $e) {
// Invalid parameters were supplied to Stripe's API
echo json_encode(array('status' => 500, 'error' => $e->getMessage()));
exit();
}
}

这是我用来提交表单的 JavaScript:

$(function() {
var $form = $('#payment-form');
$form.submit(function(event) {
$form.find('.submit').prop('disabled', true);
$form.find('.submit').val('Please wait...');

Stripe.card.createToken($form, stripeResponseHandler);
return false;
});
});

function stripeResponseHandler(status, response)
{
if (response.error) {
alert(response.error.message);
}
else {
$.ajax({
url: '<?php echo base_url('payment/process');?>',
data: {access_token: response.id},
type: 'POST',
dataType: 'JSON',
success: function(response){
console.log(response);
if(response.success)
window.location.href="<?php echo base_url('booking/thankyou'); ?>";
},
error: function(error){
console.log(error);
}
});
}
}

最佳答案

我发现您正在使用旧代码,在较新版本的 Stripe 中,您可以像这样进行Charge:

// Token is created using Stripe.js or Checkout!
// Get the payment token ID submitted by the form:
$token = $_POST['stripeToken'];

$charge = \Stripe\Charge::create(array(
"amount" => 2000,
"currency" => "usd",
"description" => "Stripe Payment",
"source" => $token,
));

查看更多示例 here .

关于javascript - Stripe API 错误 - 缺少必需的参数 : amount - PHP library,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45976031/

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