NRazorPay 1.0.1

dotnet add package NRazorPay --version 1.0.1
                    
NuGet\Install-Package NRazorPay -Version 1.0.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="NRazorPay" Version="1.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="NRazorPay" Version="1.0.1" />
                    
Directory.Packages.props
<PackageReference Include="NRazorPay" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add NRazorPay --version 1.0.1
                    
#r "nuget: NRazorPay, 1.0.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package NRazorPay@1.0.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=NRazorPay&version=1.0.1
                    
Install as a Cake Addin
#tool nuget:?package=NRazorPay&version=1.0.1
                    
Install as a Cake Tool

NRazorPay – Razorpay SDK for .NET (VB.NET)

NRazorPay is a full-featured, production-grade Razorpay client library built entirely in VB.NET and targeting .NET 9.

It wraps every Razorpay API resource in a clean, async, dependency-injection-friendly interface (IRazorpayClient) and uses Microsoft.Extensions.Http.Resilience for automatic retries, circuit breaker protection, and timeout handling.

NuGet License: MIT


Features

  • Complete API Coverage – Orders, Payments, Refunds, Customers, Payment Links, Plans, Subscriptions, Addons, Invoices, Settlements, Transfers, Virtual Accounts, QR Codes, Items, Fund Accounts, Disputes, Tokens, Webhooks, Sub-merchant Accounts, Stakeholders, Products, IIN, Cards, and Documents.
  • Production-Ready HTTP Stack – Polly-based resilience, configurable timeouts, and Basic Authentication via IHttpClientFactory.
  • Secure by Design – Secrets are never logged; signature verification uses constant-time comparison to prevent timing attacks.
  • Structured Error HandlingRazorpayApiException exposes error code, description, HTTP status code, and field-level validation details.
  • Intuitive API – Simple method names such as CreateAsync, FetchAsync, CaptureAsync, and ListAsync.
  • Flexible Configuration – Uses the Options Pattern (RazorpayClientOptions) and standard .NET dependency injection.
  • Webhook & Signature Utilities – Includes SignatureVerifier for payment response validation and webhook HMAC-SHA256 verification.

Installation

dotnet add package NRazorPay

Requirements

  • .NET 9 or later

Quick Start

1. Register the Client in Dependency Injection

Imports Microsoft.Extensions.DependencyInjection
Imports NRazorPay
Imports NRazorPay.Configuration

Dim services = New ServiceCollection()

services.AddNRazorPay(Sub(opts)
                           opts.KeyId = "rzp_test_xxxx"
                           opts.KeySecret = "your_secret"
                       End Sub)

Dim serviceProvider = services.BuildServiceProvider()

Dim client = serviceProvider.GetRequiredService(Of IRazorpayClient)()

2. Create an Order

Dim orderRequest = New OrderRequest With {
    .Amount = 50000,   ' ₹500.00 in paise
    .Currency = "INR",
    .Receipt = "rcpt_001"
}

Dim order = Await client.Orders.CreateAsync(orderRequest)

Console.WriteLine($"Order created: {order.Id}")

3. Verify a Payment Signature

Dim isValid = SignatureVerifier.VerifyPaymentSignature(
    orderId:="order_...",
    paymentId:="pay_...",
    signature:="signature_hex",
    secret:="your_secret"
)

No magic strings. No dictionaries. Simply pass the order ID, payment ID, signature, and secret.


4. Handle Webhooks

<HttpPost>
Public Async Function Receive() As Task(Of IActionResult)

    Dim rawBody = Await New StreamReader(Request.Body).ReadToEndAsync()

    Dim signature = Request.Headers("X-Razorpay-Signature").FirstOrDefault()

    If SignatureVerifier.VerifyWebhookSignature(
        rawBody,
        signature,
        "webhook_secret"
    ) Then

        ' Process webhook event
        Return Ok()
    End If

    Return Unauthorized()

End Function

Using NRazorPay in a VB.NET WinForms Application

The following example demonstrates how to integrate Razorpay Checkout inside a WinForms application using WebView2 and verify payments using NRazorPay.


