The subscription is not created when the user is created

Viewed 24

When registering, a user is created, but a subscription is not created in Stripe and the Trial period does not appear. What is the correct way to write the "createAndStartSubscription" function?

public function __construct(User $user)
    {
        $this->user = $user;
        $this->invoiceService = new InvoiceService();
    }
    /**
     * @param User $user
     * @return SubscriptionService
     */
    public static function user(User $user)
    {
        return new self($user);
    }
    /**
     * @param array $options
     * @return void
     */
    public function createAndStartSubscription(array $options = [])
    {
        $this->createCustomer($options);
        $this->newSubscription();
    }
    /**
     * @param array $options
     * @return \Stripe\Customer
     * @throws \Laravel\Cashier\Exceptions\CustomerAlreadyCreated
     */
    public function createCustomer(array $options = [])
    {
        return $this->user->createAsStripeCustomer($options);
    }
    /**
     * @param $paymentMethod
     * @return void
     */
    public function addPaymentMethod($paymentMethod)
    {
        $this->user->addPaymentMethod($paymentMethod);
        $this->user->updateDefaultPaymentMethod($paymentMethod);
    }
    /**
     * @param $plan
     * @param $paymentMethod
     * @return void
     * @throws \Laravel\Cashier\Exceptions\IncompletePayment
     */
    public function newSubscription($plan, $paymentMethod)
    {
        $this->user->newSubscription('default', self::E_PLANS[$plan])
            ->trialDays(1)
            ->create($paymentMethod);

        $this->user->subscription_type = $plan;
        $this->user->save();
    }

I really need help. Thanks to everyone who responded!

0 Answers
Related