epp-lib 0.0.3 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. package/esm2022/lib/component/index.mjs +3 -0
  2. package/esm2022/lib/component/rapyd/rapyd.component.mjs +180 -0
  3. package/esm2022/lib/component/vodds-loader/vodds-loader.component.mjs +19 -0
  4. package/esm2022/lib/model/broadcast/broadcast-event-type.mjs +5 -0
  5. package/esm2022/lib/model/broadcast/broadcast-event.mjs +13 -0
  6. package/esm2022/lib/model/broadcast/ibroadcast-event.mjs +2 -0
  7. package/esm2022/lib/model/checkout.mjs +13 -2
  8. package/esm2022/lib/model/count-down-time.mjs +56 -0
  9. package/esm2022/lib/model/domain.mjs +2 -2
  10. package/esm2022/lib/model/index.mjs +11 -0
  11. package/esm2022/lib/model/payment-type.mjs +3 -1
  12. package/esm2022/lib/model/timer.mjs +41 -0
  13. package/esm2022/lib/service/event-emitter.service.mjs +23 -0
  14. package/esm2022/lib/service/iframe-message.service.mjs +10 -5
  15. package/esm2022/lib/service/index.mjs +5 -0
  16. package/esm2022/lib/service/payment.service.mjs +48 -31
  17. package/esm2022/public-api.mjs +4 -16
  18. package/fesm2022/epp-lib.mjs +463 -109
  19. package/fesm2022/epp-lib.mjs.map +1 -1
  20. package/lib/component/index.d.ts +2 -0
  21. package/lib/component/rapyd/rapyd.component.d.ts +36 -0
  22. package/lib/component/vodds-loader/vodds-loader.component.d.ts +7 -0
  23. package/lib/model/broadcast/broadcast-event-type.d.ts +3 -0
  24. package/lib/model/broadcast/broadcast-event.d.ts +9 -0
  25. package/lib/model/broadcast/ibroadcast-event.d.ts +5 -0
  26. package/lib/model/checkout.d.ts +5 -1
  27. package/lib/model/count-down-time.d.ts +16 -0
  28. package/lib/model/index.d.ts +10 -0
  29. package/lib/model/payment-type.d.ts +3 -1
  30. package/lib/model/timer.d.ts +10 -0
  31. package/lib/service/event-emitter.service.d.ts +10 -0
  32. package/lib/service/index.d.ts +4 -0
  33. package/lib/service/payment.service.d.ts +7 -8
  34. package/package.json +3 -2
  35. package/public-api.d.ts +3 -12
@@ -1,109 +1,264 @@
1
- import * as i1 from '@angular/common/http';
2
- import { HttpParams, HttpHeaders } from '@angular/common/http';
3
1
  import * as i0 from '@angular/core';
4
- import { Injectable } from '@angular/core';
5
- import { Observable, Subject } from 'rxjs';
2
+ import { Input, Component, Injectable, Inject, inject } from '@angular/core';
3
+ import { Subject, Observable, timer, takeUntil } from 'rxjs';
4
+ import * as i1 from '@angular/material/dialog';
5
+ import { MAT_DIALOG_DATA } from '@angular/material/dialog';
6
+ import * as i1$1 from '@angular/common/http';
7
+ import { HttpHeaders, HttpParams } from '@angular/common/http';
6
8
 
7
- class IParam {
8
- getMobileFlag() {
9
- return /android|mobi/i.test(navigator.userAgent.toLowerCase());
10
- }
11
- toJson() {
12
- return JSON.stringify(this);
13
- }
14
- toFormUrlEncoded() {
15
- return new URLSearchParams(Object.entries(this).map(([key, value]) => [key, String(value)])).toString();
9
+ class VoddsLoaderComponent {
10
+ constructor() {
11
+ this.message = '';
12
+ this.showAjaxLoader = false;
16
13
  }
14
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: VoddsLoaderComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
15
+ static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "17.3.12", type: VoddsLoaderComponent, isStandalone: true, selector: "vodds-loader", inputs: { message: "message", showAjaxLoader: "showAjaxLoader" }, ngImport: i0, template: "@if (showAjaxLoader) {\r\n <div class=\"load-indicator\">\r\n <img src=\"/assets/jayeson/common/img/ajax-loader16.gif\">\r\n {{message != undefined ? message : ''}}\r\n </div>\r\n}\r\n", styles: [""] }); }
17
16
  }
17
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: VoddsLoaderComponent, decorators: [{
18
+ type: Component,
19
+ args: [{ selector: 'vodds-loader', standalone: true, imports: [], template: "@if (showAjaxLoader) {\r\n <div class=\"load-indicator\">\r\n <img src=\"/assets/jayeson/common/img/ajax-loader16.gif\">\r\n {{message != undefined ? message : ''}}\r\n </div>\r\n}\r\n" }]
20
+ }], propDecorators: { message: [{
21
+ type: Input
22
+ }], showAjaxLoader: [{
23
+ type: Input
24
+ }] } });
18
25
 