Step 1 – Install Required Packages

dotnet add package NRazorPay
dotnet add package Microsoft.Extensions.DependencyInjection
dotnet add package Microsoft.Web.WebView2

Step 2 – MainForm.vb

Imports System.Web
Imports Microsoft.Extensions.DependencyInjection
Imports Microsoft.Web.WebView2.Core
Imports NRazorPay
Imports NRazorPay.Configuration
Imports NRazorPay.Models.Order
Imports NRazorPay.Utilities

Public Class MainForm

    Private _razorpayClient As IRazorpayClient
    Private _currentOrderId As String
    Private _secret As String = "your_api_secret"

    Public Sub New()
        InitializeComponent()
        ConfigureServices()
    End Sub

    Private Sub ConfigureServices()

        Dim services = New ServiceCollection()

        services.AddNRazorPay(Sub(opts)
                                   opts.KeyId = "rzp_test_xxxx"
                                   opts.KeySecret = _secret
                               End Sub)

        Dim provider = services.BuildServiceProvider()

        _razorpayClient =
            provider.GetRequiredService(Of IRazorpayClient)()

    End Sub

    Private Async Sub MainForm_Load(
        sender As Object,
        e As EventArgs
    ) Handles MyBase.Load

        Await WebView21.EnsureCoreWebView2Async()

        WebView21.NavigateToString(
            "<html><body></body></html>"
        )

    End Sub

    Private Async Sub btnCreateOrder_Click(
        sender As Object,
        e As EventArgs
    ) Handles btnCreateOrder.Click

        Try

            Dim orderRequest = New OrderRequest With {
                .Amount = 50000,
                .Currency = "INR",
                .Receipt = $"rcpt_{DateTime.Now.Ticks}",
                .Notes = New Dictionary(Of String, String) From {
                    {"source", "winforms"}
                }
            }

            Dim order =
                Await _razorpayClient.Orders.CreateAsync(orderRequest)

            _currentOrderId = order.Id

            Dim checkoutScript =
                $"openCheckout('{order.Id}', {order.Amount}, '{order.Currency}')"

            Await WebView21.ExecuteScriptAsync(checkoutScript)

            lblStatus.Text = "Waiting for payment..."

        Catch ex As RazorpayApiException

            lblStatus.Text = $"Error: {ex.Description}"

        Catch ex As Exception

            lblStatus.Text = $"Error: {ex.Message}"

        End Try

    End Sub

    Private Sub OnPaymentCallback(callbackUrl As String)

        Dim uri = New Uri(callbackUrl)
        Dim query = HttpUtility.ParseQueryString(uri.Query)

        Dim paymentId = query("razorpay_payment_id")
        Dim orderId = query("razorpay_order_id")
        Dim signature = query("razorpay_signature")

        If String.IsNullOrWhiteSpace(paymentId) OrElse
           String.IsNullOrWhiteSpace(orderId) OrElse
           String.IsNullOrWhiteSpace(signature) Then

            Invoke(Sub()
                       lblStatus.Text =
                           "Invalid callback parameters"
                   End Sub)

            Return

        End If

        Dim isValid =
            SignatureVerifier.VerifyPaymentSignature(
                orderId:=orderId,
                paymentId:=paymentId,
                signature:=signature,
                secret:=_secret
            )

        Invoke(Sub()
                   lblStatus.Text =
                       If(
                           isValid,
                           "Payment verified successfully!",
                           "Signature verification failed"
                       )
               End Sub)

    End Sub

    Private Sub WebView21_CoreWebView2InitializationCompleted(
        sender As Object,
        e As CoreWebView2InitializationCompletedEventArgs
    ) Handles WebView21.CoreWebView2InitializationCompleted

        Dim html =
            "<html><body>" &
            "<script src=""https://checkout.razorpay.com/v1/checkout.js""></script>" &
            "<script>" &
            "function openCheckout(orderId, amount, currency) {" &
            " var options = {" &
            "   key: 'rzp_test_xxxx'," &
            "   amount: amount," &
            "   currency: currency," &
            "   name: 'Your App Name'," &
            "   description: 'Test Transaction'," &
            "   order_id: orderId," &
            "   handler: function(response) {" &
            "       var callbackUrl =" &
            "       'https://yoursite.com/callback?razorpay_payment_id=' +" &
            "       response.razorpay_payment_id +" &
            "       '&razorpay_order_id=' +" &
            "       response.razorpay_order_id +" &
            "       '&razorpay_signature=' +" &
            "       response.razorpay_signature;" &
            "       window.chrome.webview.postMessage(callbackUrl);" &
            "   }," &
            "   prefill: {" &
            "       email: 'test@example.com'," &
            "       contact: '9999999999'" &
            "   }," &
            "   theme: {" &
            "       color: '#3399cc'" &
            "   }" &
            " };" &
            " var rzp = new Razorpay(options);" &
            " rzp.open();" &
            "}" &
            "</script>" &
            "</body></html>"

        WebView21.NavigateToString(html)

    End Sub

    Private Sub WebView21_WebMessageReceived(
        sender As Object,
        e As CoreWebView2WebMessageReceivedEventArgs
    ) Handles WebView21.WebMessageReceived

        Dim callbackUrl =
            e.TryGetWebMessageAsString()

        If Not String.IsNullOrWhiteSpace(callbackUrl) Then
            OnPaymentCallback(callbackUrl)
        End If

    End Sub

