Skip to content

Instantly share code, notes, and snippets.

Avatar

Larry Ullman LarryUllman

  • State College, PA
View GitHub Profile
@LarryUllman
LarryUllman / gist:fbe8db2f1ecc6c92e74a
Created Jul 23, 2014
Stripe - Calculate Subscription Proration
View gist:fbe8db2f1ecc6c92e74a
proration cost = (period end - API request time) / (period end - period start) * quantity * plan price
@LarryUllman
LarryUllman / gist:b3cf527b0a864d6921aa
Last active Aug 29, 2015
Stripe - PHP - Upgrade Subscription Plan, Invoice Now
View gist:b3cf527b0a864d6921aa
// Retrieve the customer:
$customer = Stripe_Customer::retrieve($customer_id);
// Retrieve the subscription being updated:
$subscription = $customer->subscriptions->retrieve($subscription_id);
// Change the plan:
$subscription->plan = '25_monthly'; // Was 10_monthly
// Use proration (default; not required):
@LarryUllman
LarryUllman / gist:0db8a6c5a9ec355c0ccb
Created Jul 23, 2014
Stripe - PHP - Upgrade Subscription Plan
View gist:0db8a6c5a9ec355c0ccb
// Retrieve the customer:
$customer = Stripe_Customer::retrieve($customer_id);
// Retrieve the subscription being updated:
$subscription = $customer->subscriptions->retrieve($subscription_id);
// Change the plan:
$subscription->plan = '25_monthly'; // Was 10_monthly
// Use proration (default; not required):
@LarryUllman
LarryUllman / gist:2b2939245b92a1d1eb96
Last active Sep 8, 2020
Stripe - PHP - Update Subscription
View gist:2b2939245b92a1d1eb96
// Retrieve the customer:
$customer = Stripe_Customer::retrieve($customer_id);
// Retrieve the subscription being updated:
$subscription = $customer->subscriptions->retrieve($subscription_id);
// Change the subscription settings:
$subscription->trial_end = strtotime('first day of next month 12:00');
// Save the changes:
@LarryUllman
LarryUllman / gist:76b45e6d2ea79001ac87
Last active Aug 29, 2015
Stripe - PHP - Create customer with Subscription, No Trial
View gist:76b45e6d2ea79001ac87
// Create a customer, subscribe them to a plan, with NO trial:
$cu = Stripe_Customer::create(array(
'email' => $email,
'card' => $token,
'plan' => '10_monthly_trial',
'trial_end' => 'now', // Trial ends now (i.e., no trial)
)
);
@LarryUllman
LarryUllman / gist:86b67f3f3b7e969604c8
Created Jul 23, 2014
Stripe - PHP - Create Customer with Subscription
View gist:86b67f3f3b7e969604c8
// Create a customer, subscribe them to a plan, with a 7 day trial:
$cu = Stripe_Customer::create(array(
'email' => $email,
'card' => $token,
'plan' => '10_monthly'
'trial_end' => time() + (7 * 24 * 60 * 60), // 7 days
)
);
@LarryUllman
LarryUllman / gist:99a3d43d12dddd0cb1b6
Last active Aug 29, 2015
Stripe - PHP - Set API Version
View gist:99a3d43d12dddd0cb1b6
// Mmmmmm...Composer for the Stripe PHP library:
require_once('./vendor/autoload.php');
// Set your API key:
Stripe::setApiKey('sk_test_whatever');
// Set the API version to use for these transactions:
Stripe::setApiVersion('2014-06-17');