Search.../

createOfflineOrder( )

Developer Preview

Creates an order for a buyer who purchased the plan with an offline transaction.

Description

The createOfflineOrder() function returns a Promise that resolves to an order object when the order has been created.

Payment of an offline order is handled in 1 of 2 ways.

  • When creating the order, select true in the paid request parameter.
  • After creation, with the markAsPaid() function.

When creating a non-free offline order:

  • The order's status is set to "PENDING" if the start date is in the future. Otherwise, the status is set to "ACTIVE".

The order's last payment status is set to "UNPAID" or "PAID".

When creating a free offline order:

  • The order's status is set to "PENDING" if the start date is in the future. Otherwise, the status is set to "ACTIVE".
  • The order's last payment status is set to "NOT_APPLICABLE".
Admin Method

This function requires elevated permissions to run. This function is not universal and runs only on the backend.

Syntax

function createOfflineOrder(planId: string, memberId: string, options: CreateOfflineOrderOptions): Promise<CreateOfflineOrderResponse>

createOfflineOrder Parameters

NAME
TYPE
DESCRIPTION
planId
string

ID of the plan being ordered. See Plans for more information about plan IDs

memberId
string

ID of the member ordering the plan.

options
Optional
CreateOfflineOrderOptions

Options for creating an offline order.

Returns

Fulfilled - The order of the plan.

Return Type:

Promise<
CreateOfflineOrderResponse
>
NAME
TYPE
DESCRIPTION
order
Order

Order.

Was this helpful?

Create an offline order

Copy Code
1import { orders } from 'wix-pricing-plans.v2';
2import { elevate } from 'wix-auth';
3
4/* Sample planId value: 'cb4a8c57-273a-4567-94e3-cc43d5d339f2'
5 *
6 * Sample memberId value: '554c9e11-f4d8-4579-ac3a-a17f7e6cb0b4'
7 */
8
9const elevatedCreateOfflineOrder = elevate(orders.createOfflineOrder);
10
11export async function myCreateOfflineOrderFunction(planId, memberId) {
12 try {
13 const newOrder = await elevatedCreateOfflineOrder(planId, memberId);
14
15 return newOrder;
16 } catch (error) {
17 console.error(error);
18 // Handle the error
19 }
20}
21
22/* Promise resolves to:
23 * {
24 * "_createdDate": "2024-01-28T09:49:21.041Z",
25 * "_id": "82d99338-5653-459a-a751-b57483f7cfb5",
26 * "_updatedDate": "2024-01-28T09:49:21.041Z",
27 * "autoRenewCanceled": false,
28 * "buyer": {
29 * "contactId": "554c9e11-f4d8-4579-ac3a-a17f7e6cb0b4",
30 * "memberId": "554c9e11-f4d8-4579-ac3a-a17f7e6cb0b4"
31 * },
32 * "currentCycle": {
33 * "endedDate": "2024-04-27T09:49:21.041Z",
34 * "index": 0,
35 * "startedDate": "2024-01-28T09:49:21.041Z"
36 * },
37 * "cycles": [
38 * {
39 * "endedDate": "2024-04-27T09:49:21.041Z",
40 * "index": 0,
41 * "startedDate": "2024-01-28T09:49:21.041Z"
42 * }
43 * ],
44 * "earliestEndDate": "2026-04-27T09:49:21.041Z",
45 * "endDate": "2026-04-27T09:49:21.041Z",
46 * "formData": {
47 * "submissionData": {
48 * "formId": "3ef36359-24bd-471a-aa8b-a5ca683b50f4",
49 * "submissionData": {},
50 * "submissionId": "e65d5d60-7e07-4d2f-971f-e471dcebd0d2"
51 * },
52 * },
53 * "freeTrialDays": 90,
54 * "lastPaymentStatus": "UNPAID",
55 * "pausePeriods": [],
56 * "planDescription": "3 mo free trial with discount for 1 year",
57 * "planId": "cb4a8c57-273a-4567-94e3-cc43d5d339f2",
58 * "planName": "Beginner's Plan",
59 * "planPrice": "50",
60 * "pricing": {
61 * "prices": [
62 * {
63 * "duration": {
64 * "cycleFrom": 1,
65 * "numberOfCycles": 2
66 * },
67 * "price": {
68 * "currency": "USD",
69 * "discount": "0",
70 * "fees": [],
71 * "proration": "0",
72 * "subtotal": "50.00",
73 * "total": "50.00"
74 * }
75 * }
76 * ],
77 * "subscription": {
78 * "cycleCount": 2,
79 * "cycleDuration": {
80 * "count": 1,
81 * "unit": "YEAR"
82 * }
83 * }
84 * },
85 * "startDate": "2024-01-28T09:49:21.041Z",
86 * "statusNew": "DRAFT",
87 * "subscriptionId": "305f8fc9-3724-4cac-9f67-4e29f2c46def",
88 * "type": "OFFLINE",
89 * "wixPayOrderId": "2f0e79d8-f15d-46c6-ac1a-10ec7a2030fb"
90 * }
91 */
92
Create an offline order with options