19
- class BaseForm extends IParam {
26
+ class EventEmitterService {
20
27
  constructor() {
21
- super();
22
- this.isMobile = 'false';
23
- }
24
- /**
25
- * Use this function for building POST params with form url encoded content type.
26
- * Remeber to call params.toString() when passing to http request
27
- */
28
- getUrlSearchParam() {
29
- const params = new URLSearchParams();
30
- params.set('isMobile', this.isMobile);
31
- return params;
32
- }
33
- /**
34
- * Use this function for building GET params
35
- */
36
- getHttpParams() {
37
- let params = new HttpParams();
38
- params = params.append('isMobile', this.isMobile);
39
- return params;
28
+ this.eventBus = new Subject();
40
29
  }
41
- /**
42
- * Add isMobile = 'true' to paramters
43
- * @param params : object
44
- */
45
- addIsMobile(params) {
46
- params['isMobile'] = this.isMobile;
30
+ broadcast(event) {
31
+ this.eventBus.next(event);
47
32
  }
48
- /**
49
- * For POST request with form-urlencoded
50
- */
51
- getHeaderWithContentTypeForm() {
52
- const headers = new HttpHeaders()
53
- .set('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
54
- return headers;
55
- }
56
- /**
57
- * For POST request with json body
58
- */
59
- getHeaderWithContentTypeJson() {
60
- const headers = new HttpHeaders()
61
- .set('Content-Type', 'application/json; charset=utf-8');
62
- return headers;
33
+ getEventBus() {
34
+ return this.eventBus;
63
35
  }
36
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: EventEmitterService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
37
+ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: EventEmitterService, providedIn: 'root' }); }
64
38
  }
39
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: EventEmitterService, decorators: [{
40
+ type: Injectable,
41
+ args: [{
42
+ providedIn: 'root',
43
+ }]
44
+ }] });
65
45
 
