'Laravel Stripe MultiPlan Subscription

I want to add Add On to my subscription. Thus i follow this MultiPlan in Laravel doc. For every new subscription, new stripe product are create (means every plan have different product. including the addon). User need to subscribe to any subscription before subscript to the addon. There are no error, but the Subscription DB from stripe for the current subscription will return null quantity and null stripe_plan. Then create error from that database as i cant call the current subscription. Why does the stripe does that? or am I surpose to create new plans under the same product id in Stripe?

My code to create stripe product and plan

$stripe = new StripeClient(env('STRIPE_SECRET'));
$product_stripe = $stripe->products->create([
            'name' => $request->service_name,
        ]);
$plan_stripe = $stripe->plans->create([
            // 'id' => $stripe_plan,
            'nickname' => $request->service_name,
            'product' => $product_stripe['id'],
            'amount' => $request->price*100,
            'currency' => 'usd',
            'interval' => $request->period,
            'interval_count' => $request->period_num,
        ]);

This is my code to subscribe to addon

$user = auth()->user();
$user->subscription('default')->addPlanAndInvoice('plan_stripe_id', 'quantity');

Note that default is the user current subscription.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source