Skip to content

Instantly share code, notes, and snippets.

@adamjstevenson
Created October 23, 2015 21:59
Show Gist options
  • Save adamjstevenson/8bb2697383d50d74924b to your computer and use it in GitHub Desktop.
Save adamjstevenson/8bb2697383d50d74924b to your computer and use it in GitHub Desktop.
PHP Stripe Connect subscription flow
<?php
// Create a customer and subscribe them to a plan on a connected account -- should add some error handling
// Set your secret key -- generally this should be stored in a config file or ENV variable separate from this code
\Stripe\Stripe::setApiKey(PLATFORM_SECRET_KEY);
$token = $_POST['stripeToken'];
$acct = "acct_yourConnectedAcctID";
// Create a customer on the connected account
$customer = \Stripe\Customer::create(array(
'description' => 'Marty Mcfly',
'source' => $token
), array('stripe_account' => $acct));
// Create a plan on the connected account if one doesn't exist already
\Stripe\Plan::create(array(
"amount" => 2000,
"interval" => "month",
"name" => "Amazing Gold Plan",
"currency" => "usd",
"id" => "gold"
), array('stripe_account' => $acct));
// Subscribe the customer to the plan and set a 10% app fee
$customer->subscriptions->create(array(
"plan" => "gold",
"application_fee_percent" =>10
), array('stripe_account' => $acct));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment