useSubscription
This page's documentation only applies to Chord's Next.js starter prior to the release of the React. 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 Guidefor details on how to upgrade.
The useSubscription hook returns the current loaded subscription and functions for managing the subscription.
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. |
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:
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:
The cancelSubscription function calls the Chord API to cancel a subscription.
Arguments:
None.
Returns:
Promise<Subscription>: A Promise that resolves with the subscription.
Example:
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:
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:
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: