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.
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.
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"
.
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
ID of the member ordering the plan.
Options for creating an offline order.
Returns
Fulfilled - The order of the plan.
Return Type:
NAME
TYPE
DESCRIPTION
Order.
Was this helpful?
1import { orders } from 'wix-pricing-plans.v2';23/* Sample planId value: 'cb4a8c57-273a-4567-94e3-cc43d5d339f2'4 *5 * Sample memberId value: '554c9e11-f4d8-4579-ac3a-a17f7e6cb0b4'6 */78export async function myCreateOfflineOrderFunction(planId, memberId) {9 try {10 const newOrder = await orders.createOfflineOrder(planId, memberId);1112 return newOrder;13 } catch (error) {14 console.error(error);15 // Handle the error16 }17}1819/* Promise resolves to:20 * {21 * "_createdDate": "2024-01-28T09:49:21.041Z",22 * "_id": "82d99338-5653-459a-a751-b57483f7cfb5",23 * "_updatedDate": "2024-01-28T09:49:21.041Z",24 * "autoRenewCanceled": false,25 * "buyer": {26 * "contactId": "554c9e11-f4d8-4579-ac3a-a17f7e6cb0b4",27 * "memberId": "554c9e11-f4d8-4579-ac3a-a17f7e6cb0b4"28 * },29 * "currentCycle": {30 * "endedDate": "2024-04-27T09:49:21.041Z",31 * "index": 0,32 * "startedDate": "2024-01-28T09:49:21.041Z"33 * },34 * "cycles": [35 * {36 * "endedDate": "2024-04-27T09:49:21.041Z",37 * "index": 0,38 * "startedDate": "2024-01-28T09:49:21.041Z"39 * }40 * ],41 * "earliestEndDate": "2026-04-27T09:49:21.041Z",42 * "endDate": "2026-04-27T09:49:21.041Z",43 * "formData": {44 * "submissionData": {45 * "formId": "3ef36359-24bd-471a-aa8b-a5ca683b50f4",46 * "submissionData": {},47 * "submissionId": "e65d5d60-7e07-4d2f-971f-e471dcebd0d2"48 * },49 * },50 * "freeTrialDays": 90,51 * "lastPaymentStatus": "UNPAID",52 * "pausePeriods": [],53 * "planDescription": "3 mo free trial with discount for 1 year",54 * "planId": "cb4a8c57-273a-4567-94e3-cc43d5d339f2",55 * "planName": "Beginner's Plan",56 * "planPrice": "50",57 * "pricing": {58 * "prices": [59 * {60 * "duration": {61 * "cycleFrom": 1,62 * "numberOfCycles": 263 * },64 * "price": {65 * "currency": "USD",66 * "discount": "0",67 * "fees": [],68 * "proration": "0",69 * "subtotal": "50.00",70 * "total": "50.00"71 * }72 * }73 * ],74 * "subscription": {75 * "cycleCount": 2,76 * "cycleDuration": {77 * "count": 1,78 * "unit": "YEAR"79 * }80 * }81 * },82 * "startDate": "2024-01-28T09:49:21.041Z",83 * "statusNew": "DRAFT",84 * "subscriptionId": "305f8fc9-3724-4cac-9f67-4e29f2c46def",85 * "type": "OFFLINE",86 * "wixPayOrderId": "2f0e79d8-f15d-46c6-ac1a-10ec7a2030fb"87 * }88 */
1import { Permissions, webMethod } from 'wix-web-module';2import { orders } from 'wix-pricing-plans.v2';3import { elevate } from 'wix-auth';45/*6 * Sample planId value: 'cb4a8c57-273a-4567-94e3-cc43d5d339f2'7 *8 * Sample memberId value: '554c9e11-f4d8-4579-ac3a-a17f7e6cb0b4'9 */1011const elevatedCreateOfflineOrder = elevate(orders.createOfflineOrder);1213export const myCreateOfflineOrderFunction = webMethod(Permissions.Anyone, async (planId, memberId) => {14 try {15 const newOrder = await elevatedCreateOfflineOrder(planId, memberId);1617 return newOrder;18 } catch (error) {19 console.error(error);20 // Handle the error21 }22});2324/* Promise resolves to:25 * {26 * "_createdDate": "2024-01-28T09:49:21.041Z",27 * "_id": "82d99338-5653-459a-a751-b57483f7cfb5",28 * "_updatedDate": "2024-01-28T09:49:21.041Z",29 * "autoRenewCanceled": false,30 * "buyer": {31 * "contactId": "554c9e11-f4d8-4579-ac3a-a17f7e6cb0b4",32 * "memberId": "554c9e11-f4d8-4579-ac3a-a17f7e6cb0b4"33 * },34 * "currentCycle": {35 * "endedDate": "2024-04-27T09:49:21.041Z",36 * "index": 0,37 * "startedDate": "2024-01-28T09:49:21.041Z"38 * },39 * "cycles": [40 * {41 * "endedDate": "2024-04-27T09:49:21.041Z",42 * "index": 0,43 * "startedDate": "2024-01-28T09:49:21.041Z"44 * }45 * ],46 * "earliestEndDate": "2026-04-27T09:49:21.041Z",47 * "endDate": "2026-04-27T09:49:21.041Z",48 * "formData": {49 * "submissionData": {50 * "formId": "3ef36359-24bd-471a-aa8b-a5ca683b50f4",51 * "submissionData": {},52 * "submissionId": "e65d5d60-7e07-4d2f-971f-e471dcebd0d2"53 * },54 * },55 * "freeTrialDays": 90,56 * "lastPaymentStatus": "UNPAID",57 * "pausePeriods": [],58 * "planDescription": "3 mo free trial with discount for 1 year",59 * "planId": "cb4a8c57-273a-4567-94e3-cc43d5d339f2",60 * "planName": "Beginner's Plan",61 * "planPrice": "50",62 * "pricing": {63 * "prices": [64 * {65 * "duration": {66 * "cycleFrom": 1,67 * "numberOfCycles": 268 * },69 * "price": {70 * "currency": "USD",71 * "discount": "0",72 * "fees": [],73 * "proration": "0",74 * "subtotal": "50.00",75 * "total": "50.00"76 * }77 * }78 * ],79 * "subscription": {80 * "cycleCount": 2,81 * "cycleDuration": {82 * "count": 1,83 * "unit": "YEAR"84 * }85 * }86 * },87 * "startDate": "2024-01-28T09:49:21.041Z",88 * "statusNew": "DRAFT",89 * "subscriptionId": "305f8fc9-3724-4cac-9f67-4e29f2c46def",90 * "type": "OFFLINE",91 * "wixPayOrderId": "2f0e79d8-f15d-46c6-ac1a-10ec7a2030fb"92 * }93 */94
This example provides a dropdown list of site members and public plans to complete a manual offline transaction.
1/*******************************2 * Backend code - utils.web.js *3 *******************************/45import { Permissions, webMethod } from 'wix-web-module';6import { orders, plans } from 'wix-pricing-plans.v2';7import { elevate } from 'wix-auth';89const elevatedListPublicPlans = elevate(plans.listPublicPlans);10const elevatedCreateOfflineOrder = elevate(orders.createOfflineOrder);11const elevatedMarkAsPaid = elevate(orders.markAsPaid);1213export const listPublicPlans = webMethod(14 Permissions.Anyone,15 async () => {16 try {17 const plansResponse = await elevatedListPublicPlans();18 const plans = plansResponse.plans;1920 return plans;21 } catch (error) {22 console.error(error);23 // Handle the error24 }25 });2627export const createOfflineOrder = webMethod(28 Permissions.Anyone,29 async (planId, memberId) => {30 try {31 const newOrder = await elevatedCreateOfflineOrder(planId, memberId);3233 return newOrder;34 } catch (error) {35 console.error(error);36 // Handle the error37 }38 });3940export const markAsPaid = webMethod(41 Permissions.Anyone,42 async (orderId) => {43 try {44 await elevatedMarkAsPaid(orderId);4546 return;47 } catch (error) {48 console.error(error);49 // Handle the error50 }51 });525354/*************55 * Page code *56 *************/5758import { createOfflineOrder, listPublicPlans, markAsPaid } from 'backend/utils.web';59import { members } from 'wix-members.v2';6061$w.onReady(async function () {62 $w('#newOrderBtn').disable();63 await populatePlansDropdown();64 let planId;65 let memberId;6667 // Populate #membersDropdown68 const membersQueryResults = await members.queryMembers().find();69 $w('#membersListDropdown').options = membersQueryResults.items.map(member => {70 return {71 label: member.profile.nickname,72 value: member._id73 }74 });7576 $w('#membersListDropdown').onChange(() => {77 memberId = $w('#membersListDropdown').value;78 });7980 $w('#plansDropdown').onChange(() => {81 planId = $w('#plansDropdown').value;82 $w('#newOrderBtn').enable();83 });8485 $w('#newOrderBtn').onClick(async () => {86 const newOrder = await createOfflineOrder(planId, memberId);87 const orderId = newOrder.orders._id;88 markAsPaid(orderId);89 });90});9192async function populatePlansDropdown() {93 const plans = await listPublicPlans();94 $w('#plansListDropdown').options = plans.map((item) => {95 return {96 label: item.name,97 value: item._id98 }99 });100}
1import { Permissions, webMethod } from 'wix-web-module';2import { orders } from 'wix-pricing-plans.v2';3import { elevate } from 'wix-auth';45/*6 * Sample planId value: 'cb4a8c57-273a-4567-94e3-cc43d5d339f2'7 *8 * Sample memberId value: '554c9e11-f4d8-4579-ac3a-a17f7e6cb0b4'9 *10 * Sample options value:11 * {12 * couponCode: 'e4ddd93a-5601-4696-99dd-3356f0e558c0',13 * paid: true,14 * startDate: '2024-01-29T11:50:21.041Z',15 * submissionId: '9e128ddb-f62f-4a4a-adb5-064af40f18db'16 * }17 */1819const elevatedCreateOfflineOrder = elevate(orders.createOfflineOrder);2021export const myCreateOfflineOrderFunctionWithOptions = webMethod(Permissions.Anyone, async (planId, memberId, options) => {22 try {23 const newOrder = await elevatedCreateOfflineOrder(planId, memberId, options);2425 return newOrder;26 } catch (error) {27 console.error(error);28 // Handle the error29 }30});3132/* Promise resolves to:33 * {34 * order: {35 * "_createdDate": "2024-01-28T09:49:21.041Z",36 * "_id": "82d99338-5653-459a-a751-b57483f7cfb5",37 * "_updatedDate": "2024-01-28T09:49:21.041Z",38 * "autoRenewCanceled": false,39 * "buyer": {40 * "contactId": "554c9e11-f4d8-4579-ac3a-a17f7e6cb0b4",41 * "memberId": "554c9e11-f4d8-4579-ac3a-a17f7e6cb0b4"42 * },43 * "cycles": [44 * {45 * "endedDate": "2024-04-27T09:49:21.041Z",46 * "index": 0,47 * "startedDate": "2024-01-28T09:49:21.041Z"48 * }49 * ],50 * "currentCycle": {51 * "endedDate": "2024-04-27T09:49:21.041Z",52 * "index": 0,53 * "startedDate": "2024-01-28T09:49:21.041Z"54 * },55 * "endDate": "2026-04-27T09:49:21.041Z",56 * "earliestEndDate": "2026-04-27T09:49:21.041Z",57 * "formData": {58 * "formId": "3ef36359-24bd-471a-aa8b-a5ca683b50f4",59 * "submissionData": {},60 * "submissionId": "e65d5d60-7e07-4d2f-971f-e471dcebd0d2"61 * },62 * "freeTrialDays": 90,63 * "lastPaymentStatus": "UNPAID",64 * "pausePeriods": [],65 * "planDescription": "3 mo free trial with discount for 1 year",66 * "planId": "cb4a8c57-273a-4567-94e3-cc43d5d339f2",67 * "planName": "Beginner's Plan",68 * "planPrice": "50",69 * "pricing": {70 * "prices": [71 * {72 * "duration": {73 * "cycleFrom": 1,74 * "numberOfCycles": 275 * },76 * "price": {77 * "currency": "USD",78 * "discount": "0",79 * "fees": [],80 * "proration": "0",81 * "subtotal": "50.00",82 * "total": "50.00"83 * }84 * }85 * ],86 * "subscription": {87 * "cycleCount": 2,88 * "cycleDuration": {89 * "count": 1,90 * "unit": "YEAR"91 * }92 * }93 * },94 * "startDate": "2024-01-28T09:49:21.041Z",95 * "status": "ACTIVE",96 * "statusNew": "DRAFT",97 * "subscriptionId": "305f8fc9-3724-4cac-9f67-4e29f2c46def",98 * "type": "OFFLINE",99 * "wixPayOrderId": "2f0e79d8-f15d-46c6-ac1a-10ec7a2030fb"100 * }101 * }102 */103