SDK Reference
SDK reference for @chordcommerce/gatsby-theme-autonomy

Introduction

The Chord client-side Javascript SDK is installed as a Gatsby theme. It's available as an npm package, @chordcommerce/gatsby-theme-autonomy, via GitHub Packages.
Despite the name, this package does not provide a visual theme. To quote from the Gatsby documentation:
Gatsby themes are plugins that include a gatsby-config.js file and add pre-configured functionality, data sourcing, and/or UI code to Gatsby sites. You can think of Gatsby themes as separate Gatsby sites that can be put together and allow you to split up a larger Gatsby project!
The gatsby-theme-autonomy theme includes the Chord SDK, a set of methods you can import and use in your React components to do things like add items to a cart and check out. The theme also preconfigures your Gatsby site with a number of useful ecommerce features like product feeds and internationalization support.

useAnalytics()

1
import { useAnalytics } from '@chordcommerce/gatsby-theme-autonomy`
2
// inside a function componentconst { trackViewCart } = useAnalytics()
Copied!
The useAnalytics hook returns a series of functions that fire a tracking event to Segment, our integrated analytics platform.
Many Segment events are fired automatically by the @chordcommerce/gatsby-theme-autonomy theme. However, some events need to be closely tied to the UI, like click tracking. These events are available via the useAnalytics hook and listed below.

trackClickCollection()

1
trackClickCollection(title, slug, url)
Copied!
The trackClickCollection function fires a Collection Clicked event to Segment. You should call this function when the user clicks on a link to a collection.
Example
1
import { Link } from 'gatsby'
2
import { useAnalytics } from '@chordcommerce/gatsby-theme-autonomy'
3
4
export default ({ title, slug, children }) => {
5
const { trackClickCollection } = useAnalytics()
6
const url = `/shop/?collection=${slug}`
7
8
return (
9
<Link to={url} onClick={() => trackClickCollection(title, slug, url)}>
10
{children}
11
</Link>
12
)
13
}
Copied!

trackClickProduct()

1
trackClickProduct(slug)
Copied!
The trackClickProduct function fires a Product Clicked event to Segment. You should call this function when the user clicks on a link to a product.
Example
1
import { Link } from 'gatsby'
2
import { useAnalytics } from '@chordcommerce/gatsby-theme-autonomy'
3
4
export default ({ slug, children }) => {
5
const { trackClickProduct } = useAnalytics()
6
const url = `/products/${slug}/`
7
8
return (
9
<Link to={url} onClick={() => trackClickProduct(slug)}>
10
{children}
11
</Link>
12
)
13
}
Copied!

trackCreateStockRequest()

1
trackCreateStockRequest(email, sku)
Copied!
The trackCreateStockRequest function fires a Stock Request Created event to Segment. You should call this function when a product waitlist form is submitted.
Example
1
import { useAnalytics } from '@chordcommerce/gatsby-theme-autonomy'
2
3
export default ({ sku }) => {
4
const { trackCreateStockRequest } = useAnalytics()
5
const onSubmit = ({ email, sku }) => {
6
trackCreateStockRequest(email, sku)
7
}
8
9
// return sign up form
10
}
Copied!

trackViewCart()

1
trackViewCart()
Copied!
The trackViewCart function fires a Cart Viewed event to Segment. You should call this function when the cart page is viewed.
Example
1
import { useAnalytics } from '@chordcommerce/gatsby-theme-autonomy'
2
3
export default () => {
4
const { trackViewCart } = useAnalytics()
5
6
useEffect(() => {
7
trackViewCart()
8
}, [])
9
10
// return cart page
11
}
Copied!

trackProductViewed()

1
trackProductViewed({ product })
Copied!
The trackProductViewed function fires a Product Viewed event to Segment. You should call this function when a product page is opened.
Example
1
import { useAnalytics } from '@chordcommerce/gatsby-theme-autonomy'
2
3
export default (product) => {
4
const { trackProductViewed } = useAnalytics()
5
6
useEffect(() => {
7
trackProductViewed({ product })
8
}, [product])
9
10
// return product page
11
}
Copied!

useAuth()

