UNPKG

ng-orel-card-ipg

Version:

## Installation

180 lines (173 loc) 8.23 kB
import * as i0 from '@angular/core'; import { Injectable, Inject, Component, NgModule } from '@angular/core'; import { Observable } from 'rxjs'; import Pusher from 'pusher-js'; import axios from 'axios'; import { DomSanitizer } from '@angular/platform-browser'; import { CommonModule } from '@angular/common'; class NgOrelCardIpgService { constructor(config) { 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 = (apiKey, channel) => { this.pusher = new Pusher(apiKey, { cluster: 'ap2', forceTLS: false }); this.pusher.logToConsole = this.currentStage !== 'prod'; this.pusher.log = (msg) => { console.log(msg); }; this.channel = this.pusher.subscribe(channel + '-channel'); }; this.writeLog = (stage, msg) => { if (stage !== 'prod') { console.log('ng-orel-card-ipg: INFO: ' + msg); } }; axios.defaults.baseURL = this.configuration[config.stage].apiUrl; axios.defaults.headers.post['Content-Type'] = 'application/json'; axios.defaults.headers.common['x-plugin-source'] = 'ng-orel-card-ipg'; axios.defaults.headers.common['x-plugin-version'] = '1.0.10'; this.showPage$ = new Observable(x => this.ifShowPage = x); this.getSession$ = new Observable(st => this.setSession = st); this.selectedStage$ = new Observable(stg => this.setStage = stg); this.currentStage = config.stage; } AddCard(token, reference) { this.writeLog(this.currentStage, 'AddCard: ' + token + '-' + reference); this.setStage.next(this.config.stage); return new Promise((resolve, reject) => { axios.defaults.headers.common.Authorization = 'Bearer ' + token; axios.post('/getGatewaySession', { reference }) .then(response => { this.writeLog(this.currentStage, 'gateway-response: ' + response.data); if (response.data.status === 200) { console.log('getGatewaySession', 'success'); const sessionData = response.data.data; const sessionId = sessionData.session; this.setSession.next(sessionId); this.activePuser(sessionData._apk, sessionId); this.ifShowPage.next(true); this.channel.bind(sessionId, (paymentResponse) => { this.pusher.unsubscribe(sessionId + '-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(error => { this.writeLog(this.currentStage, 'gateway-error-response: ' + error); let msg = ''; if (error.response.status === 401) { msg = 'Unauthorized, Invalid token.'; } else { msg = 'Something went wrong.'; } reject({ status: 400, data: { error: 'INIT_ERROR', message: msg } }); }); }); } } NgOrelCardIpgService.ɵprov = i0.ɵɵdefineInjectable({ factory: function NgOrelCardIpgService_Factory() { return new NgOrelCardIpgService(i0.ɵɵinject("config")); }, token: NgOrelCardIpgService, providedIn: "root" }); NgOrelCardIpgService.decorators = [ { type: Injectable, args: [{ providedIn: 'root' },] } ]; NgOrelCardIpgService.ctorParameters = () => [ { type: undefined, decorators: [{ type: Inject, args: ['config',] }] } ]; class NgOrelCardIpgComponent { constructor(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', } }; } ngOnInit() { this.cardIpgService.showPage$.subscribe(lst => this.ifShowPage = lst); this.cardIpgService.getSession$.subscribe(st => { this.pageUrl = this.sanitizer.bypassSecurityTrustResourceUrl(this.configuration[this.setStage].gtUrl + '/' + st); }); this.cardIpgService.selectedStage$.subscribe(stg => this.setStage = stg); } } NgOrelCardIpgComponent.decorators = [ { type: Component, args: [{ selector: 'lib-ng-orel-card-ipg', template: ` <div *ngIf="this.ifShowPage"> <iframe class='e2e-iframe-trusted-src holds-the-iframe' [src]="pageUrl"></iframe> </div> `, 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 = () => [ { type: DomSanitizer }, { type: NgOrelCardIpgService } ]; class NgOrelCardIpgModule { static forRoot(config) { return { ngModule: NgOrelCardIpgModule, providers: [ NgOrelCardIpgService, { provide: 'config', useValue: config } ] }; } } NgOrelCardIpgModule.decorators = [ { type: NgModule, args: [{ declarations: [NgOrelCardIpgComponent], imports: [ CommonModule ], exports: [NgOrelCardIpgComponent] },] } ]; /* * Public API Surface of ng-orel-card-ipg */ /** * Generated bundle index. Do not edit. */ export { NgOrelCardIpgComponent, NgOrelCardIpgModule, NgOrelCardIpgService }; //# sourceMappingURL=ng-orel-card-ipg.js.map