Question

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);
}
Was it helpful?

Solution 2

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.

OTHER TIPS

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();        
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top