1
import { useAuth } from '@chordcommerce/gatsby-theme-autonomy`
2
3
// inside a function component
4
const {
5
isLoggedIn,
6
isFetching,
7
token,
8
getToken,
9
handleCallback,
10
login,
11
logout
12
} = useAnalytics()
Copied!
The useAuth hook returns information about the current authentication session and functions for logging in and logging out. Chord supports passwordless authentication with Magic.

isLoggedIn

isLoggedIn is a boolean indicating whether the user is currently logged in.
Example
1
import { useAuth } from '@chordcommerce/gatsby-theme-autonomy`
2
3
const { isLoggedIn } = useAuth()
4
5
if (isLoggedIn) {
6
// return component
7
}
Copied!

isFetching

isFetching is a boolean indicating whether the user's authentication status is currently being fetched.
Example
1
import { useAuth } from '@chordcommerce/gatsby-theme-autonomy`
2
3
const { isFetching } = useAuth()
4
5
if (isFetching) {
6
// return loading animation
7
}
Copied!

token

token is a string representing the user's authentication token. This token is automatically appended to Chord API requests when the user has an active session.

handleCallback()

1
handleCallback()
Copied!
The handleCallback function completes the login process, when the user is redirected back to the site after clicking a link in their email. The SDK calls this function automatically when the Magic url parameter is detected on page load, so you are unlikely to need to call this function.

getToken()

1
getToken()
Copied!
The getToken function retrieves an authentication token for the current user session. While you are unlikely to need the token directly, since the SDK automatically appends it to relevant Chord API requests, you can use this function to check whether the user's session is still active. If the user's session has expired, getToken will throw an error.
You may choose to call getToken on page load or when a user visits a protected route (like an account page) to check that their session has not expired since the last time you checked.
Example
1
import { useEffect, useState } from 'react'
2
import { navigate } from 'gatsby'
3
import { useAuth } from '@chordcommerce/gatsby-theme-autonomy'
4
5
const PrivateRoute = () => {
6
const { getToken } = useAuth()
7
const [isLoggedIn, setIsLoggedIn] = useState(false)
8
9
useEffect(() => {
10
const checkStatus = async () => {
11
try {
12
await getToken()
13
setIsLoggedIn(true)
14
}
15
catch (error) {
16
navigate('/account/login')
17
}
18
}
19
checkStatus()
20
}, [getToken])
21
22
if (!isLoggedIn) return null
23
24
// return protected page
25
}
26
27
export default PrivateRoute
Copied!

login()

The login function should be called when a user submits a login form. It will trigger an email to the user for verification.
The showUI option controls whether Magic's default UI will display from when login is called until the user clicks the link they've received in an email.
Example
1
import { navigate } from 'gatsby'
2
import { useAuth } from '@chordcommerce/gatsby-theme-autonomy'
3
4
export default () => {
5
const { login } = useAuth()
6
const onSubmit = async ({ email }) => {
7
try {
8
await login({ email })
9
navigate('/some-private-route')
10
}
11
catch (error) {
12
console.error(error)
13
}
14
}
15
16
// return login form
17
}
Copied!

logout()

1
logout()
Copied!
The logout function terminates the user's current session.
Example
1
import { useAuth } from '@chordcommerce/gatsby-theme-autonomy'
2
3
export default () => {
4
const { logout } = useAuth()
5
6
return <button onClick={() => logout()}>Logout</button>
7
}
Copied!

useCart()

1
import { useCart } from '@chordcommerce/gatsby-theme-autonomy`
2
3
// inside a function component
4
const { cart, addToCart } = useCart()
Copied!

cart

Example
1
import { useCart } from '@chordcommerce/gatsby-theme-autonomy`
2
3
const { cart } = useCart()
4
const { lineItems } = cart.data
Copied!

addPromoCode()

1
addPromoCode(promoCode)
Copied!
Example
1
import { useCart } from '@chordcommerce/gatsby-theme-autonomy'
2
3
export default () => {
4
const { addPromoCode } = useCart()
5
const onSubmit = ({ promoCode }) => {
6
addPromoCode(promoCode)
7
}
8
}
Copied!

addReferralIdentifier()

1
addReferralIdentifier(referralIdentifier)
Copied!
Example
1
import { useCart } from '@chordcommerce/gatsby-theme-autonomy'
2
3
export default () => {
4
const { addReferralIdentifier } = useCart()
5
const onSubmit = ({ referralIdentifier }) => {
6
addReferralIdentifier(referralIdentifier)
7
}
8
}
Copied!

