Skip to main content

Payment for the order by a registered user

✅ 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:

  • We do not handle errors in these examples.
  • You can handle errors in trycatch or in a construction like "await Promise.catch((error) => error)"

Scenario

1. Import oneEntry and define url and token

Example:

import { defineOneEntry } from 'oneentry';

const PROJECT_URL = 'your-project-url';
const APP_TOKEN = 'your-app-token';

2. Creating an API client with defineOneEntry() function

Example:

const { AuthProvider, Orders, Payments, Forms } = defineOneEntry(PROJECT_URL, {
token: APP_TOKEN,
});

3. User authorization with AuthProvider.auth()

Data:

[
{
"marker": "email_reg",
"value": "your-user@email.com"
},
{
"marker": "password_reg",
"value": "123456"
}
]

Example:

const user = await AuthProvider.auth('email', authData);
Result:
{
"userIdentifier": "your-user@email.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": 14,
"quantity": 1
}
]
}

Example:

const orderData = await Orders.createOrder('orders', body);
Result:
{
"id": 89,
"formIdentifier": "order",
"paymentAccountIdentifier": "cash",
"formData": [
{
"type": "string",
"marker": "name",
"value": "Christina Thomas"
}
],
"products": [
{
"productId": 14,
"quantity": 1
}
],
"currency": "USD",
"totalSum": 340,
"createdDate": "2025-04-30T20:15:29.254Z"
}

Creation of payment session with Payments.createSession()

Example:

const sessionData = await Payments.createSession(orderData.id, 'session');
Result:
{
"id": 46,
"createdDate": "2025-04-30T20:15:30.506Z",
"updatedDate": "2025-04-30T20:15:30.506Z",
"type": "session",
"status": "waiting",
"paymentAccountId": 1,
"orderId": 89,
"paymentUrl": null
}

Get one payment session object by order identifier 🔐 with Payments.getSessionByOrderId()

Example:

const sessionByOrderId = await Payments.getSessionByOrderId(orderData.id);
Result:
{
"id": 46,
"createdDate": "2025-04-30T20:15:30.506Z",
"updatedDate": "2025-04-30T20:15:30.506Z",
"type": "session",
"status": "waiting",
"paymentAccountId": 1,
"orderId": 89,
"paymentUrl": null
}

Final example

// 1. Import oneEntry 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-user@email.com',
},
{
marker: 'password_reg',
value: '123456',
},
],
};
const user = await AuthProvider.auth('email', authData);

// 4. Creation of an order in the order storage with Orders.createOrder()
const body = {
formIdentifier: 'order',
paymentAccountIdentifier: 'cash',
formData: [
{
type: 'string',
marker: 'name',
value: 'Christina Thomas',
},
],
products: [
{
productId: 1,
quantity: 1,
},
],
};
const orderData = await Orders.createOrder('orders', body);

// 5. Creation of payment session with Payments.createSession()
const sessionData = await Payments.createSession(orderData.id, 'session');

// 6. Get one payment session object by order identifier 🔐
const sessionByOrderId = await Payments.getSessionByOrderId(orderData.id);
console.log(sessionByOrderId);