【问题标题】:Stripe payment error (You must supply either a card or a customer id) using Laravel使用 Laravel 进行条带支付错误(您必须提供卡或客户 ID)
【发布时间】:2015-02-12 04:33:35
【问题描述】:

我正在尝试使用条纹在我的应用程序中使用 Laravel 制作一个小额付款表格。我什至遵循了 Laracast 的教程。我收到此错误

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 相同。有什么想法吗?

【问题讨论】:

    标签: php laravel laravel-4 stripe-payments


    【解决方案1】:

    编辑2:你在Stripe::setApiKey(Config::get('stripe.secrete_key'))中使用了secrete_key——应该是secret_key吗?

    编辑 1: billing.js 和 laracasts 之间的唯一区别是 Stripe.createToken 末尾的两个右括号之间有一个空格:

    Stripe.createToken(this.form, $.proxy(this.stripeResponseHandler, this) );
    

    假设这不能解决问题,您是否尝试过在处理费用之前创建一个 Stripe 客户?我有一个类似的系统(来自同一个 Laracast),它首先创建了一个客户:

    public function createStripeCustomer($email, $token)
    {
        $key = Config::get('stripe.secret');
    
        Stripe::setApiKey($key);
    
        $customer = Stripe::customers()->create([
            'card' => $token,
            'email' => $email,
            'description' => 'desc'
        ]);
        // error checking
    
        return $customer['id'];
    

    您希望返回客户 ID,然后在 Stripe_Charge 数组中使用它:

    return Stripe_Charge::create(
            [
                'amount' => 1000, // $10
                'currency' => 'usd',
                'customer' => $customer['id'],
                'description' => $data['email'],
                'card'=>$data['token']
            ]);
    

    【讨论】:

      猜你喜欢
      • 2019-09-20
      • 2021-08-26
      • 2021-11-29
      • 2020-09-04
      • 2021-04-18
      • 2020-11-05
      • 2017-04-25
      • 2016-03-28
      • 2011-08-20
      相关资源
      最近更新 更多