66
- class CallbackMessage {
67
- constructor(errorMessage) {
68
- this.errorMessage = '';
69
- this.errorMessage = errorMessage;
46
+ class BroadcastEvent {
47
+ constructor(eventType, eventData) {
48
+ this.eventType = eventType;
49
+ this.eventData = eventData;
50
+ }
51
+ getEventType() {
52
+ return this.eventType;
53
+ }
54
+ getEventData() {
55
+ return this.eventData;
70
56
  }
71
57
  }
72
58
 
73
- var PaymentType;
74
- (function (PaymentType) {
75
- PaymentType[PaymentType["NA"] = 0] = "NA";
76
- PaymentType[PaymentType["JETON"] = 1] = "JETON";
77
- })(PaymentType || (PaymentType = {}));
59
+ var BroadcastEventType;
60
+ (function (BroadcastEventType) {
61
+ BroadcastEventType[BroadcastEventType["COMPLETE_RAPYD"] = 0] = "COMPLETE_RAPYD";
62
+ })(BroadcastEventType || (BroadcastEventType = {}));
78
63
 
79
- class Checkout {
80
- constructor() {
81
- this.requestId = '';
82
- this.paymentType = PaymentType.NA;
83
- this.url = '';
84
- this.errorMessage = '';
64
+ class RapydComponent {
65
+ constructor(dialogRef, data, eventEmitter) {
66
+ this.dialogRef = dialogRef;
67
+ this.data = data;
68
+ this.eventEmitter = eventEmitter;
69
+ this.isOpen = false;
70
+ this.checkoutToolKit = undefined;
71
+ this.visaMasterTimeout = 300;
72
+ this.visaMasterCheckoutId = '';
73
+ this.displayTimer = "00:00";
74
+ this.isShow = false;
75
+ this.isLoading = true;
76
+ this.errorMessage = "";
77
+ this.defaultExpirationSec = 300; // 5mins
78
+ this.handleLoading = (event) => {
79
+ console.log("handleLoading");
80
+ if (!event.detail.loading && this.isLoading) {
81
+ this.isShow = true;
82
+ this.isLoading = false;
83
+ this.startTimer();
84
+ }
85
+ };
86
+ this.handleCheckoutPaymentSuccess = (event) => {
87
+ console.log("handleCheckoutPaymentSuccess");
88
+ this.closeDialog(false);
89
+ this.emitCompleteRapyd('');
90
+ };
91
+ this.handleCheckoutPaymentFailure = (event) => {
92
+ console.log("handleCheckoutPaymentFailure");
93
+ this.stopTimer();
94
+ this.isShow = false;
95
+ console.error("Failed to deposit visa!", event.detail);
96
+ this.emitCompleteRapyd(event.detail.message);
97
+ };
98
+ this.visaMasterTimeout = data.expiration ?? data.expiration;
99
+ this.visaMasterCheckoutId = data.checkoutUrl;
100
+ }
101
+ ngOnDestroy() {
102
+ this.stopTimer();
103
+ window.removeEventListener('onLoading', this.handleLoading);
104
+ window.removeEventListener('onCheckoutPaymentSuccess', this.handleCheckoutPaymentSuccess);
105
+ window.removeEventListener('onCheckoutPaymentFailure', this.handleCheckoutPaymentFailure);
106
+ }
107
+ ngAfterViewInit() {
108
+ if (this.checkout) {
109
+ this.visaMasterTimeout = this.checkout.expiration;
110
+ this.visaMasterCheckoutId = this.checkout.url;
111
+ }
112
+ console.log("constructor: ", this.visaMasterCheckoutId, this.visaMasterTimeout);
113
+ this.createCheckoutToolKit();
114
+ }
115
+ createCheckoutToolKit() {
116
+ this.checkoutToolKit = new RapydCheckoutToolkit({
117
+ pay_button_text: "Rapyd checkout",
118
+ id: this.visaMasterCheckoutId,
119
+ wait_on_payment_redirect: true,
120
+ style: {
121
+ cardFields: {
122
+ title: {
123
+ color: '#80807F'
124
+ },
125
+ saveForFutureLabel: {
126
+ color: '#80807F'
127
+ }
128
+ },
129
+ input: {
130
+ base: {
131
+ fontWeight: "400",
132
+ borderRadius: "5px",
133
+ }
134
+ },
135
+ orderDetails: {
136
+ title: {
137
+ color: '#80807F'
138
+ },
139
+ totalLabel: {
140
+ color: '#80807F'
141
+ },
142
+ totalValue: {
143
+ color: '#80807F'
144
+ }
145
+ },
146
+ submit: {
147
+ base: {
148
+ backgroundColor: "#F48215",
149
+ color: "#FFFFFF",
150
+ fontWeight: "900",
151
+ borderRadius: "5px",
152
+ border: "none",
153
+ boxShadow: "0px 0px 20px 0px #28303A33",
154
+ height: "35px",
155
+ }
156
+ }
157
+ }
158
+ });
159
+ this.displayCheckout();
160
+ window.addEventListener('onLoading', this.handleLoading);
161
+ window.addEventListener('onCheckoutPaymentSuccess', this.handleCheckoutPaymentSuccess);
162
+ window.addEventListener('onCheckoutPaymentFailure', this.handleCheckoutPaymentFailure);
163
+ }
164
+ closeDialog(isCloseCheckout = true) {
165
+ console.log("closeDialog");
166
+ this.stopTimer();
167
+ if (this.checkoutToolKit && isCloseCheckout) {
168
+ try {
169
+ this.checkoutToolKit.closeCheckout();
170
+ }
171
+ catch (err) {
172
+ console.error("Error when closing checkout", err);
173
+ }
174
+ }
175
+ this.checkoutToolKit = undefined;
176
+ this.isShow = false;
177
+ // this.dialogRef.close();
85
178
  }
179
+ ;
180
+ startTimer() {
181
+ console.log("startTimer");
182
+ if (this.visaMasterTimer)
183
+ this.stopTimer();
184
+ this.visaMasterTimer = setInterval(() => {
185
+ if (this.visaMasterTimeout <= 0) {
186
+ this.closeDialog();
187
+ return;
188
+ }
189
+ this.visaMasterTimeout--;
190
+ this.updateDisplayTimer();
191
+ }, 1000);
192
+ }
193
+ stopTimer() {
194
+ console.log("stopTimer");
195
+ clearInterval(this.visaMasterTimer);
196
+ }
197
+ updateDisplayTimer() {
198
+ console.log("updateDisplayTimer");
199
+ const min = this.pad(Math.floor(this.visaMasterTimeout / 60));
200
+ const sec = this.pad(this.visaMasterTimeout % 60);
201
+ this.displayTimer = `${min}:${sec}`;
202
+ }
203
+ pad(number) {
204
+ console.log("pad");
205
+ return `${number < 10 ? '0' : ''}${number}`;
206
+ }
207
+ displayCheckout() {
208
+ console.log("padisplayCheckoutd");
209
+ if (document.getElementById("rapyd-checkout")) {
210
+ this.checkoutToolKit.displayCheckout();
211
+ }
212
+ else {
213
+ setTimeout(() => {
214
+ this.displayCheckout();
215
+ }, 10);
216
+ }
217
+ }
218
+ emitCompleteRapyd(errorMessage) {
219
+ console.log("emitCompleteRapyd");
220
+ this.eventEmitter.broadcast(new BroadcastEvent(BroadcastEventType.COMPLETE_RAPYD, errorMessage));
221
+ }
222
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: RapydComponent, deps: [{ token: i1.MatDialogRef }, { token: MAT_DIALOG_DATA }, { token: EventEmitterService }], target: i0.ɵɵFactoryTarget.Component }); }
223
+ static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "17.3.12", type: RapydComponent, isStandalone: true, selector: "v-rapyd", inputs: { checkout: "checkout" }, providers: [EventEmitterService], ngImport: i0, template: "<div id=\"visa-card\">\r\n <div class=\"top\">\r\n <h2>$-addpwdr_paymentInformation-$</h2>\r\n <svg class=\"clsbtn my-account\" (click)=\"closeDialog()\" width=\"11\" height=\"11\" viewBox=\"0 0 11 11\" fill=\"none\" xmlns=\"http://www.w3.org/2000/svg\">\r\n <path d=\"M9.89214 0L5.5 4.39214L1.10786 0L0 1.10786L4.39214 5.5L0 9.89214L1.10786 11L5.5 6.60786L9.89214 11L11 9.89214L6.60786 5.5L11 1.10786L9.89214 0Z\" fill=\"white\"/>\r\n </svg>\r\n </div>\r\n <div class=\"flex-center\">\r\n <vodds-loader [showAjaxLoader]=\"isLoading\"></vodds-loader>\r\n </div>\r\n @if (!isLoading && !isShow) {\r\n <div class=\"visa-card-message\">\r\n $-addpwdr_visaCardErrorMessage-$ <br> $-addpwdr_visaCardErrorMessage2-$\r\n </div>\r\n }\r\n <div class=\"visa-card-form\" [style]=\"{display: isShow ? 'flex' : 'none'}\">\r\n <div class=\"timer\">\r\n <svg width=\"14\" height=\"14\" viewBox=\"0 0 14 14\" xmlns=\"http://www.w3.org/2000/svg\">\r\n <path d=\"M7 2.56067C9.76142 2.56067 12 4.79925 12 7.56067C12 10.3221 9.76142 12.5607 7 12.5607C4.23858 12.5607 2 10.3221 2 7.56067C2 4.79925 4.23858 2.56067 7 2.56067ZM6.25 4.06067V7.93567L6.5498 8.16028L8.5498 9.66028L9.4502 8.46106L7.75 7.18567V4.06067H6.25Z\" fill=\"#B5B5B5\"/>\r\n <line x1=\"10.0303\" y1=\"0.530339\" x2=\"12.8588\" y2=\"3.35877\" stroke=\"#B5B5B5\" stroke-width=\"1.5\"/>\r\n <line y1=\"-0.75\" x2=\"4\" y2=\"-0.75\" transform=\"matrix(-0.707107 0.707107 0.707107 0.707107 4.82861 1.06067)\" stroke=\"#B5B5B5\" stroke-width=\"1.5\"/>\r\n </svg>\r\n <span class=\"label\">&nbsp;$-addpwdr_visaCardTimeout-$&nbsp;</span> <span class=\"display-time\"> {{displayTimer}}</span>\r\n </div>\r\n <div id=\"rapyd-checkout\"></div>\r\n </div>\r\n</div>\r\n", styles: [".flex-center{display:flex;justify-content:center;align-items:center}#visa-card{height:auto;width:500px;top:0;left:710px;z-index:101}.top{width:100%;align-items:center;margin-bottom:8px;border-radius:0;background:#dd453c;position:relative;color:#fff;display:flex;justify-content:space-between}.top h2{padding-left:15px;text-align:left;font-size:16px;font-weight:800}.top svg{position:unset;padding-right:15px;width:18px;height:18px}.visa-card-form{display:flex;flex-direction:column;align-items:center;min-height:500px!important;width:100%}.visa-card-form .timer{display:flex;align-items:center}#rapyd-checkout{min-height:550px;max-height:550px;overflow-y:auto;scrollbar-width:none}#rapyd-checkout::-webkit-scrollbar{display:none}.ui-widget.ui-widget-content.vodds-visa-card-dialog{padding:0;border:none;border-radius:10px}.vodds-visa-card-dialog .ui-dialog-content{display:flex;align-items:center;flex-direction:column;padding:0;margin:0}.vodds-visa-card-dialog .ui-dialog-content .top{width:100%;display:flex;align-items:center;padding:6px 18px;margin-bottom:8px;border-radius:8px}.vodds-visa-card-dialog .ui-dialog-content .top h2{text-align:left;font-size:16px;font-weight:800}#trading-platform.dark .vodds-visa-card-dialog .label,.vodds-visa-card-dialog .label{color:#80807f!important}#trading-platform.dark .vodds-visa-card-dialog span{color:#000!important}#trading-platform.dark .vodds-visa-card-dialog{background:#fff!important}\n"], dependencies: [{ kind: "component", type: VoddsLoaderComponent, selector: "vodds-loader", inputs: ["message", "showAjaxLoader"] }] }); }
86
224
  }
