Search code examples
phpstripe-connect

Shared Customers and Subscriptions in Stripe Connect


Problem Statement:

My Customers will have subscriptions with various publishers that have created their projects. I have to attach a customer to platform account and create a subscription which charges them behalf of the Connect custom accounts. So how can I make a shared customer and subscribe them to various subscriptions in a connect account.


Solution

  • Once you have that customer on your platform account, you can share them with a connected account by first creating a one-time use token:

     $token = \Stripe\Token::create(array(
     "customer" => "cus_xxxx",
     ), array("stripe_account" => "{CONNECTED_STRIPE_ACCOUNT_ID}"));
    

    Once you have this token, you could (a) use it to create a charge to that customer that lands directly in the connected account, but since you want to create a subscription you want to (b) use the token to copy the customer into the connected account and then create a subscription in that connected account for the copied customer. To copy a customer from platform to connected account you can do the following:

    $copiedCustomer = \Stripe\Customer::create(array(
    "description" => "Customer for xxx@xxx.com",
    "source" => $token // obtained with Stripe.js
    ), array("stripe_account" => "{CONNECTED_STRIPE_ACCOUNT_ID}"));
    

    This copied customer now has a new customer id in the connected account. Then you can setup the subscription on the connected account as follows:

    \Stripe\Subscription::create(array(
    "customer" => $copiedCustomer.id,
    "plan" => "xxx"
    ), array("stripe_account" => "{CONNECTED_STRIPE_ACCOUNT_ID}"));
    

    Step 3 here mentions the above method for creating subscriptions for shared customers (but doesn't show the example, their example is a one-off charge for shared customers) https://stripe.com/docs/connect/shared-customers