addToCart()

1
addToCart(sku, quantity)
Copied!
Example
1
import { useCart } from '@chordcommerce/gatsby-theme-autonomy'
2
3
export default () => {
4
const { addToCart } = useCart()
5
const onSubmit = ({ sku, quantity }) => {
6
addToCart(sku, quantity)
7
}
8
}
Copied!

checkout()

1
checkout()
Copied!
Example
1
import { useCart } from '@chordcommerce/gatsby-theme-autonomy'
2
import { loadStripe } from '@stripe/stripe-js'
3
4
const stripePromise = loadStripe(process.env.GATSBY_STRIPE_PK_KEY, { stripeAccount: process.env.GATSBY_STRIPE_CONNECTED_ACCOUNT })
5
6
export default () => {
7
const { checkout } = useCart()
8
const onSubmit = async () => {
9
const cart = await checkout()
10
const stripe = await stripePromise
11
stripe.redirectToCheckout({ sessionId: cart.checkoutSessionId })
12
}
13
}
Copied!

finalizeCheckout()

1
finalizeCheckout()
Copied!
This function should be called on the order confirmation page, when the user is redirected back to the site from checking out via Stripe.
Example
1
import { setState } from 'react'
2
import { useCart } from '@chordcommerce/gatsby-theme-autonomy'
3
4
export default () => {
5
const { finalizeCheckout } = useCart()
6
const [cart, setCart] = useState(null)
7
8
useEffect(() => {
9
finalizeCheckout().then(cart => { setCart(cart) })
10
}, [finalizeCheckout, loadUser])
11
}
Copied!

forgetCart()

forgetCart()
This function can be called at any time to clear the current order from the session. It is called automatically by finalizeCheckout and logout, so no need to call it in those cases.
Example
1
import { useCart } from '@chordcommerce/gatsby-theme-autonomy'
2
3
export default () => {
4
const { forgetCart } = useCartuth()
5
6
return <button onClick={() => forgetCart()}>Clear order</button>
7
}
Copied!

loadCart()

1
loadCart()
Copied!

modifyCart()

1
modifyCart({ lineItems: [] })
Copied!

modifyQuantity()

1
modifyQuantity(lineItemId, quantity)
Copied!

modifyLineItem()

Updates a line item in the current order.
1
const lineItemId = '123'
2
3
// update line item quantity
4
await modifyQuantity(lineItemId, {
5
quantity: 2,
6
})
7
8
// update line item options
9
await modifyQuantity(lineItemId, {
10
options: {
11
price: 8.5,
12
},
13
})
Copied!

modifyGiftCards()

The giftCardsDetails object is returned in the lineItem object if the lineItem is a gift card. Additionally, newly redeemed gift cards are available in the user object for indicating to the user that they have received a gift.
The gift cards can be updated by including the gift card id along with any of the following params: recipientName, recipientEmail, giftMessage, purchaserName, sendEmailAt.The recipient email is a required field as that will be the account used to redeem the gift cards.
1
modifyGiftCards({
2
"giftCardsDetails": [
3
{
4
"recipientEmail": "[email protected]",
5
"giftMessage": "Hi!",
6
"sendEmailAt": "2021-11-15",
7
"id": "49"
8
},
9
{
10
"recipientEmail": "[email protected]",
11
"giftMessage": "",
12
"sendEmailAt": "2021-11-16",
13
"id": "50"
14
}
15
]
16
})
Copied!

removeFromCart()

1
removeFromCart(lineItemId)
Copied!

removePromoCode

1
removePromoCode(promoCode)
Copied!

subscribeProduct()

1
subscribeProduct({ sku, quantity, interval, endDate })
Copied!
Note: endDate is optional. The subscription will renew indefinitely if endDate is not specified.
Example
1
import { useCart } from '@chordcommerce/gatsby-theme-autonomy'
2
3
export default () => {
4
const { subscribeProduct } = useCart()
5
const onSubmit = ({ sku, quantity, interval, endDate }) => {
6
subscribeProduct({ sku, quantity, interval, endDate })
7
}
8
}
Copied!

useProduct()

1
import { useProduct } from '@chordcommerce/gatsby-theme-autonomy'
2
3
// inside a function component
4
const { createStockRequest } = useProduct()
Copied!

createStockRequest()

