Walkthrough: Create a Subscription Plan and Manage Subscriptions
In this cURL-based walkthrough, you set up a subscription program for a gym membership, create customer subscriptions, and verify customer billing. You also test both scenarios: sending a subscription invoice to a customer's email address and charging a customer's card on file. You test the walkthrough in the Square Sandbox.
Create two customers and add a card on file for one of these customers.
To charge a customer for the subscription, you must add a card on file. To add a card on file, you use a fake payment token ("cnon:card-nonce-ok") that Square provides for Sandbox testing. The resulting card on file is a fake card that is never charged. For more information, see Sandbox Test Values.
The cURL commands in this exercise specify the connect.squareupsandbox.com
domain in the endpoint URLs for Sandbox testing. In production, the domain is connect.squareup.com
.
Follow these steps to gather account information for your Sandbox environment:
Sign in to the Developer Dashboard.
Open one of your applications, which provides you with the credentials you use. If you do not have an application, you first create an application.
Get Sandbox credentials:
On the Credentials page, you can toggle between the Sandbox mode and Production mode. Choose Sandbox.
Copy the access token from Sandbox Access Token.
Get a location ID. When creating subscriptions, you provide a seller location ID where the subscription was created.
In the left pane, choose Locations.
On the Locations page, choose a location ID.
You can create subscriptions only for customers that have a profile in the seller's Customer Directory. In this step, create two customers and add a card on file for one of these customers.
You must provide a valid email address when creating these customers. Square emails the subscription invoices and receipts to this email address.
Create a customer:
Call CreateCustomer to create a customer.
In the response, note the customer ID. You provide this ID when creating a subscription.
Create another customer. This time add a card on file for this customer. Make sure to provide a valid email address to receive emails.
Call
CreateCustomer
to create a customer.In the response, note the customer ID. You need this ID when adding a card on file and creating a subscription.
Call
CreateCard
to add a card on file using the payment token ("cnon:card-nonce-ok") that Square provides for Sandbox testing.In the response, note the card ID. When adding a subscription for this customer, you provide this card ID so that Square can charge the subscription fee to this card.
Call the UpsertCatalogObject to create a subscription plan. In the request:
name
specifies the gym membership.phases
includes two subscription phases.Phase 1 offers a significant discount. It specifies a monthly
cadence
with only $1 (price_money
). Also, the phaseperiod
value is set to 1, indicating a month-long phase. For more information about cadence, see Set up a subscription plan.Note
You can set the price to 0 to offer a free initial phase. In this case, Square does not send an invoice until the initial free period is over. Therefore, the price is set to $1 so you can immediately verify the invoice.
Phase 2 identifies the weekly
cadence
withprice_money
set to $15. That is, customers pay a $15 weekly subscription fee. The phase does not specify theperiod
, which indicates a continuous subscription.The following is an example response:
Create subscriptions for the two customers you created. One of the customers has a card on file so you include that card ID in the CreateSubscription
request.
Make sure you have the following information:
Subscription plan ID
Customer ID
Card ID for the card on file
Location ID
Call
CreateSubscription
to create a subscription for the customer without a card on file.The following is an example response:
In production, after the subscription is created, Square sends an invoice to the customer's email address (the Square Sandbox does not send emails). An example is shown as follows:
The customer can choose Pay Invoice to open the Square-hosted invoice page to pay the invoice. The seller also receives a similar email indicating an invoice is sent.
Call
CreateSubscription
to create a subscription for the customer with a card on file. In the request,card_id
is the card ID.The following is an example response:
If you test this in production, after charging the customer's card on file, Square sends a receipt to the customer's email address.
Verify the invoices in the Seller Dashboard.
Sign in to the Developer Dashboard.
In the Sandbox Test Accounts section, choose open for the Default Test Account.
In the left pane, choose Invoices, and then verify that the two invoices (paid and unpaid) are present.
If you need more assistance, contact Developer Support or ask for help in the Developer Forums.