Skip to content

dodopayments/dodopayments-react-native-demo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

9 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Dodo Payments React Native Demo App

A demonstration application showcasing two payment integration methods with Dodo Payments in React Native:

  1. React Native SDK - Native payment sheet with full customization
  2. Payment Link (InAppBrowser) - Hosted checkout page in browser
  • πŸ“¦ Install our SDK from NPM
  • πŸ“š Read our Integration Guide for detailed documentation.
  • πŸŽ₯ Watch our demo video to see the Dodo Payments SDK in action.
React Native SDK Demo

Features

  • πŸ”„ Two Payment Flows: Switch between SDK and Payment Link methods
  • πŸ”’ Secure payment processing with PCI compliance
  • πŸ’³ Support for multiple payment methods
  • πŸ“± Native UI components for Android and iOS
  • 🎨 Customizable payment interface
  • πŸŒ“ Light and dark mode support
  • πŸ”— Deep linking for payment callbacks

Prerequisites

  • Node.js (v14 or higher)
  • React Native development environment setup
  • iOS: Xcode and CocoaPods
  • Android: Android Studio and Android SDK
  • Dodo Payments account and API keys

Installation

  1. Clone the repository:
git clone https://github.com/dodopayments/dodopayments-react-native-demo.git
cd dodopaymentdemoapp
  1. Install dependencies:
npm install
# or
yarn install
  1. Install iOS dependencies:
cd ios && pod install && cd ..

Configuration

Backend Server Setup

  1. Navigate to the server directory and create .env file:
cd server
cp .env.example .env
  1. Get your credentials from Dodo Payments Dashboard:

  2. Edit server/.env with your credentials:

DODOPAYMENTS_TEST_API_KEY=key_test_your_api_key_here
DODO_PUBLISHABLE_KEY=pk_test_your_publishable_key_here
DODO_PRODUCT_ID=pdt_your_product_id_here
  1. Install server dependencies and start:
npm install
npm start

Server will run on http://localhost:5252

Frontend App Configuration

  1. Update App.tsx with your publishable key (line 9):
const PUBLISHABLE_KEY = 'pk_test_your_publishable_key_here';
  1. Configure network settings in src/config.ts based on your device:

For Android Emulator:

export const IS_ANDROID_EMULATOR = true;

For Physical Device:

export const IS_ANDROID_EMULATOR = false;
export const YOUR_COMPUTER_IP = '192.168.1.100'; // Your computer's IP

Running the App

Important: Start the backend server first!

  1. Start Backend Server (in server/ directory):
cd server
npm start
  1. Start Metro Bundler (in root directory):
npm start
  1. Launch App:

iOS

npm run ios

Android

npm run android

Using the App

The app features a bottom tab bar with two payment methods:

1. SDK Payment (Tab 1)

  • Native payment sheet
  • Fully customizable UI
  • Processes payment via React Native SDK
  • Best for production apps

2. Payment Link (Tab 2)

  • Opens hosted checkout in InAppBrowser
  • Quick integration, no SDK setup needed
  • Good for testing or fallback option
  • Returns to app via deep linking

Project Structure

dodopayments-react-native-demo/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ Components/           # Reusable UI components
β”‚   β”‚   β”œβ”€β”€ PaymentContent.tsx    # Shared payment UI
β”‚   β”‚   β”œβ”€β”€ BottomTabBar.tsx      # Tab navigation
β”‚   β”‚   └── ...
β”‚   β”œβ”€β”€ constants/            # Shared constants & data
β”‚   β”‚   └── mockData.ts           # Product data & calculations
β”‚   β”œβ”€β”€ utils/                # Utility functions
β”‚   β”œβ”€β”€ PaymentScreen.tsx     # SDK payment flow
β”‚   β”œβ”€β”€ PaymentLinkScreen.tsx # InAppBrowser flow
β”‚   └── config.ts             # Network configuration
β”œβ”€β”€ server/                   # Backend server
β”‚   β”œβ”€β”€ server.js             # Express API server
β”‚   β”œβ”€β”€ .env.example          # Environment template
β”‚   └── package.json
β”œβ”€β”€ ios/                      # iOS native code
β”œβ”€β”€ android/                  # Android native code
└── App.tsx                   # Main app entry

Integration Guide

1. Setup Payment Provider

Wrap your app with the DodoPaymentProvider:

import {DodoPaymentProvider} from 'dodopayments-sdk-react-native';

function App() {
  return (
    <DodoPaymentProvider publishableKey={process.env.DODO_PUBLISHABLE_KEY}>
      <PaymentScreen />
    </DodoPaymentProvider>
  );
}

2. Implement Payment Screen

import { useCheckout } from 'dodopayments-sdk-react-native';

const PaymentScreen = () => {
  const { initPaymentSession, presentPaymentSheet } = useCheckout();

  const handlePayment = async () => {
    try {
      const { clientSecret } = await fetchPaymentParams();
      const params = await initPaymentSession({ clientSecret });
      const result = await presentPaymentSheet(params);

      if (result?.status === 'succeeded') {
        // Handle successful payment
      }
    } catch (error) {
      // Handle error
    }
  };

  return (
    // Your payment UI
  );
};

Customization

Appearance Configuration

const appearance = {
  colors: {
    light: {
      primary: '#F8F8F2',
      background: '#ffffff',
      // ... other colors
    },
    dark: {
      primary: '#00ff0099',
      background: '#ff0000',
      // ... other colors
    },
  },
  shapes: {
    borderRadius: 10,
    borderWidth: 1,
  },
};

Testing

Use test card numbers in development:

  • Test Card Number: 4242 4242 4242 4242
  • Expiry: Any future date
  • CVC: Any 3 digits

Error Handling

const handlePaymentResult = paymentSheetResponse => {
  switch (paymentSheetResponse?.status) {
    case 'cancelled':
      // Handle cancellation
      break;
    case 'succeeded':
      // Handle success
      break;
    case 'failed':
      // Handle failure
      break;
  }
};

Contributing

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Support

For support, email support@dodopayments.com or visit our documentation.

About

React Native Demo for Dodo Payments

Topics

Resources

Stars

Watchers

Forks

Contributors 3

  •  
  •  
  •