# Odoo plugin

> Install TapPay for Odoo, set the keys and the webhook, test in the sandbox, and refund payments.

Source: https://docs.tappay.mn/no-code/plugins/odoo/

The TapPay module for Odoo (`payment_tappay`) opens a hosted [checkout session](https://docs.tappay.mn/glossary.md#checkout-session) for each [payment](https://docs.tappay.mn/glossary.md#payment) transaction and marks it as paid when TapPay confirms the payment. If you prefer to connect your shop with code, follow the [checkout guide](https://docs.tappay.mn/guides/checkout.md) instead.

## Requirements {#requirements}

| Plugin version | Minimum platform | Minimum runtime |
| - | - | - |
| `0.1.0` | Odoo 19.0 (Community/Enterprise) | Python 3.12 |

- An Odoo database with the currency of the order set to MNT. The module offers TapPay only for payments in MNT.
- A merchant account in TapPay, with at least one [terminal](https://docs.tappay.mn/glossary.md#terminal). With [one-click connect](#connect), the module gets its key and webhook for you. For [manual setup](#manual-setup), you need a [sandbox](https://docs.tappay.mn/glossary.md#sandbox) [secret key](https://docs.tappay.mn/glossary.md#secret-key). The key needs the `checkout:write`, `payments:write` and `refunds:write` [scopes](https://docs.tappay.mn/glossary.md#scope). The `webhooks:manage` scope is optional: with it, the module can also check your [webhook endpoint](https://docs.tappay.mn/glossary.md#webhook-endpoint).
- A public HTTPS address for your Odoo server, so that TapPay can send webhooks to it.

## Install {#install}

The module is not on Odoo Apps yet. Download it from the merchant portal.

1. In the merchant portal, open **Connections › TapPay systems › Online store** and choose **Download plugin (.zip)** for Odoo. You get the file `payment_tappay.zip`, which contains the folder `payment_tappay`.
2. Unzip the file into a folder of the `addons_path` of your Odoo server. Then restart Odoo, open **Apps**, update the app list, and install **TapPay Payment Provider**.
3. Open **Accounting > Configuration > Payment Providers** (or **Website > Configuration > Payment Providers**) and open **TapPay**.

## Configure {#configure}

### Connect in one click {#connect}

1. In the provider form, choose **Connect to TapPay** for the sandbox (**Test Mode**).
2. The merchant portal opens. Sign in if it asks. A sandbox connection opens the sandbox portal, and a [production](https://docs.tappay.mn/glossary.md#production) connection opens the production portal.
3. Check the site address on the page. The connection belongs to one terminal: if your business has several, choose one.
4. Choose **Approve**. In production, the portal may ask for two-step verification first. After it, choose **Approve** again.
5. The portal sends you back to Odoo. The module saves the keys and shows **Connected**.

The connection creates a secret key with the `checkout:write`, `payments:write`, `refunds:write` and `webhooks:manage` scopes. It also creates a webhook endpoint with the [events](https://docs.tappay.mn/glossary.md#event) that the module needs. To approve, you need the permissions to manage API keys and webhooks. In Odoo, only users in the Administration / Settings group can connect.

To go live, choose **Connect to TapPay** for production, then set the provider state to **Enabled**. The production connection is separate from the sandbox one.

To disconnect, choose **Disconnect** in the provider form, or open the system under **Developers › API keys & webhooks** in the merchant portal and choose **Disable**. Both revoke the key and disable the webhook endpoint.

### Manual setup (fallback) {#manual-setup}

Use these steps when you cannot use one-click connect. In the provider form, the fields are under **Manual setup**.

1. Sign in to the merchant portal in the sandbox and create a secret key. Your sandbox key looks like `sk_test_YOUR_SECRET_KEY`, and it starts with `sk_test_`.
2. In the merchant portal, open **Developers › API keys & webhooks** and create a webhook endpoint with the URL `https://your-odoo.example/payment/tappay/webhook`. Use the public address of your Odoo server, and do not change the path. Choose these [events](https://docs.tappay.mn/glossary.md#event): `payment.succeeded`, `payment.overpaid`, `payment.failed`, `payment.processing`, `invoice.expired`, `invoice.partially_paid`, `refund.succeeded` and `refund.failed`.
3. Copy the [webhook secret](https://docs.tappay.mn/glossary.md#webhook-secret) of the endpoint. It starts with `whsec_` and the portal shows it once.
4. In the provider form, enter the sandbox secret key and the sandbox webhook secret, and save. The module refuses a key with the wrong prefix, such as a `sk_live_` key in the sandbox field.
5. Set the provider state to **Test Mode**. This is the sandbox mode of the module.
6. Choose **Check connection**. The module reads your account with the key. If the key has the `webhooks:manage` scope, it also looks for an active webhook endpoint with exactly the URL of the module.

Optional fields: the **[Terminal](https://docs.tappay.mn/glossary.md#terminal) ID** (needed when your key does not belong to one terminal) and the **Request signing secret** (needed when TapPay signs requests for your account).

A secret field is write-only. After you save, the form shows a secret only as `••••` and its last four characters. Leave the field empty to keep the saved value. Only users in the Administration / Settings group can change the secrets.

### Go live {#go-live}

When the sandbox works, switch the provider to [production](https://docs.tappay.mn/glossary.md#production). The [go-live](https://docs.tappay.mn/go-live.md) checklist applies:

- Create a production secret key, and enter it in the production field.
- Create a **separate** production webhook endpoint with the same URL and the same events. Enter its own webhook secret. The sandbox secret does not work in production.
- Add the outgoing IP address of your server to the system's IP restriction under **Developers › API keys & webhooks** in the merchant portal.
- If your account uses request signing, enter the request signing secret.
- Set the provider state to **Enabled**, which is the production mode of the module, save, and choose **Check connection**.

The module does not take the page that the [customer](https://docs.tappay.mn/glossary.md#customer) sees after paying as proof of payment. It sends an `Idempotency-Key` with every request, so you do nothing more for those two points.

## Test in sandbox {#test-in-sandbox}

1. Create a quotation or an [invoice](https://docs.tappay.mn/glossary.md#invoice), and choose **TapPay** on the payment page (**Pay now**).
2. On the hosted page, pay with the [test card](https://docs.tappay.mn/glossary.md#test-card) `4242 4242 4242 4242`. The [testing](https://docs.tappay.mn/testing.md) page lists more cards, and the [simulator](https://docs.tappay.mn/glossary.md#simulator) lets you create other outcomes.
3. After the redirect to your Odoo site, the payment transaction is **Done** and the order or the invoice is paid. The payment id is the provider reference of the transaction.
4. If the transaction stays **Pending**, the webhook has not arrived. See Troubleshooting below.

## Refunds {#refunds}

A [refund](https://docs.tappay.mn/glossary.md#refund) starts on the payment transaction: open it, choose **Refund**, and enter the amount. Partial refunds are supported. It is asynchronous: Odoo shows the refund transaction at once, and TapPay confirms it with the `refund.succeeded` webhook. If TapPay sends `refund.failed`, the module marks the refund transaction as failed and adds a note. See the [refunds guide](https://docs.tappay.mn/guides/refunds.md) for the rules of the API.

## Troubleshooting {#troubleshooting}

- **The transaction stays "Pending".** The webhook URL in the portal does not equal `https://<your Odoo address>/payment/tappay/webhook`. Copy it again, exactly. Also check that the endpoint has the events listed above, and that the webhook secret is the one of this endpoint and this mode. See the [webhooks guide](https://docs.tappay.mn/guides/webhooks.md).
- **"Invalid key" or error `EVT-206` or `EVT-207`.** The key belongs to the other mode. Use a `sk_test_` key and a sandbox endpoint with the state **Test Mode**, and a `sk_live_` key with the state **Enabled**.
- **TapPay is not offered at checkout.** The module works only with payments in MNT. Set the currency of the order to MNT, and check that the provider state is not **Disabled**.
- **The webhook returns `401`.** The webhook secret is wrong, or a proxy changes the body of the request. Enter the secret of this endpoint again.
- **"Repeat the same refund".** A refund is asynchronous. After a temporary error (a timeout, or a `5xx`, `429` or `403` answer), the module remembers the refund. Repeat it with exactly the same amount. The module rejects a different amount, so that the customer is not refunded twice.
- **"An earlier TapPay refund … was never confirmed".** The module repeats a remembered refund only within 23 hours, because TapPay keeps an [idempotency key](https://docs.tappay.mn/glossary.md#idempotency-key) for 24 hours. After that it stops, so that the customer is not refunded twice. Check the payment in the TapPay dashboard. If the refund is not there, open the original transaction, choose **TapPay: clear unconfirmed refund attempt**, and refund again.
- **"The development override is active".** The system parameter `payment_tappay.api_base_override` is for TapPay platform developers only. Remove it in **Settings > Technical > System Parameters**.

## Changelog {#changelog}

The latest version is shown in the table in Requirements. The full history is in the `CHANGELOG.md` file of the plugin repository, and on the **Changelog** tab of the plugin page.
