3
我正在嘗試使用條紋在我的應用程序中使用Laravel製作小型付款表單。我甚至跟着Laracast的教程。我得到這個錯誤使用Laravel條形支付錯誤(您必須提供卡或客戶ID)
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');
}
}
}
可能是什麼問題?我甚至從github採取了相同的代碼,但同樣的錯誤。一切都和Laracast相同。任何想法?