> To build or manage a Wix site with an AI agent, follow https://www.wix.com/headless/skill.md
> It builds a new Wix site or puts your own site online, from a prompt, and keeps changing it afterwards. The pages are code in any web technology, and Wix runs the backend.
> It works through the Wix plugin (the Wix MCP and the Wix skills), the Wix CLI or no Wix login, and puts the site live on Wix hosting or on another host.
> Business features include a store, bookings, events and tickets, a restaurant, a blog, forms, members and many more.
> Read the Wix skills online at https://www.wix.com/skills
> 
> Portal Navigation:
> 
> - Append `.md` to any URL under `https://dev.wix.com/docs/` to get its markdown version.
> - Pages are either content pages (article or reference text) or menu pages (a list of links to child pages).
> - To get a menu page, truncate any URL to a parent path and append `.md` (e.g. `https://dev.wix.com/docs/sdk.md`, `https://dev.wix.com/docs/sdk/core-modules.md`).
> - If a reference page seems to be missing its schema (parameters, return types, or type definitions), append `?schema=true` to its `.md` URL (e.g. `https://dev.wix.com/docs/contexts/contexts/stores/category-info/use-category-info-context.md?schema=true`).
> - Top-level index of all portals: https://dev.wix.com/docs/llms.txt
> - Full concatenated docs: https://dev.wix.com/docs/llms-full.txt

# Method name:

sitePricingPlans.startOnlinePurchase(planId: string, startDate: Date)

# Method Link:

https://dev.wix.com/docs/sdk/frontend-modules/pricing-plans/checkout/start-online-purchase.md

# Method Description:

Orders and purchases a pricing plan.

