```bash npm install @newageerp/node-cart ```
npm install @newageerp/node-cart``bash`
npm install @newageerp/node-cart
PAYMENTS_PRIMER_BACKEND - if primer is used*
PAYMENTS_PAYPAL_BACKEND - if paypal is used*
PAYMENTS_STRIPE_WALLET_BACKEND - if stripe wallets is used*
PAYMENTS_STRIPE_ORDER_BACKEND - if stripe credit card form is used*
* AMQP_CART_QUEUE
* CRM_CART_BACKEND_V3
`bash
CRM_CART_BACKEND_V3=https://cart.crm.apidata.app
AMQP_CART_QUEUE=internal.crm.cart
PAYMENTS_PRIMER_BACKEND=https://primer.crm.apidata.app/app/public/session
PAYMENTS_PAYPAL_BACKEND=https://pp.crm.apidata.app/app/public/rt
PAYMENTS_STRIPE_WALLET_BACKEND=https://stripe.crm.apidata.app/app/public/wallet
PAYMENTS_STRIPE_ORDER_BACKEND=https://stripe.crm.apidata.app/app/public/wallet
`
PAYMENTS_* - replace apidata.app with project domain (if this is a test/RnD project, then use the domain of the main project, whose payments are used*)
CRM_CART_BACKEND_V3 - replace apidata.app with project domain (if this is a test/RnD project, then use the domain of the main project, whose payments are used*)
* AMQP_CART_QUEUE possible production variables
* biofema.crm.cart
* cosmic.crm.cart
* mellow.crm.cart
* parenting.crm.cart
* shiftmind.crm.cart
* today.crm.cart
* wingman.crm.cart
`typescript
import { cartNextSrv } from '@newageerp/node-cart'
export async function middleware(req: NextRequest) {
const cartResp = await cartNextSrv.checkForRoutes(req)
if (cartResp) {
return cartResp
}
}
export const config = {
matcher: '/((?!_next/static|_next/image|favicon.ico).*)',
}
`
in examples you can see cartBrowser or cartSrv calls, make sure you are using the correct method depending on the context.
Almost all methods are available in both environments
* call it after PaymentWindow was opened
* call it after purchase, before first upsell shown, most often it is up/[uuid/ page
it is safe to call multiple times, only one instance will be created
`typescript
await cartBrowser.create({
cart: cart.cart.items,
currency: currency,
extraData: {
totals: cart.totals,
},
id, // order uuid for main purchase or ${uuid}-up for upsell
customerId, // not neccessary if customerId = id (for main purchase)
})
`
`typescript
const cartData = await cartSrv.paid({
pm, // payment method (query param from paid/[uuid] route)
id, // order uuid for main purchase or ${uuid}-up for upsell
})
`
most often used in upsell flow to add item to the cart
`typescript
await cartBrowser.appendCartItem({
id, // order uuid for main purchase or ${uuid}-up for upsell flow
cart: [
{
product: data,
quantity: 1,
},
],
})
`
call it after upsell flow.
most often it is up-paid/[uuid] page. This method also marks cart as paid (on success charge), so you don't need call paid method
`typescript
// id - cart id (order uuid + suffix)
// customerId - order uuid
const cartData = await cartBrowser.upsellPayment({
id,
customerId,
})
`
in examples you can see cartBrowser or cartSrv calls, make sure you are using the correct method depending on the context.
Almost all methods are available in both environments
Returns items in cart ( it doesn't matter if it's paid or not ). Used in upsell flow to check if the user has added something to the cart.
`typescript
// order uuid for main purchase or ${uuid}-up for upsell
const cartData = await cartBrowser.get({ id })
`
`typescript
// customerId - order uuid without suffixes
const cartData = await cartBrowser.getPaid({ customerId })
`
#### cart total
`typescript``
// just calculate all items total sum
const total = cartUtils.total(items);