Skip to main content

Place an order as a guest

Places an order as a guest, without user registration.

What this example does:

  • The user is not signed in
  • The user fills out a contact form (for example, guest_order)
  • The user selects products (you can preset a list)
  • The order is created without an access token. The guest user group must have permission to create orders and payment sessions

Prerequisites:

  • A valid PROJECT_URL and APP_TOKEN for the OneEntry API.
  • An order storage with the marker guest_orders and a linked order form with the marker guest_order.
  • Permission for the guest user group to create orders and payment sessions.
  • A list of productId and quantity

Notes:

  • The form fields (marker, type) must match the form settings in the admin panel.
  • To send a notification about an order, use Events.
  • 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. With isShell: false it 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 { Orders, Payments } = defineOneEntry(PROJECT_URL, {
token: APP_TOKEN,
});

3. Prepare the data that usually comes from the frontend form​

const guestFormData = [
{
marker: 'guest_name',
type: 'string',
value: 'John Smith',
},
{
marker: 'guest_phone',
type: 'string',
value: '+12025550147',
},
{
marker: 'guest_email',
type: 'string',
value: 'john@example.com',
},
];
const productsData = [
{
productId: 15,
quantity: 1,
},
];
const body: IOrderData = {
formIdentifier: 'guest_order',
paymentAccountIdentifier: 'cash',
formData: guestFormData,
products: productsData,
};
Result:
{
"formIdentifier": "guest_order",
"paymentAccountIdentifier": "cash",
"formData": [
{
"marker": "guest_name",
"type": "string",
"value": "John Smith"
},
{
"marker": "guest_phone",
"type": "string",
"value": "+12025550147"
},
{
"marker": "guest_email",
"type": "string",
"value": "john@example.com"
}
],
"products": [
{
"productId": 15,
"quantity": 1
}
]
}

4. Create a guest order​

const order = await Orders.createOrder('guest_orders', body);

if ('statusCode' in order) {
throw new Error(order.message);
}
Result:
{
"id": 113,
"formIdentifier": "guest_order",
"paymentAccountIdentifier": "cash",
"formData": [
{
"marker": "guest_name",
"type": "string",
"value": "John Smith"
},
{
"marker": "guest_phone",
"type": "string",
"value": "+12025550147"
},
{
"marker": "guest_email",
"type": "string",
"value": "john@example.com"
}
],
"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": "guest_upcoming",
"statusLocalizeInfos": {
"title": "Upcoming"
},
"createdDate": "2026-06-06T11:37:20.044Z"
}

5. Create a payment session​

const paymentSession = await Payments.createSession(
order.id,
'session',
false,
);

if ('statusCode' in paymentSession) {
throw new Error(paymentSession.message);
}

console.log(paymentSession);
Result:
{
"id": 62,
"createdDate": "2026-06-06T11:37:21.260Z",
"updatedDate": "2026-06-06T11:37:21.260Z",
"type": "session",
"status": "waiting",
"paymentAccountId": 1,
"orderId": 113,
"amount": null,
"paymentUrl": null
}

6. Get the payment session by order ID with Payments.getSessionByOrderId()​

const sessionByOrderId = await Payments.getSessionByOrderId(order.id);

if ('statusCode' in sessionByOrderId) {
throw new Error(sessionByOrderId.message);
}

console.log(sessionByOrderId, paymentSession);
Result:
[
{
"id": 62,
"createdDate": "2026-06-06T11:37:21.260Z",
"updatedDate": "2026-06-06T11:37:21.260Z",
"type": "session",
"status": "waiting",
"paymentAccountId": 1,
"orderId": 113,
"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 { Orders, Payments } = defineOneEntry(PROJECT_URL, {
token: APP_TOKEN,
});

// 3. Prepare the data that usually comes from the frontend form
const guestFormData = [
{
marker: 'guest_name',
type: 'string',
value: 'John Smith',
},
{
marker: 'guest_phone',
type: 'string',
value: '+12025550147',
},
{
marker: 'guest_email',
type: 'string',
value: 'john@example.com',
},
];
const productsData = [
{
productId: 15,
quantity: 1,
},
];
const body: IOrderData = {
formIdentifier: 'guest_order',
paymentAccountIdentifier: 'cash',
formData: guestFormData,
products: productsData,
};

// 4. Create a guest order
const order = await Orders.createOrder('guest_orders', body);

if ('statusCode' in order) {
throw new Error(order.message);
}

// 5. Create a payment session
const paymentSession = await Payments.createSession(
order.id,
'session',
false,
);

if ('statusCode' in paymentSession) {
throw new Error(paymentSession.message);
}

console.log(paymentSession);

// 6. Get the payment session by order ID
const sessionByOrderId = await Payments.getSessionByOrderId(order.id);

if ('statusCode' in sessionByOrderId) {
throw new Error(sessionByOrderId.message);
}

console.log(sessionByOrderId, paymentSession);