Pay for an order as a registered user
Signs in a user, creates an order and opens a payment session for it. With an online payment account, redirect the user to the session's paymentUrl.
What this example does:
- Signs in a registered user
- Creates an order
- Creates a payment session
Prerequisites:
- A valid PROJECT_URL and APP_TOKEN for the OneEntry API.
- A registered user
- Configured order storage with marker "orders"
Notes:
- The examples handle errors minimally: they throw when a call returns an error object.
- By default (
isShell: true) the SDK returns an error object instead of throwing, so check the result, e.g.'statusCode' in result. WithisShell: falseit throws, and you handle errors with try/catch. See Errors.
Platform docs:
SDK reference:
Try it live
Run this example in the JS SDK sandbox. Connect your Project URL and App Token on first visit, then open:
Scenario
1. Import defineOneEntry and define PROJECT_URL and APP_TOKEN
import { defineOneEntry } from 'oneentry';
import type { IOrderData } from 'oneentry';
const PROJECT_URL = 'https://your-project.oneentry.cloud';
const APP_TOKEN = 'your-app-token';
2. Create an API client
const { AuthProvider, Orders, Payments } = defineOneEntry(PROJECT_URL, {
token: APP_TOKEN,
});
3. Authenticate the user with AuthProvider.auth('email', authData)
const authData = {
authData: [
{
marker: 'email_reg',
value: 'your-email',
},
{
marker: 'password_reg',
value: 'your-password',
},
],
};
const user = await AuthProvider.auth('email', authData);
if ('statusCode' in user) {
throw new Error(user.message);
}
console.log(user);
Result:
{
"userIdentifier": "john@example.com",
"authProviderIdentifier": "email",
"accessToken": "eyJhbGciOiJIUzI1NiIsInR...pZCI6MTYsImF1dGhQ",
"refreshToken": "1745494429101-...-2834edf8"
}
4. Create an order with Orders.createOrder()
const body: IOrderData = {
formIdentifier: 'order',
paymentAccountIdentifier: 'cash',
formData: [
{
type: 'string',
marker: 'name',
value: 'John Smith',
},
],
products: [
{
productId: 15,
quantity: 1,
},
],
};
const orderData = await Orders.createOrder('orders', body);
if ('statusCode' in orderData) {
throw new Error(orderData.message);
}
Result:
{
"id": 116,
"formIdentifier": "order",
"paymentAccountIdentifier": "cash",
"formData": [
{
"type": "string",
"marker": "name",
"value": "John Smith"
}
],
"products": [
{
"productId": 15,
"quantity": 1
}
],
"currency": "USD",
"totalSum": 400,
"bonusApplied": 0,
"totalDue": 400,
"discountConfig": {
"orderDiscounts": [],
"productDiscounts": [],
"coupon": null,
"settings": {
"allowStacking": false,
"maxDiscountValue": null,
"allowGiftStacking": false,
"maxBonusPaymentPercent": null,
"minBonusAmount": null,
"minOrderAmountForBonus": null,
"giftRefundPolicy": "KEEP_GIFT"
},
"additionalDiscountsMarkers": [],
"totalRaw": 400,
"totalSumWithDiscount": 400,
"excludedGiftProductIds": [],
"bonus": {
"availableBalance": 0,
"maxBonusDiscount": 0,
"minBonusAmount": null,
"minOrderAmountForBonus": null,
"bonusApplied": 0
},
"bonusApplied": 0,
"totalDue": 400
},
"statusIdentifier": "upcoming",
"statusLocalizeInfos": {
"title": "Upcoming"
},
"createdDate": "2026-06-06T11:38:21.644Z"
}
5. Create a payment session with Payments.createSession()
const sessionData = await Payments.createSession(orderData.id, 'session');
if ('statusCode' in sessionData) {
throw new Error(sessionData.message);
}
Result:
{
"id": 65,
"createdDate": "2026-06-06T11:38:22.125Z",
"updatedDate": "2026-06-06T11:38:22.125Z",
"type": "session",
"status": "waiting",
"paymentAccountId": 1,
"orderId": 116,
"amount": null,
"paymentUrl": null
}
6. Get the payment session by order ID with Payments.getSessionByOrderId()
const sessionByOrderId = await Payments.getSessionByOrderId(orderData.id);
if ('statusCode' in sessionByOrderId) {
throw new Error(sessionByOrderId.message);
}
console.log({ user, sessionData, sessionByOrderId });
Result:
[
{
"id": 65,
"createdDate": "2026-06-06T11:38:22.125Z",
"updatedDate": "2026-06-06T11:38:22.125Z",
"type": "session",
"status": "waiting",
"paymentAccountId": 1,
"orderId": 116,
"amount": null,
"paymentUrl": null
}
]
Final example
// 1. Import defineOneEntry and define PROJECT_URL and APP_TOKEN
import { defineOneEntry } from 'oneentry';
import type { IOrderData } from 'oneentry';
const PROJECT_URL = 'https://your-project.oneentry.cloud';
const APP_TOKEN = 'your-app-token';
// 2. Create an API client
const { AuthProvider, Orders, Payments } = defineOneEntry(PROJECT_URL, {
token: APP_TOKEN,
});
// 3. Sign in
const authData = {
authData: [
{
marker: 'email_reg',
value: 'your-email',
},
{
marker: 'password_reg',
value: 'your-password',
},
],
};
const user = await AuthProvider.auth('email', authData);
if ('statusCode' in user) {
throw new Error(user.message);
}
console.log(user);
// 4. Create an order
const body: IOrderData = {
formIdentifier: 'order',
paymentAccountIdentifier: 'cash',
formData: [
{
type: 'string',
marker: 'name',
value: 'John Smith',
},
],
products: [
{
productId: 15,
quantity: 1,
},
],
};
const orderData = await Orders.createOrder('orders', body);
if ('statusCode' in orderData) {
throw new Error(orderData.message);
}
// 5. Create a payment session
const sessionData = await Payments.createSession(orderData.id, 'session');
if ('statusCode' in sessionData) {
throw new Error(sessionData.message);
}
// 6. Get the payment session by order ID
const sessionByOrderId = await Payments.getSessionByOrderId(orderData.id);
if ('statusCode' in sessionByOrderId) {
throw new Error(sessionByOrderId.message);
}
console.log({ user, sessionData, sessionByOrderId });