@onramp.money/onramp-react-native-sdk
Version:
React-Native SDK for Onramp payment gateway.
56 lines (55 loc) • 2.02 kB
JavaScript
;
import { NativeEventEmitter, NativeModules, Platform } from 'react-native';
const LINKING_ERROR = `The package 'react-native-onramp' doesn't seem to be linked. Make sure: \n\n` + Platform.select({
ios: "- You have run 'pod install'\n",
default: ''
}) + '- You rebuilt the app after installing the package\n' + '- You are not using Expo Go\n';
const Onramp = NativeModules.OnrampSDK ? NativeModules.OnrampSDK : new Proxy({}, {
get() {
throw new Error(LINKING_ERROR);
}
});
const isValidPhoneNumber = phoneNumber => {
const encodedRegex = /^%2[Bb]\d+-\d+$/;
return encodedRegex.test(phoneNumber);
};
export const startOnrampSDK = config => {
if (!config.appId) {
throw new TypeError("'appId is missing or null.'");
}
if (config.phoneNumber && !isValidPhoneNumber(config.phoneNumber)) {
if (typeof config.phoneNumber !== 'string' || !isValidPhoneNumber(config.phoneNumber)) {
throw new TypeError('Invalid phoneNumber format. Expected URL-encoded "+countryCode-phoneNumber" format; use encodeURIComponent to encode the phone number');
}
}
return Onramp.startSdk(config);
};
export const startOnrampLogin = params => {
if (!params.appId) {
throw new TypeError("'appId is missing or null.'");
}
return Onramp.startOnrampLogin(params);
};
export const initiateOnrampKyc = params => {
if (!params.appId) {
throw new TypeError("'appId is missing or null.'");
}
if (!params.payload) {
throw new TypeError("'payload is missing or null.'");
}
if (!params.signature) {
throw new TypeError("'signature is missing or null.'");
}
if (!params.customerId) {
throw new TypeError("'customerId is missing or null.'");
}
if (!params.apiKey) {
throw new TypeError("'apiKey is missing or null.'");
}
return Onramp.initiateOnrampKyc(params);
};
export const closeOnrampSDK = () => {
return Onramp.closeSdk();
};
export const onRampSDKNativeEvent = new NativeEventEmitter(NativeModules.OnrampSDK);
//# sourceMappingURL=index.js.map