I'm trying to use the stripe to make a small payment form in my application using Laravel. I followed even the tutorials from Laracast. I'm getting this error
Stripe_InvalidRequestError
You must supply either a card or a customer id
.
//billing.js
(function(){
var StripeBilling = {
init: function(){
this.form=$('#billing-form');
this.submitButton = this.form.find('input[type=submit]');
this.submitButtonValue = this.submitButton.val();
var stripeKey=$('meta[name="publishable-key"]').attr('content');
Stripe.setPublishableKey(stripeKey);
this.bindEvents();
},
bindEvents: function(){
this.form.on('submit', $.proxy(this.sendToken, this));
},
sendToken: function(event){
this.submitButton.val('One Moment').prop('disabled', true);
Stripe.createToken(this.form, $.proxy(this.stripeResponseHandler, this) );
event.preventDefault();
},
stripeResponseHandler: function(status, response){
if(response.error){
this.form.find('.payment-errors').show().text(response.error.message);
return this.submitButton.prop('disabled', false).val(this.submitButtonValue);
}
$('<div>', {
type: 'hidden',
name: 'stripe-token',
value: response.id
}).appendTo(this.form);
this.form[0].submit();
}
};
StripeBilling.init();
})();
.
//StripeBilling.php
<?php
namespace Acme\Billing;
use Stripe;
use Stripe_Charge;
use Config;
class StripeBilling implements BillingInterface {
public function __construct()
{
Stripe::setApiKey(Config::get('stripe.secrete_key'));
}
public function charge(array $data)
{
try
{
return Stripe_Charge::create([
'amount' => 1000, // $10
'currency' => 'usd',
'description' => $data['email'],
'card'=>$data['token']
]);
}
catch(Stripe_CardError $e)
{
dd('Card was declined');
}
}
}
What might be the problem? I even took the same code from the github but same error. Everything is same as that of the Laracast. Any idea?