Skip to main content

Orders and Payments

Overview​

The order option is the important part that instructs declo in how to convert a basket to an order. The order can also have it's own data schema, to hold information like payment ids or other data that is related to the order and not the basket.

Data schema​

declo-config.ts
import { z } from 'zod'
import { DecloConfig } from "@declo/config"

DecloConfig()
.order({
schema: z.object({
paymentId: z.string()
})
})

Configure the initiation of an order​

declo-config.ts
import { z } from 'zod'
import { DecloConfig } from "@declo/config"

DecloConfig()
.order({
init: async (basket, { callbackUrl, id }) => {
const { token, url } = await createPaymentSession({
amount: basket.price,
callbackUrl,
id
});

return { order: id, payment: { token: token, url: url } };
}
})

Configure the completion of the order​

declo-config.ts
import { z } from 'zod'
import { DecloConfig } from "@declo/config"

DecloConfig()
.order({
callback: async (order, queryParams, bodyData) => {
const payment = await getPaymentDataFromCallback(queryParams);
return {
order: {
data: {
paymentId: payment.id
}
}
};
}
})