If you use the Planship Stripe app, all of your customers and their subscriptions are automatically mirrored in Planship. You can go straight to the Getting Customer Entitlements and Reporting Usage integration guides.
constsubscription=awaitplanship.createSubscription(customer.id,// customer ID'medium',// plan slug)
constsubscription:SubscriptionWithPlan=awaitplanship.createSubscription(customer.id,// customer ID'medium',// plan slug)
subscription=planship.create_subscription(customer.id,# customer ID"medium",# plan slug)
SubscriptionWithPlansubscription=planship.createSubscription(customer.getId(),// customer ID"medium"// plan slug)
The returned subscription object contains a subscription id, which is required when managing and modifying subscriptions. However, unlike customer IDs, subscription IDs don't need to be persisted in your product database as you can retrieve them programatically for a customer.
Info
The customer ID can be the Planship-generated customer ID or your own ID provided to Planship as an alternative ID.
Listing customer subscriptions
To find a subscription ID, simply list all subscriptions for a given customer.
The return value is a list of subscription objects that contain a subscription ID, plan, renew-plan slug, the customer's role in the subscription, and more.
Change subscription plan and renew plan (upgrades and downgrades)
When a customer upgrades their plan, you may want to apply this change immediately. This can be done by changing the subscription plan.
constsubscription=awaitplanship.changeSubscriptionPlan(customer.id,// customer IDsubscription.id,// existing subscription ID'large',// new plan slug)
constsubscription:CustomerSubscriptionWithPlan=awaitplanship.changeSubscriptionPlan(customer.id,// customer IDsubscription.id,// existing subscription ID'large',// new plan slug)
subscription=planship.change_subscription_plan(customer.id,# customer IDsubscription.id,# subscription ID"large",# new plan slug)
CustomerSubscriptionWithPlansubscription=planship.changeSubscriptionPlan(customer.getId(),// customer ID stringsubscription.getId(),// subscription ID"large",// new plan slug)
The same operation can be used when customers downgrade their subscriptions with an immediate effect (usually accompanied by a refund). However, downgrades are often processed at the end of a subscription period. This way, customers continue to have access to all of the product resources (like features and/or usage limits) they already paid for. To accomplish this, change the subscription's renew plan instead.
constsubscription=awaitplanship.changeSubscriptionRenewPlan(customer.id,// customer IDsubscription.id,// existing subscription ID'large',// new renew plan slug)
constsubscription:CustomerSubscriptionWithPlan=awaitplanship.changeSubscriptionRenewPlan(customer.id,// customer IDsubscription.id,// existing subscription ID'large',// new renew plan slug)
subscription=planship.change_subscription_renew_plan(customer.id,# customer IDsubscription.id,# subscription ID"large",# new renew plan slug)
CustomerSubscriptionWithPlansubscription=planship.changeSubscriptionRenewPlan(customer.getId(),// customer ID stringsubscription.getId(),// subscription ID"large",// new renew plan slug)
Instead of downgrading a subscription to a different plan, you may want to cancel it completely. To do so, set the subsciptions's auto renew property to false.
constsubscription=awaitplanship.setSubscriptionAutoRenew(customer.id,// customer IDsubscription.id,// existing subscription IDfalse,// set subscription auto-renew to false)
constsubscription:CustomerSubscriptionWithPlan=awaitplanship.setSubscriptionAutoRenew(customer.id,// customer IDsubscription.id,// existing subscription IDfalse,// set subscription auto-renew to false)
subscription=planship.set_subscription_auto_renew(customer.id,# customer IDsubscription.id,# subscription IDFalse,# set subscription auto-renew to false)
CustomerSubscriptionWithPlansubscription=planship.setSubscriptionAutoRenew(customer.getId(),// customer ID stringsubscription.getId(),// subscription IDfalse,// set subscription auto-renew to false)
The same call can be used to set a subscription's auto renew property to true.
Team subscriptions
Add a customer to a team subscription
If your plans support team subscriptions, instead of creating a new subscription for a customer, you may want to add them to an exisiting subscription.
constnewSubscriptionCustomer=awaitplanship.addSubscriptionCustomer(customer.id,// customer IDsubscription.id,// existing subscription IDnewCustomer.id,// new subscription customer ID)
constnewSubscriptionCustomer:SubscriptionCustomer=awaitplanship.addSubscriptionCustomer(customer.id,// customer IDsubscription.id,// existing subscription IDnewCustomer.id,// new subscription customer ID)
new_subscription_customer=planship.add_subscription_customer(customer.id,# customer IDsubscription.id,# existing subscription IDnew_customer.id,# new subscription customer ID)
SubscriptionCustomernewSubscriptionCustomer=planship.addSubscriptionCustomer(customer.getId(),// customer IDsubscription.getId(),// existing subscription IDnewCustomer.getId(),// new subscription customer ID)
Please note that this operation requires two customer IDs:
ID of an existing subscription customer to execute the operation, has to be an administrator of the subscription with a given ID
ID of a customer to be added to the subscription with a given ID
Remove a customer from a team subscription
Customers can be also removed from subscriptions they belong to.
constremovedSubscriptionCustomer=awaitplanship.removeSubscriptionCustomer(customer.id,// customer IDsubscription.id,// existing subscription IDcustomerToRemove.id,// ID of a customer being removed)
constremovedSubscriptionCustomer:SubscriptionCustomerInDbBase=awaitplanship.removeSubscriptionCustomer(customer.id,// customer IDsubscription.id,// existing subscription IDcustomerToRemove.id,// ID of a customer being removed)
removed_subscription_customer=planship.remove_subscription_customer(customer.id,# customer IDsubscription.id,# existing subscription IDnew_customer.id,# ID of a customer being removed)
SubscriptionCustomerInDbBaseremovedSubscriptionCustomer=planship.removeSubscriptionCustomer(customer.getId(),// customer IDsubscription.getId(),// existing subscription IDcustomerToRemove.getId(),// ID of a customer being removed)
Just as when adding a customer to a subscription, two customer IDs are required.
Info
Customers can remove themselves from a subscription as long as they are not the only administrator or subscriber of the subscription.