Laravel Cashier:麻烦更新卡(致命错误)

Zac*_*ach 6 php laravel stripe-payments laravel-5

我已经在我的项目中安装了Laravel Cashier(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');
}
Run Code Online (Sandbox Code Playgroud)

我已经验证了理智检查项目:

  1. 实际上发布到这个控制器
  2. 成功传递令牌

但每次我尝试提交它,我在收银员本身都会收到错误:

FatalErrorException in StripeGateway.php line 454:
Call to a member function create() on null
Run Code Online (Sandbox Code Playgroud)

我已经调查了这个,看起来它正在传递$token给以下内容:$card = $customer->cards->create(['card' => $token]);

所以,然后我dd($token)在那个方法中做了另一个健全性检查,并且确切地返回了我的表格所提供的内容.看起来这个区块最近变化不大 - 但是有一些PSR-2和一次性购买更新; 这两者似乎与这里发生的事情无关.所以我在这里结束了什么,但任何线索都将是一个巨大的帮助.谢谢!

更新

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

我使用https://www.youtube.com/watch?v=iPaKX7aPczQ作为灵感来实现这一目标应该是多么简单,并且在这方面取得了成功,但不是我的.

更新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');
    }
}
Run Code Online (Sandbox Code Playgroud)

Stripe.coffee

(($) ->
  'use strict'

  StripeBilling =
    init: ->
      @form = $('.js-subscription__create')
      @submitButton = @form.find '.js-subscription__create__submit'
      @submitButtonText = @submitButton.text()

      stripeKey = $('meta[name="publishable_key"]').attr 'content'
      Stripe.setPublishableKey stripeKey

      @bindEvents()
      return

    bindEvents: ->
      @form.on('submit', $.proxy(@sendToken, @))
      return

    sendToken: (event) ->
      event.preventDefault()
      @submitButton.attr("disabled", true).text 'One Moment'

      Stripe.createToken(@form, $.proxy(@stripeResponseHandler, @))
      return

    stripeResponseHandler: (status, response) ->
      if response.error
        @form.find('.js-form__errors').removeClass("uk-hidden").text response.error.message
        return @submitButton.text(@submitButtonText).attr('disabled', false)

      $('<input>'
        type: 'hidden'
        name: 'stripe-token'
        value: response.id
      ).appendTo @form

      @form[0].submit()
      return

  StripeBilling.init()

  return
) jQuery
Run Code Online (Sandbox Code Playgroud)

Tom*_*ett 4

我认为这是由于 Stripe 端的 API 更改所致。如果您查看他们的更改日志,您会注意到“卡片”属性最近已更改为“来源”。

更新

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

Stripe::setApiVersion("2015-02-10");
Run Code Online (Sandbox Code Playgroud)

(该版本号对我有用,但可能我们需要旧版本。)