Laravel Cashier: Problem Update Card (Fatal Error)

I installed Laravel Cashier (v3.0.4) in my project and am able to allow users to update their credit cards, but I am having problems trying to do this. Here are the relevant elements of my controller that handle it:

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'); } 

I checked the health check elements:

  • Actually messages for this controller
  • Successfully transfer token

But every time I try to send it, I get an error message at the box office:

 FatalErrorException in StripeGateway.php line 454: Call to a member function create() on null 

I reviewed this, and it looks like it passes $token as follows: $card = $customer->cards->create(['card' => $token]);

So, I then did another test to verify the health of dd($token) in this method and which returns exactly what my form provides. This block does not seem to have changed much recently - but there were some PSR-2 updates and one-time purchases; none of which seem to have anything to do with what is happening here. So I'm at my end, that is here, but any clues would be a huge help. Thanks!

Update

Checked the execution of dd($customer->cards) inside the updateCard() method returns null - possibly because it does not save the last four in the database when creating a subscription. Struggling to see how I can create a subscription (tested on Stripe), cancel and renew, but my card details are not updated locally and I cannot exchange cards.

I used https://www.youtube.com/watch?v=iPaKX7aPczQ as an inspiration for how simple it "should be" for this, with success on this, but not with mine.

Update 2

Here's my entire user controller and coffee implementation, if that helps:

 <?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 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.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 
+6
source share
1 answer

I think this is due to an API change at the end of Stripe. If you look at their change log, you will notice that the attribute "maps" has been changed to "sources" quite recently.

UPDATE

You can select the version of the API that Stripe's own PHP structure uses, with the following static method:

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

(This version number worked for me, but maybe we need an older version.)

+4
source

Source: https://habr.com/ru/post/983021/


All Articles