Mobile
Mobile SDKs

React Native

Integrating React Native with Judopay

Prerequisites

  • You have set up your Judopay account.
    • Sign up for your sandbox account, to receive access to your Judopay dashboard and the sandbox environment.
  • Your judoIds and tokens are configured and enabled as appropriate.
    • For more information on permissions, see Permissions.
  • You have the development environment set up for React Native, here.
  • Judopay's React Native SDK requires React Native Version 0.69.7 (and higher).

For Mobile apps, we recommend using payment session authentication.

The Judopay SDK for React Native is available as a node package and can be added to the project via npm or yarn.

Judopay's React Native examples use TypeScript, however you can also use JavaScript.



Adding and Initialising React Native

To add the Judopay React Native SDK to your app:

  1. Enter the following line into the terminal: `npm install judokit-react-native` or, `yarn add judokit-react-native`

Below is an example of a package.json file with the Judopay SDK dependency:

{ "name": "my-app", "version": "1.0.0", "scripts": { ... }, "dependencies": { "judo-react-native": "4.0.0", ... }, "devDependencies": { ... }, ... }

To initialise the Judopay React Native SDK:

  1. Import the JudoPay class from the judokit-react-native package: import JudoPay from 'judokit-react-native'`
  2. Provide your token and secret OR paymentSession: `const judoPay = new JudoPay({token: "my-token", secret: "my-secret"})` Or, `const judoPay = new JudoPay({token: "my-token", paymentSession: "my-payment-session"})` You can generate a payment session using one of our Server SDKs, or by making a call to our Transaction API. 
  3. Set the SDK in sandbox mode: `judoPay.isSandboxed = true`


Making a Transaction

The method for making a transaction and configuring the flow:

Making a Transaction


Parameter

Description

type JudoTransactionType

An enum value that describes the transaction type.

configuration JudoConfiguration

A configuration object that configures the payment flow.

The response is handled via a Promise which resolves to a JudoResponse.

To make a transaction:

Transaction Example



React Native Server to Server Transactions

This feature is intended to allow the merchant to access cardTokens stored securely by the Mobile SDK, to then use the cardToken to make a server-to-server transaction using our Server SDK Integration, or our Transaction API.

This is typically intended for scenarios where a merchant might want to process a Merchant Initiated Transaction using the card details stored by the consumer.

Specify a Server to Server Transaction

Set the JudoTransactionMode to ServerToServer when calling the Judo methods:

judo.invokePaymentMethodScreen(JudoTransactionMode.ServerToServer, configuration) .then((response) => {/* Handle response */}) .catch((error) => {/* Handle error */})

Specify an Apple Pay™ Server to Server Transaction

judo.invokeApplePay(JudoTransactionMode.ServerToServer, configuration) .then((response) => {/* Handle response */})

Specify a Google Pay™ Server to Server Transaction

judo.invokeGooglePay(JudoTransactionMode.ServerToServer, configuration) .then((response) => {/* Handle response */})


Token Payments

If you are building your own card wallet, and not using a UI you can make a /preauth or /payment using a stored card token.

To make a token payment or pre-auth token payment:

  1. Use the /savecard endpoint to return a card token. For details on endpoints, see Transaction API Reference.

The method signature is as follows:

public async performTokenTransaction( mode: JudoTransactionMode, configuration: JudoConfiguration, cardToken: string, securityCode: string, cardholderName: string, cardScheme: string ): Promise<JudoResponse>;

Parameter

Description

mode JudoTransactionMode

A value used to specify either a pre-auth or payment.

configuration JudoConfiguration

An object used to configure the payment flow.

cardToken String

The card token used for the token transaction.

securityCode String

The saved card token security code.

cardholderName String

The saved card token cardholder name.

cardScheme String

The saved card token scheme name, for example:

  • Visa
  • Mastercard
  • Amex

The result is a JudoResponse object containing the transaction details:

Response Example



3D Secure 2 for React Native

JudoKit-ReactNative supports 3D Secure 2 (EMV 3DS).

3D Secure 2 is available in JudoKit React Native version 3.0.0 or higher, and is available on Github.

3D Secure 2 Payment Example



Customising the Payment Experience



Adding Payment Methods

Before you can process Apple Pay™ payments with Judopay, you will need to set up Apple Pay™.

Apple Pay™ is not supported on all Apple devices.

Prerequisite

Before invoking any Apple Pay™ functionality within your app, test if it is supported on the device by performing these checks:

  • Use PKPaymentAuthorizationViewController canMakePayments
    • Checks if the device supports Apple Pay™ and has it enabled.
    • Queries both the device hardware and whether Apple Pay™ is enabled in the user’s region.
  • Use PKPaymentAuthorizationViewController canMakePaymentsUsingNetworks
    • A more detailed check to query whether a user has a registered card with particular card schemes.
    • Useful if you do not accept all card types.

Both methods are explained in the Apple developer documentation here.