Search.../

createOfflineOrder( )

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.

Note: The pricing plan createOnlineOrder() and the createOfflineOrder() APIs replace the deprecated paid plans orderPlan() API. The deprecated API will continue to work, but will not receive updates. To keep any existing code compatible with future changes, see the migration instructions.

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.

Creating a non-free offline order causes:

  • 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".

Creating a free offline order causes:

  • 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".

The onOrderCreated() event handler runs when an offline order is created.

Note: Only site visitors with the Manage Pricing Plans and Manage Subscriptions permissions can create offline orders. You can override the permissions by setting the function's suppressAuth option to true.

Syntax

function createOfflineOrder(planId: string, buyerId: string, [options: CreateOfflineOrderOptions]): Promise<Order>

createOfflineOrder Parameters

NAME
TYPE
DESCRIPTION
planId
string

ID of the plan being ordered.

buyerId
string

Member ID for the buyer.

options
Optional
CreateOfflineOrderOptions

Additional options for creating the offline order.

Returns

Fulfilled - The order of the plan.

Return Type:

Promise<Order>
NAME
TYPE
DESCRIPTION
_id
string

Order ID.

planId
string

ID of the plan that was ordered.

subscriptionId
string

ID of the related Wix subscription.

Every pricing plan order corresponds to a Wix subscription, including orders for single payment plans. You can see all orders from your site's Subscriptions page in the Dashboard.

wixPayOrderId
string

ID of the associated Wix Pay order.

Created by the createOnlineOrder() or createfflineOrder() function. For online orders, send this value as a parameter to the Wix Pay startPayment() function to enable your buyer to pay for the order. wixPayOrderId is omitted if the order is free.

buyer
Buyer

The buyer's IDs. Includes memberId and contactId.

Currently, Pricing Plan orders are limited to members only. contactId is returned, but a buyer will not be able to order a plan without a memberId.

priceDetails
PriceDetails

Deprecated. Use pricing instead.

pricing
Pricing

Order pricing model, price, and payment schedule.

type
string

How the order was processed. Supported values:

  • "ONLINE". The buyer ordered the plan using the site.
  • "OFFLINE". The buyer made a manual, offline order without using the site.
status
string

Status of the order. Supported values:

  • "DRAFT". The order has been initiated but payment hasn't been processed yet. The plan isn't yet available for use.
  • "PENDING". The order has been processed and its start date is set in the future. The plan isn't yet available for use.
  • "ACTIVE". The order has been processed. The plan is available for use.
  • "PAUSED". The order, and use of the plan, is paused. For example, if the buyer is away. The order, and use of the plan, can be resumed.
  • "ENDED". The order has completed its duration and is no longer available for use.
  • "CANCELED". The order has been canceled.
autoRenewCanceled
boolean

Whether the order will be canceled at the next payment date.

If true, the order status will be CANCELED and the next payment won't be charged. Omitted for single payment orders.

cancellation
Cancellation

Details about the cancellation of an order. Only present if the status is "CANCELED".

lastPaymentStatus
string

Status of the last payment for the order. This is updated automatically for online orders. The site owner updates this manually for offline orders. Supported values:

  • "PAID". The last payment was paid.
  • "REFUNDED". The last payment was refunded.
  • "FAILED". The last payment transaction didn't complete.
  • "UNPAID". The last payment wasn't paid.
  • "PENDING". Awaiting payment.
  • "NOT_APPLICABLE". No payment was necessary. For example, for free plans or free trials.
startDate
Date

Start date and time for the ordered plan.

endDate
Date

Current date and time the ordered plan will expire.

endDate may be updated over the course of an order. If the order is paused, it will have a later endDate once it resumes. endDate may also be postponed.

Omitted if the order is valid until canceled and still "ACTIVE".

pausePeriods
Array<PausePeriod>

List of periods during which this order is paused.

freeTrialDays
string

Free trial period, in days. Only available for recurring plans.

earliestEndDate
Date

Earliest end date and time that the plan for this order can expire.

This is calculated by adding all pause periods to the original end date. Omitted if the order is active until canceled. Reserved for future use.

