forked from dmitry-blackwave/adyen-react-native
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
123 lines (119 loc) · 3.56 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 } from 'react-native';
const Adyen = NativeModules.Adyen || NativeModules.AdyenReactNative;
const events = new NativeEventEmitter(Adyen);
export default {
cancelPayment() {
return Adyen.cancelPayment();
},
/**
* The Quick integration of the SDK provides UI components for payment method selection, entering payment method details (credit card entry form, iDEAL issuer selection, etc.).
* @returns {*}
*/
startPayment() {
return Adyen.startPayment();
},
/**
* Generating StartPaymentParameters
*
* @param {String} encodedToken
*
* @returns {*}
*/
confirmPayment(encodedToken) {
this._validateParam(encodedToken, 'confirmPayment', 'string');
return Adyen.confirmPayment(encodedToken);
},
/**
* @param {String} encodedToken
* @returns {*}
*/
createPaymentSession(encodedToken) {
this._validateParam(encodedToken, 'createPaymentSession', 'string');
return Adyen.createPaymentSession(encodedToken);
},
/**
* Starting payment process.
* @returns {*}
*/
initPayment() {
return Adyen.initPayment();
},
/**
* @callback mOnRequestPaymentSession
* @param {String} token
* @param {String} returnUrl
*/
/**
* Native event. Calling when CheckoutController calls delegate in the native call.
* It calling with token and returnUrl (can be empty, no worries)
* @param {mOnRequestPaymentSession} mOnRequestPaymentSession
*/
onRequestPaymentSession(mOnRequestPaymentSession) {
this._validateParam(mOnRequestPaymentSession, 'onRequestPaymentSession', 'function');
events.addListener('onRequestPaymentSession', response => {
mOnRequestPaymentSession(response['token'], response['returnUrl']);
});
},
/**
* @callback mOnPaymentResult
* @param {Number} code
* @param {String} payload
*/
/**
* After successfully payment, added payload data for confirmation payments
* @param {mOnPaymentResult} mOnPaymentResult
*/
onPaymentResult(mOnPaymentResult) {
this._validateParam(mOnPaymentResult, 'onPaymentResult', 'function');
events.addListener('onPaymentResult', response => {
mOnPaymentResult(response['code'], response['payload']);
});
},
/**
* @callback mOnError
* @param {Number} 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');
events.addListener('onError', response => {
mOnError(response['code'], response['message']);
});
},
/**
* @callback mOnSelectPaymentMethod
* @param {Array<>} preferred
* @param {Array<>} other
* @param {number} count
*/
/**
* //TODO custom integration
* @param {mOnSelectPaymentMethod} mOnSelectPaymentMethod
*/
onSelectPaymentMethod(mOnSelectPaymentMethod) {
this._validateParam(mOnSelectPaymentMethod, 'onSelectPaymentMethod', 'function');
events.addListener('onSelectPaymentMethod', response => {
mOnSelectPaymentMethod(response['preferred'], response['other'], response['count']);
});
},
/**
* @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
};