225
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: RapydComponent, decorators: [{
226
+ type: Component,
227
+ args: [{ selector: 'v-rapyd', standalone: true, imports: [VoddsLoaderComponent], providers: [EventEmitterService], template: "<div id=\"visa-card\">\r\n <div class=\"top\">\r\n <h2>$-addpwdr_paymentInformation-$</h2>\r\n <svg class=\"clsbtn my-account\" (click)=\"closeDialog()\" width=\"11\" height=\"11\" viewBox=\"0 0 11 11\" fill=\"none\" xmlns=\"http://www.w3.org/2000/svg\">\r\n <path d=\"M9.89214 0L5.5 4.39214L1.10786 0L0 1.10786L4.39214 5.5L0 9.89214L1.10786 11L5.5 6.60786L9.89214 11L11 9.89214L6.60786 5.5L11 1.10786L9.89214 0Z\" fill=\"white\"/>\r\n </svg>\r\n </div>\r\n <div class=\"flex-center\">\r\n <vodds-loader [showAjaxLoader]=\"isLoading\"></vodds-loader>\r\n </div>\r\n @if (!isLoading && !isShow) {\r\n <div class=\"visa-card-message\">\r\n $-addpwdr_visaCardErrorMessage-$ <br> $-addpwdr_visaCardErrorMessage2-$\r\n </div>\r\n }\r\n <div class=\"visa-card-form\" [style]=\"{display: isShow ? 'flex' : 'none'}\">\r\n <div class=\"timer\">\r\n <svg width=\"14\" height=\"14\" viewBox=\"0 0 14 14\" xmlns=\"http://www.w3.org/2000/svg\">\r\n <path d=\"M7 2.56067C9.76142 2.56067 12 4.79925 12 7.56067C12 10.3221 9.76142 12.5607 7 12.5607C4.23858 12.5607 2 10.3221 2 7.56067C2 4.79925 4.23858 2.56067 7 2.56067ZM6.25 4.06067V7.93567L6.5498 8.16028L8.5498 9.66028L9.4502 8.46106L7.75 7.18567V4.06067H6.25Z\" fill=\"#B5B5B5\"/>\r\n <line x1=\"10.0303\" y1=\"0.530339\" x2=\"12.8588\" y2=\"3.35877\" stroke=\"#B5B5B5\" stroke-width=\"1.5\"/>\r\n <line y1=\"-0.75\" x2=\"4\" y2=\"-0.75\" transform=\"matrix(-0.707107 0.707107 0.707107 0.707107 4.82861 1.06067)\" stroke=\"#B5B5B5\" stroke-width=\"1.5\"/>\r\n </svg>\r\n <span class=\"label\">&nbsp;$-addpwdr_visaCardTimeout-$&nbsp;</span> <span class=\"display-time\"> {{displayTimer}}</span>\r\n </div>\r\n <div id=\"rapyd-checkout\"></div>\r\n </div>\r\n</div>\r\n", styles: [".flex-center{display:flex;justify-content:center;align-items:center}#visa-card{height:auto;width:500px;top:0;left:710px;z-index:101}.top{width:100%;align-items:center;margin-bottom:8px;border-radius:0;background:#dd453c;position:relative;color:#fff;display:flex;justify-content:space-between}.top h2{padding-left:15px;text-align:left;font-size:16px;font-weight:800}.top svg{position:unset;padding-right:15px;width:18px;height:18px}.visa-card-form{display:flex;flex-direction:column;align-items:center;min-height:500px!important;width:100%}.visa-card-form .timer{display:flex;align-items:center}#rapyd-checkout{min-height:550px;max-height:550px;overflow-y:auto;scrollbar-width:none}#rapyd-checkout::-webkit-scrollbar{display:none}.ui-widget.ui-widget-content.vodds-visa-card-dialog{padding:0;border:none;border-radius:10px}.vodds-visa-card-dialog .ui-dialog-content{display:flex;align-items:center;flex-direction:column;padding:0;margin:0}.vodds-visa-card-dialog .ui-dialog-content .top{width:100%;display:flex;align-items:center;padding:6px 18px;margin-bottom:8px;border-radius:8px}.vodds-visa-card-dialog .ui-dialog-content .top h2{text-align:left;font-size:16px;font-weight:800}#trading-platform.dark .vodds-visa-card-dialog .label,.vodds-visa-card-dialog .label{color:#80807f!important}#trading-platform.dark .vodds-visa-card-dialog span{color:#000!important}#trading-platform.dark .vodds-visa-card-dialog{background:#fff!important}\n"] }]
228
+ }], ctorParameters: () => [{ type: i1.MatDialogRef }, { type: undefined, decorators: [{
229
+ type: Inject,
230
+ args: [MAT_DIALOG_DATA]
231
+ }] }, { type: EventEmitterService }], propDecorators: { checkout: [{
232
+ type: Input
233
+ }] } });
87
234
 
