मुख्य सामग्री पर जाएं

React Native SDK एकीकरण

Dodo Payments React Native SDK आपको अपने मूल Android और iOS ऐप्स में सुरक्षित भुगतान अनुभव बनाने की अनुमति देता है। हमारा SDK भुगतान विवरण एकत्र करने के लिए अनुकूलन योग्य UI घटक और स्क्रीन प्रदान करता है।
  • 📦 हमारे SDK को NPM से स्थापित करें
  • 📚 पूर्ण कार्यान्वयन उदाहरणों के लिए हमारे डेमो रिपॉजिटरी को देखें
  • 🎥 Dodo Payments SDK को क्रियान्वित होते हुए देखने के लिए हमारा डेमो वीडियो देखें

विशेषताएँ

Simplified Security

PCI अनुपालन बनाए रखते हुए संवेदनशील भुगतान डेटा को सुरक्षित रूप से एकत्र करें

Multiple Payment Methods

वैश्विक पहुँच बढ़ाने के लिए विभिन्न payment methods स्वीकार करें

Native UI

Android और iOS के लिए मूल स्क्रीन और तत्व
वर्तमान में, React Native SDK में Apple Pay, Google Pay, Cash App, और UPI समर्थित नहीं हैं। हम इन भुगतान विधियों के लिए भविष्य के रिलीज़ में समर्थन जोड़ने पर सक्रिय रूप से काम कर रहे हैं।

स्थापना

1

Install the SDK

अपने पसंदीदा पैकेज मैनेजर का उपयोग करके Dodo Payments SDK इंस्टॉल करें:
npm install dodopayments-react-native-sdk
2

Platform-specific setup

अपनी iOS फ़ोल्डर में pod install चलाएँ:
cd ios && pod install && npm run ios

क्लाइंट-साइड सेटअप

1

Get Publishable Key

Dodo Payments डैशबोर्ड से अपना publishable key प्राप्त करें। (टेस्ट और लाइव मोड दोनों के लिए अलग-अलग) https://app.dodopayments.com/developer/others
2

Setup Payment Provider

DodoPaymentProvider के साथ अपने ऐप को रैप करें:
App.tsx
import React from 'react';
import { DodoPaymentProvider } from 'dodopayments-react-native-sdk';
import PaymentScreen from './PaymentScreen';

function App() {
  return (
    <DodoPaymentProvider publishableKey="YOUR_PUBLISHABLE_KEY">
      <PaymentScreen />
    </DodoPaymentProvider>
  );
}

export default App;
आपको अपने Dodo Payments डैशबोर्ड से API कीज़ उत्पन्न करनी होंगी। विस्तृत निर्देशों के लिए हमारी API key generation guide देखें।
3

Create payment utility function

अपनी backend API से भुगतान पैरामीटर प्राप्त करने के लिए एक उपयोगिता फ़ंक्शन बनाएं:
utils/fetchPaymentParams.ts
const API_URL = 'YOUR_BACKEND_URL'; // Replace with your server URL

const fetchPaymentParams = async () => {
  const response = await fetch(`${API_URL}/create-payment`, {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
    },
  });
  
  if (!response.ok) {
    throw new Error('Failed to fetch payment parameters');
  }
  
  return await response.json();
};

export default fetchPaymentParams;
यह फ़ंक्शन मानता है कि आपके पास एक backend API endpoint है जो payment intents बनाता है और एक client secret लौटाता है। सुनिश्चित करें कि आपका backend भुगतान निर्माण को संभालने के लिए ठीक से कॉन्फ़िगर किया गया है। बैकएंड सेटअप उदाहरणों के लिए हमारी API Integration Tutorial देखें।
4

Implement the payment screen

useCheckout हुक का उपयोग करके अपनी भुगतान स्क्रीन बनाएं। यहाँ एक पूर्ण कार्यान्वयन है:
PaymentScreen.tsx
import React from 'react';
import { View, Text, useColorScheme } from 'react-native';
import { useCheckout, type sessionParams } from 'dodopayments-react-native-sdk';
import fetchPaymentParams from './utils/fetchPaymentParams';

