-
Notifications
You must be signed in to change notification settings - Fork 47
/
index.js
50 lines (44 loc) · 1.54 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
'use strict';
let {NativeModules, Platform} = require('react-native')
let {PayPal, MFLReactNativePayPal} = NativeModules;
let constants;
if (Platform.OS === 'android') {
constants = {};
let constantNames = Object.keys(PayPal).filter(p => p == p.toUpperCase());
constantNames.forEach(c => constants[c] = PayPal[c]);
} else {
constants = {
SANDBOX: 0,
PRODUCTION: 1,
NO_NETWORK: 2,
USER_CANCELLED: 'USER_CANCELLED',
INVALID_CONFIG: 'INVALID_CONFIG'
}
}
let functions = {
paymentRequest(payPalParameters) {
return new Promise(function(resolve, reject) {
if (Platform.OS === 'android') {
PayPal.paymentRequest(payPalParameters, resolve, reject);
} else {
MFLReactNativePayPal.initializePaypalEnvironment(payPalParameters.environment, payPalParameters.clientId);
MFLReactNativePayPal.preparePaymentOfAmount(payPalParameters.price, payPalParameters.currency, payPalParameters.description);
MFLReactNativePayPal.prepareConfigurationForMerchant("Shape A Future", true, "[email protected]");
MFLReactNativePayPal.presentPaymentViewControllerForPreparedPurchase((error, payload) => {
if (error) {
reject(constants.INVALID_CONFIG, error)
} else {
if (payload.status === 1) {
resolve(payload);
} else {
reject(constants.USER_CANCELLED, payload);
}
}
});
}
});
}
};
var exported = {};
Object.assign(exported, constants, functions);
module.exports = exported;