End Class

Important: Replace rzp_test_xxxx and your_api_secret with your actual Razorpay credentials. For production deployments, store secrets in environment variables, Azure Key Vault, AWS Secrets Manager, or another secure configuration provider.


API Resources

Service Description
Orders Create, fetch, and list orders
Payments Create, capture, fetch, and list payments
Refunds Create, fetch, and list refunds
Customers Create, fetch, list, and edit customers
Payment Links Create, fetch, list, and cancel payment links
Plans Create, fetch, and list plans
Subscriptions Create, fetch, list, and cancel subscriptions
Addons Create, fetch, list, and delete addons
Invoices Create, fetch, list, issue, and cancel invoices
Settlements Fetch and list settlements
Transfers Create, fetch, list, and reverse transfers
Virtual Accounts Create, fetch, list, and close virtual accounts
QR Codes Create, fetch, list, and close QR codes
Items Create, fetch, list, edit, and delete items
Fund Accounts Create and list fund accounts
Disputes Fetch, list, accept, and contest disputes
Tokens Fetch, list, and delete customer tokens
Webhooks Create, fetch, list, edit, and delete webhooks
Accounts Create, fetch, list, edit, and delete sub-merchant accounts
Stakeholders Create, fetch, list, and edit stakeholders
Products Create, fetch, list, and edit products
IIN Retrieve card issuer information
Cards Fetch card details
Documents Upload, fetch, and list account documents

Error Handling

RazorpayApiException provides structured access to API errors.

Try

    Dim order =
        Await client.Orders.CreateAsync(request)

Catch ex As RazorpayApiException

    Console.WriteLine($"Status: {ex.HttpStatusCode}")
    Console.WriteLine($"Code: {ex.ErrorCode}")
    Console.WriteLine($"Description: {ex.Description}")

    If ex.FieldErrors IsNot Nothing Then

        For Each field In ex.FieldErrors
            Console.WriteLine(
                $"Field '{field.Key}': {field.Value}"
            )
        Next

    End If

End Try

Supported Frameworks

  • .NET 9
  • Future .NET releases supported through explicit multi-targeting updates

Documentation

  • XML documentation included for all public APIs.
  • Full IntelliSense support in Visual Studio 2022 and later.
  • Async-first API surface throughout the library.

License

Licensed under the MIT License.

See the LICENSE file for details.


Contributing

Contributions are welcome.

Please open an issue to discuss significant changes before submitting a pull request.

Areas where contributions are especially appreciated:

  • Additional integration examples
  • Documentation improvements
  • Unit and integration tests
  • Performance optimizations
  • New Razorpay API feature support

Acknowledgements

Built with ❤️ by NJAC

Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.1 157 6/23/2026
1.0.0 125 6/22/2026