const PaymentScreen = () => {
  const { initPaymentSession, presentPaymentSheet } = useCheckout();
  const [error, setError] = React.useState('');
  const [message, setMessage] = React.useState('');
  const [loading, setLoading] = React.useState(false);
  const [showSuccessScreen, setShowSuccessScreen] = React.useState(false);
  const isDarkMode = useColorScheme() === 'dark';

  const processPayment = async () => {
    setLoading(true);
    setMessage('');
    setError('');

    try {
      // 1. Get payment parameters from your backend
      const key = await fetchPaymentParams();
      
      // 2. Initialize payment session
      const paymentSheetParamsResult = await initPaymentSession({
        clientSecret: key.clientSecret,
      });
      
      // 3. Configure and present payment sheet
      const params: sessionParams = {
        ...(paymentSheetParamsResult as sessionParams),
        configuration: {
          appearance: {
            themes: isDarkMode ? 'dark' : 'light',
            primaryButton: {
              colors: {
                light: {
                  background: 'green',
                  componentBorder: 'green',
                  placeholderText: 'yellow',
                },
                dark: {
                  background: 'green',
                  componentBorder: 'green',
                  placeholderText: 'yellow',
                },
              },
              shapes: {
                borderRadius: 30,
                borderWidth: 3,
              },
            },
          },
          mode: 'test', // DEFAULTS TO TEST MODE
        },
      };

      const paymentSheetResponse = await presentPaymentSheet(params);

      // 4. Handle payment result
      switch (paymentSheetResponse?.status) {
        case 'cancelled':
          setError('Payment cancelled by user.');
          break;
        case 'succeeded':
          setMessage('');
          setShowSuccessScreen(true);
          break;
        case 'failed':
          setError('Payment failed : \n' + paymentSheetResponse?.message);
          break;
        default:
          setError(paymentSheetResponse?.message);
          setMessage('');
      }
    } catch (err) {
      setError('Failed to process payment');
    } finally {
      setLoading(false);
    }
  };

  return (
    <View>
      <Button 
        onPress={processPayment}
        disabled={loading}
        title={loading ? 'Processing...' : 'Pay Now'}
      />
      {error && <Text style={{ color: 'red' }}>{error}</Text>}
      {message && <Text style={{ color: 'green' }}>{message}</Text>}
      {showSuccessScreen && (
        <PaymentSuccessScreen
          amount={total}
          onContinue={() => setShowSuccessScreen(false)}
        />
      )}
    </View>
  );
};

export default PaymentScreen;
स्टाइलिंग, त्रुटि हैंडलिंग, और अनुकूलन विकल्पों के साथ पूर्ण उदाहरणों के लिए हमारे डेमो रिपॉजिटरी देखें:

कॉन्फ़िगरेशन विकल्प

सत्र पैरामीटर

clientSecret
string
आवश्यक
आपकी भुगतान मंशा से प्राप्त client secret, जिसे वन टाइम पेमेंट या सब्सक्रिप्शन API से प्राप्त किया गया है।
mode
string
आवश्यक
भुगतान सत्र का मोड (test या live)।
configuration.appearance
object
भुगतान शीट की उपस्थिति के लिए अनुकूलन विकल्प
configuration.appearance.themes
string
थीम मोड: 'light' या 'dark'

उपस्थिति अनुकूलन

आप appearance पैरामीटर को संशोधित करके React Native Unified Checkout को अपने ऐप की डिज़ाइन के अनुरूप अनुकूलित कर सकते हैं जब आप initPaymentSession() को कॉल करते हैं।

रंग अनुकूलन

प्रत्येक रंग श्रेणी UI में एक या अधिक घटकों का रंग निर्धारित करती है। उदाहरण के लिए, primary Pay बटन का रंग निर्धारित करता है।
Color CategoryUsage
primaryPay बटन और चयनित आइटम के लिए प्राथमिक रंग
backgroundभुगतान पृष्ठ की पृष्ठभूमि का रंग
componentBackgroundइनपुट, टैब, और अन्य घटकों के लिए पृष्ठभूमि रंग
componentBorderइनपुट, टैब, और अन्य घटकों के लिए बाहरी सीमा का रंग
componentDividerघटकों के लिए आंतरिक सीमा का रंग (साझा सीमाएँ)
primaryTextहेडर टेक्स्ट का रंग
secondaryTextइनपुट फ़ील्ड्स के लिए लेबल टेक्स्ट का रंग
componentTextइनपुट टेक्स्ट का रंग (जैसे कार्ड नंबर, ज़िप कोड)
placeholderTextइनपुट फ़ील्ड्स के लिए प्लेसहोल्डर टेक्स्ट का रंग
iconआइकन (जैसे क्लोज़ बटन) का रंग
errorत्रुटि संदेशों और विनाशकारी क्रियाओं का रंग
हल्का और गहरा मोड समर्थन के साथ उदाहरण कॉन्फ़िगरेशन:
const appearance = {
  colors: {
    light: {
      primary: '#F8F8F2',
      background: '#ffffff',
      componentBackground: '#E6DB74',
      componentBorder: '#FD971F',
      componentDivider: '#FD971F',
      primaryText: '#F8F8F2',
      secondaryText: '#75715E',
      componentText: '#AE81FF',
      placeholderText: '#E69F66',
      icon: '#F92672',
      error: '#FF0000',
    },
    dark: {
      primary: '#00ff0099',
      background: '#ff0000',
      componentBackground: '#ff0080',
      componentBorder: '#62ff08',
      componentDivider: '#d6de00',
      primaryText: '#5181fc',
      secondaryText: '#ff7b00',
      componentText: '#00ffff',
      placeholderText: '#00ffff',
      icon: '#f0f0f0',
      error: '#0f0f0f',
    },
  },
};

