Reputation: 179
I have implemented a Stripe payment, but the problem is that I am continuously getting this error:
{status: 500, error: "Missing required param: amount."}
As can be seen in the code, I have all the parameters, but still I do not know why this error is coming up. Here is the code I am using:
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();
}
}
This is the javascript I am using to submit the form:
$(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);
}
});
}
}
Upvotes: 2
Views: 9330
Reputation: 6209
I see you are using a legacy code, in the newer versions of Stripe you can make the Charge
like this:
// 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,
));
See more examples here.
Upvotes: 5