0
votes

Laravel Cashier is not saving stripe data to my DB after a user is created.

When I create a new user and then try to assign a subscription() to that user (or any other user for that matter) the data is being sent to Stripe approriately, as I can see the customer id, plan chosen, etc... But my database user stripe columns do not get updated in my database.

When I remove the code to create() a user and just subscribe a user, the data persists to the database like it should. It only doesn't work after I've created a new user THEN try to subscribe any user.

I'm using Jeffrey Way's Model Validation Package.

$user = $this->userModel->create($input);

if ($user->hasErrors()) {
    throw new \Exception($user->getErrors());
}

$this->createStripeSubscription($user->id, $input['creditCardToken']);

private function createStripeSubscription($user_id, $token) {
    //$this->userModel->find(1)->subscription('monthly')->create($token); // Doesn't work either
    $this->userModel->find($user_id)->subscription('monthly')->create($token);
}
2
Does it work when you do $user->save() before creating the Stripe subscription ?user2629998
That's what I was originally doing but it does not :(Pathsofdesign

2 Answers

1
votes

I had similar problem with Ardent validation in Confide.

Overriding saving method of BillableTrait in user model solved the issue.

class User extends ConfideUser implements BillableInterface {

    use BillableTrait;

    public function saveBillableInstance()
    {                            
        $this->forceSave();        
    }
}
0
votes

The problem was a conflict with Jeffrey Way's Validation Model package. Or at least the way I was trying to implement it while using Cashier. I decided to abstract out my Validation in it's own class and remove the Validation Model package. All is good.