currentCycle
CurrentCycle

Current payment cycle for the order.

currentCycle will be omitted if the order's status is CANCELED or ENDED, or if the startDate hasn't passed yet.

planName
string

Name of the plan at the time of the order.

planDescription
string

Description of the plan at the time of the order.

planPrice
string

Plan price as it was at the moment of order creation.

_createdDate
Date

Date and time the order was created.

_updatedDate
Date

Date and time the order was last updated. For example, the date and time an order was paused, resumed, or canceled.

Was this helpful?

Create an offline order

Copy Code
1import { Permissions, webMethod } from 'wix-web-module';
2import { checkout } from 'wix-pricing-plans-backend';
3
4// Sample planId value: '099e2c86-3b7e-4477-8c27-f77402b8cceb'
5//
6// Sample buyerId value: '0c9bca47-1f00-4b92-af1c-7852452e949a'
7
8export const myCreateOfflineOrderFunction = webMethod(Permissions.Anyone, async (planId, buyerId) => {
9 try {
10 const order = await checkout.createOfflineOrder(planId, buyerId);
11 const plan = order.planName;
12 const orderType = order.type;
13
14 return order;
15 } catch (error) {
16 console.error(error);
17 }
18});
19
20/* Promise resolves to:
21 *
22 * {
23 * "_id": "810a10b7-9da4-4de3-87e3-b4a3d7ed9654",
24 * "planId": "099e2c86-3b7e-4477-8c27-f77402b8cceb",
25 * "subscriptionId": "8bd53121-a1b3-4754-981e-64d5779a6821",
26 * "wixPayOrderId": "6c56901d-d17f-44c8-acfa-05979b63e11f",
27 * "buyer": {
28 * "memberId": "0c9bca47-1f00-4b92-af1c-7852452e949a",
29 * "contactId": "0c9bca47-1f00-4b92-af1c-7852452e949a"
30 * },
31 * "priceDetails": {
32 * "subtotal": "74.99",
33 * "discount": "0",
34 * "total": "74.99",
35 * "planPrice": "74.99",
36 * "currency": "EUR",
37 * "subscription": {
38 * "cycleDuration": {
39 * "count": 1,
40 * "unit": "MONTH"
41 * },
42 * "cycleCount": 3
43 * }
44 * },
45 * "pricing": {
46 * "subscription": {
47 * "cycleDuration": {
48 * "count": 1,
49 * "unit": "MONTH"
50 * },
51 * "cycleCount": 3
52 * },
53 * "prices": [
54 * {
55 * "duration": {
56 * "cycleFrom": 1,
57 * "numberOfCycles": 3
58 * },
59 * "price": {
60 * "subtotal": "74.99",
61 * "discount": "0",
62 * "total": "74.99",
63 * "currency": "EUR"
64 * }
65 * }
66 * ]
67 * },
68 * "type": "OFFLINE",
69 * "orderMethod": "UNKNOWN",
70 * "status": "ACTIVE",
71 * "autoRenewCanceled": false,
72 * "lastPaymentStatus": "UNPAID",
73 * "startDate": "2022-07-13T04:20:50.320Z",
74 * "endDate": "2022-10-13T04:20:50.320Z",
75 * "pausePeriods": [],
76 * "earliestEndDate": "2022-10-13T04:20:50.320Z",
77 * "currentCycle": {
78 * "index": 1,
79 * "startedDate": "2022-07-13T04:20:50.320Z",
80 * "endedDate": "2022-08-13T04:20:50.320Z"
81 * },
82 * "planName": "Platinum Pro",
83 * "planDescription": "",
84 * "planPrice": "74.99",
85 * "_createdDate": "2022-07-13T04:20:50.320Z",
86 * "_updatedDate": "2022-07-13T04:20:50.320Z"
87 * }
88 */
Create an offline order with additional options

This example demonstrates how to create an offline order that is already marked as paid, starts at a later date, and uses a coupon code for a discount. This example also bypasses permission checks using the suppressAuth option.

