Create Subscriptions for 'Shared Customer' in stripe connect account

303 views
Skip to first unread message

Kishan N

unread,
Apr 24, 2018, 4:02:07 AM4/24/18
to Stripe API Discussion
hello, my name is Kishan.

i have website where there is two types of user, 
Pro users and customers.

pro user has ability to create plan (stripe subscription Plans).
pro user 's are connected to platform account with stripe connect express account.

what i am doing right now is creating subscription plans on platform account.
and creating customer on platform account.

when user try to subscribe to plan.
i generate token to use shared customer.

and then i try to create subscription like this:


$subscription
= \Stripe\Subscription::create(array(
             
"customer" => $customer->id,
             
"source" => $token->id,
             
"plan" => "someplan_id",
             
"application_fee_percent" => 10,
           
), array("stripe_account" => $stripe_connect_id));


it gives me the following error :
No such customer:cus_xxxxxxxx

what i need is to be able to create customer in platform account so it can be used with all connected accounts. and i want the customer to be able to subscribe to multiple accounts.

am i doing something wrong ?

please provide some guidelines.

Thanks.

Remi J.

unread,
Apr 24, 2018, 4:11:38 AM4/24/18
to api-d...@lists.stripe.com
Hello Kishan,

You're definitely on the right track here and are simply missing one or two steps to be able to complete this. Whenever you create a subscription, the customer and the plan have to exist on the account where the subscription will be created. In your case, you are trying to create the subscription on a connected account using the customer and the plan stored on the platform which will not work. Instead, you have to recreate new objects on the connected account.

The idea is that, when you create the plan, you have to create it on each connected account where you will create a subscription for a given customer. This means that if John Doe subscribes to a $10 monthly plan from 3 Pro users, you need to do the same operations on each of the Pros accounts.

For the plan, it's just a matter of passing the `Stripe-Account` header on Plan creation the same way you do on the subscription creation. This needs to be done on each connected account where that plan will be used.

For the customer, you need to do 2 separate things. First, you need to create a new token for the card you want to charge based on the one saved in the platform. This is done using Shared Customers as you discovered already. Once you have that new token, you have to create a brand new/separate customer object on the Pro account.
This is done using the Create Customer API and passing the `Stripe-Account` header again. This new customer will be completely separate from the one in the platform. There will be no link between both and you likely want to keep track of this mapping on your end in your own database. Once you have that new customer and its new id (cus_1234), you can then create that subscription by passing its id in `customer`. You don't need to pass the `source` parameter here since it will automatically charge the default source on that customer.

You would have to do those steps for each Pro account in this case. In the case where the customer subscribes to 3 Pro users you would end up with:
- 3 plans: one per connected account, that have the same settings
- 4 customers: one on the platform, one per connected account, each with their own card object.
- 3 subscriptions: one per connected account

I hope this clarifies how to build this!
Best,
Remi

--
You received this message because you are subscribed to the Google Groups "Stripe API Discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to api-discuss+unsubscribe@lists.stripe.com.
To post to this group, send email to api-d...@lists.stripe.com.
Visit this group at https://groups.google.com/a/lists.stripe.com/group/api-discuss/.

Reply all
Reply to author
Forward
0 new messages