Skip to content

SDKs

React Native SDK

Take crypto payments in a React Native app (Android and iOS, bare or Expo dev build). The checkout opens as a full-screen modal in your app and returns a typed result.

How it works

  1. The app asks your server to start a payment.
  2. Your server creates it with the secret key and returns the checkout_url (PHP / Laravel, Node.js, Python).
  3. The app opens the checkout. The customer pays.
  4. The app gets success, pending, cancelled or failed and tells your server.
  5. Your server verifies the signature and the real status. Only the server marks the order paid.

1. Install

Shell
npm install @razcrypto/react-native react-native-webview
cd ios && pod install      # iOS only

Expo: npx expo install react-native-webview, then npm install @razcrypto/react-native. It works in a development build and in EAS builds.

From the download (local / offline)

Shell
curl -L -o razcrypto-react-native-sdk.zip https://razcryptogateway.com/downloads/razcrypto-react-native-sdk.zip
mkdir razcrypto-react-native-sdk && unzip razcrypto-react-native-sdk.zip -d razcrypto-react-native-sdk
cd razcrypto-react-native-sdk
npm install && npm run build && npm pack        # creates razcrypto-react-native-1.0.0.tgz
cd ../your-app
npm install ../razcrypto-react-native-sdk/razcrypto-react-native-1.0.0.tgz react-native-webview

A packed .tgz works better with Metro than a symlinked folder.

Android

The internet permission is already in every React Native app. To let Android 11+ open wallet apps directly, add this to android/app/src/main/AndroidManifest.xml inside <manifest>:

xml
<queries>
  <intent><action android:name="android.intent.action.VIEW" /><data android:scheme="metamask" /></intent>
  <intent><action android:name="android.intent.action.VIEW" /><data android:scheme="trust" /></intent>
</queries>

2. Open the checkout

Hook (promise style)

tsx
import { Alert, Button } from 'react-native';
import { useRazCryptoCheckout } from '@razcrypto/react-native';

export function PayWithCrypto({ amount }: { amount: number }) {
  const { open, element } = useRazCryptoCheckout();

  const pay = async () => {
    const order = await api.post('/payments/razcrypto/create', { amount });   // { payment_id, checkout_url }
    const r = await open({ checkoutUrl: order.checkout_url, locale: 'en' });  // or 'hi'

    switch (r.status) {
      case 'success': {
        const res = await api.post('/payments/razcrypto/verify', {
          payment_id: r.paymentId,
          reference_id: r.referenceId,
          status: r.paymentStatus,
          signature: r.signature,
        });
        res.status === 'completed' ? showPaid() : waitForPaid(r.paymentId);
        break;
      }
      case 'pending':                 // on-chain, confirming
        waitForPaid(r.paymentId);
        break;
      case 'cancelled':               // closed; order stays pending
        break;
      case 'failed':
        Alert.alert('Payment failed', r.message);
    }
  };

  return (
    <>
      <Button title="Pay with crypto" onPress={pay} />
      {element}
    </>
  );
}

Render {element} once in the screen; it is the checkout modal.

Component

tsx
import { RazCryptoCheckout } from '@razcrypto/react-native';

<RazCryptoCheckout
  visible={open}
  options={{ checkoutUrl }}           // or { key: 'pk_live_…', paymentId: 'pay_…' }
  onResult={(r) => {
    setOpen(false);
    handle(r);
  }}
/>

waitForPaid polls your server (GET /payments/razcrypto/status/{id}) for about 30 seconds, then tells the customer the order will update shortly.

3. Server side

A complete Laravel backend (migration, admin settings, create / verify / status / webhook) is on the PHP SDK page. Node.js: Node.js SDK.

  • signature = hex HMAC-SHA256(webhook signing secret, payment_id|reference_id|status). Verify it on the server.
  • Fulfil only when payments.retrieve(id) returns paid or on the verified payment.paid webhook.

Reference

OptionsUse
{ checkoutUrl, locale? }Recommended. The checkout_url from your server.
{ key, paymentId, payHost?, locale? }Publishable key + payment id. payHost only for staging / self-hosted.
Result statusOther fields
'success'paymentId, referenceId, paymentStatus, signature
'pending'paymentId
'cancelled'—
'failed'code, message

What the customer sees: network → coin → QR or "Open in MetaMask / Trust" → green success screen that closes by itself. Android Back asks "Leave this payment?".

Test and go live

  1. Server on sk_test_…, open a payment, then simulate(paymentId, 'paid') on the server.
  2. Check Dashboard → API apps → Webhooks for the delivery.
  3. Live: sk_live_… + live signing secret + live webhook URL, then one small real payment.

Develop the SDK

Shell
npm install
npm run typecheck && npm test && npm run build