ngx-mercadopago
Version:
An Angular wrapper for Mercado Pago SDK for JavaScript
134 lines (127 loc) • 3.92 kB
JavaScript
import { __awaiter } from 'tslib';
import { InjectionToken, Component, NgModule } from '@angular/core';
import { bindCallback } from 'rxjs';
import { map } from 'rxjs/operators';
/** @hidden */
const pathSDK = 'https://secure.mlstatic.com/sdk/javascript/v1/mercadopago.js';
/** @hidden */
const ConfigToken = new InjectionToken('config');
class NgxMercadopagoService {
constructor(config) {
this.config = config;
if (!config.pathSDK) {
config.pathSDK = pathSDK;
}
this.initialized = false;
}
initialize(publishKey) {
return new Promise((resolve, reject) => {
const sdkMercadoPago = this.loadMPScript(this.config.pathSDK);
sdkMercadoPago.onload = () => {
this.initialized = true;
Mercadopago.setPublishableKey(publishKey || this.config.publishKey);
return resolve(Mercadopago);
};
sdkMercadoPago.onerror = (error) => reject(error);
});
}
loadMPScript(src) {
const script = document.createElement('script');
script.type = 'text/javascript';
script.src = src;
document.body.appendChild(script);
return script;
}
clearSession() {
return __awaiter(this, void 0, void 0, function* () {
Mercadopago.clearSession();
});
}
;
getPaymentMethod(card) {
return bindCallback(Mercadopago.getPaymentMethod)(card).pipe(map(([status, resp]) => {
if (status === 200) {
return { status, data: resp, error: null };
}
else {
return { status, data: null, error: resp };
}
}));
}
getPaymentMethods() {
return Mercadopago.getPaymentMethods();
}
getIdentificationTypes() {
return bindCallback(Mercadopago.getIdentificationTypes)().pipe(map(([status, data]) => ({ status, data })));
}
getInstallments(card) {
return bindCallback(Mercadopago.getInstallments)(card).pipe(map(([status, resp]) => {
if (status === 200) {
return { status, data: resp, error: null };
}
else {
return { status, data: null, error: resp };
}
}));
}
createToken(form) {
return bindCallback(Mercadopago.createToken)(form).pipe(map(([status, resp]) => {
if (status === 200) {
return { status, data: resp, error: null };
}
else {
return { status, data: null, error: resp };
}
}));
}
validateExpiryDate(date) {
return Mercadopago.validateExpiryDate(date);
}
validateExpiryMonthYear(month, year) {
return Mercadopago.validateExpiryDate(month, year);
}
}
class NgxMercadopagoComponent {
constructor() { }
ngOnInit() {
}
}
NgxMercadopagoComponent.decorators = [
{ type: Component, args: [{
selector: 'lib-ngx-mercadopago',
template: `
<p>
ngx-mercadopago works!
</p>
`
},] }
];
NgxMercadopagoComponent.ctorParameters = () => [];
class NgxMercadopagoModule {
static forRoot(libConfiguration) {
return {
ngModule: NgxMercadopagoModule,
providers: [
{
provide: ConfigToken,
useValue: libConfiguration
},
{
provide: NgxMercadopagoService,
deps: [ConfigToken]
}
]
};
}
}
NgxMercadopagoModule.decorators = [
{ type: NgModule }
];
/*
* Public API Surface of ngx-mercadopago
*/
/**
* Generated bundle index. Do not edit.
*/
export { ConfigToken, NgxMercadopagoComponent, NgxMercadopagoModule, NgxMercadopagoService };
//# sourceMappingURL=ngx-mercadopago.js.map