# Connect Razorpay to Avox

> Connect Razorpay to Avox to send payment links in WhatsApp chats, check whether they were paid, refund payments and get paid updates instantly, and know what Avox does when Razorpay fails.

Source: https://docs.theavoxai.com/connections/apps/razorpay

Connect Razorpay and Avox can send a payment link in a WhatsApp chat, check whether it was paid, refund
a payment and hear about payments the moment they happen. Customers pay with whatever your Razorpay
account offers, such as UPI, cards and netbanking. The money goes straight to your own Razorpay
account; Avox never holds it. This page covers everything from connecting to disconnecting,
including what Avox does when Razorpay is slow, down or says no.

## What Avox can and cannot do with Razorpay

Avox can:

- create a Razorpay Payment Link from an automation and send it in the chat;
- check a payment link or a payment, and show every payment on your account;
- refund a paid payment, all of it or part of it, and cancel a link that is still unpaid;
- update a payment's status by itself when Razorpay sends a paid, cancelled, expired or refund update.

Avox cannot:

- hold or move your money, or change your Razorpay settings;
- send Razorpay's own SMS or email reminders. Those are switched off so the link only comes in the chat;
- refund more than what is left on a payment ([AVX-3719](https://docs.theavoxai.com/error-codes/avx-3719)), or refund a payment
  that was not paid ([AVX-3720](https://docs.theavoxai.com/error-codes/avx-3720)).

## What you need before you start

- A Razorpay account and someone in it who can create an API key. A live key takes real payments; a test
  key is for trying things out.
- A plan with room for another connected app, and the **Manage connected apps** permission in
  **Settings > Switchboard** (Admins have it; an Admin can give it to a Manager).

## Connect Razorpay

**1. Create a key in Razorpay**

In the Razorpay Dashboard open **Account & Settings**, then **API Keys**, and generate a key. Copy the
**Key ID** (it starts with `rzp_live_` or `rzp_test_`) and the **Key secret**. Razorpay shows the secret
once, so copy it before you leave.

**2. Open Razorpay in Apps**

In Avox open **Apps** in the sidebar (under **Connect & Monitor**), then **Razorpay**, click **Connect**,
read **What Avox can do** and click **Continue**.

**3. Paste the keys**

Fill in **Key ID** and **Key secret**, and click **Connect**. **Webhook secret** is optional here and can
be added later.

**4. Avox checks the keys**

Avox tries the keys with Razorpay before saving them. The check gives up after 10 seconds. If Razorpay
refuses them you see [AVX-3686](https://docs.theavoxai.com/error-codes/avx-3686) and nothing is saved. Otherwise you see
**Razorpay is connected**, and the keys are stored encrypted and never shown again, not even to you.

### Turn on instant updates

1. On Razorpay's **Overview** in Avox, under **Instant updates**, copy **Avox's address for Razorpay**.
   Keep it private: it belongs to your Switchboard only.
2. In Razorpay open **Webhooks**, add a webhook with that address and a secret of your own, and tick
   `payment_link.paid`, `payment_link.cancelled`, `payment_link.expired` and `refund.processed`.
3. In Avox click **Add** next to **Webhook secret** and paste the same secret.

Without the secret, Avox shows [AVX-3709](https://docs.theavoxai.com/error-codes/avx-3709) and refuses the updates, because it
cannot check they came from Razorpay.

## What you see in Avox afterwards

Razorpay has its own menu under **Apps**: **Overview**, **Payments** and **Activity** (tabs along the
top on a phone).

- **Overview**: the status, your account and its mode (Live or Test), who connected it, when it last
  worked, the last problem with its code, and what uses Razorpay. **Test connection**, **Reconnect**
  and **Disconnect** are here too.
- **Payments** has two lists. **Sent by Avox** is every payment link Avox sent, with the automation that
  sent it and the chat it was for. **In Razorpay** is every payment on your account, 20 at a time with
  **Load more**. Statuses are Paid, Pending, Partly paid, Failed, Refunded, Partly refunded,
  Expired and Cancelled.
- Open a payment for its details, then **Copy payment link**, **Open payment link**,
  **Open in Razorpay**, **Check status now**, **Refund** (you type the amount again to confirm,
  [AVX-3723](https://docs.theavoxai.com/error-codes/avx-3723)) and **Cancel link** while it is unpaid. Refund, cancel and check
  need the **Manage connected apps** permission.
- **Activity**: **Usage** (calls a day over 7, 30 or 90 days, success rate, average time) and the
  **Log** with **Calls** and **Webhooks** tabs. Click an entry for what Avox asked and what came back.

The connection status is **Connected**, **Needs reconnecting**, **Having trouble** or **Disconnected**.
**Test connection** asks Razorpay for one payment and says whether the key is accepted and in which mode.

## Using Razorpay in Avox

Payment links come from an automation. In the builder add the step **Use a connected app**, choose
**Create a payment link**, pick Razorpay (or another payments app you connected) and fill in:

| Detail | Notes |
| --- | --- |
| Amount | Required. Type it the way you write it, like `499` or `499.50`, or a value like `{{item.price}}`. |
| Currency | Required. 3 letters, like `INR`. |
| What it's for | Required. Up to 200 characters; the customer sees it. |
| Your reference | Optional. Up to 40 letters, numbers, `-` and `_`. |
| Customer name, email, phone | Optional. |
| Link works for | Optional, in minutes: from 30 minutes to 30 days. |

The step's values, like `{{payment.url}}`, can go in the next message. An automation can also start
when a customer submits a Flow, and its steps can use the customer's answers, so a Flow answer can
decide the amount or the description. The Avox library has a premade automation, **Payment link after a
booking**, that does this with your tables.

Example (hypothetical): a customer books a service. An automation looks up the service's price in your
price table, creates a payment link for it with a reference taken from the booking, and sends a template
message containing `{{payment.url}}`. When the customer pays, Razorpay tells Avox and the payment shows
as Paid.

## Limits

- 120 calls a minute per Switchboard to Razorpay ([AVX-3695](https://docs.theavoxai.com/error-codes/avx-3695) after that).
- Each call gives up after 10 seconds, and an answer larger than 1 MB is not read.
- Amounts must be above zero. Lists load 20 at a time and are reused for 30 seconds; **Refresh** reads again.

## When Razorpay fails or says no

1. **Avox tries again only when that is safe.** Looking things up is repeated: on a network problem, or
   when Razorpay answers busy or unavailable (HTTP 429, 502, 503 or 504), Avox tries up to two more times,
   after about 0.4 and then 1.2 seconds, and waits up to 5 seconds if Razorpay says how long. Creating a
   payment link, refunding and cancelling are never repeated by Avox, so nothing is made or paid out
   twice. If one fails, check the payment in Razorpay before trying again.
2. **The status changes only when it should.** If Razorpay refuses the key (regenerated, deleted or
   wrong), the status becomes **Needs reconnecting** at once ([AVX-3692](https://docs.theavoxai.com/error-codes/avx-3692); the
   log shows [AVX-3686](https://docs.theavoxai.com/error-codes/avx-3686)). If 5 calls in a row fail on Razorpay's
   side (not answering, busy or refusing the request: [AVX-3694](https://docs.theavoxai.com/error-codes/avx-3694),
   [AVX-3695](https://docs.theavoxai.com/error-codes/avx-3695), [AVX-3713](https://docs.theavoxai.com/error-codes/avx-3713)), it becomes **Having trouble**. One good
   call after that returns it to **Connected** by itself. A wrong detail, such as an amount Razorpay does
   not accept, does not count against its health, and neither does an unticked permission.
3. **The call is logged** with the time, action, result, tries and code. Secrets are removed, customer
   details masked and links cut down to their address, so the log never holds the data itself.
4. **Automations and Flows keep going.** A payment step either **Stops the run** or **Carries on with
   the next step**, whichever you chose under **If it can't be done**
   ([AVX-3605](https://docs.theavoxai.com/error-codes/avx-3605)). For a payment link, stopping is usually safer, so the customer
   never gets a message without a link. While Razorpay **Needs reconnecting**, the step does not run and
   nothing is sent to Razorpay; the run log shows [AVX-3596](https://docs.theavoxai.com/error-codes/avx-3596). If your Switchboard
   is paused, Avox does not call Razorpay ([AVX-3711](https://docs.theavoxai.com/error-codes/avx-3711)) and automations do not
   start ([AVX-3611](https://docs.theavoxai.com/error-codes/avx-3611)). Your Inbox and automations without a payment step are not
   affected.
5. **The pages show what Avox saved.** If Razorpay cannot be read, **Payments** shows the links Avox sent
   with [AVX-3717](https://docs.theavoxai.com/error-codes/avx-3717) and the reason's own code, and refund and cancel wait.
   Click **Refresh** once it is back.

## Disconnect Razorpay

Click **Disconnect** on the **Overview**. Avox lists what uses Razorpay (those steps stop until you
connect again, [AVX-3708](https://docs.theavoxai.com/error-codes/avx-3708)), deletes the keys it saved and keeps the log for your
retention period. Avox does not cancel links you already sent. To be sure the keys cannot be used again,
regenerate the key in Razorpay and delete Avox's webhook there.

## Common questions

**Live key or test key?**

A live key takes real payments. A test key is for trying the steps. **Reconnect** lets you swap one for
the other; Avox treats a new key as the same account.

**A payment is paid but Avox still says Pending**

Check **Instant updates** on the **Overview**: the webhook must use Avox's address, the four events
must be ticked and the secret must match. Meanwhile, open the payment and click **Check status now**.

**Can I refund only part of a payment?**

Yes. Click **Refund**, type the amount, and type it again to confirm. You can refund up to what is left.

**Why didn't my customer get an SMS or email from Razorpay?**

Avox switches Razorpay's messages off when it makes the link, because the link is sent in the chat.

**I regenerated my key in Razorpay**

Click **Reconnect** and paste the new Key ID and Key secret. Leave **Webhook secret** empty to keep the one saved.

## Related
