Skip to main content

Overview

The Moment React Native SDK enables seamless payment integration into any React Native application. The SDK provides a simple, declarative API with React hooks to handle the entire payment flow through a native bottom sheet experience. Built with React Native and modern hooks, the SDK works with both iOS and Android platforms and integrates naturally with your React Native workflow. Moment Mobile SDK

Key Features

  • React Hooks API – Declarative interface with useCheckout hook
  • Native Experience – Bottom sheet presentation feels native on both platforms
  • TypeScript Support – Full type definitions included
  • Flexible Callbacks – Handle success, failure, cancellation, retry, and expiry events
  • Secure – Sensitive payment data handled entirely in Moment’s secure WebView
  • Cross-Platform – Single codebase for iOS and Android
  • PCI Compliant – No card data touches your application

How It Works

  1. App startsMomentProvider + MomentCheckoutProvider mount, registering your fetchClientToken, fetchSessionStatus, and event callbacks (onSuccess, onFailure, etc.)
  2. Customer taps Paycheckout.launch() is called from your component
  3. SDK calls fetchClientToken — your callback creates a session on your backend (with a success_url deep link) and returns the client_token
  4. Checkout opens in a native bottom sheet
  5. Customer submits payment — Moment takes over and redirects to the authentication page
  6. Customer completes authentication on the external page
  7. Customer is redirected back to your app via redirect link with ?session_id=abc123
  8. SDK detects the redirect link and calls your fetchSessionStatus('abc123') callback automatically
  9. Your callback fetches the status from your backend, which queries Moment API
  10. SDK routes to the right handleronSuccess, onFailure, onExpired, or onCancel
  11. Webhooks are delivered to your backend regardless of outcome

Installation

NPM (Bare React Native)

Yarn (Bare React Native)

Expo

Expo vs Bare React Native: If you’re using Expo, use the Expo CLI installation. For bare React Native projects, use npm/yarn and follow the iOS pod install instructions below.

Install iOS Dependencies (Bare React Native Only)


Platform Configuration

For Expo Projects: Most platform configurations are handled automatically by Expo. Ensure you’re using Expo SDK 49 or later. If you need custom native configurations, you may need to use a development build.

Bare React Native Setup

iOS Setup

Add to ios/YourApp/Info.plist:
Minimum iOS version in ios/Podfile:

Android Setup

Add to android/app/src/main/AndroidManifest.xml:
Ensure minimum SDK version in android/app/build.gradle:

Quick Start

1. Initialize the SDK

Wrap your app with MomentProvider (SDK level) at the root, then nest MomentCheckoutProvider (checkout product) inside it with your fetch callbacks and event handlers — the SDK calls them automatically at the right moments, so you never manage tokens or session IDs manually. Backend endpoints:
server.js
React Native — wrap your app with MomentProvider + MomentCheckoutProvider:
App.tsx

2. Open Checkout

Add useCheckout to any component and call checkout.launch() to trigger checkout:
CheckoutScreen.tsx

API Reference

MomentProvider (SDK level)

Wraps your React Native app and initializes the SDK. Must be a parent of MomentCheckoutProvider and any component using useCheckout.

MomentCheckoutProvider (checkout product)

React Native’s equivalent of moment.checkout() — configures the checkout product and makes it available to any child component via useCheckout. Must be a child of MomentProvider. Example:

useCheckout(config)

React Native hook that returns a checkout instance for triggering checkout from any component. Callbacks defined here are component-level and fire alongside any global callbacks on MomentCheckoutProvider. Returns a checkout object — checkout.launch(), checkout.close(), and checkout.submit().

checkout.launch()

Opens the payment checkout in a native bottom sheet. Internally calls fetchClientToken from MomentCheckoutProvider to retrieve a fresh token.
Returns a Promise that resolves once the checkout is open.

checkout.close()

Manually closes the bottom sheet checkout.

Callback Strategies

The Moment React Native SDK offers flexible callback handling at both the global (provider) and component (hook) levels. Understanding when to use each approach helps you write cleaner, more maintainable code.

Global Callbacks (MomentCheckoutProvider Level)

Define callbacks once at the MomentCheckoutProvider level to apply consistent behavior across your entire application. ✅ Best for:
  • App-wide analytics tracking
  • Global error logging
  • Consistent navigation patterns
  • Shared alert/toast notifications
App.tsx

Component-Level Callbacks (useCheckout Hook)

Override or supplement global callbacks with component-specific behavior. ✅ Best for:
  • Component-specific state updates
  • Different flows for different payment contexts
  • Local UI feedback
  • Context-aware error handling
SubscriptionScreen.tsx

Callback Precedence

Important: Component-level callbacks do not override global callbacks. Both will fire:
  1. Component-level callback fires first (if defined)
  2. Global callback fires second (if defined)
This allows you to handle both component-specific and app-wide logic.

Advanced Usage

Custom Hook for Payment Logic

hooks/usePayment.ts

Using the Custom Hook

ProductScreen.tsx

Security Best Practices

  1. Never expose your secret key (sk_...) in your React Native app
  2. Always create sessions server-side via your backend API
  3. Validate webhooks to confirm payment state before fulfilling orders
  4. Use HTTPS for all backend communication
  5. Handle token expiry — the SDK calls fetchClientToken on every open(), so tokens are always fresh
  6. Secure your backend endpoints with proper authentication
  7. Use environment variables for sensitive keys (use react-native-config)

Troubleshooting

Expo Build Issues

If you encounter issues with Expo: 1. Rebuild your project:
2. Development builds required: If the SDK uses custom native modules, you’ll need to create a development build:
3. Clear Expo cache:

iOS Build Issues (Bare React Native)

If you encounter build issues on iOS:

Android Build Issues (Bare React Native)

If you encounter build issues on Android:

Next Steps