const subscriptionsApi = client.subscriptionsApi;
SubscriptionsApi
- Create Subscription
- Search Subscriptions
- Retrieve Subscription
- Update Subscription
- Delete Subscription Action
- Cancel Subscription
- List Subscription Events
- Pause Subscription
- Resume Subscription
- Swap Plan
Creates a subscription to a subscription plan by a customer.
If you provide a card on file in the request, Square charges the card for
the subscription. Otherwise, Square bills an invoice to the customer's email
address. The subscription starts immediately, unless the request includes
the optional start_date
. Each individual subscription is associated with a particular location.
async createSubscription(
body: CreateSubscriptionRequest,
requestOptions?: RequestOptions
): Promise<ApiResponse<CreateSubscriptionResponse>>
Parameter | Type | Tags | Description |
---|---|---|---|
body |
CreateSubscriptionRequest |
Body, Required | An object containing the fields to POST for the request. See the corresponding object definition for field details. |
requestOptions |
RequestOptions | undefined |
Optional | Pass additional request options. |
const contentType = null;
const bodyPriceOverrideMoneyCurrency: string = {'' : null, '' : null, '' : null } const bodyPriceOverrideMoney: Money = {};
bodyPriceOverrideMoney.amount = BigInt(100);
bodyPriceOverrideMoney.currency = bodyPriceOverrideMoneyCurrency;
const bodySource: SubscriptionSource = {};
const body: CreateSubscriptionRequest = {
locationId: 'S8GWD5R9QB376',
planId: '6JHXF3B2CW3YKHDV4XEM674H',
customerId: 'CHFGVKYY8RSV93M5KCYTG4PN0G',
};
body.idempotencyKey = '8193148c-9586-11e6-99f9-28cfe92138cf';
body.startDate = '2021-10-20';
body.taxPercentage = '5';
body.priceOverrideMoney = bodyPriceOverrideMoney;
body.cardId = 'ccof:qy5x8hHGYsgLrp4Q4GB';
body.timezone = 'America/Los_Angeles';
body.source = bodySource;
try {
const { result, ...httpResponse } = await subscriptionsApi.createSubscription(body);
// Get more response info...
// const { statusCode, headers } = httpResponse;
} catch(error) {
if (error instanceof ApiError) {
const errors = error.result;
// const { statusCode, headers } = error;
}
}
Searches for subscriptions.
Results are ordered chronologically by subscription creation date. If the request specifies more than one location ID, the endpoint orders the result by location ID, and then by creation date within each location. If no locations are given in the query, all locations are searched.
You can also optionally specify customer_ids
to search by customer.
If left unset, all customers
associated with the specified locations are returned.
If the request specifies customer IDs, the endpoint orders results
first by location, within location by customer ID, and within
customer by subscription creation date.
For more information, see Retrieve subscriptions.
async searchSubscriptions(
body: SearchSubscriptionsRequest,
requestOptions?: RequestOptions
): Promise<ApiResponse<SearchSubscriptionsResponse>>
Parameter | Type | Tags | Description |
---|---|---|---|
body |
SearchSubscriptionsRequest |
Body, Required | An object containing the fields to POST for the request. See the corresponding object definition for field details. |
requestOptions |
RequestOptions | undefined |
Optional | Pass additional request options. |
const contentType = null;
const bodyQueryFilterCustomerIds: string[] = ['CHFGVKYY8RSV93M5KCYTG4PN0G'];
const bodyQueryFilterLocationIds: string[] = ['S8GWD5R9QB376'];
const bodyQueryFilterSourceNames: string[] = ['My App'];
const bodyQueryFilter: SearchSubscriptionsFilter = {};
bodyQueryFilter.customerIds = bodyQueryFilterCustomerIds;
bodyQueryFilter.locationIds = bodyQueryFilterLocationIds;
bodyQueryFilter.sourceNames = bodyQueryFilterSourceNames;
const bodyQuery: SearchSubscriptionsQuery = {};
bodyQuery.filter = bodyQueryFilter;
const body: SearchSubscriptionsRequest = {};
body.query = bodyQuery;
try {
const { result, ...httpResponse } = await subscriptionsApi.searchSubscriptions(body);
// Get more response info...
// const { statusCode, headers } = httpResponse;
} catch(error) {
if (error instanceof ApiError) {
const errors = error.result;
// const { statusCode, headers } = error;
}
}
Retrieves a subscription.
async retrieveSubscription(
subscriptionId: string,
include?: string,
requestOptions?: RequestOptions
): Promise<ApiResponse<RetrieveSubscriptionResponse>>
Parameter | Type | Tags | Description |
---|---|---|---|
subscriptionId |
string |
Template, Required | The ID of the subscription to retrieve. |
include |
string | undefined |
Query, Optional | A query parameter to specify related information to be included in the response. The supported query parameter values are: - actions : to include scheduled actions on the targeted subscription. |
requestOptions |
RequestOptions | undefined |
Optional | Pass additional request options. |
const subscriptionId = 'subscription_id0';
try {
const { result, ...httpResponse } = await subscriptionsApi.retrieveSubscription(subscriptionId);
// Get more response info...
// const { statusCode, headers } = httpResponse;
} catch(error) {
if (error instanceof ApiError) {
const errors = error.result;
// const { statusCode, headers } = error;
}
}
Updates a subscription. You can set, modify, and clear the
subscription
field values.
async updateSubscription(
subscriptionId: string,
body: UpdateSubscriptionRequest,
requestOptions?: RequestOptions
): Promise<ApiResponse<UpdateSubscriptionResponse>>
Parameter | Type | Tags | Description |
---|---|---|---|
subscriptionId |
string |
Template, Required | The ID of the subscription to update. |
body |
UpdateSubscriptionRequest |
Body, Required | An object containing the fields to POST for the request. See the corresponding object definition for field details. |
requestOptions |
RequestOptions | undefined |
Optional | Pass additional request options. |
const subscriptionId = 'subscription_id0';
const contentType = null;
const body: UpdateSubscriptionRequest = {};
try {
const { result, ...httpResponse } = await subscriptionsApi.updateSubscription(subscriptionId, body);
// Get more response info...
// const { statusCode, headers } = httpResponse;
} catch(error) {
if (error instanceof ApiError) {
const errors = error.result;
// const { statusCode, headers } = error;
}
}
Deletes a scheduled action for a subscription.
async deleteSubscriptionAction(
subscriptionId: string,
actionId: string,
requestOptions?: RequestOptions
): Promise<ApiResponse<DeleteSubscriptionActionResponse>>
Parameter | Type | Tags | Description |
---|---|---|---|
subscriptionId |
string |
Template, Required | The ID of the subscription the targeted action is to act upon. |
actionId |
string |
Template, Required | The ID of the targeted action to be deleted. |
requestOptions |
RequestOptions | undefined |
Optional | Pass additional request options. |
DeleteSubscriptionActionResponse
const subscriptionId = 'subscription_id0';
const actionId = 'action_id6';
try {
const { result, ...httpResponse } = await subscriptionsApi.deleteSubscriptionAction(subscriptionId, actionId);
// Get more response info...
// const { statusCode, headers } = httpResponse;
} catch(error) {
if (error instanceof ApiError) {
const errors = error.result;
// const { statusCode, headers } = error;
}
}
Schedules a CANCEL
action to cancel an active subscription
by setting the canceled_date
field to the end of the active billing period
and changing the subscription status from ACTIVE to CANCELED after this date.
async cancelSubscription(
subscriptionId: string,
requestOptions?: RequestOptions
): Promise<ApiResponse<CancelSubscriptionResponse>>
Parameter | Type | Tags | Description |
---|---|---|---|
subscriptionId |
string |
Template, Required | The ID of the subscription to cancel. |
requestOptions |
RequestOptions | undefined |
Optional | Pass additional request options. |
const subscriptionId = 'subscription_id0';
try {
const { result, ...httpResponse } = await subscriptionsApi.cancelSubscription(subscriptionId);
// Get more response info...
// const { statusCode, headers } = httpResponse;
} catch(error) {
if (error instanceof ApiError) {
const errors = error.result;
// const { statusCode, headers } = error;
}
}
Lists all events for a specific subscription.
async listSubscriptionEvents(
subscriptionId: string,
cursor?: string,
limit?: number,
requestOptions?: RequestOptions
): Promise<ApiResponse<ListSubscriptionEventsResponse>>
Parameter | Type | Tags | Description |
---|---|---|---|
subscriptionId |
string |
Template, Required | The ID of the subscription to retrieve the events for. |
cursor |
string | undefined |
Query, Optional | When the total number of resulting subscription events exceeds the limit of a paged response, specify the cursor returned from a preceding response here to fetch the next set of results. If the cursor is unset, the response contains the last page of the results. For more information, see Pagination. |
limit |
number | undefined |
Query, Optional | The upper limit on the number of subscription events to return in a paged response. |
requestOptions |
RequestOptions | undefined |
Optional | Pass additional request options. |
ListSubscriptionEventsResponse
const subscriptionId = 'subscription_id0';
try {
const { result, ...httpResponse } = await subscriptionsApi.listSubscriptionEvents(subscriptionId);
// Get more response info...
// const { statusCode, headers } = httpResponse;
} catch(error) {
if (error instanceof ApiError) {
const errors = error.result;
// const { statusCode, headers } = error;
}
}
Schedules a PAUSE
action to pause an active subscription.
async pauseSubscription(
subscriptionId: string,
body: PauseSubscriptionRequest,
requestOptions?: RequestOptions
): Promise<ApiResponse<PauseSubscriptionResponse>>
Parameter | Type | Tags | Description |
---|---|---|---|
subscriptionId |
string |
Template, Required | The ID of the subscription to pause. |
body |
PauseSubscriptionRequest |
Body, Required | An object containing the fields to POST for the request. See the corresponding object definition for field details. |
requestOptions |
RequestOptions | undefined |
Optional | Pass additional request options. |
const subscriptionId = 'subscription_id0';
const contentType = null;
const body: PauseSubscriptionRequest = {};
try {
const { result, ...httpResponse } = await subscriptionsApi.pauseSubscription(subscriptionId, body);
// Get more response info...
// const { statusCode, headers } = httpResponse;
} catch(error) {
if (error instanceof ApiError) {
const errors = error.result;
// const { statusCode, headers } = error;
}
}
Schedules a RESUME
action to resume a paused or a deactivated subscription.
async resumeSubscription(
subscriptionId: string,
body: ResumeSubscriptionRequest,
requestOptions?: RequestOptions
): Promise<ApiResponse<ResumeSubscriptionResponse>>
Parameter | Type | Tags | Description |
---|---|---|---|
subscriptionId |
string |
Template, Required | The ID of the subscription to resume. |
body |
ResumeSubscriptionRequest |
Body, Required | An object containing the fields to POST for the request. See the corresponding object definition for field details. |
requestOptions |
RequestOptions | undefined |
Optional | Pass additional request options. |
const subscriptionId = 'subscription_id0';
const contentType = null;
const body: ResumeSubscriptionRequest = {};
try {
const { result, ...httpResponse } = await subscriptionsApi.resumeSubscription(subscriptionId, body);
// Get more response info...
// const { statusCode, headers } = httpResponse;
} catch(error) {
if (error instanceof ApiError) {
const errors = error.result;
// const { statusCode, headers } = error;
}
}
Schedules a SWAP_PLAN
action to swap a subscription plan in an existing subscription.
async swapPlan(
subscriptionId: string,
body: SwapPlanRequest,
requestOptions?: RequestOptions
): Promise<ApiResponse<SwapPlanResponse>>
Parameter | Type | Tags | Description |
---|---|---|---|
subscriptionId |
string |
Template, Required | The ID of the subscription to swap the subscription plan for. |
body |
SwapPlanRequest |
Body, Required | An object containing the fields to POST for the request. See the corresponding object definition for field details. |
requestOptions |
RequestOptions | undefined |
Optional | Pass additional request options. |
const subscriptionId = 'subscription_id0';
const contentType = null;
const body: SwapPlanRequest = {
newPlanId: null,
};
try {
const { result, ...httpResponse } = await subscriptionsApi.swapPlan(subscriptionId, body);
// Get more response info...
// const { statusCode, headers } = httpResponse;
} catch(error) {
if (error instanceof ApiError) {
const errors = error.result;
// const { statusCode, headers } = error;
}
}