ng-orel-card-ipg
Version:
## Installation
214 lines (202 loc) • 11.4 kB
JavaScript
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('rxjs'), require('pusher-js'), require('axios'), require('@angular/platform-browser'), require('@angular/common')) :
typeof define === 'function' && define.amd ? define('ng-orel-card-ipg', ['exports', '@angular/core', 'rxjs', 'pusher-js', 'axios', '@angular/platform-browser', '@angular/common'], factory) :
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global['ng-orel-card-ipg'] = {}, global.ng.core, global.rxjs, global.Pusher, global.axios, global.ng.platformBrowser, global.ng.common));
}(this, (function (exports, i0, rxjs, Pusher, axios, platformBrowser, common) { 'use strict';
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
function _interopNamespace(e) {
if (e && e.__esModule) return e;
var n = Object.create(null);
if (e) {
Object.keys(e).forEach(function (k) {
if (k !== 'default') {
var d = Object.getOwnPropertyDescriptor(e, k);
Object.defineProperty(n, k, d.get ? d : {
enumerable: true,
get: function () {
return e[k];
}
});
}
});
}
n['default'] = e;
return Object.freeze(n);
}
var i0__namespace = /*#__PURE__*/_interopNamespace(i0);
var Pusher__default = /*#__PURE__*/_interopDefaultLegacy(Pusher);
var axios__default = /*#__PURE__*/_interopDefaultLegacy(axios);
var NgOrelCardIpgService = /** @class */ (function () {
function NgOrelCardIpgService(config) {
var _this = this;
this.config = config;
this.configuration = {
local: {
apiUrl: 'https://orel.mpg/api/extGateway',
},
dev: {
apiUrl: 'https://dev.paymediasolutions.com/v1/mpg/api/extGateway',
},
prod: {
apiUrl: 'https://prod.orelpay.lk/v1/mpg/api/extGateway',
}
};
this.activePuser = function (apiKey, channel) {
_this.pusher = new Pusher__default['default'](apiKey, {
cluster: 'ap2',
forceTLS: false
});
_this.pusher.logToConsole = _this.currentStage !== 'prod';
_this.pusher.log = function (msg) {
console.log(msg);
};
_this.channel = _this.pusher.subscribe(channel + '-channel');
};
this.writeLog = function (stage, msg) {
if (stage !== 'prod') {
console.log('ng-orel-card-ipg: INFO: ' + msg);
}
};
axios__default['default'].defaults.baseURL = this.configuration[config.stage].apiUrl;
axios__default['default'].defaults.headers.post['Content-Type'] = 'application/json';
axios__default['default'].defaults.headers.common['x-plugin-source'] = 'ng-orel-card-ipg';
axios__default['default'].defaults.headers.common['x-plugin-version'] = '1.0.10';
this.showPage$ = new rxjs.Observable(function (x) { return _this.ifShowPage = x; });
this.getSession$ = new rxjs.Observable(function (st) { return _this.setSession = st; });
this.selectedStage$ = new rxjs.Observable(function (stg) { return _this.setStage = stg; });
this.currentStage = config.stage;
}
NgOrelCardIpgService.prototype.AddCard = function (token, reference) {
var _this = this;
this.writeLog(this.currentStage, 'AddCard: ' + token + '-' + reference);
this.setStage.next(this.config.stage);
return new Promise(function (resolve, reject) {
axios__default['default'].defaults.headers.common.Authorization = 'Bearer ' + token;
axios__default['default'].post('/getGatewaySession', { reference: reference })
.then(function (response) {
_this.writeLog(_this.currentStage, 'gateway-response: ' + response.data);
if (response.data.status === 200) {
console.log('getGatewaySession', 'success');
var sessionData = response.data.data;
var sessionId_1 = sessionData.session;
_this.setSession.next(sessionId_1);
_this.activePuser(sessionData._apk, sessionId_1);
_this.ifShowPage.next(true);
_this.channel.bind(sessionId_1, function (paymentResponse) {
_this.pusher.unsubscribe(sessionId_1 + '-channel');
_this.writeLog(_this.currentStage, 'gateway-3ds-response: ' + paymentResponse);
resolve(paymentResponse);
});
}
else {
reject({
status: 400,
data: {
error: 'SERVER_ERROR',
message: 'Payment session create failed.'
}
});
}
})
.catch(function (error) {
_this.writeLog(_this.currentStage, 'gateway-error-response: ' + error);
var msg = '';
if (error.response.status === 401) {
msg = 'Unauthorized, Invalid token.';
}
else {
msg = 'Something went wrong.';
}
reject({
status: 400,
data: {
error: 'INIT_ERROR',
message: msg
}
});
});
});
};
return NgOrelCardIpgService;
}());
NgOrelCardIpgService.ɵprov = i0__namespace.ɵɵdefineInjectable({ factory: function NgOrelCardIpgService_Factory() { return new NgOrelCardIpgService(i0__namespace.ɵɵinject("config")); }, token: NgOrelCardIpgService, providedIn: "root" });
NgOrelCardIpgService.decorators = [
{ type: i0.Injectable, args: [{
providedIn: 'root'
},] }
];
NgOrelCardIpgService.ctorParameters = function () { return [
{ type: undefined, decorators: [{ type: i0.Inject, args: ['config',] }] }
]; };
var NgOrelCardIpgComponent = /** @class */ (function () {
function NgOrelCardIpgComponent(sanitizer, cardIpgService) {
this.sanitizer = sanitizer;
this.cardIpgService = cardIpgService;
this.configuration = {
local: {
gtUrl: 'https://orel.mpg/app',
},
dev: {
gtUrl: 'https://testgateway.paymediasolutions.com',
},
prod: {
gtUrl: 'https://gateway.orelpay.lk',
}
};
}
NgOrelCardIpgComponent.prototype.ngOnInit = function () {
var _this = this;
this.cardIpgService.showPage$.subscribe(function (lst) { return _this.ifShowPage = lst; });
this.cardIpgService.getSession$.subscribe(function (st) {
_this.pageUrl = _this.sanitizer.bypassSecurityTrustResourceUrl(_this.configuration[_this.setStage].gtUrl + '/' + st);
});
this.cardIpgService.selectedStage$.subscribe(function (stg) { return _this.setStage = stg; });
};
return NgOrelCardIpgComponent;
}());
NgOrelCardIpgComponent.decorators = [
{ type: i0.Component, args: [{
selector: 'lib-ng-orel-card-ipg',
template: "\n <div *ngIf=\"this.ifShowPage\">\n <iframe class='e2e-iframe-trusted-src holds-the-iframe' [src]=\"pageUrl\"></iframe>\n </div>\n ",
styles: [".holds-the-iframe{background:url(\"data:image/svg+xml,%3Csvg width='129px' height='129px' xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100' preserveAspectRatio='xMidYMid' class='lds-double-ring' style='background: none;'%3E%3Ccircle cx='50' cy='50' ng-attr-r='%7B%7Bconfig.radius%7D%7D' ng-attr-stroke-width='%7B%7Bconfig.width%7D%7D' ng-attr-stroke='%7B%7Bconfig.c1%7D%7D' ng-attr-stroke-dasharray='%7B%7Bconfig.dasharray%7D%7D' fill='none' stroke-linecap='round' r='40' stroke-width='4' stroke='%23012480' stroke-dasharray='62.83185307179586 62.83185307179586' transform='rotate(130.065 50 50)'%3E%3CanimateTransform attributeName='transform' type='rotate' calcMode='linear' values='0 50 50;360 50 50' keyTimes='0;1' dur='2s' begin='0s' repeatCount='indefinite'%3E%3C/animateTransform%3E%3C/circle%3E%3Ccircle cx='50' cy='50' ng-attr-r='%7B%7Bconfig.radius2%7D%7D' ng-attr-stroke-width='%7B%7Bconfig.width%7D%7D' ng-attr-stroke='%7B%7Bconfig.c2%7D%7D' ng-attr-stroke-dasharray='%7B%7Bconfig.dasharray2%7D%7D' ng-attr-stroke-dashoffset='%7B%7Bconfig.dashoffset2%7D%7D' fill='none' stroke-linecap='round' r='35' stroke-width='4' stroke='%23a0a0a0' stroke-dasharray='54.97787143782138 54.97787143782138' stroke-dashoffset='54.97787143782138' transform='rotate(-130.065 50 50)'%3E%3CanimateTransform attributeName='transform' type='rotate' calcMode='linear' values='0 50 50;-360 50 50' keyTimes='0;1' dur='2s' begin='0s' repeatCount='indefinite'%3E%3C/animateTransform%3E%3C/circle%3E%3C/svg%3E\") center center no-repeat;top:0;left:0;bottom:0;right:0;width:100%;height:700px;border:none;margin:0;padding:0;overflow:hidden}\n"]
},] }
];
NgOrelCardIpgComponent.ctorParameters = function () { return [
{ type: platformBrowser.DomSanitizer },
{ type: NgOrelCardIpgService }
]; };
var NgOrelCardIpgModule = /** @class */ (function () {
function NgOrelCardIpgModule() {
}
NgOrelCardIpgModule.forRoot = function (config) {
return {
ngModule: NgOrelCardIpgModule,
providers: [
NgOrelCardIpgService,
{ provide: 'config', useValue: config }
]
};
};
return NgOrelCardIpgModule;
}());
NgOrelCardIpgModule.decorators = [
{ type: i0.NgModule, args: [{
declarations: [NgOrelCardIpgComponent],
imports: [
common.CommonModule
],
exports: [NgOrelCardIpgComponent]
},] }
];
/*
* Public API Surface of ng-orel-card-ipg
*/
/**
* Generated bundle index. Do not edit.
*/
exports.NgOrelCardIpgComponent = NgOrelCardIpgComponent;
exports.NgOrelCardIpgModule = NgOrelCardIpgModule;
exports.NgOrelCardIpgService = NgOrelCardIpgService;
Object.defineProperty(exports, '__esModule', { value: true });
})));
//# sourceMappingURL=ng-orel-card-ipg.umd.js.map