Chord OMS
...
Next.js
SDK Reference
useSubscription
12 min
this page's documentation only applies to chord's next js starter prior to the release of the react docid\ ewxkrz0jhh0zpphikkcri 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 docid\ qmilhjfpz9wbjyzbe50ku for details on how to upgrade the usesubscription hook returns the current loaded subscription and functions for managing the subscription example import { usesubscription } from ' /hooks/actions' export default () => { const { subscription } = usesubscription() return ( \<p>your subscription will be renewed on {subscription actionabledate}\</p> ) } import { usesubscription } from ' /hooks/actions' // inside a function component const { subscripion, loadsubscription } = usesubscription() 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 import { usesubscription } from ' /hooks/actions' export default subscriptionid => { const { subscription, loadsubscription } = usesubscription() useeffect(() => { loadsubscription(subscriptionid) }, \[]) return ( \<p>your subscription will be renewed on {subscription actionabledate}\</p> ) } 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 import { usesubscription } from ' /hooks/actions' export default subscriptionid => { const { subscription, skipsubscription } = usesubscription() useeffect(() => { skipsubscription() }, \[]) return ( \<p>your subscription will be renewed on {subscription actionabledate}\</p> ) } 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 import { usesubscription } from ' /hooks/actions' export default subscriptionid => { const { subscription, cancelsubscription } = usesubscription() useeffect(() => { cancelsubscription() }, \[]) return \<p>your subscription was canceled\</p> } pausesubscription the pausesubscription function calls the chord api to pause a subscription paused subscriptions will not be processed until manually resumed or the actionabledate is 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 import { usesubscription } from ' /hooks/actions' export default () => { const { pausesubscription } = usesubscription(subscription id) const onsubmit = async data => { try { let response = await pausesubscription({ 'actionabledate' '2030 08 18' }) console log(response) } catch (error) { console error(error) } } } resumesubscription the resumesubscription function calls the chord api to resume a subscription paused subscriptions will not be processed until manually resumed or the actionabledate is 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 import { usesubscription } from ' /hooks/actions' export default () => { const { resumesubscription } = usesubscription(subscription id) const onsubmit = async data => { try { let response = await resumesubscription({ 'actionabledate' '2030 08 18' }) console log(response) } catch (error) { console error(error) } } } updatesubscription the updatesubscription 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 import { usesubscription } from ' /hooks/actions' export default () => { const { updatesubscription } = usesubscription(subscription id) const onsubmit = async data => { try { let response = await updatesubscription({ 'shipaddressattributes' data addressattributes, 'billaddressattributes' data addressattributes, 'intervalunits' 'month', 'intervallength' 2, 'enddate' '2021/12/31', 'actionabledate' '2030 08 18' }) console log(response) } catch (error) { console error(error) } } } / default form values const address = subscription\['shipaddress'] const addressattributes = { name address name, address1 address address1, address2 address address2, city address city, state name address state abbr, country iso address country iso, zipcode address zipcode } /