I'm new to Stripe and really like how simple the implementation is. But despite that, I'm still having some difficulties finding the best way to implement it into my e-commerce site.
In this site, a customer can add to cart a regular item and subscription item. For example like this:
Item A $ 10 Item B $ 20 Subscription C (Monthly) $ 10 Subscription D (Weekly) $ 5
And at checkout, I want to process all those items at once.
I am thinking of implementing it like this:
First create the customer
$customer = \Stripe\Customer::create(array(
"source" => $token,
"description" => "Example customer")
);
Then charge the regular item price (30$ from example above)
\Stripe\Charge::create(array(
"amount" => 3000,
"currency" => "usd",
"customer" => $customer->id)
);
Then charge the subscriptions using for loop
foreach ($plans as $plan_id) {
\Stripe\Subscription::create(array(
"customer" => $customer->id,
"plan" => $plan_id
));
}
But I'm feeling that my code above is not the correct way to do this. Also it would result in many charges (as many as the subscription) and I don't think its a good idea.
I would like some advice on how to properly solve this problem.
I highly appreciate any suggestion. Thank you!