88
235
  class Domain {
89
236
  constructor() {
90
237
  this.defaultDomain = '';
91
- this.allowedOrigins = [];
238
+ this.allowedOrigins = ['http://localhost:9000'];
92
239
  this.specialDomain = [];
93
240
  this.jetonDomain = '';
94
241
  }
95
242
  }
96
243
 
244
+ const ApiRoute = {
245
+ GET_DOMAIN: { url: "/getDomain", method: "get" }
246
+ };
247
+
248
+ var PaymentType;
249
+ (function (PaymentType) {
250
+ PaymentType[PaymentType["NA"] = 0] = "NA";
251
+ PaymentType[PaymentType["JETON"] = 1] = "JETON";
252
+ PaymentType[PaymentType["ECOPAYZ"] = 2] = "ECOPAYZ";
253
+ PaymentType[PaymentType["RAPYD"] = 3] = "RAPYD";
254
+ })(PaymentType || (PaymentType = {}));
255
+
97
256
  var IframeMessageType;
98
257
  (function (IframeMessageType) {
99
258
  IframeMessageType[IframeMessageType["OPEN_PAYMENT_FORM"] = 0] = "OPEN_PAYMENT_FORM";
100
259
  IframeMessageType[IframeMessageType["PAYMENT_CALLBACK"] = 1] = "PAYMENT_CALLBACK";
101
260
  })(IframeMessageType || (IframeMessageType = {}));