`startOnlinePurchase()` returns a Promise that resolves to a `Purchase`
 object when the member completes the purchase process. Depending on whether the plan
 is free, the `Purchase` object returns different properties.

 To process pricing plans on a site, a site first must be set up to offer pricing plans
 as described in [Pricing Plans: An Overview](https://support.wix.com/en/article/pricing-plans-an-overview).
 When setting up a site to accept pricing plans, [define the plans you want to offer](https://support.wix.com/en/article/pricing-plans-creating-a-one-time-payment-plan),
 including the payment method.

 Purchasing a plan orders the plan and continues the
 payment process with the [Wix Pay API](https://dev.wix.com/docs/velo/apis/wix-pay-frontend/introduction.md). After payment is complete, the plan
 is assigned to the member.

 To understand the lifecycle of how `startOnlinePurchase()` is used,
 see [Direct Purchase of a Pricing Plan](https://dev.wix.com/docs/velo/apis/wix-pricing-plans-frontend/introduction.md#apis_wix-pricing-plans-frontend_direct-order-of-a-pricing-plan).

 > **Note:**
 > + To work with the Pricing Plans API, a site needs to be published publish.

# Method Permissions:



# Method Permissions Scopes IDs:

undefined



# Method Code Examples:

## Purchase a non-free plan on button click

```javascript
import { checkout } from '@wix/site-pricing-plans';

// Sample planId value: '099e2c86-3b7e-4477-8c27-f77402b8cced'

$w('#myOrderButton').onClick((event) => {
    checkout.startOnlinePurchase(planId)
    .then((purchasedOrder) => {
      const myOrderId = purchasedOrder.order._id;
      const myWixPayOrderId = purchasedOrder.order.wixPayOrderId;
      const myWixPayStatus = purchasedOrder.wixPayOrderStatus   

      console.log('Success! Created order:', purchasedOrder);
      return purchasedOrder;
    })
    .catch((error) => {
        console.error(error);
    })
});

/* myPurchase object after payment processed
 * {
 *   "_id": "89dcd5fd-8c6b-4b76-93b7-ee7160366583",
 *   "planId": "099e2c86-3b7e-4477-8c27-f77402b8cceb",
 *   "subscriptionId": "18926aae-b6d0-4487-a8de-7e1b8dd97441",
 *   "wixPayOrderId": "69fd8594-6b40-4fd8-9da4-9ea8cb5dff49",
 *   "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": "ONLINE",
 *   "orderMethod": "UNKNOWN",
 *   "status": "DRAFT",
 *   "autoRenewCanceled": false,
 *   "lastPaymentStatus": "UNPAID",
 *   "startDate": "2022-08-23T22:59:18.864Z",
 *   "endDate": "2022-11-23T22:59:18.864Z",
 *   "pausePeriods": [],
 *   "earliestEndDate": "2022-11-23T22:59:18.864Z",
 *   "currentCycle": {
 *     "index": 1,
 *     "startedDate": "2022-08-23T22:59:18.864Z",
 *     "endedDate": "2022-09-23T22:59:18.864Z"
 *   },
 *   "planName": "Platinum Pro",
 *   "planDescription": "",
 *   "planPrice": "74.99",
 *   "_createdDate": "2022-08-23T22:59:18.864Z",
 *   "_updatedDate": "2022-08-23T22:59:18.864Z"
 * }
 */
```

## Purchase a free plan that will start at a later date

```javascript
import { checkout } from '@wix/site-pricing-plans';

// Sample planId value: '099e2c86-3b7e-4477-8c27-f77402b8cced'
//
// Sample startDate value: new Date('2022-08-25T07:44:00.000Z')

$w('#buyPlanButton').onClick((event) => {
  checkout.startOnlinePurchase(planId, startDate)
  .then((freeOrder) => {
      const myOrderId = freeOrder.order._id; 
      const myOrderType = freeOrder.order.type;
      console.log('Success! Created order:', freeOrder);
      return freeOrder;          
  })
  .catch((error) => {
    console.error(error);
  })      
});

/* The object returns without wixPay properties,
 * because no payment is necessary.
 * {
 *   "_id": "d9667014-b773-40b1-871d-041cedd9302e",
 *   "planId": "60f0e90f-06f6-4b9c-8cd7-5a02d015d98b",
 *   "subscriptionId": "14e11d7d-46e2-46be-a8a0-5484f595701c",
 *   "buyer": {
 *     "memberId": "0c9bca47-1f00-4b92-af1c-7852452e949a",
 *     "contactId": "0c9bca47-1f00-4b92-af1c-7852452e949a"
 *   },
 *   "priceDetails": {
 *     "subtotal": "0",
 *     "discount": "0",
 *     "total": "0",
 *     "planPrice": "0",
 *     "currency": "EUR",
 *     "singlePaymentForDuration": {
 *       "count": 1,
 *       "unit": "MONTH"
 *     }
 *   },
 *   "pricing": {
 *     "singlePaymentForDuration": {
 *       "count": 1,
 *       "unit": "MONTH"
 *     },
 *     "prices": [
 *       {
 *         "duration": {
 *           "cycleFrom": 1,
 *           "numberOfCycles": 1
 *         },
 *         "price": {
 *           "subtotal": "0",
 *           "discount": "0",
 *           "total": "0",
 *           "currency": "EUR"
 *         }
 *       }
 *     ]
 *   },
 *   "type": "ONLINE",
 *   "orderMethod": "UNKNOWN",
 *   "status": "ACTIVE",
 *   "lastPaymentStatus": "NOT_APPLICABLE",
 *   "startDate": "2022-08-25T07:44:00.000Z",
 *   "endDate": "2022-09-25T07:44:00.000Z",
 *   "pausePeriods": [],
 *   "earliestEndDate": "2022-09-25T07:44:00.000Z",
 *   "planName": "Free Trial",
 *   "planDescription": "Come try it out!",
 *   "planPrice": "0",
 *   "_createdDate": "2022-08-23T23:57:36.745Z",
 *   "_updatedDate": "2022-08-23T23:57:36.745Z"
 * }
 */
```