Skip to content

Razorpay Setup & Integration Guide

The razorpay provider integrates Razorpay Payment Links, Subscriptions, e-Mandates (UPI, Cards, NACH), and Dispute Management into the Kirak payments runtime.


Razorpay integration requires the official razorpay Python SDK. Install the Kirak extra:

Terminal window
pip install "kirak[payments-razorpay]"

In the Razorpay Dashboard:

  1. Navigate to Account & Settings $\rightarrow$ API Keys.
  2. Generate a Key ID (rzp_test_... or rzp_live_...) and Key Secret.

Declare the Razorpay instance:

{
"payments": {
"default_provider": "razorpay",
"providers": {
"razorpay": {
"type": "razorpay",
"success_url": "https://your-domain.com/payment/success",
"cancel_url": "https://your-domain.com/payment/cancel",
"timeout": 15
}
}
}
}
Terminal window
KIRAK_PAYMENT_RAZORPAY_KEY_ID=rzp_test_...
KIRAK_PAYMENT_RAZORPAY_KEY_SECRET=...
KIRAK_PAYMENT_RAZORPAY_WEBHOOK_SECRET=your_chosen_secret # Entered in Step 4

In the Razorpay Dashboard, navigate to Settings $\rightarrow$ Webhooks $\rightarrow$ Add New Webhook:

  1. Webhook URL: https://your-domain.com/payments/webhook/razorpay
  2. Secret: Choose a strong secret string and set it as KIRAK_PAYMENT_RAZORPAY_WEBHOOK_SECRET.
  3. Select at minimum the following events:
    • Payments: payment.captured, payment.failed, payment.authorized
    • Subscriptions: subscription.activated, subscription.charged, subscription.cancelled, subscription.paused, subscription.resumed
    • Refunds: refund.created
    • e-Mandates / Tokens: token.confirmed, token.rejected, token.cancelled
  4. Active Events: Save the webhook.

[!NOTE] Signature & Deduplication Detail: Razorpay does not sign the x-razorpay-event-id header. To prevent replay attacks and duplicate processing, Kirak hashes the signed raw webhook body for deduplication in payments_webhook_events.


Amounts are passed in paise (1 INR = 100 paise):

result = await kirak.payments.initiate_payment({
"provider": "razorpay",
"user_id": "usr_200",
"amount": 299900, # ₹2,999.00 in paise
"currency": "INR",
"name": "Standard Course",
"type": "one_time",
"payment_email": "customer@example.in",
"customer_phone": "+919876543210", # Enables SMS delivery
})
payment_link_url = result["data"]["url"]

Create recurring plans beforehand in the Razorpay Dashboard or via API. Kirak links subscriptions via the Plan ID:

result = await kirak.payments.initiate_payment({
"provider": "razorpay",
"user_id": "usr_200",
"amount": 0, # Set by the Razorpay Plan
"currency": "INR",
"name": "Pro Monthly Plan",
"type": "subscription",
"subscription_plan_id": "plan_ABC123XYZ",
"payment_email": "customer@example.in",
})
subscription_url = result["data"]["url"]

[!TIP] Hosted Subscription Flow: Kirak creates the subscription without attaching a pre-existing customer ID so Razorpay’s hosted checkout page can collect customer and payment details cleanly. Razorpay’s subscription.charged events are automatically processed as renewal records.

Requires Recurring Payments enabled on your Razorpay account:

  1. setup_payment_method creates a registration link.
  2. Accepts method (card, upi, emandate, or nach), max_amount (paise ceiling), customer_name, and customer_phone.
  3. Cards and UPI charge an authorization token payment (100 paise) to register the mandate.
  4. e-Mandates/NACH become active only when the customer’s bank returns token.confirmed.

Normalized event Gateway Events Description
payment_completed payment.captured Payment captured and settled
payment_failed payment.failed Payment declined or timed out
subscription_renewed subscription.charged Recurring cycle billed
subscription_updated subscription.paused, subscription.resumed Subscription state changed
subscription_cancelled subscription.cancelled Subscription cancelled
refund_completed refund.created Refund processed
payment_method_saved token.confirmed Mandate approved by bank
payment_method_removed token.rejected, token.cancelled Mandate rejected or revoked