Example
1
import { useProduct } from '@chordcommerce/gatsby-theme-autonomy'
2
3
export default () => {
4
const { createStockRequest } = useProduct()
5
await createStockRequest({ email, sku })
6
}
Copied!

useSubscription()

1
import { useSubscription } from '@chordcommerce/gatsby-theme-autonomy'
2
3
// inside a function component
4
const { subscripion, loadSubscription } = useSubscription()
Copied!
The useSubscription hook returns the current loaded subscription and functions for managing the subscription.

subscription

The subscription object represents a subscription. You will need to explicitly call loadSubscription before this object will be populated.
Example
1
import { useSubscription } from '@chordcommerce/gatsby-theme-autonomy'
2
3
export default () => {
4
const { subscription } = useSubscription()
5
6
return (
7
<p>Your subscription will be renewed on {subscription.actionableDate}</p>
8
)
9
}
Copied!

loadSubscription()

1
loadSubscription()
Copied!
The loadSubscription function loads information about the subscription from the Chord API.
Example
1
import { useSubscription } from '@chordcommerce/gatsby-theme-autonomy'
2
3
export default subscriptionId => {
4
const { subscription, loadSubscription } = useSubscription()
5
6
useEffect(() => {
7
loadSubscription(subscriptionId)
8
}, [])
9
10
return (
11
<p>Your subscription will be renewed on {subscription.actionableDate}</p>
12
)
13
}
Copied!

skipSubscription()

1
skipSubscription()
Copied!
The skipSubscription function calls the Chord API to skip the next subscription delivery.
Example
1
import { useSubscription } from '@chordcommerce/gatsby-theme-autonomy'
2
3
export default subscriptionId => {
4
const { subscription, skipSubscription } = useSubscription()
5
6
useEffect(() => {
7
skipSubscription(subscriptionId)
8
}, [])
9
10
return (
11
<p>Your subscription will be renewed on {subscription.actionableDate}</p>
12
)
13
}
Copied!

cancelSubscription()

1
cancelSubscription()
Copied!
The cancelSubscription function calls the Chord API to cancel a subscription.
Example
1
import { useSubscription } from '@chordcommerce/gatsby-theme-autonomy'
2
3
export default subscriptionId => {
4
const { subscription, cancelSubscription } = useSubscription()
5
6
useEffect(() => {
7
cancelSubscription(subscriptionId)
8
}, [])
9
10
return <p>Your subscription was canceled</p>
11
}
Copied!

pauseSubscription()

1
pauseSubscription()
Copied!
ThepauseSubscription function calls the Chord API to pause a subscription.
Paused subscriptions will not be processed until manuallyresumedor theactionable_dateis reached. Subscriptions can be either paused until a specifiedactionable_dateby sending an optionalactionable_dateparam or paused indefinitely by not passing any params. The minimum date to whichactionable_datecan be set is the next day.
1
import { useSubscription } from '@chordcommerce/gatsby-theme-autonomy'
2
3
export default () => {
4
const { pauseSubscription } = useSubscription(subscription.id)
5
const onSubmit = async data => {
6
try {
7
let response = await pauseSubscription({
8
'actionable_date': '2030-08-18'
9
})
10
console.log(response)
11
} catch (error) {
12
console.error(error)
13
}
14
}
15
}
Copied!

resumeSubscription()

1
resumeSubscription()
Copied!
TheresumeSubscriptionfunction calls the Chord API to resume a subscription.
Paused subscriptions will not be processed until manuallyresumedor theactionable_dateis reached. Subscriptions can be resumed at a specifiedactionable_dateby sending an optionalactionable_dateparam or resumed the next day (the minimum to which actionable_datecan be set) by not passing any params.
1
import { useSubscription } from '@chordcommerce/gatsby-theme-autonomy'
2
3
export default () => {
4
const { resumeSubscription } = useSubscription(subscription.id)
5
const onSubmit = async data => {
6
try {
7
let response = await resumeSubscription({
8
'actionable_date': '2030-08-18'
9
})
10
console.log(response)
11
} catch (error) {
12
console.error(error)
13
}
14
}
15
}
Copied!

updateSubscription()

