React Native integration via SDK

Ramp ReactNative SDK is a library that allows you to easily integrate Ramp into your React Native app and communicate with it.

Overview

This guide describes how to add and use Ramp SDK to your React Native app.

Install the Package

At the root level of your project, install the package with yarn or npm inside the terminal:

yarn

yarn add @ramp-network/react-native-sdk

npm

npm install --save @ramp-network/react-native-sdk

iOS integration

note

Please ensure that you are using the latest XCode version, since the SDK is written in Swift 5.5. As of this writing, this is Xcode 13.0.

The minimum iOS version is 11.0. Make sure to include this in the Podfile:

platform :ios, '11.0'

If your project doesn't have a Podfile, create it in the root directory of your project and paste the following code into it. Remember to change target name to the one you are using.

Add the following sources and the Ramp pod reference to proper target sections.

// Podfile
platform :ios, '11.0'
inhibit_all_warnings!
source 'https://github.com/CocoaPods/Specs.git'
source 'https://github.com/passbase/zoomauthentication-cocoapods-specs.git'
source 'https://github.com/passbase/cocoapods-specs.git'
source 'https://github.com/passbase/microblink-cocoapods-specs.git'
target 'ReactNativeApp' do
use_frameworks!
pod 'Ramp', :git => 'git@github.com:RampNetwork/ramp-sdk-ios.git', :tag => '2.0.0'
end

Then, navigate inside the terminal into your project folder and run the pod install command to install Ramp SDK as a dependency.

In your terminal, you should see logs similar to the following:

$ pod install
Analyzing dependencies
Pre-downloading: `Ramp` from `git@github.com:RampNetwork/ramp-sdk-ios.git`, tag `v0.9.0`
Downloading dependencies
Installing Microblink (5.11.1)
Installing Passbase (2.4.0)
Installing Ramp (0.0.1)
Installing ZoomAuthentication (8.7.1)
Generating Pods project
Integrating client project
[!] Please close any current Xcode sessions and use `ExampleCocoapods.xcworkspace` for this project from now on.
Pod installation complete! There is 1 dependency from the Podfile and 4 total pods installed.

Project setup

After integrating Ramp SDK, you need to adjust your app's permissions.

Ramp uses Passbase SDK for Know Your Customer process. In order for Passbase to work, you have to set up permissions for Camera Usage and Photo Library Usage.

Please add the following permissions to your app's Info.plist file, so that the verification library can access a user's camera to run the verification process. You can do this in the property list view or by editing the code.

If you choose to do it via GUI, open the Info.plist, right-click somewhere outside the table and select Add Row. Your entries should look like the following:

If you prefer to do this step by editing the file directly, right-click on Info.plist and select Open As -> Source Code. Add these lines below somewhere inside the <dict> </dict>

<!-- permission strings to be included in info.plist -->
<key>NSCameraUsageDescription</key>
<string>Please give us access to your camera, to complete the verification.</string>
<key>NSPhotoLibraryUsageDescription</key>
<string>Please give us access to your photo library to verify you.</string>

Android integration

To install Ramp Android SDK, add its repository in your root build.gradle at the end of repositories:

allprojects {
repositories {
maven { url 'https://jitpack.io' }
maven { url 'https://button.passbase.com/__android' }
}
}

Please use minSdkVersion 21 in your build.gradle (Module:app)

android {
defaultConfig {
minSdkVersion 21
// ...
}
}

Initializing the SDK

Importing the SDK

All setup is done - let's start working on the integration. First, import the module:

import RampSdk from '@ramp-network/react-native-sdk';

Filling the configuration object with your data

In order to start the widget, you need to provide some basic configuration to the constructor of our SDK. Most of the parameters are optional. You can set options such as user wallet address, desired cryptocurrency and cryptocurrency amount, etc. A more detailed list of the available configuration parameters with examples can be found here. A basic example looks like this:

const ramp = new RampSdk({
hostAppName: 'Ramp RN Demo',
hostLogoUrl: 'https://rampnetwork.github.io/assets/misc/test-logo.png',
deepLinkScheme: 'ramprndemo',
});

Returning from third-party apps in iOS

Some payment methods redirect users to an external app such as banking apps (Revolut, Monzo, etc.). To redirect the user back to your app after the payment, you can set a custom URL scheme for your app and then pass the scheme to deepLinkScheme configuration parameter of our SDK.

Implementing events

After getting the RampSDK object from the constructor we called in the example above, you can run its methods to subscribe to and unsubscribe from SDK events.

Available event types:

  • WidgetEventTypes.PURCHASE_CREATED is called when a purchase is created, and returns a Purchase object, containing all its parameters. All fields of are described in the documentation here.

  • WidgetEventTypes.WIDGET_CLOSE is called when Ramp finishes the flow and can be closed, or user closed it manually.

Event subscription methods:

  • on(type: TAllEvents['type'] | '*', callback: (event: TAllEvents) => any)

    Use this method to subscribe to events. You can pass event type to pick specific a one or pass '*' to get all of them. On callback parameter handle the event.

    Example:

    ramp.on(WidgetEventTypes.WIDGET_CLOSE, (event) => {
    // react to the event here
    });
  • unsubscribe(type: TAllEventsAllEvents['type'] | '*', callback: (event: TAllEvents) => any)

    Use this method to unsubscribe from events.

    Example:

    ramp.unsubscribe(WidgetEventTypes.WIDGET_CLOSE, yourCallback);

Starting the widget

Now that the SDK is configured, you just need to run the show() method to open the Ramp widget.

rampSdk.show();

Full example

import React from 'react';
import { StyleSheet, View, Button } from 'react-native';
import RampSdk from '@ramp-network/react-native-sdk';
export default function App() {
const ramp = new RampSdk({
url: 'https://ri-widget-staging.firebaseapp.com',
hostAppName: 'React Native Example',
hostLogoUrl: 'https://rampnetwork.github.io/assets/misc/test-logo.png',
}).on('*', (event) => {
console.log(`RampSdk.on('*')`, event);
});
return (
<View style={styles.container}>
<Button title={`Run Ramp Widget`} onPress={() => ramp?.show()} />
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
alignItems: 'center',
justifyContent: 'center',
},
});

Troubleshooting

Build failed (xCode >= 12.0) with the error below:

Undefined symbol: __swift_FORCE_LOAD_$_swiftWebKit

Go to the Build Phases tab and add libswiftWebKit.tbd in the Link Binary with Libraries section.