Use this guide to integrate Pesaswap SDK to your React Native app. You can use the following Demo App as a reference with your Pesaswap credentials to test the setup.
Demo App
Before following these steps, please configure your payment methods.Requirements
- Android 5.0 (API level 21) and above
- Android Gradle Plugin 7.3.1
- Gradle 7.5.1+
- AndroidX
- iOS 12.4 and above
- CocoaPods
- npm
1. Setup the Server
Follow the Server Setup section.2. Build Checkout Page on the Client
2.1 Install the Pesaswap-sdk-react-native Libraries
Install the packages and import them into your code:2.2 Peer Dependencies
Install the following dependencies:react-native-klarna-inapp-sdk, please remove it from the dependencies.
2.3 iOS Only
Run pod install in the iOS folder:2.4 Android Only
In the Android folder inside thestrings.xml file (android/app/src/main/res/values/strings.xml), add the below line:
android/settings.gradle file, add the following line to link react-native-code-push:
android/app/src/main/AndroidManifest.xml), add these lines to the existing code:
2.5 Add HyperProvider to Your React Native App
UseHyperProvider to ensure that you stay PCI compliant by sending payment details directly to the Pesaswap server.
2.6 Use HyperProvider
To initialize Pesaswap in your React Native app, wrap your payment screen with theHyperProvider component. Only the API publishable key in publishableKey is required. The following example shows how to initialize Pesaswap using the HyperProvider component:
3. Complete the Checkout on the Client
3.1 Import useHyper to Your Checkout Page
In the checkout of your app, import theuseHyper() hook:
3.2 Fetch the PaymentIntent Client Secret
Make a network request to the backend endpoint you created in the previous step. TheclientSecret returned by your endpoint is used to complete the payment:
3.3 Collect Payment Details
CallinitPaymentSession from the useHyper hook to customize the payment sheet, billing or shipping addresses, and initialize the payment sheet:
3.4 Handle Payment Response
To display the Payment Sheet, integrate a “Pay Now” button within the checkout page, which, when clicked, invokes thepresentPaymentSheet() function. This function will return an asynchronous payment response with various payment statuses: