Payment for the order by a registered user
In this example, we demonstrate how to process a payment for an order placed by a registered user using the OneEntry API.
✅ Purpose of the scenario:
- Registered user authorization
- Create order
- Creation of payment session
✅ What you need:
- A valid PROJECT_URL and APP_TOKEN for authentication with the OneEntry API.
- Registered user
- Configured order storage with marker "orders"
📌 Important:
- These examples do not include error handling.
- You can manage errors using a try-catch block or by employing a construction like await Promise.catch((error) => error).
📚 See in documentation:
📦 SDK reference:
Try it live
Run this method interactively in the JS SDK sandbox — connect your Project URL and App Token on first visit, then open:
- Payment for the order by a registered user — In this example, we demonstrate how to process a payment for an order placed by a registered user using the OneEntry API.
Scenario
1. Import defineOneEntry from SDK and define PROJECT_URL and APP_TOKEN
Example:
import { defineOneEntry } from 'oneentry';
const PROJECT_URL = 'your-project-url';
const APP_TOKEN = 'your-app-token';
2. Creating an API client
Example:
const { AuthProvider, Orders, Payments } = defineOneEntry(PROJECT_URL, {
token: APP_TOKEN,
});
3. User authorization with AuthProvider.auth('email', authData)
Example:
const authData = {
authData: [
{
marker: 'email_reg',
value: 'your-email',
},
{
marker: 'password_reg',
value: 'your-password',
},
],
};
const user = await AuthProvider.auth('email', authData);
console.log(user);
Result:
{
"userIdentifier": "kvasssukr.net@gmail.com",
"authProviderIdentifier": "email",
"accessToken": "eyJhbGciOiJIUzI1NiIsInR...pZCI6MTYsImF1dGhQ"
"refreshToken": "1745494429101-...-2834edf8"
}
4. Create order with Orders.createOrder()
Data:
{
"formIdentifier": "order",
"paymentAccountIdentifier": "cash",
"formData": {
"en_US": [
{
"type": "string",
"marker": "name",
"value": "Christina Thomas"
}
]
},
"products": [
{
"productId": 15,
"quantity": 1
}
]
}
Example:
const body = {
formIdentifier: 'order',
paymentAccountIdentifier: 'cash',
formData: [
{
type: 'string',
marker: 'name',
value: 'Christina Thomas',
},
],
products: [
{
productId: 15,
quantity: 1,
},
],
};
const orderData = (await Orders.createOrder('orders', body as any).catch(
(e: any) => e,
)) as any;
if ('statusCode' in orderData) {
throw new Error(orderData.message);
}
Result:
{
"id": 116,
"formIdentifier": "order",
"paymentAccountIdentifier": "cash",
"formData": [
{
"type": "string",
"marker": "name",
"value": "Christina Thomas"
}
],
"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. Creation of payment session with Payments.createSession()
Example:
const sessionData = await Payments.createSession(
orderData?.id,
'session',
).catch((e: any) => e);
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 one payment session object by order identifier with Payments.getSessionByOrderId()
Example:
const sessionByOrderId = await Payments.getSessionByOrderId(orderData?.id).catch(
(e: any) => e,
);
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 from SDK and define PROJECT_URL and APP_TOKEN
import { defineOneEntry } from 'oneentry';
const PROJECT_URL = 'your-project-url';
const APP_TOKEN = 'your-app-token';
// 2. Creating an API client
const { AuthProvider, Orders, Payments } = defineOneEntry(PROJECT_URL, {
token: APP_TOKEN,
});
// 3. User authorization 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);
console.log(user);
// 4. Create order with [Orders.createOrder()](/docs/orders/createOrder)
const body = {
formIdentifier: 'order',
paymentAccountIdentifier: 'cash',
formData: [
{
type: 'string',
marker: 'name',
value: 'Christina Thomas',
},
],
products: [
{
productId: 15,
quantity: 1,
},
],
};
const orderData = (await Orders.createOrder('orders', body as any).catch(
(e: any) => e,
)) as any;
if ('statusCode' in orderData) {
throw new Error(orderData.message);
}
// 5. Creation of payment session with [Payments.createSession()](/docs/payments/createSession)
const sessionData = await Payments.createSession(
orderData?.id,
'session',
).catch((e: any) => e);
// 6. Get one payment session object by order identifier with [Payments.getSessionByOrderId()](/docs/payments/getSessionByOrderId)
const sessionByOrderId = await Payments.getSessionByOrderId(orderData?.id).catch(
(e: any) => e,
);
console.log({ user, sessionData, sessionByOrderId });