fiuu-mobile-xdk-reactnative
Version:
Razer Merchant Services mobile payment for React Native
54 lines (47 loc) • 1.83 kB
JavaScript
import { Platform, NativeModules } from 'react-native';
console.log("Available Native Modules:", NativeModules);
const { FiuuPayment } = NativeModules;
if (!FiuuPayment) {
throw new Error("FiuuPayment not found");
}
export default {
startMolpay: (paymentDetails, successCallback, errorCallback) => {
if (Platform.OS === 'android') {
if (typeof paymentDetails == "string") {
try {
paymentDetails = JSON.parse(JSON.stringify(paymentDetails));
} catch (e) {
if (errorCallback) {
errorCallback("Payment Details content wrong value or format");
return;
} else {
return;
}
}
} else if (typeof paymentDetails == "object") {
paymentDetails = JSON.stringify(paymentDetails);
}
FiuuPayment.setPaymentDetails(paymentDetails, function (paymentResult) {
if (successCallback) {
successCallback(JSON.stringify(paymentResult));
}
}, function (error) {
if (errorCallback) {
errorCallback(error);
}
});
} else if (Platform.OS === 'ios') {
if (typeof paymentDetails !== 'object') {
if (errorCallback) {
errorCallback("Payment Details must be a valid object");
}
return;
}
FiuuPayment.setPaymentDetails(paymentDetails, (paymentResult) => {
if (successCallback) {
successCallback(paymentResult); // No need to JSON.stringify for iOS
}
});
}
}
}