Copy Code
1
2import { Permissions, webMethod } from 'wix-web-module';
3import { checkout } from 'wix-pricing-plans-backend';
4
5/* Sample planId value: '099e2c86-3b7e-4477-8c27-f77402b8cceb'
6 *
7 * Sample buyerId value: 'fac761ea-e6f1-4e3d-8b30-a4852f091416'
8 *
9 * Sample options value:
10 * {
11 * startDate: new Date('2022-09-15T03:00:00Z'),
12 * paid: true,
13 * suppressAuth: true,
14 * couponCode: 'ONEMONTHFREE'
15 * }
16 */
17
18export const myCreateOfflineOrderWithOptionsFunction = webMethod(Permissions.Anyone, async (planId, buyerId, options) => {
19 try {
20 const order = await checkout.createOfflineOrder(planId, buyerId, options);
21 const plan = order.planName;
22 const orderType = order.type;
23
24 return order;
25 } catch (error) {
26 console.error(error);
27 }
28});
29
30/* Promise resolves to:
31 *
32 * {
33 * "_id": "5080a56a-b6f6-4841-b5ad-2d46e9702619",
34 * "planId": "099e2c86-3b7e-4477-8c27-f77402b8cceb",
35 * "subscriptionId": "00f669b9-9084-43b2-bcdf-991a1e7905d3",
36 * "wixPayOrderId": "6ff8a88b-6946-43ad-af86-00b90339e10d",
37 * "buyer": {
38 * "memberId": "fac761ea-e6f1-4e3d-8b30-a4852f091416",
39 * "contactId": "fac761ea-e6f1-4e3d-8b30-a4852f091416"
40 * },
41 * "priceDetails": {
42 * "subtotal": "74.99",
43 * "discount": "74.99",
44 * "total": "0",
45 * "planPrice": "74.99",
46 * "currency": "EUR",
47 * "subscription": {
48 * "cycleDuration": {
49 * "count": 1,
50 * "unit": "MONTH"
51 * },
52 * "cycleCount": 3
53 * },
54 * "coupon": {
55 * "code": "ONEMONTHFREE",
56 * "amount": "74.99",
57 * "_id": "5061dd91-8cfc-4948-aae2-66fbc4b31af7"
58 * }
59 * },
60 * "pricing": {
61 * "subscription": {
62 * "cycleDuration": {
63 * "count": 1,
64 * "unit": "MONTH"
65 * },
66 * "cycleCount": 3
67 * },
68 * "prices": [
69 * {
70 * "duration": {
71 * "cycleFrom": 1,
72 * "numberOfCycles": 1
73 * },
74 * "price": {
75 * "subtotal": "74.99",
76 * "coupon": {
77 * "code": "ONEMONTHFREE",
78 * "amount": "74.99",
79 * "_id": "5061dd91-8cfc-4948-aae2-66fbc4b31af7"
80 * },
81 * "discount": "74.99",
82 * "total": "0",
83 * "currency": "EUR"
84 * }
85 * },
86 * {
87 * "duration": {
88 * "cycleFrom": 2,
89 * "numberOfCycles": 2
90 * },
91 * "price": {
92 * "subtotal": "74.99",
93 * "discount": "0",
94 * "total": "74.99",
95 * "currency": "EUR"
96 * }
97 * }
98 * ]
99 * },
100 * "type": "OFFLINE",
101 * "orderMethod": "UNKNOWN",
102 * "status": "ACTIVE",
103 * "autoRenewCanceled": false,
104 * "lastPaymentStatus": "PAID",
105 * "startDate": "2022-09-15T03:00:00.000Z",
106 * "endDate": "2022-12-15T03:00:00.000Z",
107 * "pausePeriods": [],
108 * "earliestEndDate": "2022-12-15T03:00:00.000Z",
109 * "planName": "Platinum Pro",
110 * "planDescription": "",
111 * "planPrice": "74.99",
112 * "_createdDate": "2022-09-12T14:10:16.041Z",
113 * "_updatedDate": "2022-09-12T14:10:16.041Z"
114 * }
115 */
116