This repository has been archived by the owner on Jun 26, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathindex.js
54 lines (42 loc) · 2.11 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
import { NativeModules } from 'react-native';
const { MercadoPagoCheckoutModule } = NativeModules;
const defaultOptions = {
backgroundColor: "#009EE3",
enableDarkFont: false
};
export class MercadoPagoCheckout {
/**
* This function starts MercadoPago checkout to get a PaymentResult object, so you don't create the Payment in your servers.
*
* @param publicKey - MercadoPago API public Key
* @param preferenceId - MercadoPago Items preference id
* @param options - An Object containing properties like: backgroundColor, enableDarkFont
* @returns {Promise.<*>} - Promise that if resolves gives a PaymentResult object
*/
static async startForPayment(publicKey, preferenceId, options) {
const params = { ...defaultOptions, ...options, publicKey, preferenceId };
MercadoPagoCheckout._checkParams(params);
return await MercadoPagoCheckoutModule.startCheckoutForPayment(publicKey, preferenceId, params.backgroundColor, params.enableDarkFont);
}
/**
* This function starts MercadoPago checkout to get a PaymentData object, so you can create the Payment in your servers.
*
* @param publicKey - MercadoPago API public Key
* @param preferenceId - MercadoPago Items preference id
* @param options - An Object containing properties like: backgroundColor, enableDarkFont
* @returns {Promise.<*>} - Promise that if resolves gives a PaymentData object
*/
static async startForPaymentData(publicKey, preferenceId, options) {
const params = { ...defaultOptions, ...options, publicKey, preferenceId };
MercadoPagoCheckout._checkParams(params);
return await MercadoPagoCheckoutModule.startCheckoutForPaymentData(publicKey, preferenceId, params.backgroundColor, params.enableDarkFont);
}
static _validate(key, value) {
if (typeof value === 'undefined') {
throw `${key} required to start MercadoPago checkout`;
}
}
static _checkParams(params) {
Object.keys(params).forEach(key => params.hasOwnProperty(key) && MercadoPagoCheckout._validate(key, params[key]));
}
}