1
updateSubscription()
Copied!
TheupdateSubscription function calls the Chord API to update a subscription.
To update the addresses, all fields need to be sent even if only a single field is updated. The two addresses that can be updated are shipAddressAttributes and billAddressAttributes.
In addition, the interval_unit('day'/'week'/'month'/'year'), interval_length, actionable_date and the end_date(null for no end date ) can be updated.
1
import { useSubscription } from '@chordcommerce/gatsby-theme-autonomy'
2
3
export default () => {
4
const { updateSubscription } = useSubscription(subscription.id)
5
const onSubmit = async data => {
6
try {
7
let response = await updateSubscription({
8
'shipAddressAttributes': data.addressAttributes,
9
'billAddressAttributes': data.addressAttributes,
10
'interval_units': 'month',
11
'interval_length': '2',
12
'end_date': '2021/12/31',
13
'actionable_date': '2030-08-18'
14
})
15
console.log(response)
16
} catch (error) {
17
console.error(error)
18
}
19
}
20
}
21
22
/*
23
Default Form Values:
24
25
const address = subscription['shipAddress']
26
const addressAttributes = {
27
name: address.name,
28
address1: address.address1,
29
address2: address.address2,
30
city: address.city,
31
state_name: address.state.abbr,
32
country_iso: address.country.iso,
33
zipcode: address.zipcode
34
}
35
*/
Copied!

useTranslate

1
import { useTranslate } from '@chordcommerce/gatsby-theme-autonomy`
2
3
// inside a function component
4
const translate = useTranslate()
Copied!
The useTranslate hook provides support for internationalization, powered by gatsby-plugin-intl.
To localize the text in your React components, use the translate function returned by the useTranslate hook. translate will load the specified string from your language resource file.
We recommend using translate even if your site currently only supports one language. It's easier to edit your website text if it's all in a single configuration file, and it makes it trivial to add multi-language support in the future.
Example
1
import { useTranslate } from '@chordcommerce/gatsby-theme-autonomy'
2
3
export default () => {
4
const { translate } = useTranslate()
5
6
return <h1>{translate('site.title')}</h1>
7
}
Copied!
The component above assumes there is a file at /src/intl/<language>.json that looks like this:
1
// /src/intl/en-US.json
2
3
{
4
"site": {
5
"title": "My Site"
6
}
7
}
Copied!

useUser()

1
import { useUser } from '@chordcommerce/gatsby-theme-autonomy`
2
3
// inside a function component
4
const { user, loadUser } = useUser()
Copied!
The useUser hook returns the current user and functions for loading data about the user. At the moment, the only user information Chord supports is the user's referral identifier and personalized referral url.

user

The user object represents the current user. You will need to explicitly call loadUser or loadUserReferralIdentifier before this object will be populated.
Example
1
import { useUser } from '@chordcommerce/gatsby-theme-autonomy'
2
3
export default () => {
4
const { user } = useUser()
5
const referralPurl = user.referralIdentifier && user.referralIdentifier.purl
6
7
return (
8
<p>Refer your friends with your personal referral link: {referralPurl}</p>
9
)
10
}
Copied!

loadUser()

1
loadUser()
Copied!
The loadUser function loads information about the current order's associated user from the Chord API.
Example
1
import { useUser } from '@chordcommerce/gatsby-theme-autonomy'
2
3
export default () => {
4
const { cart } = useCart()
5
const { user, loadUser } = useUser()
6
7
useEffect(() => {
8
loadUser()
9
}, [])
10
11
return <p>Welcome, {user.data.email}!</p>
12
}
Copied!

loadUserReferralIdentifier()

1
loadUserReferralIdentifier(email)
Copied!
The loadUserReferralIdentifier function loads the referral identifier information for a user with the given email address from the Chord API.
Example
1
import { useUser } from '@chordcommerce/gatsby-theme-autonomy'
2
3
export default () => {
4
const { user, loadUserReferralIdentifier } = useUser()
5
const referralPurl = user.referralIdentifier && user.referralIdentifier.purl
6
7
useEffect(() => {
8
loadUserReferralIdentifier()
9
}, [])
10
11
return (
12
<p>Refer your friends with your personal referral link: {referralPurl}</p>
13
)
14
}
Copied!

modifyUser()

The modifyUser function is used to update the user's profile information.
Example
1
import { useUser } from '@chordcommerce/gatsby-theme-autonomy'
2
3
export default () => {
4
const { modifyUser } = useUser()
5
const onSubmit = ({ email }) => {
6
modifyUser({ email })
7
}
8
9
// return profile edit form
10
}
Copied!

