RK

Search products

Search plugins, packages and apps, or jump to a section.

Nativephp Razorpay SDK

A NativePHP Mobile plugin that opens the Razorpay Standard Checkout UI on Android and iOS.

NativePHP Plugin
iOSAndroid
v1.0.02 downloads

NativephpRazorpaySdk Plugin for NativePHP Mobile

A NativePHP Mobile plugin that opens the Razorpay Standard Checkout UI on Android and iOS, modeled after the official razorpay_flutter package.

open() launches native checkout and returns immediately — the payment result (success, error, or external wallet selection) is delivered later as a NativePHP event, exactly like Flutter's Razorpay.on(...) callbacks.

Installation

composer require codingwithrk/nativephp-razorpay-sdk
php artisan native:plugin:register codingwithrk/nativephp-razorpay-sdk

Usage

use Codingwithrk\NativephpRazorpaySdk\Facades\NativephpRazorpaySdk;

NativephpRazorpaySdk::open([
    'key' => config('services.razorpay.key'),
    'amount' => 50000, // ₹500.00, in paise
    'currency' => 'INR',
    'name' => 'Acme Corp',
    'order_id' => $order->razorpay_order_id, // create server-side via the Razorpay Orders API
    'prefill' => [
        'contact' => $user->phone,
        'email' => $user->email,
    ],
    'theme' => ['color' => '#F37254'],
]);

key and amount are required; open() throws an InvalidArgumentException otherwise.

Listening for the result

use Native\Mobile\Attributes\OnNative;
use Codingwithrk\NativephpRazorpaySdk\Events\PaymentSuccess;
use Codingwithrk\NativephpRazorpaySdk\Events\PaymentError;
use Codingwithrk\NativephpRazorpaySdk\Events\ExternalWallet;

#[OnNative(PaymentSuccess::class)]
public function handlePaymentSuccess(string $paymentId, ?string $orderId = null, ?string $signature = null)
{
    // Verify $signature server-side before fulfilling the order.
}

#[OnNative(PaymentError::class)]
public function handlePaymentError(int $code, string $description, ?string $orderId = null, ?string $paymentId = null)
{
    // Payment failed or checkout was cancelled.
}

#[OnNative(ExternalWallet::class)]
public function handleExternalWallet(string $walletName)
{
    // Customer selected an external wallet (e.g. Paytm).
}

Always verify the payment signature server-side before marking an order as paid — never trust the client-side event alone.

JavaScript Usage

import { NativephpRazorpaySdk, Events } from '@codingwithrk/nativephp-razorpay-sdk';
import { on } from '@nativephp/native';

on(Events.PaymentSuccess, ({ paymentId, orderId, signature }) => { /* ... */ });
on(Events.PaymentError, ({ code, description }) => { /* ... */ });

await NativephpRazorpaySdk.open({
    key: 'rzp_test_xxxxxxxx',
    amount: 50000,
    order_id: 'order_xxxxxxxx',
});

How it works

  • Android: open() starts a dedicated NativephpRazorpayCheckoutActivity, since the Razorpay Android SDK requires the calling Activity to implement PaymentResultWithDataListener/ExternalWalletListener.
  • iOS: a singleton delegate conforms to RazorpayPaymentCompletionProtocolWithData/ExternalWalletSelectionProtocol and presents checkout from the topmost view controller.
  • No Razorpay secret ships with the plugin — pass your Key ID at call time. Keep your Key Secret server-side only.

License

Proprietary. This is a paid plugin — see LICENSE. Redistribution is not permitted.

We only use essential cookies to keep you signed in, remember your cart and protect forms. No tracking or ads. Learn more