आकार अनुकूलन

आप भुगतान इंटरफ़ेस में उपयोग किए जाने वाले सीमा त्रिज्या, सीमा चौड़ाई, और छाया को अनुकूलित कर सकते हैं:
const appearance = {
  shapes: {
    borderRadius: 10, // Border radius for input fields, tabs, and components
    borderWidth: 1,   // Border width for components
  },
};

घटक-विशिष्ट अनुकूलन

आप प्राथमिक बटन (भुगतान बटन) जैसे विशिष्ट UI घटकों को अनुकूलित कर सकते हैं। ये सेटिंग्स वैश्विक उपस्थिति सेटिंग्स पर प्राथमिकता लेती हैं:
const appearance = {
  primaryButton: {
    colors: {
      background: '#000000',
      text: '#ffffff',
      border: '#ff00ff',
    },
    shapes: {
      borderRadius: 10,
      borderWidth: 1.5,
    },
  },
};
इन अनुकूलनों को लागू करने के लिए, उन्हें अपने भुगतान सत्र कॉन्फ़िगरेशन में शामिल करें:
const params: sessionParams = {
  ...paymentSheetParams,
  configuration: {
    appearance: {
      themes: isDarkMode ? 'dark' : 'light',
      ...appearance, // Include your custom appearance settings
    },
  },
};

त्रुटि हैंडलिंग

अपने चेकआउट फ़ंक्शन में विभिन्न भुगतान राज्यों को संभालें:
const handlePaymentResult = (paymentSheetResponse) => {
  switch (paymentSheetResponse?.status) {
    case 'cancelled':
      // User cancelled the payment
      console.log('Payment cancelled by user');
      break;
    case 'succeeded':
      // Payment completed successfully
      console.log('Payment succeeded');
      // Navigate to success screen or update UI
      break;
    case 'failed':
      // Payment failed
      console.log('Payment failed:', paymentSheetResponse?.message);
      // Show error message to user
      break;
    default:
      console.log('Unknown payment status:', paymentSheetResponse?.status);
  }
};
  • Network connectivity issues: सुनिश्चित करें कि इंटरनेट कनेक्शन स्थिर है
  • Invalid client secret: सत्यापित करें कि बैकएंड मान्य भुगतान मंशाएँ उत्पन्न कर रहा है
  • Missing peer dependencies: सभी आवश्यक निर्भरताएँ इंस्टॉल करें
  • Platform-specific setup: iOS और Android कॉन्फ़िगरेशन चरणों को पूरा करें
  • API errors: विस्तृत त्रुटि हैंडलिंग के लिए हमारे Error Codes Reference को देखें
  • विकास में debug लॉगिंग सक्षम करें
  • अपने बैकएंड के लिए नेटवर्क अनुरोधों की जांच करें
  • सत्यापित करें कि API कीज़ सही तरीके से कॉन्फ़िगर की गई हैं
  • दोनों iOS और Android प्लेटफ़ॉर्म पर परीक्षण करें
  • सामान्य समस्याओं के लिए हमारे Technical FAQs की समीक्षा करें
  • Test vs Live Mode का उपयुक्त उपयोग करें

परीक्षण भुगतान विधियाँ

विकास में वास्तविक भुगतान प्रोसेस किए बिना अपने एकीकरण को सत्यापित करने के लिए टेस्ट कार्ड नंबरों का उपयोग करें। हमारे testing process और उपलब्ध टेस्ट परिवेशों के बारे में अधिक जानें।