102
261
 
103
- const ApiRoute = {
104
- GET_DOMAIN: { url: "/getDomain", method: "get" }
105
- };
106
-
107
262
  class VoddsHttpService {
108
263
  constructor(httpClient) {
109
264
  this.httpClient = httpClient;
@@ -146,7 +301,7 @@ class VoddsHttpService {
146
301
  getFullUrl(url, param) {
147
302
  return `${url}?${param.toFormUrlEncoded()}`;
148
303
  }
149
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: VoddsHttpService, deps: [{ token: i1.HttpClient }], target: i0.ɵɵFactoryTarget.Injectable }); }
304
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: VoddsHttpService, deps: [{ token: i1$1.HttpClient }], target: i0.ɵɵFactoryTarget.Injectable }); }
150
305
  static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: VoddsHttpService, providedIn: 'root' }); }
151
306
  }
152
307
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: VoddsHttpService, decorators: [{
@@ -154,7 +309,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.12", ngImpo
154
309
  args: [{
155
310
  providedIn: 'root',
156
311
  }]
157
- }], ctorParameters: () => [{ type: i1.HttpClient }] });
312
+ }], ctorParameters: () => [{ type: i1$1.HttpClient }] });
158
313
 
159
314
  class IframeMessageService {
160
315
  constructor(ngZone, http) {
@@ -163,7 +318,9 @@ class IframeMessageService {
163
318
  this.messages$ = new Subject();
164
319
  this.thirdPartyMessages$ = new Subject();
165
320
  this.listener = (event) => {
321
+ // console.log("message: ", event);
166
322
  if (!this.domain.allowedOrigins.includes(event.origin)) {
323
+ console.log("listener not allow: ", event);
167
324
  if (this.domain.jetonDomain == event.origin) {
168
325
  this.ngZone.run(() => {
169
326
  this.thirdPartyMessages$.next(event);
@@ -172,9 +329,11 @@ class IframeMessageService {
172
329
  }
173
330
  return;
174
331
  }
175
- this.ngZone.run(() => {
176
- this.messages$.next(event.data);
177
- });
332
+ if (event.data && IframeMessageType[event.data.type]) {
333
+ this.ngZone.run(() => {
334
+ this.messages$.next(event.data);
335
+ });
336
+ }
178
337
  };
179
338
  this.domain = new Domain();
180
339
  this.http.get(ApiRoute.GET_DOMAIN.url).subscribe({
@@ -211,7 +370,7 @@ class IframeMessageService {
211
370
  sendMessageToIframe(iframe, message) {
212
371
  if (iframe == undefined)
213
372
  return;
214
- iframe.nativeElement.contentWindow?.postMessage(message, window.location.hostname);
373
+ iframe.nativeElement.contentWindow?.postMessage(message, window.location.origin);
215
374
  }
216
375
  static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: IframeMessageService, deps: [{ token: i0.NgZone }, { token: VoddsHttpService }], target: i0.ɵɵFactoryTarget.Injectable }); }
217
376
  static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: IframeMessageService, providedIn: 'root' }); }
@@ -223,42 +382,122 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.12", ngImpo
223
382
  }]
224
383
  }], ctorParameters: () => [{ type: i0.NgZone }, { type: VoddsHttpService }] });
225
384
 
