website logo
Navigate through spaces
Chord Commerce
⌘K
Getting Started
CMS
Data
OMS
Integrations
👩‍💻Developer Tools
Shopify
Docs powered by archbee 

useSubscription

This page's documentation only applies to Chord's Next.js starter prior to the release of the React SDK. The Next.js starter now uses the React SDK and does not use the methods documented on this page. Check out the React SDK Reference for complete documentation, and the React SDK Migration Guide for details on how to upgrade.

The useSubscription hook returns the current loaded subscription and functions for managing the subscription.

Example

JS
|
JS
|

Returns

The useSubscription hook returns an object with these properties:

Property

Description

subscription

An object representing a subscription. You will need to explicitly call loadSubscription before this object will be populated.

loadSubscription

A function that loads the subscription.

skipSubscription

A function that skips the next subscription delivery.

cancelSubscription

A function that cancels the subscription.

pauseSubscription

A function that pauses the subscription.

resumeSubscription

A function that resumes the subscription.

updateSubscription

A function that updates the subscription.

Functions

loadSubscription

The loadSubscription function loads information about the subscription from the Chord API.

Arguments:

loadSubscription(subscriptionId)

Argument

Type

Description

subscriptionId

Number

The id of the subscription to load.

Returns:

Promise<Subscription>: A Promise that resolves with the subscription.

Example:

JS
|

skipSubscription

The skipSubscription function calls the Chord API to skip the next subscription delivery.

Arguments:

None.

Returns:

Promise<Subscription>: A Promise that resolves with the subscription.

Example:

JS
|

cancelSubscription

The cancelSubscription function calls the Chord API to cancel a subscription.

Arguments:

None.

Returns:

Promise<Subscription>: A Promise that resolves with the subscription.

Example:

JS
|

pauseSubscription

ThepauseSubscription function calls the Chord API to pause a subscription.

Paused subscriptions will not be processed until manuallyresumedor theactionableDateis reached.

Arguments:

pauseSubscription(options)

Argument

Type

Description

options?.actionableDate?

String

(Optional): A date string representing when the subscription should resume. The minimum date is the next day. If actionableDate is omitted, the subscription will be paused indefinitely.

Returns:

Promise<Subscription>: A Promise that resolves with the subscription.

Example:

JS
|

resumeSubscription

TheresumeSubscriptionfunction calls the Chord API to resume a subscription.

Paused subscriptions will not be processed until manuallyresumedor theactionableDateis reached.

Arguments:

resumeSubscription(options)

Argument

Type

Description

options?.actionableDate?

String

(Optional): A date string representing when the subscription should resume. The minimum date is the next day. If actionableDate is omitted, the subscription will be resumed the next day.

Returns:

Promise<Subscription>: A Promise that resolves with the subscription.

Example:

JS
|

updateSubscription

TheupdateSubscription function calls the Chord API to update a subscription.

Arguments:

updateSubscription(options)

Argument

Type

Description

options.actionableDate?

String

(Optional): A date string representing when the subscription should resume. The minimum date is the next day. If actionableDate is omitted, the subscription will be resumed the next day.

options.billAddressAttributes?

Object

(Optional) An object representing the billing address. All fields need to be sent even if only a single field is updated.

options.endDate?

String | Null

(Optional) A string representing the end date of the subscription. If null, the subscription will renew indefinitely.

options.shipAddressAttributes?

Object

(Optional) An object representing the shipping address. All fields need to be sent even if only a single field is updated.

options.intervalLength?

Number

(Optional): The number of units. Example: if the subscription should be delivered every three months, this would be 3.

options.intervalUnit?

"day" | "week" | "month" | "year"

(Optional): The interval unit. Example: if the subscription should be delivered every three months, this would be month.

Returns:

Promise<Subscription>: A Promise that resolves with the subscription.

Example:

JS
|
Updated 14 Nov 2022
Did this page help you?
Yes
No
UP NEXT
useSubscriptions
Docs powered by archbee 
TABLE OF CONTENTS
Example
Returns
Functions
loadSubscription
skipSubscription
cancelSubscription
pauseSubscription
resumeSubscription
updateSubscription