Purchase of goods and services without user registration
✅ Purpose of the scenario:
- User is not authorized.
- The user fills out a form with contacts (for example, guest_orders).
- Selects products (you can pre-set a list).
- The order is placed for the user guest_user.
✅ What you need:
- A valid PROJECT_URL and APP_TOKEN for authentication with the OneEntry API.
- marker of the guest order form, for example guest_orders
- list productId and quantity
📌 Important:
- The form fields (marker, type) must match the form settings in the admin panel.
- If you need to send a notification about an order, you can use Events.
- 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. We form an array with fields required for user authorization
required fields: email = "email_reg", password = "password_reg"
Result:
[
{
"marker": "email_reg",
"value": "guest@onnentry.cloud"
},
{
"marker": "password_reg",
"value": "12345121334"
}
]
4. Log in as a guest user with AuthProvider.auth() to place an order
Data:
[
{
"marker": "email_reg",
"value": "guest@onnentry.cloud"
},
{
"marker": "password_reg",
"value": "12345121334"
}
]
Example:
const user = await AuthProvider.auth("email", {authData: authData});
Result:
{
"userIdentifier": "guest@onnentry.cloud",
"authProviderIdentifier": "email",
"accessToken": "eyJhbGciOiJIUzI1NiIsInR...pZCI6MTYsImF1dGhQ"
"refreshToken": "1745494429101-...-2834edf8"
}
5. Generate data that is usually received from the frontend form
Example:
{
"formIdentifier": "guest_order",
"paymentAccountIdentifier": "cash",
"formData": {
"en_US": [
{
"marker": "guest_name",
"type": "string",
"value": "Christina Thomas"
},
{
"marker": "guest_phone",
"type": "string",
"value": "+18005000500"
},
{
"marker": "guest_email",
"type": "string",
"value": "guest@yourmail.com"
}
]
},
"products": [
{
"productId": 10,
"quantity": 1
}
]
}
6. Create a guest order with Orders.createOrder()
Example:
const orderData = await Orders.createOrder("guest_orders", body);
7. Creation of payment session with Payments.createSession()
Example:
const payment = await Payments.createSession(order.id, 'session', false);
Result:
{
"id": 47,
"createdDate": "2025-04-30T21:47:45.344Z",
"updatedDate": "2025-04-30T21:47:45.344Z",
"type": "session",
"status": "waiting",
"paymentAccountId": 1,
"orderId": 90,
"paymentUrl": null
}
8. Get one payment session object by order identifier withPayments.getSessionByOrderId()
Example:
const sessionByOrderId = await Payments.getSessionByOrderId(order.id);
Result:
{
"id": 47,
"createdDate": "2025-04-30T21:47:45.344Z",
"updatedDate": "2025-04-30T21:47:45.344Z",
"type": "session",
"status": "waiting",
"paymentAccountId": 1,
"orderId": 90,
"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 } = defineOneEntry(PROJECT_URL, {
token: APP_TOKEN,
});
// 3. We form an array with fields required for user authorization
const authData = [
{
// registration form email marker
marker: 'email_reg',
value: 'guest@onnentry.cloud',
},
{
// registration form password marker
marker: 'password_reg',
value: '12345121334',
},
];
// 4. Log in as a guest user to place an order
const user = await AuthProvider.auth('email', {
authData: authData,
});
// 5. we generate data that is usually received from the frontend
const guestFormData = [
{
marker: 'guest_name',
type: 'string',
value: 'Christina Thomas',
},
{
marker: 'guest_phone',
type: 'string',
value: '+18005000500',
},
{
marker: 'guest_email',
type: 'string',
value: 'guest@yourmail.com',
},
];
const productsData = [
{
productId: 1,
quantity: 1,
},
];
const body: IOrderData = {
formIdentifier: 'guest_order',
// paymentAccountIdentifier: cash | stripe
paymentAccountIdentifier: 'cash',
formData: guestFormData,
products: productsData,
};
// 6. Create a guest order
const order = await Orders.createOrder('guest_orders', body);
// 7. Creation of payment session
const paymentSession = await Payments.createSession(
order.id,
'session',
false,
);
// 8. Update session by id
const updateSession = await Payments.updateSessionById(paymentSession.id, {
status: 'guest_completed',
paymentUrl: paymentSession.paymentUrl,
});
// 9. Get one payment session object by order identifier
const sessionByOrderId = await Payments.getSessionByOrderId(order.id);
console.log(sessionByOrderId);