React Native
- 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.
- 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.
To add the Judopay React Native SDK to your app:
- 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:
To initialise the Judopay React Native SDK:
- Import the JudoPay class from the judokit-react-native package: import JudoPay from 'judokit-react-native'`
- 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.
- Set the SDK in sandbox mode: `judoPay.isSandboxed = true`
The method for making a transaction and configuring the flow:
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:
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.
Set the JudoTransactionMode to ServerToServer when calling the Judo methods:
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:
- Use the /savecard endpoint to return a card token. For details on endpoints, see Transaction API Reference.
The method signature is as follows:
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:
|
The result is a JudoResponse object containing the transaction details:
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.
Every transaction requires a JudoConfiguration object to be passed as a parameter. The JudoConfiguration object sets all the required parameters for configuring the payment flow, including all optional parameters to customise the payment experience.
To configure the payment flow:
Import:
- JudoConfiguration
- JudoAmount
- JudoReference
from the judokit-react-native package:
You can customise the payment experience for the consumer by configuring the following UI behaviour properties in the JudoUIConfiguration object:
The JudoUIConfiguration object allows you to:
- Enable | disable the Address Verification Service
- Enable | disable consumers entering the CVV/CV2 code
- Show | hide the amount in the payment button
- Show | hide the amount in the Payments Widget
- Enable | disable consumers entering their billing information
- Set a custom theme
To create the JudoUIConfiguration object:
Parameter | Description |
---|---|
isAVSEnabled Boolean Required | Enable | disable the Address Verification Service when making card transactions. Default = False |
shouldPaymentMethodsVerifySecurityCode Boolean Required | Enable | disable the merchant entering the CV2 code for every Token Payment | Pre-auth transaction in the Payment Method Selection screen. Default = True |
shouldPaymentButtonDisplayAmount Boolean Required | Show | hide the transaction amount on the Payment | Pre-auth button. Default = False |
shouldPaymentMethodsDisplayAmount Boolean Required | Show | hide the transaction amount from the Payments Widget. Default = True |
shouldAskForBillingInformation Boolean Optional | Show | hide the billing information screen. Default = False |
theme Object Optional | Customise various elements of the payment screen. For example:
|
The incremental authorisation feature allows you to increment the value of your original preAuth for scenarios where you need to charge your customer a higher total amount.
By incrementing the preAuth value, you will be able to capture the total amount that you wish to charge your customer when you are ready.
The allowIncrement flag allows you to set up your initial preAuth so that it can be incremented by an additional amount.
This feature is only available with a limited set of processors - please check with your account manager before you use this feature.
- isAllowIncrement is a part of the main judo-configuration config object, and can be set directly in the configuration object.
- If present = it is automatically applied for preAuth requests.
- If no value is provided = then false is set by default.
Example:
To set up the transaction amount:
To set the primary account details when using an alternative payment method, see Adding Payment Methods.
It is mandatory for merchants who have an MCC code of 6012 to submit additional Information about the primary account holder in primaryAccountDetails property for payment pre-authorisation.
To set the primary account details to be sent with the transaction:
The above properties are optional, so set only the ones you need.
To change the default supported card networks:
- Set your own supportedCardNetworks value.
For the purpose of this exercise, Visa and MasterCard are set as the only supported card networks: const cardNetworks = JudoCardNetwork.Visa | JudoCardNetwork.Mastercard
To explicitly set all card networks to be supported, instead of using the | operator to combine all the card networks, set: const cardNetworks = JudoCardNetwork.All
To set the card address when using an alternative payment method, see Adding Payment Methods.
To send additional card address details with the transaction:
- Set the cardAddress parameter in the JudoConfiguration object:
By default, all payment methods are displayed in the Payments Widget (as long as the required parameters are set). As a merchant, you have flexibility over which payment methods to support.
- Change the paymentMethods property to the JudoPaymentMethod value in the JudoConfiguration instance:
An example of the JudoPaymentMethod:
You can set multiple values using the | operator. For the purpose of this exercise, Card and Apple Pay™ are set as available payment methods: const myPaymentMethods = JudoPaymentMethod.Card | JudoPaymentMethod.ApplePay To explicitly state all payment methods are to be displayed, instead of using the | operator to combine all the payment methods, set: const myPaymentMethods = JudoPaymentMethod.All
You can:
- Add any language you need.
- Override some or all of the translations of an existing language. The Judokit React Native SDK supports: en (default), fr, es.
For your React Native project (the wrapper for the Android and iOS SDKs), language translations can override the strings using the standard Android and iOS localisation processes.
Use Existing Translations
- To use or test one of Judopay's default language transalations, simply change the language on your:
- Android:
- Settings → System → Language & input → Languages
- iOS:
- Settings → General → Language & Region → iPhone Language
The translation will be applied automatically.
Override Existing Translations
To override existing translations, follow the Android or iOS localisation modifying steps below:
- Identify the SDK String Keys. The SDK uses string resources defined in its strings.xml file. You can find the list of all String Keys below.
- To modify the value of an existing string, add a new one with the same key to the strings.xml file in your Android project. You will find this located in the "res/values directory". This will override the SDK value of this string.
If your app supports multiple languages, ensure you add translations for the overridden string in the appropriate values <language_code> folders. For example values-fr for French or values-es for Spanish.
- Identify the SDK String Keys. The SDK uses string resources defined in its Localizable.strings file. You can find the list of all String Keys below.
- To modify the value of an existing string, add a new one with the same key to the Localizable.strings file in your iOS project. This will override the SDK value of this string,
If your app supports multiple languages, ensure you add translations for the overridden string in the corresponding .lproj directories. For example: fr.lproj for French, es.lproj for Spanish.
Also, remember to declare any new language in "Project > Info > Localizations". This will ensure the translation is recognised by the framework.
To add a new language
To add a new language, follow the Android or iOS steps below:
- Identify the SDK String Keys and prepare the translations for all values in the language you wish to add or override. You can find the list of all String Keys below.
- In your app’s "res/values directory", create a new folder for the language you want to add.
- Make sure you use the correct language and region codes, for example:
- ‘values-es’ for Spanish
- ‘values-zh-rCN’ for Simplified Chinese
- Inside the new language folder, create a strings.xml file if one does not already exist.
- Within the newly created strings.xml ensure you provide the translations for all String Keys used by the SDK, otherwise the translation may end up incomplete.
When overriding or adding new String Keys, be careful to avoid String Key conflicts between the SDK and your app. Any matching Key will cause your app’s value to override the SDK's default value, which could potentially lead to unintended behaviour, or mismatched translations.
- Identify the SDK String Keys and prepare the translations for all values in the language you wish to add or override. You can find the list of all String Keys below.
- In your app’s project directory, create a new .lproj folder for the language you want to add.
- Ensure you use the correct language and region codes. For example:
- es.lproj for Spanish
- zh-Hans.lproj for Simplified Chinese.
- Inside the new language folder, create a Localizable.strings file if one does not already exist.
- Within the newly created Localizable.strings file ensure you provide the translations for all String Keys used by the SDK, otherwise the translation may end up incomplete.
- Declare the new language in: "Project > Info > Localizations". This will ensure the translation is recognised by the framework.
When overriding or adding new String Keys, be careful to avoid String Key conflicts between the SDK and your app. Any matching Key will cause your app’s value to override the SDK's default value, which could potentially lead to unintended behaviour, or mismatched translations.
String Keys
To make custom fonts work, they must be added to your client app first.
Styling The JudoTheme property handles the:
- Font families
- Font sizes
- Font colors
Please note this will only apply styles and themes to the iOS platform.
Custom Fonts
An example of a complete custom theme:
To set up the Payments Widget for React Native:
- Set up the JudoConfiguration instance:
Setting up the transaction reference enables you to also set up your consumerReference and paymentReference which are included within the transaction. These references help you to identify your consumer and transaction.
To set up the transaction reference:
- From the imported JudoReference interface:
2. Use the interface to set your consumerReference. A unique reference to identify your consumer.
3. You can also set optional fields, for example:
- paymentReference: A unique payment reference for the transaction.
- metaData: Any additional organisation or system details to be included in the transaction.
For example a consumerReference is set:
For the purpose of this exercise, the:
- amount
- reference
- judoID
are set in the JudoConfiguration instance:
All the required parameters are now set up, and ready to make a transaction.
A complete JudoConfiguration example:
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.
- You have set up your Apple Pay™ Developer Account to get your Merchant IDs. For more details, see Configuring Apple Pay for iOS.
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.
Step One: Configure Apple Pay™:
Create an applePayConfiguration instance:
Parameter | Description |
---|---|
merchantId String Required | Your Apple Pay™ merchant ID.This confirms you are able to accept payments. |
countryCode String Required | An ISO 3166-1 Alpha-2 country code. |
paymentSummaryItems String Required | The list of items. |
requiredBillingContactFields JudoContactField Optional | Select between one or more billing contact fields. For example:
|
requiredShippingContactFields JudoContactField Optional | Select between one or more shipping contact fields. For example:
|
shippingMethods JudoShippingMethod[] Optional | Describe some of the shipping methods that you provide. Although this parameter is optional, if you set shipping contact fields as required, you must also provide the shipping type and shipping methods. |
shippingType JudoShippingType Optional | Select a shipping type:
Although this parameter is optional, if you set shipping contact fields as required, you must also provide the shipping type and shipping methods. |
returnedInfo JudoReturnedInfo Optional | Select to receive some of the billing and/or shipping details as a response property. |
Step Two: Check Availability and Make an Apple Pay™ Transaction
Displaying Apple Pay™ as a Payment Method
To display Apple Pay™ in the Payments Widget:
Add the applePayConfiguration property to the JudoConfiguration instance:
Call the ApplePay method and handle the response:
Use the JudoTransactionMode property for Payments or Pre-auths with Apple Pay™.
Making an Apple Pay™ Transaction
An example of an Apple Pay™ transaction:
The last item in the JudoPaymentSummaryItem list must always represent the total amount of the previous items.
Prerequisite
- You have set up your Google Pay™ payments profile.
To make a Google Pay™ transaction, or add Google Pay™ as a payment method in the Payment Method Selection screen:
- Provide a JudoGooglePayConfiguration property.
Example of a googlePayConfiguration property:
Field | Description |
---|---|
countryCode String Required | An ISO 3166-1 Alpha-2 country code. |
environment JudoGooglePayEnvironment enum Required | Sets the Google Pay™ environment to either:
In order to go-live you will need to have set up your Google Pay™ API merchant live account. |
IsEmailRequired Boolean Optional | Specifies if the user is required to add their email address. |
IsBillingAddressRequired Boolean Optional | Specifies if the user is required to add their billing information. |
billingAddressParameters JudoBillingAddressParameters Optional | Describes the full or minimum:
Although this parameter is optional, if you set billing / shipping fields as required, you must also provide the billing / shipping parameters. |
IsShippingAddressRequired Boolean Optional | Specifies if the user is required to add their shipping information. |
ShippingAddressParameters JudoBillingAddressParameters Optional | Describes the allowed country codes and phone number requirements. Although this parameter is optional, if you set billing / shipping fields as required, you must also provide the billing / shipping parameters. |
Displaying Google Pay™ as a Payment Method
To display Google Pay™ in the Payments Widget:
Add the googlePayConfiguration property to the JudoConfiguration instance:
Invoke the GooglePay method and handle the response:
Use the JudoTransactionMode property for Payments or PreAuths with Google Pay.
Making a Google Pay™ Transaction
Example of a Google Pay™ transaction:
To add iDEAL support to your Payments Widget:
- Set the currency code to EUR (Euro)
- Set the judoId
- Include iDEAL as a payment method
An example of a valid iDEAL configuration:
Once the currency and judoId are set, iDEAL will be available as a payment method in the Payments Widget.