markAsPaid( )
Marks an offline order as paid.
Description
The markAsPaid()
function returns a Promise that resolves when the offline order is successfully marked as paid.
The entire order is marked as paid, even if the order's payments are recurring.
Note: Marking separate payment cycles as paid is not yet supported. Subsequent offline payments do trigger events and emails, but are not registered as additional offline payments.
Marking an offline order as paid causes the following changes:
- The order's
lastPaymentStatus
changes to"PAID"
. - The order's status changes to either
"PENDING"
or"ACTIVE"
, depending on the order'sstartDate
.
An error occurs if you attempt to:
- Mark an already-paid, offline order as paid. You cannot make an offline order as paid twice.
- Mark an online order as paid. The
markAsPaid()
function is supported for offline orders only.
This function requires elevated permissions to run. This function is not universal and runs only on the backend.
Syntax
function markAsPaid(_id: string): Promise<void>
markAsPaid Parameters
NAME
TYPE
DESCRIPTION
Order ID.
Returns
Fulfilled - When the order is marked as paid.
Return Type:
Was this helpful?
1import { orders } from 'wix-pricing-plans.v2';2import { elevate } from 'wix-auth';34/* Sample _id value: '82d99338-5653-459a-a751-b57483f7cfb5' */56const elevatedMarkAsPaid = elevate(orders.markAsPaid);78export async function myMarkAsPaidFunction(_id) {9 try {10 await elevatedMarkAsPaid(_id);1112 return;13 } catch (error) {14 console.error(error);15 // Handle the error16 }17}1819/* Promise resolves to void */
1import { Permissions, webMethod } from 'wix-web-module';2import { orders } from 'wix-pricing-plans.v2';3import { elevate } from 'wix-auth';45// Sample _id value: '82d99338-5653-459a-a751-b57483f7cfb5'67const elevatedMarkAsPaid = elevate(orders.markAsPaid);89export const myMarkAsPaidFunction = webMethod(Permissions.Anyone, async (_id) => {10 try {11 await elevatedMarkAsPaid(_id);1213 return;14 } catch (error) {15 console.error(error);16 // Handle the error17 }18});1920/* Promise resolves to void */21
In this example, the page code provides a checkable list of unpaid customer orders. The site owner or admin selects the unpaid orders to be cancelled or updated to a PAID
payment status.
1/*******************************2 * Backend code - utils.web.js *3 *******************************/45import { Permissions, webMethod } from 'wix-web-module';6import { orders } from 'wix-pricing-plans.v2';7import { elevate } from 'wix-auth';89const elevatedManagementListOrders = elevate(orders.managementListOrders);10const elevatedCancelOrder = elevate(orders.cancelOrder);11const elevatedMarkAsPaid = elevate(orders.markAsPaid);1213export const getUnpaidOrders = webMethod(14 Permissions.Anyone,15 async () => {16 const options = { paymentStatuses: 'UNPAID' };17 try {18 const ordersList = await elevatedManagementListOrders(options);1920 return ordersList;21 } catch (error) {22 console.error(error);23 // Handle the error24 }25 });2627export const cancelOrder = webMethod(28 Permissions.Anyone,29 async (orderId) => {30 const effectiveAt = 'NEXT_PAYMENT_DATE';31 try {32 await elevatedCancelOrder(orderId, effectiveAt);3334 return;35 } catch (error) {36 console.error(error);37 // Handle the error38 }39 });4041export const markAsPaid = webMethod(42 Permissions.Anyone,43 async (orderId) => {44 try {45 await elevatedMarkAsPaid(orderId);4647 return;48 } catch (error) {49 console.error(error);50 // Handle the error51 }52 });5354/*************55 * Page code *56 *************/5758import { getUnpaidOrders, cancelOrder, markAsPaid } from 'backend/utils.web';5960$w.onReady(function () {61 $w('#ordersCheckbox').hide();62 $w('#markAsPaidBtn').disable();63 $w('#cancelOrderBtn').disable();646566 populateOrdersCheckbox();67 let orderValues;6869 $w('#ordersCheckbox').onChange(() => {70 orderValues = $w('#ordersCheckbox').value;71 });7273 // Cancel multiple orders74 $w('#cancelOrderBtn').onClick(() => {75 orderValues.forEach(async (orderId) => {76 await cancelOrder(orderId);77 });78 });7980 // Mark multiple orders as paid81 $w('#markAsPaidBtn').onClick(() => {82 orderValues.forEach(async (orderId) => {83 await markAsPaid(orderId);84 });85 });86});8788async function populateOrdersCheckbox() {89 const unpaidOrders = await getUnpaidOrders();9091 // Displays each order with its corresponding member ID92 $w('#ordersCheckbox').options = unpaidOrders.orders.map(item => {93 return {94 label: `${item.planName} - memberId: ${item.buyer.memberId}`,95 value: item._id96 }97 });98 $w('#ordersCheckbox').show();99 $w('#markAsPaidBtn').enable();100 $w('#cancelOrderBtn').enable();101}
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}