Copy Code
1import { orders } from 'wix-pricing-plans.v2';
2import { elevate } from 'wix-auth';
3
4/* Sample planId value: 'cb4a8c57-273a-4567-94e3-cc43d5d339f2'
5 *
6 * Sample memberId value: '554c9e11-f4d8-4579-ac3a-a17f7e6cb0b4'
7 *
8 * Sample options value:
9 * {
10 * couponCode: 'e4ddd93a-5601-4696-99dd-3356f0e558c0',
11 * paid: true,
12 * startDate: '2024-01-29T11:50:21.041Z',
13 * submissionId: '9e128ddb-f62f-4a4a-adb5-064af40f18db'
14 * }
15 */
16
17const elevatedCreateOfflineOrder = elevate(orders.createOfflineOrder);
18
19export async function myCreateOfflineOrderFunctionWithOptions(planId, memberId, options) {
20 try {
21 const newOrder = await elevatedCreateOfflineOrder(planId, memberId, options);
22
23 return newOrder;
24 } catch (error) {
25 console.error(error);
26 // Handle the error
27 }
28}
29
30/* Promise resolves to:
31 * {
32 * order: {
33 * "_createdDate": "2024-01-28T09:49:21.041Z",
34 * "_id": "82d99338-5653-459a-a751-b57483f7cfb5",
35 * "_updatedDate": "2024-01-28T09:49:21.041Z",
36 * "autoRenewCanceled": false,
37 * "buyer": {
38 * "contactId": "554c9e11-f4d8-4579-ac3a-a17f7e6cb0b4",
39 * "memberId": "554c9e11-f4d8-4579-ac3a-a17f7e6cb0b4"
40 * },
41 * "cycles": [
42 * {
43 * "endedDate": "2024-04-27T09:49:21.041Z",
44 * "index": 0,
45 * "startedDate": "2024-01-28T09:49:21.041Z"
46 * }
47 * ],
48 * "currentCycle": {
49 * "endedDate": "2024-04-27T09:49:21.041Z",
50 * "index": 0,
51 * "startedDate": "2024-01-28T09:49:21.041Z"
52 * },
53 * "endDate": "2026-04-27T09:49:21.041Z",
54 * "earliestEndDate": "2026-04-27T09:49:21.041Z",
55 * "formData": {
56 * "formId": "3ef36359-24bd-471a-aa8b-a5ca683b50f4",
57 * "submissionData": {},
58 * "submissionId": "e65d5d60-7e07-4d2f-971f-e471dcebd0d2"
59 * },
60 * "freeTrialDays": 90,
61 * "lastPaymentStatus": "UNPAID",
62 * "pausePeriods": [],
63 * "planDescription": "3 mo free trial with discount for 1 year",
64 * "planId": "cb4a8c57-273a-4567-94e3-cc43d5d339f2",
65 * "planName": "Beginner's Plan",
66 * "planPrice": "50",
67 * "pricing": {
68 * "prices": [
69 * {
70 * "duration": {
71 * "cycleFrom": 1,
72 * "numberOfCycles": 2
73 * },
74 * "price": {
75 * "currency": "USD",
76 * "discount": "0",
77 * "fees": [],
78 * "proration": "0",
79 * "subtotal": "50.00",
80 * "total": "50.00"
81 * }
82 * }
83 * ],
84 * "subscription": {
85 * "cycleCount": 2,
86 * "cycleDuration": {
87 * "count": 1,
88 * "unit": "YEAR"
89 * }
90 * }
91 * },
92 * "startDate": "2024-01-28T09:49:21.041Z",
93 * "status": "ACTIVE",
94 * "statusNew": "DRAFT",
95 * "subscriptionId": "305f8fc9-3724-4cac-9f67-4e29f2c46def",
96 * "type": "OFFLINE",
97 * "wixPayOrderId": "2f0e79d8-f15d-46c6-ac1a-10ec7a2030fb"
98 * }
99 * }
100 */