Skip to content

reepay/reepay-checkout-demo-app-react-native

Repository files navigation

Reepay Checkout - React Native Example

This is an example of Reepay Checkout using React Native app.

Setup

This React Native app is built with Expo CLI. The development environment is described in React Native Docs. Install node modules with npm install.

Global Expo CLI is deprecated: npm install -g expo-cli

Local Expo CLI is now included in the expo package. New Expo CLI.

Table of Contents

Available Scripts

The project is built with node version v18.16.1, npm version 9.5.1, expo version 49.0.16, React Native version 0.72.6 and React Native WebView 13.2.2.

npm run start

Runs your app in development mode.

npm run start

npm run tunnel

Runs your app in Expo development client by scanning the generated QR code. The app can be viewed using Expo for Android or Expo Go for iOS.

npm run tunnel

npm run android

Like npm run start, but also attempts to open your app on a connected Android device or Android emulator. It requires installation of Android build tools (see React Native Docs for how to run on devices). An Android folder will be generated which can be opened with Android Studio.

npm run android

npm run ios

Like npm run start, but also attempts to open your app on an iOS simulator. An iOS folder will be generated which can be opened in Xcode, which you can run your app on an iOS device. There may be some issues with Apple Silicon processor (M1) if you are using nvm and running your app with npm run ios. Read more under Troubleshooting.

npm run ios

npm run web

Runs your app in a web browser.

npm run web

npm run eject

If you plan to include your own native code, you will need to "eject" to create your own native builds. The "React Native CLI Quickstart" instructions will be required to continue working on this project.

Warning: Running eject is a permanent action (aside from whatever version control system you use). An ejected app will require you to have an Xcode and/or Android Studio environment set up.

npm run eject

Events

In the app, we will use URL path changes as events that WebView listens to, thus checking whether URL contains accept or cancel in the path.

URL path changes

As we are using WebView by passing session URL, we will receive response with as either Accept URL or Cancel URL as defined in the request body docs:

{
  ...
  "accept_url":"https://webshop.com/accept/order-12345",
  "cancel_url":"https://webshop.com/decline/order-12345"
}

In the WebView, we will listen to URL changes when the checkout has completed a redirect, either accept or cancel by checking the URL path. For example the above cancel_url, we will check for /decline meaning the cancel_url has been triggered and WebView has redirected.

Extra

For additional parameters to be passed, use query parameters in accept_url or cancel_url. For example, https://webshop.com/decline/order-12345?myEvent=someValue&yourEvent=anotherValue.

Usage

Card payment steps:

  1. Generate Private API Key from your Reepay account.
  2. Add the Private API Key to Globals.ts or in the app.
  3. (Optional) Add an unique identifier for your Order and/or Customer handle.
  4. Generate a charge session.
  5. Create Reepay checkout in the webview.
  6. Complete the purchase with a test card or cancel the checkout.

Accept flow

accept.MOV

Cancel flow

cancel.MOV

Reepay Private API Key

When you have generated a Private API Key from Reepay. Add the value to REEPAY_PRIVATE_API_KEY located at ./src/Globals.ts.

Alternatively, run your app and add it directly in the Private API Key input field.

Screenshot 2022-07-29 at 12 37 23

Reepay MobilePay Checkout

MobilePay Online must be activated in your Reepay account under Configuration -> Payment Methods -> Mobile Payments. For Reepay Test accounts, it is required to get MobilePay Sandbox app. Reepay Live accounts will use MobilePay app.

Recommended to use npm run tunnel for testing MobilePay Checkout.

MobilePay Online steps:

  1. Generate Private API Key from your Reepay account.
  2. Add the Private API Key to Globals.ts or in the app.
  3. Add a Danish phone number.
  4. Generate a charge session.
  5. Create MobilePay checkout in the webview.
  6. Complete the purchase with a MobilePay test user or reject the payment.
mobilepay.mov

Troubleshooting

Apple Silicon build issues

An issue have been found regarding building React Native apps for iOS using Apple Silicon processors (M1). There are conflicts with node version when using nvm thus creating errors on build.

Upon receiving PhaseScriptExecution [CP-User] error when building iOS using npm run ios. Follow this temporary solution.

Note that the iOS build works when running in Xcode. In case of the Xcode build error Could not find node. Make sure it is in bash PATH or set the NODE_BINARY environment variable., please refer to this.

About

No description or website provided.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published