# 43 · OnPay: orders, workflows and abandoned carts

**Purpose:** connect your OnPay account so every order from your OnPay order forms becomes a contact in Wsapme, starts your WhatsApp workflows when an order is received, paid, cancelled or gets a tracking number, and reminds customers who left an order form without ordering.

## Before you start

- You are an owner or admin of the workspace. Members can see the OnPay orders list; only owners and admins can connect OnPay or change its settings.
- An OnPay account (`https://yourstore.onpay.my`) on a plan that includes **API & Webhook**.
- At least one connected WhatsApp number, for the workflows that message your customers.

> No real OnPay account was connected while this guide was written, so the steps are described **from the documentation, not captured**.

## Part 1 · Connect OnPay

1. In Wsapme, open **Settings → Integrations** and click **Connect OnPay** on the **OnPay** card.
2. Type your OnPay address, for example `https://yourstore.onpay.my` (just `yourstore` also works).
3. **Webhook Token**: Wsapme suggests a strong token. Click the copy button.
4. In OnPay, open **Settings → System → API & Webhook**. Tick **Enable webhook** and paste the token into **Webhook Token**. If your OnPay account already has a Webhook Token that another tool uses, copy OnPay's token into Wsapme instead: OnPay has one Webhook Token per account.
5. Optional but recommended: in the same OnPay page, tick **Enable API**, set an **API token**, and paste it into **API token** in Wsapme. With it, Wsapme can test the connection and checks your newest orders every 10 minutes, so an order whose webhook was missed, or a tracking number you add later, is still noticed.
6. Click **Connect**. The account is listed with the status **Connected**.

Good to know:

- Wsapme stores both tokens encrypted and never shows them again; the page only shows their last characters.
- You can connect several OnPay accounts to one workspace. Click **Connect another OnPay account**.
- **Change tokens** replaces a token. Leave a field empty to keep the saved one.

## Part 2 · Add the Wsapme webhook address to your order forms

OnPay sends orders to the webhook address set on each order form.

1. On the OnPay page in Wsapme, copy the **Webhook address** of your account.
2. In OnPay, open **Forms**, edit an order form, and paste the address into its **Webhook URL**. Tick the activities you want (new order, confirmed, cancelled).
3. Save the form. Repeat for every order form you sell with.
4. Place a test order on the form with your own phone number. Within seconds it appears under **Orders** in Wsapme, with the badge **Order received**. A contact with your number is created (or your existing contact is used), with the tags you chose.

Good to know:

- OnPay sends three events: **Order received** (a new order), **Paid (confirmed)** and **Cancelled**. Wsapme adds a fourth: **Tracking number added**, when a tracking number appears on the order.
- Each event is handled once per order, even when OnPay sends it again.
- **New webhook address** makes a new address and stops the old one at once. Paste the new address into every order form.

## Part 3 · Settings for each OnPay account

- **Name in Wsapme**: how the account is named in Wsapme and in `{{onpay_store}}`.
- **WhatsApp number for OnPay workflows**: the number that sends the OnPay workflows, unless the workflow chooses its own number.
- **Owner of new contacts** and **Tags for customers (first order)**: given to the customer's contact on their first OnPay order. Tick tags or type a **New tag** and click **Add**. A new OnPay account has the tag **onpay** ticked; untick it if you don't want it. To add tags to customers of earlier orders, save, then click **Also tag existing customers…**: it shows how many customers will get the tags, and adds them only after you confirm. No messages are sent and no workflows start.

Click **Save settings**.

## Part 4 · Send WhatsApp messages with workflows

OnPay messages are workflows, so you can write them, add waits and conditions, and test them in the simulator.

1. Under **Ready-made workflows**, click **Create the starter workflows**. Three workflows are created as **drafts** (off):
   - **OnPay: order confirmation** — thanks the customer when the order is paid, with the items and total.
   - **OnPay: shipping update** — sends the courier and the tracking link when a tracking number is added.
   - **OnPay: abandoned-cart reminder** — reminds a customer who left the order form (Part 5).
