-
Notifications
You must be signed in to change notification settings - Fork 35
/
index.js
123 lines (121 loc) · 4.39 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
import {NativeEventEmitter, NativeModules,Platform} from 'react-native';
const { AdyenPayment } = NativeModules;
const events = new NativeEventEmitter(AdyenPayment);
let onAdyenPaymentSuccessListener;
let onAdyenPaymentErrorListener;
const DROPIN = "dropin";
const IDEAL = "ideal";
const MOLPAY_MALAYSIA = "molpay_ebanking_fpx_MY";
const MOLPAY_THAILAND = "molpay_ebanking_TH";
const MOLPAY_VIETNAM = "molpay_ebanking_VN";
const DOTPAY = "dotpay";
const EPS = "eps";
const ENTERCASH = "entercash";
const OPEN_BANKING = "openbanking_UK";
const SCHEME = "scheme";
const GOOGLE_PAY = "paywithgoogle";
const SEPA = "sepadirectdebit";
const BCMC = "bcmc";
const WECHAT_PAY_SDK = "wechatpaySDK";
const APPLE_PAY = "applepay";
const AFTERPAY="afterpay_default";
export default {
DROPIN,
IDEAL,
MOLPAY_MALAYSIA,MOLPAY_THAILAND,MOLPAY_VIETNAM,DOTPAY,EPS,ENTERCASH,OPEN_BANKING,
SCHEME,
GOOGLE_PAY,
SEPA,
BCMC,
WECHAT_PAY_SDK,
APPLE_PAY,
AFTERPAY,
initialize(appServiceConfigData){
return AdyenPayment.initialize(appServiceConfigData);
},
startPaymentPromise(component,componentData,paymentDetails){
const default_components = [DROPIN,IDEAL,MOLPAY_MALAYSIA,MOLPAY_THAILAND,MOLPAY_VIETNAM,DOTPAY,
EPS,ENTERCASH,OPEN_BANKING,SCHEME,SEPA,BCMC];
var supported_components;
if(Platform.OS === 'ios'){
supported_components = [APPLE_PAY];
}
else if (Platform.OS === 'android') {
supported_components = [WECHAT_PAY_SDK,GOOGLE_PAY,AFTERPAY];
}
if(default_components.indexOf(component) !== -1 || supported_components.indexOf(component) !== -1){
return AdyenPayment.startPaymentPromise(component,componentData,paymentDetails)
}else{
throw new Error(`${component} is not supported for ${Platform.OS} Platform`);
}
},
startPayment(component,componentData,paymentDetails){
const default_components = [DROPIN,IDEAL,MOLPAY_MALAYSIA,MOLPAY_THAILAND,MOLPAY_VIETNAM,DOTPAY,
EPS,ENTERCASH,OPEN_BANKING,SCHEME,SEPA,BCMC];
var supported_components;
if(Platform.OS === 'ios'){
supported_components = [APPLE_PAY];
}
else if (Platform.OS === 'android') {
supported_components = [WECHAT_PAY_SDK,GOOGLE_PAY,AFTERPAY];
}
if(default_components.indexOf(component) !== -1 || supported_components.indexOf(component) !== -1){
return AdyenPayment.startPayment(component,componentData,paymentDetails)
}else{
throw new Error(`${component} is not supported for ${Platform.OS} Platform`);
}
},
/**
* @callback mOnSuccess
* @param {Object} message
*/
/**
* After successfully payment, added payload data for confirmation payments
* @param {mOnSuccess} mOnSuccess
*/
onSuccess(mOnSuccess) {
this._validateParam(mOnSuccess, 'onSuccess', 'function');
if (onAdyenPaymentSuccessListener) {
onAdyenPaymentSuccessListener.remove();
}
onAdyenPaymentSuccessListener = events.addListener('onSuccess', (response) => {
mOnSuccess(response['message']);
});
},
/**
* @callback mOnError
* @param {String} error_code
* @param {String} message
*/
/**
* If payment was cancelled or something else. Calling instead of onPaymentResult event.
* @param {mOnError} mOnError
*/
onError(mOnError) {
this._validateParam(mOnError, 'onError', 'function');
if (onAdyenPaymentErrorListener) {
onAdyenPaymentErrorListener.remove();
}
onAdyenPaymentErrorListener = events.addListener('onError', (response) => {
mOnError(response['code'], response['message']);
});
},
/**
* @param {*} param
* @param {String} methodName
* @param {String} requiredType
* @private
*/
_validateParam(param, methodName, requiredType) {
if (typeof param !== requiredType) {
throw new Error(`Error: Adyen.${methodName}() requires a ${requiredType === 'function' ? 'callback function' : requiredType} but got a ${typeof param}`);
}
},
events,
removeListeners(){
if(null != onAdyenPaymentSuccessListener)
onAdyenPaymentSuccessListener.remove();
if(null != onAdyenPaymentErrorListener)
onAdyenPaymentErrorListener.remove();
}
};