forked from tolu360/react-native-paystack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
44 lines (33 loc) · 1.22 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
import React from 'react'
import { NativeModules, Platform } from 'react-native'
const { RNPaystackModule } = NativeModules;
const checkInit = (instance) => {
if (!instance.paystackInitialized) {
throw new Error(`You should call init first, higher up your code like in your index file.\nRead more https://github.com/tolu360/react-native-paystack#3-usage`)
}
}
class RNPaystack {
paystackInitialized = false;
init(options: { [x: string]: any }) {
if (typeof options != 'object') {
return Promise.reject(new Error("Method argument can only be a Javascript object"));
}
this.paystackInitialized = true;
return RNPaystackModule.init(options);
}
chargeCard(chargeParams: { [x: string]: any }) {
if (typeof chargeParams != 'object') {
return Promise.reject(new Error("Method argument can only be a Javascript object"));
}
checkInit(this);
return RNPaystackModule.chargeCard(chargeParams);
}
chargeCardWithAccessCode(chargeParams: { [x: string]: any }) {
if (typeof chargeParams != 'object') {
return Promise.reject(new Error("Method argument can only be a Javascript object"));
}
checkInit(this);
return RNPaystackModule.chargeCardWithAccessCode(chargeParams);
}
}
export default new RNPaystack()