2. Click **Draft · open** next to one, edit the text, then switch it on.
3. To build your own: in **Workflows**, create a workflow and choose **Starts when: OnPay order event**. Tick the events (none = any), and optionally the store, a minimum total, or a product (OnPay product ID or code, or words in its name).

Placeholders for OnPay order workflows: `{{onpay_order_no}}`, `{{onpay_status}}`, `{{onpay_items}}`, `{{onpay_total}}`, `{{onpay_payment_method}}`, `{{onpay_courier}}`, `{{onpay_tracking_no}}`, `{{onpay_tracking_url}}`, `{{onpay_name}}`, `{{onpay_address}}`, `{{onpay_invoice_url}}`, `{{onpay_store}}`. The general order placeholders such as `{{order_no}}` and `{{order_tracking_url}}` also work (see [41 · Orders in the inbox and in messages](https://v3.wsapme.com/guides/orders-in-the-inbox-and-messages.md)).

## Part 5 · Abandoned carts

OnPay does not report abandoned carts by itself, so Wsapme gives you a small script for your order forms.

1. In the account's settings, tick **Capture abandoned carts**, choose the **Waiting time** (10 to 1,440 minutes, default 30) and click **Save settings**.
2. Click **Copy script**, and paste it into the custom code (footer script) of each OnPay order form.
3. Open the form in a private browser window, add a product and type a phone number, then close the window. The cart appears under **Abandoned carts** as **Open**.
4. If no order comes from that phone number within the waiting time, the cart becomes **Abandoned** and the workflow **Starts when: OnPay cart abandoned** runs once (for example the starter **OnPay: abandoned-cart reminder**).

Good to know:

- The script only sends the customer's name, e-mail, phone number, the chosen products and the total. Never the address or payment details. Mention it in your privacy notice.
- A cart closes by itself when the customer orders (**Ordered**), or when they order after the reminder (**Recovered**). Customers who opted out of messages get no reminder.
- Placeholders: `{{onpay_name}}`, `{{onpay_cart_items}}`, `{{onpay_cart_total}}`, `{{onpay_cart_url}}` (the order form), `{{onpay_form}}`, `{{onpay_store}}`.
- **New script** stops the old script at once. Replace it on every form.

## Part 6 · Disconnect

Click **Disconnect** on the account. Wsapme deletes the saved tokens and addresses; new orders and carts stop arriving. The orders list stays.

## Common problems

| Problem | What to do |
|---|---|
| "No tags yet" under the tags, so there is nothing to tick | Type a new tag in the **New tag** box and click **Add**. The tag is made in this workspace and ticked at once. Then click **Save settings**. |
| "Enter your OnPay address … it must end in .onpay.my" | Type the OnPay address of your account, such as `https://yourstore.onpay.my`, not your own domain. |
| "OnPay refused this API token." | In OnPay, check that **Enable API** is ticked and copy the API token again, without spaces. Or leave the API token empty: orders still arrive by webhook. |
| Test orders do not appear under **Orders** | Check that the form's **Webhook URL** is the Wsapme address (copy it again), that **Enable webhook** is ticked in OnPay, and that the **Webhook Token** in OnPay ends with the same characters shown in Wsapme. |
| Orders stopped arriving after **New webhook address** | The old address no longer works. Paste the new address into every OnPay order form. |
| The badge says **Order received: skipped** | OnPay sent "order received" after the order was already paid or cancelled, so no workflow started for it. This is normal after OnPay's retries. |
| An order has "This order has no valid phone number" | The customer typed a phone number that is not valid. The order is kept, but no contact or workflow is made. |
| The workflow did not send anything | Check that the workflow is switched on (not a draft), that its events are ticked, and that the account has a WhatsApp number (or the workflow chooses one). |
| The shipping update does not start | It starts when a tracking number appears on the order. Add an **API token** so Wsapme checks your newest orders every 10 minutes. |
| No carts appear under **Abandoned carts** | Check that **Capture abandoned carts** is ticked and saved, and that the script is pasted on the form you test. Type a full phone number: carts without a phone number are not kept. |
| The status says **Check the API token** | OnPay refused the saved API token. Click **Change tokens** and paste the current one. |
