Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Laravel出纳:更新卡时出现问题(致命错误)_Php_Laravel_Stripe Payments_Laravel 5 - Fatal编程技术网

Php Laravel出纳:更新卡时出现问题(致命错误)

Php Laravel出纳:更新卡时出现问题(致命错误),php,laravel,stripe-payments,laravel-5,Php,Laravel,Stripe Payments,Laravel 5,我已经在我的项目中安装了Laravel出纳(v3.0.4),并且正在允许用户更新他们的信用卡,但是当我尝试这样做时遇到了问题。以下是我的控制器处理它的相关部分: public function __construct() { $this->user = Auth::user(); } /** * Update credit card * @return \Illuminate\Http\RedirectResponse */ public function updateCa

我已经在我的项目中安装了Laravel出纳(v3.0.4),并且正在允许用户更新他们的信用卡,但是当我尝试这样做时遇到了问题。以下是我的控制器处理它的相关部分:

public function __construct() {
    $this->user = Auth::user();
}

/**
 * Update credit card
 * @return \Illuminate\Http\RedirectResponse
 */
public function updateCardPost() {
    $this->user->updateCard(Input::get('stripe-token'));

    session()->flash('flash_message', 'You have updated your credit card');
    return redirect()->route('dashboard.index');
}
我已验证了健全性检查项目:

  • 实际发布到该控制器
  • 成功传递令牌
  • 但每次我尝试提交时,出纳本身都会出错:

    FatalErrorException in StripeGateway.php line 454:
    Call to a member function create() on null
    
    我已经研究过了,它似乎正在将
    $token
    传递给以下对象:
    $card=$customer->cards->create(['card'=>$token])

    因此,我随后在该方法中通过
    dd($token)
    进行了另一次健全性检查,该检查准确地返回了表单提供的内容。看起来这个区块最近没有太大变化——但有一些PSR-2和一次性购买更新;这两者似乎都与这里发生的事情无关。所以,我对这里的情况一无所知,但任何线索都会有很大帮助。谢谢

    更新 已验证运行
    dd($customer->cards)
    内部的
    updateCard()
    方法返回null——可能是因为它在创建订阅时从未将最后四个保存到数据库中。很难想象我如何创建订阅(在条带上验证)、取消和恢复,但我的卡详细信息没有在本地更新,我也不能交换卡

    我用它作为灵感,告诉大家做这件事“应该”是多么简单,在这方面取得了成功,但不是我的

    更新2 以下是我的整个用户控制器和Coffee实现(如果有帮助):

    <?php namespace App;
    
    use Illuminate\Auth\Authenticatable;
    use Illuminate\Database\Eloquent\Model;
    use Illuminate\Auth\Passwords\CanResetPassword;
    use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
    use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract;
    use Laravel\Cashier\Billable;
    use Laravel\Cashier\Contracts\Billable as BillableContract;
    
    class User extends Model implements AuthenticatableContract, CanResetPasswordContract, BillableContract {
    
        use Authenticatable, CanResetPassword, Billable;
    
        /**
         * The database table used by the model.
         *
         * @var string
         */
        protected $table = 'users';
    
        /**
         * Laravel Cashier
         *
         * @var array
         */
        protected $dates = ['trial_ends_at', 'subscription_ends_at'];
    
        /**
         * The attributes that are mass assignable.
         *
         * @var array
         */
        protected $fillable = [
            'email',
            'password',
            'first_name',
            'last_name',
            'phone',
            'biography',
            'twitter',
            'facebook',
            'linkedin'
        ];
    
        /**
         * The attributes excluded from the model's JSON form.
         *
         * @var array
         */
        protected $hidden = ['password', 'remember_token'];
    
        /**
         * A user can have many listings
         * @return \Illuminate\Database\Eloquent\Relations\HasMany
         */
        public function listings() {
            return $this->hasMany('App\Models\Dashboard\Listing');
        }
    }
    

    我认为这是由于Stripe端的API更改。如果你看看他们的卡片,你会注意到“卡片”属性最近被改成了“来源”

    更新

    您可以通过以下静态方法选择Stripe自己的PHP框架使用的API版本:

    Stripe::setApiVersion("2015-02-10");
    

    (这个版本号对我有用,但可能是我们需要一个旧版本。)

    好吧,错误很明显:
    cards
    public属性必须是某个类的实例,但由于某种原因它没有被实例化。您可能应该查看该类的内部,看看何时以及根据哪个条件实例化
    cards
    属性?也就是说,你需要抓住那一刻,这样处理这个问题就容易多了。感谢@bad_boy的评论——这里棘手的部分是,
    卡是通过一种神奇的方法访问的,所以我在追踪这一点上有点困难。我很确定这是一个你应该报告的错误。导致您出错的代码(在出纳库中)测试不良,看起来不正确。回购协议未启用问题(仅PRs)因此,尝试一个不同的渠道,可能可以提供一些信息。创建了一个PR来解决部分问题:由于customer对象不再返回卡信息,因此检索最后四个仍然存在问题。谢谢!虽然答案当然不是降级你的API版本(因为事情应该是最新的),但我确实提交了一份PR来解决问题的“部分”
    
    Stripe::setApiVersion("2015-02-10");