> ## Documentation Index
> Fetch the complete documentation index at: https://docs.fype.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Razorpay guide

# Razorpay Integration Guide

Razorpay is a leading payment gateway in India, providing a comprehensive suite of payment products. Fype integrates seamlessly with Razorpay to offer a unified checkout experience while leveraging Razorpay's robust infrastructure.

## 1. Obtain Razorpay API Credentials

To connect Razorpay to Fype, you need your API Key ID and Key Secret.

1. Log in to your [Razorpay Dashboard](https://dashboard.razorpay.com).
2. Navigate to **Account & Settings** > **API Keys**.
3. Ensure you are in the correct environment (Test or Live) using the toggle at the top.
4. Generate a new **Key ID** and **Key Secret**.
5. Copy these credentials immediately, as the Secret will not be shown again.

## 2. Connect to Fype

1. Log in to the [Fype Dashboard](https://dashboard.fype.dev).
2. Navigate to **Connections** (or Providers).
3. Click **Connect Razorpay**.
4. Select the environment:

* **Sandbox**: Use this if you are using Razorpay **Test Mode** keys.
* **Live**: Use this for Razorpay **Live Mode** keys.

5. Enter your `Key ID` and `Key Secret`.
6. (Optional but Recommended) Enter a **Webhook Secret**. This should match the secret you set in the Razorpay Dashboard (see Step 3).
7. Click **Save Connection**.

## 3. Configure Razorpay Webhooks

Fype relies on webhooks to receive real-time updates about your transactions.

1. In the Razorpay Dashboard, go to **Account & Settings** > **Webhooks**.
2. Click **+ Add New Webhook**.
3. **Webhook URL**: Set this to `https://api.fype.dev/v1/webhooks/razorpay`.
4. **Secret**: Enter a strong, unique string. **This must match the Webhook Secret you provided in the Fype Dashboard.**
5. **Active Events**: Subscribe to the following events to ensure full synchronization:

* `payment.authorized`
* `payment.captured`
* `payment.failed`
* `refund.processed`
* `refund.failed`

6. Click **Create Webhook**.

## 4. Verification

1. **Test Transaction**: Create a payment using your Fype Test API Key.
2. **Checkout**: Follow the `checkout_url` and complete the payment using [Razorpay Test Instruments](https://razorpay.com/docs/payments/payments/test-card-details/).
3. **Status Sync**: Verify in the Fype Dashboard that the payment status transitions to `succeeded`.
4. **Webhook Delivery**: Confirm that your backend received the `payment.succeeded` event from Fype.

## Troubleshooting

### Webhook Signature Mismatch

If Fype logs "Invalid signature" for Razorpay webhooks, double-check that the Webhook Secret in Razorpay matches exactly with the one stored in Fype's Connection settings.

### Payments Stuck in "Processing"

Fype transitions a payment to `succeeded` only after receiving a `payment.captured` event. If Razorpay is configured for Manual Capture, you must capture the payment in your Razorpay Dashboard or via API before Fype will mark it as successful.

### Refund Failures

Razorpay refunds may fail if your account has insufficient funds in the "Current Balance" (distinct from "Settlement Balance"). Ensure your Razorpay balance is topped up for refund operations.
