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 thecreateOfflineOrder()
APIs replace the deprecated paid plansorderPlan()
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 thepaid
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 totrue
.
Syntax
function createOfflineOrder(planId: string, buyerId: string, [options: CreateOfflineOrderOptions]): Promise<Order>
createOfflineOrder Parameters
NAME
TYPE
DESCRIPTION
ID of the plan being ordered.
Member ID for the buyer.
Additional options for creating the offline order.
Returns
Fulfilled - The order of the plan.
Return Type:
NAME
TYPE
DESCRIPTION
Order ID.
ID of the plan that was ordered.
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.
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.
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
.
Deprecated. Use pricing
instead.
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 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.
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.
Details about the cancellation of an order. Only present if the status
is "CANCELED"
.
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.
Start date and time for the ordered plan.
List of periods during which this order is paused.
Free trial period, in days. Only available for recurring plans.
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.
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.
Name of the plan at the time of the order.
Description of the plan at the time of the order.
Plan price as it was at the moment of order creation.
Date and time the order was created.
Date and time the order was last updated. For example, the date and time an order was paused, resumed, or canceled.
Related Content:
Was this helpful?
1import { checkout } from 'wix-pricing-plans-backend';23// Sample planId value: '099e2c86-3b7e-4477-8c27-f77402b8cceb'4//5// Sample buyerId value: '0c9bca47-1f00-4b92-af1c-7852452e949a'67export async function myCreateOfflineOrderFunction(planId, buyerId) {8 try {9 const order = await checkout.createOfflineOrder(planId, buyerId);10 const plan = order.planName;11 const orderType = order.type;1213 return order;14 } catch (error) {15 console.error(error);16 }17}1819/* Promise resolves to:20 *21 * {22 * "_id": "810a10b7-9da4-4de3-87e3-b4a3d7ed9654",23 * "planId": "099e2c86-3b7e-4477-8c27-f77402b8cceb",24 * "subscriptionId": "8bd53121-a1b3-4754-981e-64d5779a6821",25 * "wixPayOrderId": "6c56901d-d17f-44c8-acfa-05979b63e11f",26 * "buyer": {27 * "memberId": "0c9bca47-1f00-4b92-af1c-7852452e949a",28 * "contactId": "0c9bca47-1f00-4b92-af1c-7852452e949a"29 * },30 * "priceDetails": {31 * "subtotal": "74.99",32 * "discount": "0",33 * "total": "74.99",34 * "planPrice": "74.99",35 * "currency": "EUR",36 * "subscription": {37 * "cycleDuration": {38 * "count": 1,39 * "unit": "MONTH"40 * },41 * "cycleCount": 342 * }43 * },44 * "pricing": {45 * "subscription": {46 * "cycleDuration": {47 * "count": 1,48 * "unit": "MONTH"49 * },50 * "cycleCount": 351 * },52 * "prices": [53 * {54 * "duration": {55 * "cycleFrom": 1,56 * "numberOfCycles": 357 * },58 * "price": {59 * "subtotal": "74.99",60 * "discount": "0",61 * "total": "74.99",62 * "currency": "EUR"63 * }64 * }65 * ]66 * },67 * "type": "OFFLINE",68 * "orderMethod": "UNKNOWN",69 * "status": "ACTIVE",70 * "autoRenewCanceled": false,71 * "lastPaymentStatus": "UNPAID",72 * "startDate": "2022-07-13T04:20:50.320Z",73 * "endDate": "2022-10-13T04:20:50.320Z",74 * "pausePeriods": [],75 * "earliestEndDate": "2022-10-13T04:20:50.320Z",76 * "currentCycle": {77 * "index": 1,78 * "startedDate": "2022-07-13T04:20:50.320Z",79 * "endedDate": "2022-08-13T04:20:50.320Z"80 * },81 * "planName": "Platinum Pro",82 * "planDescription": "",83 * "planPrice": "74.99",84 * "_createdDate": "2022-07-13T04:20:50.320Z",85 * "_updatedDate": "2022-07-13T04:20:50.320Z"86 * }87 */
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.
1import { checkout } from 'wix-pricing-plans-backend';23/* Sample planId value: '099e2c86-3b7e-4477-8c27-f77402b8cceb'4 *5 * Sample buyerId value: 'fac761ea-e6f1-4e3d-8b30-a4852f091416'6 *7 * Sample options value:8 * {9 * startDate: new Date('2022-09-15T03:00:00Z'),10 * paid: true,11 * suppressAuth: true,12 * couponCode: 'ONEMONTHFREE'13 * }14 */1516export async function myCreateOfflineOrderWithOptionsFunction(planId, buyerId, options) {17 try {18 const order = await checkout.createOfflineOrder(planId, buyerId, options);19 const plan = order.planName;20 const orderType = order.type;2122 return order;23 } catch (error) {24 console.error(error);25 }26}2728/* Promise resolves to:29 *30 * {31 * "_id": "5080a56a-b6f6-4841-b5ad-2d46e9702619",32 * "planId": "099e2c86-3b7e-4477-8c27-f77402b8cceb",33 * "subscriptionId": "00f669b9-9084-43b2-bcdf-991a1e7905d3",34 * "wixPayOrderId": "6ff8a88b-6946-43ad-af86-00b90339e10d",35 * "buyer": {36 * "memberId": "fac761ea-e6f1-4e3d-8b30-a4852f091416",37 * "contactId": "fac761ea-e6f1-4e3d-8b30-a4852f091416"38 * },39 * "priceDetails": {40 * "subtotal": "74.99",41 * "discount": "74.99",42 * "total": "0",43 * "planPrice": "74.99",44 * "currency": "EUR",45 * "subscription": {46 * "cycleDuration": {47 * "count": 1,48 * "unit": "MONTH"49 * },50 * "cycleCount": 351 * },52 * "coupon": {53 * "code": "ONEMONTHFREE",54 * "amount": "74.99",55 * "_id": "5061dd91-8cfc-4948-aae2-66fbc4b31af7"56 * }57 * },58 * "pricing": {59 * "subscription": {60 * "cycleDuration": {61 * "count": 1,62 * "unit": "MONTH"63 * },64 * "cycleCount": 365 * },66 * "prices": [67 * {68 * "duration": {69 * "cycleFrom": 1,70 * "numberOfCycles": 171 * },72 * "price": {73 * "subtotal": "74.99",74 * "coupon": {75 * "code": "ONEMONTHFREE",76 * "amount": "74.99",77 * "_id": "5061dd91-8cfc-4948-aae2-66fbc4b31af7"78 * },79 * "discount": "74.99",80 * "total": "0",81 * "currency": "EUR"82 * }83 * },84 * {85 * "duration": {86 * "cycleFrom": 2,87 * "numberOfCycles": 288 * },89 * "price": {90 * "subtotal": "74.99",91 * "discount": "0",92 * "total": "74.99",93 * "currency": "EUR"94 * }95 * }96 * ]97 * },98 * "type": "OFFLINE",99 * "orderMethod": "UNKNOWN",100 * "status": "ACTIVE",101 * "autoRenewCanceled": false,102 * "lastPaymentStatus": "PAID",103 * "startDate": "2022-09-15T03:00:00.000Z",104 * "endDate": "2022-12-15T03:00:00.000Z",105 * "pausePeriods": [],106 * "earliestEndDate": "2022-12-15T03:00:00.000Z",107 * "planName": "Platinum Pro",108 * "planDescription": "",109 * "planPrice": "74.99",110 * "_createdDate": "2022-09-12T14:10:16.041Z",111 * "_updatedDate": "2022-09-12T14:10:16.041Z"112 * }113 */