import freshcom from 'freshcom-sdk'
// Assuming you have a existing cart
// In order to create point transaction you must use a user access token.
freshcom.createAndSetAccessToken({
password: 'supersecurepassword',
scope: 'aid:aid-test-74b901b2-32f9-4e3b-8d4d-4eca2360550c',
return freshcom.retrieveCustomer({
// Include the point account relationship of the customer.
}).then(function (response) {
let customer = response.data
// Find the correct point account to use.
let storeCreditAccount = customer.pointAccounts.find(function (pointAccount) {
return pointAccount.kind === 'store_credit'
// 1. Create a pending point transaction.
return freshcom.createPointTransaction({
pointAccount: storeCreditAccount,
}).then(function (response) {
let pointTransaction = response.data
// 2. Creat point transaction line item for the cart.
return freshcom.createOrderLineItem({
target: pointTransaction,