Creates an order for a buyer who purchased the plan with an offline transaction.
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:
true
in the paid
request parameter.markAsPaid()
function.Creating a non-free offline order causes:
"PENDING"
if the start date is in the future. Otherwise, the status is set to "ACTIVE"
."UNPAID"
or "PAID"
.Creating a free offline order causes:
"PENDING"
if the start date is in the future. Otherwise, the status is set to "ACTIVE"
."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
.
function createOfflineOrder(
planId: string,
buyerId: string,
options: CreateOfflineOrderOptions,
): Promise<Order>;
ID of the plan being ordered.
Member ID for the buyer.
Additional options for creating the offline order.
import { Permissions, webMethod } from "wix-web-module";
import { checkout } from "wix-pricing-plans-backend";
// Sample planId value: '099e2c86-3b7e-4477-8c27-f77402b8cceb'
//
// Sample buyerId value: '0c9bca47-1f00-4b92-af1c-7852452e949a'
export const myCreateOfflineOrderFunction = webMethod(
Permissions.Anyone,
async (planId, buyerId) => {
try {
const order = await checkout.createOfflineOrder(planId, buyerId);
const plan = order.planName;
const orderType = order.type;
return order;
} catch (error) {
console.error(error);
}
},
);
/* Promise resolves to:
*
* {
* "_id": "810a10b7-9da4-4de3-87e3-b4a3d7ed9654",
* "planId": "099e2c86-3b7e-4477-8c27-f77402b8cceb",
* "subscriptionId": "8bd53121-a1b3-4754-981e-64d5779a6821",
* "wixPayOrderId": "6c56901d-d17f-44c8-acfa-05979b63e11f",
* "buyer": {
* "memberId": "0c9bca47-1f00-4b92-af1c-7852452e949a",
* "contactId": "0c9bca47-1f00-4b92-af1c-7852452e949a"
* },
* "priceDetails": {
* "subtotal": "74.99",
* "discount": "0",
* "total": "74.99",
* "planPrice": "74.99",
* "currency": "EUR",
* "subscription": {
* "cycleDuration": {
* "count": 1,
* "unit": "MONTH"
* },
* "cycleCount": 3
* }
* },
* "pricing": {
* "subscription": {
* "cycleDuration": {
* "count": 1,
* "unit": "MONTH"
* },
* "cycleCount": 3
* },
* "prices": [
* {
* "duration": {
* "cycleFrom": 1,
* "numberOfCycles": 3
* },
* "price": {
* "subtotal": "74.99",
* "discount": "0",
* "total": "74.99",
* "currency": "EUR"
* }
* }
* ]
* },
* "type": "OFFLINE",
* "orderMethod": "UNKNOWN",
* "status": "ACTIVE",
* "autoRenewCanceled": false,
* "lastPaymentStatus": "UNPAID",
* "startDate": "2022-07-13T04:20:50.320Z",
* "endDate": "2022-10-13T04:20:50.320Z",
* "pausePeriods": [],
* "earliestEndDate": "2022-10-13T04:20:50.320Z",
* "currentCycle": {
* "index": 1,
* "startedDate": "2022-07-13T04:20:50.320Z",
* "endedDate": "2022-08-13T04:20:50.320Z"
* },
* "planName": "Platinum Pro",
* "planDescription": "",
* "planPrice": "74.99",
* "_createdDate": "2022-07-13T04:20:50.320Z",
* "_updatedDate": "2022-07-13T04:20:50.320Z"
* }
*/
This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.