useSquareCheckout

1
import { useSquareCheckout } from '@chordcommerce/gatsby-theme-autonomy`
2
3
// inside a function component
4
const { updateOrderAddresses, getStates, updateOrderDelivery } = useSquareCheckout()
Copied!
This module allows to checkout using Square, the typical flow is:

updateOrderAddresses()

1
updateOrderAddresses(shipAddressAttributes)
Copied!
The updateOrderAddresses() function is used to update the order's ship address. A valid ship address has the following format:
1
{
2
name: 'Jane Doe', # string
3
address1: '2191 Calico Drive', # string
4
address2: 'Apt. 3', # string, optional
5
city: 'Phoenix', # string
6
country_id: 233, # integer
7
state_id: 3438, # integer
8
zipcode: '85022', # string
9
phone: '509-644-9988', # string
10
company: 'Acme Inc.' # string
11
}
Copied!
To retrieve the available states and the country id, please use getStates().
Example
1
import { useSquareCheckout } from '@chordcommerce/gatsby-theme-autonomy'
2
3
const { updateOrderAddresses } = useSquareCheckout()
4
5
const shipAddressAttributes = {
6
name: 'Jane Doe',
7
address1: '2191 Calico Drive',
8
city: 'Phoenix',
9
country_id: 233,
10
state_id: 3438,
11
zipcode: '85022',
12
phone: '509-644-9988',
13
company: 'Acme Inc.'
14
}
15
16
updateOrderAddresses(shipAddressAttributes)
Copied!

getStates()

1
getStates(iso)
Copied!
The getStates() function is used to retrieve information about countries and states available in the system to be used when we need to update the order's address. It takes the ISO code of the country and returns the list of states along with other information related to the country itself.
Example
1
import { useSquareCheckout } from '@chordcommerce/gatsby-theme-autonomy'
2
3
const { getStates } = useSquareCheckout()
4
5
getStates('US')
Copied!

updateOrderDelivery()

1
updateOrderDelivery()
Copied!
The updateOrderDelivery() function allows choosing the shipping option for the current order. At the moment we do not support multiple delivery options, so this function is only needed to move the checkout from the delivery step to the payment step. During this process, shipping costs and taxes will be added to the order.
This function should be called only when the order is in the delivery state, meaning that a valid address has been added to the order previously. This way it will be able to correctly pick the right delivery option based on the shipping address and to correctly compute taxes based on the shipment route.
Example
1
import { useSquareCheckout } from '@chordcommerce/gatsby-theme-autonomy'
2
3
const { updateOrderDelivery } = useSquareCheckout()
4
5
updateOrderDelivery()
Copied!

updateOrderPayment()

1
updateOrderPayment()
Copied!
The updateOrderPayment() function allows completing the payment step of the checkout. Before using this function, the client should retrieve a token using the Web Payments SDK provided by Square. When the order is successfully completed, the payment source will be added to the user's wallet (for authenticated users only), allowing to re-use the payment token later, without having to input the credit card information again.
This function should be called only when the order is in the payment state, meaning that a valid delivery option has been added to the order previously. At this stage the order is updated with shipping costs and taxes, allowing to complete the payment with the right amount.
For now, this endpoint doesn't support the ability to pay with an existing token. In the future we will provide this support, allowing to re-use a previously saved credit card from the user wallets.
Example
1
import { useSquareCheckout } from '@chordcommerce/gatsby-theme-autonomy'
2
3
const { updateOrderPayment } = useSquareCheckout()
4
5
const paymentAttributes = {
6
payment_method_type: 'square',
7
source_attributes: {
8
nonce: 'your-token'
9
}
10
}
11
updateOrderPayment(paymentAttributes)
Copied!

finalizeCheckout()

1
finalizeCheckout()
Copied!
finalizeCheckout() is the last method that needs to be called to complete the order with Square. Call this method when you want to move the user to the thank you page and let them start a new order.
Example
1
import { useSquareCheckout } from '@chordcommerce/gatsby-theme-autonomy'
2
3
const { finalizeCheckout } = useSquareCheckout()
4
5
finalizeCheckout()
Copied!
This function should be called only when the order is in the "confirm" state, meaning that a valid payment has been added to the order already.