LMS & eLearning

Accepting Payments With Razorpay in LearnDash

How to set up the built-in Razorpay gateway in LearnDash: keys, test mode, the webhook URL and secret, what each Razorpay event does to course access, subscriptions and trials, and a checklist before going live.

Accepting Payments With Razorpay in LearnDash

Razorpay is the third payment gateway built into LearnDash 4.18.0.1 alongside Stripe and PayPal, and the usual choice for sites billing in India. It handles one-off purchases and recurring subscriptions, with trials, for both courses and groups. Setup is short, but it only works end to end once the webhook is in place, because enrolment is driven by Razorpay's events rather than by the browser returning to your site. This guide walks through the settings, explains what each event does, and ends with a go-live checklist.

Before you start

You need a Razorpay account with API keys for test and live modes, and a LearnDash currency set under LearnDash LMS, Settings, Payments. Razorpay settles in Indian rupees for most accounts, so set the currency to INR unless your Razorpay account is enabled for international currencies. Courses and groups you want to sell must use the Buy now or Recurring access mode with a price; Open, Free and Closed courses never show a Razorpay button.

The settings

Open LearnDash LMS, Settings, Payments, and find the Razorpay section. The fields are:

  • Active. Enables the gateway. LearnDash treats Razorpay as ready only when it is active and the key ID, key secret and webhook secret for the current mode are all filled in; a missing webhook secret leaves the button hidden even when the keys are right.
  • Test Mode. Switches the gateway to the test keys. Keep this on until the checklist below passes.
  • Test: Key Id, Test: Key Secret, Test: Webhook Secret and the matching Live trio. Key ID and secret come from the API Keys page of the Razorpay dashboard; the webhook secret is the one you type when creating the webhook there.
  • Return URL. Where the learner lands after paying. The help text says to leave it blank to send the learner back to the course or group page, which is what most sites want.
  • Webhook URL. Read only. Copy this into the Razorpay dashboard under Settings, Webhooks, with the secret you entered above.

Test and live keys are stored separately, and so are the Razorpay customer IDs and plan IDs LearnDash creates, so switching modes never mixes test customers with live ones.

What happens at checkout

When a learner clicks the Razorpay button, LearnDash creates a Razorpay order for a one-off price, or a plan and subscription for a Recurring course, and opens the Razorpay checkout. The learner pays with a card, UPI, net banking or a Razorpay wallet, and is then redirected to the Return URL or the course page. Enrolment does not happen on that redirect. It happens when Razorpay sends the webhook event to your site, which usually arrives within seconds but can lag; a learner who returns before the event lands sees the course still locked for a moment.

LearnDash validates each event against the webhook secret and ignores anything that fails the signature check, then matches the order or subscription to the user and product and acts on the event type:

  • order.paid and subscription.authenticated grant access and record a transaction. Authenticated is the first event for a subscription, including one that starts with a free trial, so trial learners are enrolled before any money moves.
  • subscription.activated and subscription.resumed grant access again, which covers a paused subscription being resumed.
  • subscription.cancelled, paused, halted, pending and completed remove access. Halted and pending are Razorpay's states for repeated payment failure, and completed is sent when a subscription with a fixed count has taken its last payment, so a fixed-term plan ends access when it ends billing.

Those rules mean a learner whose card fails loses access as soon as Razorpay reports the subscription as pending, not at the end of the paid period. If you prefer a grace period, handle it with a course expiry setting or with custom code on the gateway's processed event; our guide to subscriptions, trials and billing cycles compares how the three gateways treat these states.

Subscriptions and trials

A Recurring course's billing cycle becomes a Razorpay plan with the same period and interval, and the Recurring Times setting becomes the subscription's total count. A trial is expressed as a delayed start, with the trial price charged up front when it is not zero. LearnDash caches the plan ID it creates per course and price, so changing the price on the course creates a new plan rather than editing the old one, and existing subscribers stay on their original plan at the original price.

Transactions and reporting

Each successful event records a LearnDash transaction under LearnDash LMS, Transactions, labelled Razorpay Purchase, or Razorpay Subscription with a note of whether a trial applied. The transaction holds the Razorpay order or subscription ID, which is what you search for in the Razorpay dashboard when reconciling. The purchase success email and the purchase invoice, when enabled, are sent when that transaction is created. How to read the transaction list is covered in our guide to LearnDash transactions.

Logs

The gateway writes to the Transactions log, including "Webhook received", signature failures and "Removed access to products" lines, which you can read and download from LearnDash LMS, Settings, Advanced, Logs. That log is the first place to look when a payment succeeded at Razorpay but the learner was not enrolled. The usual causes are a wrong webhook secret, a webhook created in the other mode, or a security plugin blocking the webhook URL.

Go-live checklist

  1. With Test Mode on and test keys entered, create a webhook in the Razorpay test dashboard pointing at the Webhook URL with the test secret, subscribed to the order and subscription events above.
  2. Buy a Buy now course with a test card and confirm enrolment within a minute and a Razorpay Purchase transaction.
  3. Buy a Recurring course with a trial and confirm enrolment on the authenticated event; cancel it in the dashboard and confirm access is removed.
  4. Enter the live keys, create the live webhook with the live secret, and turn Test Mode off.
  5. Make one real purchase, confirm enrolment, then refund it in Razorpay and remove the learner's access by hand, because refunds are not processed by LearnDash.

When to get help

Setup takes under an hour when the webhook works first time. Grace periods for failed payments, Razorpay for Indian learners alongside Stripe for the rest of the world, or moving existing subscribers over are tasks our LearnDash services team handles; a LearnDash developer can also trace a missing enrolment through the gateway log and the Razorpay event history. Payment-only questions, such as settlement and KYC, belong with Razorpay support.

Frequently asked questions

Why does the Razorpay button not appear?

The gateway needs Active on and the key ID, key secret and webhook secret for the current mode all filled in. Check the mode you are in and that the course has a price and a paid access mode.

The learner paid but was not enrolled. Why?

The webhook event did not arrive or failed validation. Check the Transactions log for the event, confirm the webhook URL and secret in Razorpay match the mode LearnDash is in, and look for a security plugin blocking the request.

Does LearnDash remove access on a Razorpay refund?

No. Refunds are not processed. Remove access from the user's profile or the course's Users tab after refunding.

Can I use Razorpay and Stripe together?

Yes. With both active and no registration page set, the course shows a dropdown with both options; on the registration page the learner picks a gateway at checkout.

Add WorldWin Coder to your preferred sources

Add worldwincoder.com as a preferred source on Google, or open this article in your AI assistant to use it as a source.

· Developers and project managers

Articles written and reviewed by the developers and project managers at WorldWin Coder, who build and maintain websites, web applications and mobile apps on WordPress, Moodle, PHP, Laravel, CodeIgniter and Flutter.

Keep reading

Have something to build, fix or move?

Tell us where you are. A developer reads every inquiry, and you get next steps and a free quote within one business day.