Skip to main content

Tickets order

✅ Purpose of the scenario:

  • The user logs in with their credentials
  • Selects the ticket type, date and time from the schedule
  • Pays for the order and receives a ticket by email

✅ What you need:

  • A valid PROJECT_URL and APP_TOKEN for authentication with the OneEntry API.
  • Registered user for authentication
  • Form with marker "tickets_form" and fileds "schedule" and "tickets"
  • Configured order storage with marker "tickets"

📌 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, Forms, Orders, Payments } = 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 authResponse = await AuthProvider.auth('email', {
authData,
});
Result:
{
"userIdentifier": "your-user@email.com",
"authProviderIdentifier": "email",
"accessToken": "eyJhbGciOiJIUzI1NiIsInR...pZCI6MTYsImF1dGhQ"
"refreshToken": "1745494429101-...-2834edf8"
}

4. We receive form data from OneEntry CMS withForms.getFormByMarker() to generate a form on the frontend

Example:

const formData = await Forms.getFormByMarker('tickets_form');
Result:
{
"id": 9,
"attributeSetId": 12,
"type": "order",
"localizeInfos": {
"title": "Tickets",
"titleForSite": "Tickets",
"successMessage": "",
"unsuccessMessage": "",
"urlAddress": "",
"database": "0",
"script": "0"
},
"version": 6,
"position": 1,
"identifier": "tickets_form",
"processingType": "script",
"templateId": null,
"attributes": [
{
"type": "timeInterval",
"marker": "schedule",
"isLogin": null,
"isSignUp": null,
"position": 1,
"settings": {},
"isVisible": true,
"listTitles": [],
"validators": {},
"localizeInfos": {
"title": "Schedule",
"intervals": [
{
"id": "ef9cf848-7373-4b81-98bd-7ad33aa951e2",
"range": [
"2025-04-26T21:00:00.000Z",
"2025-04-26T21:00:00.000Z"
],
"external": [],
"intervals": [
{
"id": "f2042e47-c650-4fc6-ae1c-efdb109b450f",
"end": {
"hours": 21,
"minutes": 30
},
"start": {
"hours": 16,
"minutes": 30
},
"period": 90
}
],
"inEveryWeek": true,
"inEveryMonth": true
}
]
},
"additionalFields": [],
"isNotificationEmail": null,
"isNotificationPhoneSMS": null,
"isNotificationPhonePush": null
},
{
"type": "entity",
"marker": "tickets",
"isLogin": null,
"isSignUp": null,
"position": 2,
"settings": {},
"isVisible": true,
"listTitles": [
{
"id": 8,
"depth": 0,
"title": "Tickets",
"parentId": null,
"position": "0|hzzzz3:"
},
{
"id": "p-8-10",
"depth": 1,
"title": "Bronze",
"parentId": 8,
"position": 1,
"selected": true
},
{
"id": "p-8-11",
"depth": 1,
"title": "Silver",
"parentId": 8,
"position": 2,
"selected": true
},
{
"id": "p-8-12",
"depth": 1,
"title": "Gold",
"parentId": 8,
"position": 3,
"selected": true
}
],
"validators": {
"requiredValidator": {
"strict": true
}
},
"localizeInfos": {
"title": "Tickets"
},
"additionalFields": [],
"isNotificationEmail": null,
"isNotificationPhoneSMS": null,
"isNotificationPhonePush": null
}
]
}

5. Creation of an order in the order storage withOrders.createOrder()

Data:

{
"formIdentifier": "tickets_form",
"paymentAccountIdentifier": "cash",
"formData": {
"en_US": [
{
"type": "entity",
"marker": "tickets",
"value": [
"p-8-10"
]
}
]
},
"products": [
{
"productId": 10,
"quantity": 1
}
]
}

Example:

const order = await Orders.createOrder('tickets', body);
Result:
{
"id": 92,
"formIdentifier": "tickets_form",
"paymentAccountIdentifier": "cash",
"formData": [
{
"type": "entity",
"marker": "tickets",
"value": [
"p-8-10"
]
}
],
"products": [
{
"productId": 10,
"quantity": 1
}
],
"currency": "USD",
"totalSum": 100,
"createdDate": "2025-04-30T21:54:48.918Z"
}

6. Creation of payment session with Payments.createSession()

Example:

const payment = await Payments.createSession(order.id, 'session', false);
Result:
{
"id": 49,
"createdDate": "2025-04-30T21:54:50.058Z",
"updatedDate": "2025-04-30T21:54:50.058Z",
"type": "session",
"status": "waiting",
"paymentAccountId": 1,
"orderId": 92,
"paymentUrl": null
}

8. Get one payment session object by order identifier withPayments.getSessionByOrderId()

Example:

const sessionByOrderId = await Payments.getSessionByOrderId(order.id);
Result:
{
"id": 49,
"createdDate": "2025-04-30T21:54:50.058Z",
"updatedDate": "2025-04-30T21:54:50.058Z",
"type": "session",
"status": "waiting",
"paymentAccountId": 1,
"orderId": 92,
"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, Forms, Orders, Payments } = defineOneEntry(PROJECT_URL, {
token: APP_TOKEN,
});

// 3. User authorization
const authData = [
{
marker: 'email_reg',
value: 'your-user@email.com',
},
{
marker: 'password_reg',
value: '123456',
},
];
const authResponse = await AuthProvider.auth('email', {
authData,
});

// 4. We receive form data from OneEntry CMS to generate a form on the frontend
const formData = await Forms.getFormByMarker('tickets_form');

// 5. Creation of an order in the order storage
const body = {
formIdentifier: 'tickets_form',
paymentAccountIdentifier: 'cash',
formData: [
// {
// type: 'timeInterval',
// marker: 'schedule',
// value: {},
// },
{
type: 'entity',
marker: 'tickets',
value: ['p-8-10'],
},
],
products: [
{
productId: 10, // bronze ticket
quantity: 1,
},
],
};
const order = await Orders.createOrder('tickets', body);

// 6. Creation of payment session
const paymentSession = await Payments.createSession(
order.id,
'session',
false,
);

// 7. Update session by id
let updateSession = await Payments.updateSessionById(paymentSession.id, {
status: 'expired_ticket',
paymentUrl: '',
});

// 8. Get one payment session object by order identifier
let sessionByOrderId = await Payments.getSessionByOrderId(order.id);
console.log(sessionByOrderId);