385
+ class Checkout {
386
+ constructor() {
387
+ this.requestId = 0;
388
+ this.paymentType = PaymentType.NA;
389
+ this.url = '';
390
+ this.expiration = 300;
391
+ this.errorMessage = '';
392
+ this.successMessage = '';
393
+ }
394
+ setErrorMessage(errorMessage) {
395
+ this.errorMessage = errorMessage;
396
+ this.popup = undefined;
397
+ }
398
+ setCallback(callback) {
399
+ this.successMessage = 'success';
400
+ this.callback = callback;
401
+ this.popup = undefined;
402
+ }
403
+ }
404
+
405
+ class Timer {
406
+ constructor(interval, maxTime) {
407
+ this.interval = 0;
408
+ this.maxTime = 120000; // 2 minute
409
+ this.currentTime = 0;
410
+ this.popupTimer = null;
411
+ this.popup = null;
412
+ this.interval = interval;
413
+ if (maxTime)
414
+ this.maxTime = maxTime;
415
+ }
416
+ oberserableTimer(data, callback) {
417
+ this.popup = data.popup;
418
+ console.log("investigate popup status begin: ", this.popup?.name, this.popup);
419
+ this.popupTimer = setInterval(() => {
420
+ console.log("investigate popup status: ", data);
421
+ if ((this.maxTime > 0 && this.currentTime >= this.maxTime) || !data) {
422
+ this.stopWatcher();
423
+ // TODO Hit expire time
424
+ return;
425
+ }
426
+ this.currentTime += this.interval;
427
+ if (data instanceof Checkout && (!data.popup || (data.popup && data.popup.closed))) { // Handle detect close popup by the user
428
+ console.log("Close popup");
429
+ this.stopWatcher();
430
+ if (callback) {
431
+ data.setErrorMessage("Payment popup is closed");
432
+ callback(data);
433
+ }
434
+ }
435
+ }, this.interval);
436
+ }
437
+ stopWatcher() {
438
+ if (this.popupTimer) {
439
+ clearInterval(this.popupTimer);
440
+ this.popupTimer = null;
441
+ }
442
+ }
443
+ }
444
+
226
445
  class PaymentService {
227
- constructor(iframeMessageService) {
228
- this.iframeMessageService = iframeMessageService;
229
- this.popup = new Map();
446
+ constructor() {
447
+ this.cache = new Map();
448
+ this.timer = new Timer(500); // 0.5s
449
+ this.iframeMessageService = inject(IframeMessageService);
230
450
  /**
231
451
  * Listen OPEN_PAYMENT_FORM message to open 3th party page
232
452
  */
233
453
  this.iframeMessageService.messages().subscribe(message => {
234
454
  console.log('Received from iframe:', message);
235
- if (IframeMessageType.OPEN_PAYMENT_FORM != message.type)
236
- return;
237
- this.openWindow(message.payload);
455
+ if (IframeMessageType.OPEN_PAYMENT_FORM == message.type) {
456
+ const checkout = Object.assign(new Checkout(), message.payload);
457
+ if (!checkout || this.cache.get(checkout.requestId))
458
+ return;
459
+ if (this.cache.size > 0) {
460
+ this.cache.clear();
461
+ //TODO clear the current popup
462
+ }
463
+ switch (checkout.paymentType) {
464
+ case PaymentType.JETON:
465
+ case PaymentType.ECOPAYZ:
466
+ this.openWindow(checkout);
467
+ break;
468
+ case PaymentType.RAPYD:
469
+ this.openVisaCheckout(checkout);
470
+ break;
471
+ default:
472
+ }
473
+ }
474
+ if (IframeMessageType.PAYMENT_CALLBACK == message.type) {
475
+ this.result = Object.assign(new Checkout(), message.payload);
476
+ }
238
477
  });
239
478
  }
240
479
  /**
241
480
  * Open 3th party page on the popup windown or new tab
242
481
  */
243
482
  openWindow(checkout) {
244
- if (!checkout || this.popup.get(checkout.requestId))
245
- return;
246
- if (this.popup.size > 0) {
247
- //TODO clear the current popup
248
- }
483
+ console.log("Open windown: ", this.cache);
249
484
  const width = 470;
250
485
  const height = 550;
251
486
  // var left = Math.max(0, (screen.width - width) / 2) + (screen.availLeft | 0),
252
487
  // top = Math.max(0, (screen.height - height) / 2) + (screen.availTop | 0);
253
488
  // var popup = window.open(url, "VOdds", 'width=' + width + ',height=' + height + ',left=' + left + ',top=' + top + ',status=0,location=0,menubar=0,toolbar=0');
254
- const popup = window.open(checkout.url, "VOdds", 'width=' + width + ',height=' + height + ',status=0,location=0,menubar=0,toolbar=0');
489
+ const popup = window.open(checkout.url, 'VOdds', 'width=' + width + ',height=' + height + ',status=0,location=0,menubar=0,toolbar=0');
255
490
  if (!popup) {
256
491
  checkout.errorMessage = 'Your setting prevents popups. Please change your setting to allow it.';
257
492
  this.sendMessageToIframe(checkout);
258
493
  return;
259
494
  }
260
495
  checkout.popup = popup;
261
- this.popup.set(checkout.requestId, checkout);
496
+ window.addEventListener("beforeunload", () => {
497
+ window.opener?.postMessage({ type: "vodds-popup-closing12" }, window.location.origin);
498
+ });
499
+ popup.postMessage({ type: "vodds-popup-closing" }, window.location.origin);
500
+ this.cache.set(checkout.requestId, checkout);
262
501
  popup.focus();
263
502
  this.onThirdPartyPopupClose(checkout);
264
503
  }
@@ -269,17 +508,18 @@ class PaymentService {
269
508
  this.iframeMessageService.thirdPartyMessages().subscribe(event => {
270
509
  if (this.iframeMessageService.isValidDomain(checkout.paymentType, event.origin)) {
271
510
  console.log('Received from 3th party:', event.data);
272
- //TODO close popup again
273
- checkout.popup = undefined;
274
- checkout.callback = event.data;
511
+ checkout.setCallback(event.data);
512
+ this.timer.stopWatcher();
275
513
  this.sendMessageToIframe(checkout);
276
514
  }
277
515
  });
516
+ this.timer.oberserableTimer(checkout, () => this.sendMessageToIframe(checkout));
278
517
  }
279
518
  /**
280
519
  * send the message from the parent to the iframe
281
520
  */
282
521
  sendMessageToIframe(checkout) {
522
+ console.log("send message to iframe");
283
523
  if (this.iframe == undefined)
284
524
  return;
285
525
  let message = {
@@ -288,28 +528,142 @@ class PaymentService {
288
528
  };
289
529
  this.iframeMessageService.sendMessageToIframe(this.iframe, message);
290
530
  }
291
- removePaymentIframe() {
292
- //TODO
293
- this.iframe = undefined;
531
+ // removePaymentIframe() {
532
+ // //TODO
533
+ // this.iframe = undefined;
534
+ // }
535
+ async openVisaCheckout(checkout) {
536
+ }
537
+ }
538
+
539
+ class IParam {
540
+ getMobileFlag() {
541
+ return /android|mobi/i.test(navigator.userAgent.toLowerCase());
542
+ }
543
+ toJson() {
544
+ return JSON.stringify(this);
545
+ }
546
+ toFormUrlEncoded() {
547
+ return new URLSearchParams(Object.entries(this).map(([key, value]) => [key, String(value)])).toString();
548
+ }
549
+ }
550
+
551
+ class BaseForm extends IParam {
552
+ constructor() {
553
+ super();
554
+ this.isMobile = 'false';
555
+ }
556
+ /**
557
+ * Use this function for building POST params with form url encoded content type.
558
+ * Remeber to call params.toString() when passing to http request
559
+ */
560
+ getUrlSearchParam() {
561
+ const params = new URLSearchParams();
562
+ params.set('isMobile', this.isMobile);
563
+ return params;
564
+ }
565
+ /**
566
+ * Use this function for building GET params
567
+ */
568
+ getHttpParams() {
569
+ let params = new HttpParams();
570
+ params = params.append('isMobile', this.isMobile);
571
+ return params;
572
+ }
573
+ /**
574
+ * Add isMobile = 'true' to paramters
575
+ * @param params : object
576
+ */
577
+ addIsMobile(params) {
578
+ params['isMobile'] = this.isMobile;
579
+ }
580
+ /**
581
+ * For POST request with form-urlencoded
582
+ */
583
+ getHeaderWithContentTypeForm() {
584
+ const headers = new HttpHeaders()
585
+ .set('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
586
+ return headers;
587
+ }
588
+ /**
589
+ * For POST request with json body
590
+ */
591
+ getHeaderWithContentTypeJson() {
592
+ const headers = new HttpHeaders()
593
+ .set('Content-Type', 'application/json; charset=utf-8');
594
+ return headers;
595
+ }
596
+ }
597
+
598
+ class CallbackMessage {
599
+ constructor(errorMessage) {
600
+ this.errorMessage = '';
601
+ this.errorMessage = errorMessage;
602
+ }
603
+ }
604
+
605
+ class CountDownTime {
606
+ constructor(initTime) {
607
+ this.isStart = false;
608
+ this.isStop = false;
609
+ this.nextRound = false;
610
+ this.initTime = 0;
611
+ this.timeLeft = 0;
612
+ this.isCancel = false;
613
+ this.destroy$ = new Subject();
614
+ this.initTime = initTime;
615
+ }
616
+ start() {
617
+ this.isStart = true;
618
+ this.isStop = false;
619
+ this.timeLeft = this.initTime;
620
+ }
621
+ stop() {
622
+ this.isStart = false;
623
+ this.isStop = true;
624
+ this.timeLeft = 0;
625
+ this.nextRound = true;
626
+ }
627
+ downTime() {
628
+ this.timeLeft = this.timeLeft - 1;
629
+ }
630
+ cancel() {
631
+ this.isCancel = true;
632
+ this.stop();
633
+ }
634
+ oberserableTimer(isStop) {
635
+ timer(0, 1000)
636
+ .pipe(takeUntil(this.destroy$))
637
+ .subscribe(val => {
638
+ if (this.timeLeft === 0) {
639
+ if (this.isStart) {
640
+ this.stop();
641
+ }
642
+ }
643
+ else {
644
+ this.downTime();
645
+ }
646
+ if (this.nextRound) {
647
+ this.nextRound = false;
648
+ if (isStop) {
649
+ isStop.emit();
650
+ }
651
+ }
652
+ });
653
+ }
654
+ onDestroy() {
655
+ this.destroy$.next();
656
+ this.destroy$.complete();
294
657
  }
295
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: PaymentService, deps: [{ token: IframeMessageService }], target: i0.ɵɵFactoryTarget.Injectable }); }
296
- static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: PaymentService, providedIn: 'root' }); }
297
658
  }
298
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: PaymentService, decorators: [{
299
- type: Injectable,
300
- args: [{
301
- providedIn: 'root'
302
- }]
303
- }], ctorParameters: () => [{ type: IframeMessageService }] });
304
659
 
305
660
  /*
306
661
  * Public API Surface of epp-lib
307
662
  */
308
- // Models
309
663
 
310
664
  /**
311
665
  * Generated bundle index. Do not edit.
312
666
  */
313
667
 
314
- export { ApiRoute, BaseForm, CallbackMessage, Checkout, Domain, IParam, IframeMessageService, IframeMessageType, PaymentService, PaymentType, VoddsHttpService };
668
+ export { BaseForm, CallbackMessage, Checkout, CountDownTime, Domain, EventEmitterService, IParam, IframeMessageService, IframeMessageType, PaymentService, PaymentType, RapydComponent, Timer, VoddsHttpService, VoddsLoaderComponent };
315
669
  //# sourceMappingURL=epp-lib.mjs.map