angular-klasha 0.0.1 → 1.0.0

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.
@@ -1,744 +0,0 @@
1
- (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('@angular/common')) :
3
- typeof define === 'function' && define.amd ? define('angular-klasha', ['exports', '@angular/core', '@angular/common'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global['angular-klasha'] = {}, global.ng.core, global.ng.common));
5
- }(this, (function (exports, i0, common) { 'use strict';
6
-
7
- function _interopNamespace(e) {
8
- if (e && e.__esModule) return e;
9
- var n = Object.create(null);
10
- if (e) {
11
- Object.keys(e).forEach(function (k) {
12
- if (k !== 'default') {
13
- var d = Object.getOwnPropertyDescriptor(e, k);
14
- Object.defineProperty(n, k, d.get ? d : {
15
- enumerable: true,
16
- get: function () {
17
- return e[k];
18
- }
19
- });
20
- }
21
- });
22
- }
23
- n['default'] = e;
24
- return Object.freeze(n);
25
- }
26
-
27
- var i0__namespace = /*#__PURE__*/_interopNamespace(i0);
28
-
29
- /*! *****************************************************************************
30
- Copyright (c) Microsoft Corporation.
31
-
32
- Permission to use, copy, modify, and/or distribute this software for any
33
- purpose with or without fee is hereby granted.
34
-
35
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
36
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
37
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
38
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
39
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
40
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
41
- PERFORMANCE OF THIS SOFTWARE.
42
- ***************************************************************************** */
43
- /* global Reflect, Promise */
44
- var extendStatics = function (d, b) {
45
- extendStatics = Object.setPrototypeOf ||
46
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
47
- function (d, b) { for (var p in b)
48
- if (Object.prototype.hasOwnProperty.call(b, p))
49
- d[p] = b[p]; };
50
- return extendStatics(d, b);
51
- };
52
- function __extends(d, b) {
53
- if (typeof b !== "function" && b !== null)
54
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
55
- extendStatics(d, b);
56
- function __() { this.constructor = d; }
57
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
58
- }
59
- var __assign = function () {
60
- __assign = Object.assign || function __assign(t) {
61
- for (var s, i = 1, n = arguments.length; i < n; i++) {
62
- s = arguments[i];
63
- for (var p in s)
64
- if (Object.prototype.hasOwnProperty.call(s, p))
65
- t[p] = s[p];
66
- }
67
- return t;
68
- };
69
- return __assign.apply(this, arguments);
70
- };
71
- function __rest(s, e) {
72
- var t = {};
73
- for (var p in s)
74
- if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
75
- t[p] = s[p];
76
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
77
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
78
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
79
- t[p[i]] = s[p[i]];
80
- }
81
- return t;
82
- }
83
- function __decorate(decorators, target, key, desc) {
84
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
85
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
86
- r = Reflect.decorate(decorators, target, key, desc);
87
- else
88
- for (var i = decorators.length - 1; i >= 0; i--)
89
- if (d = decorators[i])
90
- r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
91
- return c > 3 && r && Object.defineProperty(target, key, r), r;
92
- }
93
- function __param(paramIndex, decorator) {
94
- return function (target, key) { decorator(target, key, paramIndex); };
95
- }
96
- function __metadata(metadataKey, metadataValue) {
97
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
98
- return Reflect.metadata(metadataKey, metadataValue);
99
- }
100
- function __awaiter(thisArg, _arguments, P, generator) {
101
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
102
- return new (P || (P = Promise))(function (resolve, reject) {
103
- function fulfilled(value) { try {
104
- step(generator.next(value));
105
- }
106
- catch (e) {
107
- reject(e);
108
- } }
109
- function rejected(value) { try {
110
- step(generator["throw"](value));
111
- }
112
- catch (e) {
113
- reject(e);
114
- } }
115
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
116
- step((generator = generator.apply(thisArg, _arguments || [])).next());
117
- });
118
- }
119
- function __generator(thisArg, body) {
120
- var _ = { label: 0, sent: function () { if (t[0] & 1)
121
- throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
122
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function () { return this; }), g;
123
- function verb(n) { return function (v) { return step([n, v]); }; }
124
- function step(op) {
125
- if (f)
126
- throw new TypeError("Generator is already executing.");
127
- while (_)
128
- try {
129
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done)
130
- return t;
131
- if (y = 0, t)
132
- op = [op[0] & 2, t.value];
133
- switch (op[0]) {
134
- case 0:
135
- case 1:
136
- t = op;
137
- break;
138
- case 4:
139
- _.label++;
140
- return { value: op[1], done: false };
141
- case 5:
142
- _.label++;
143
- y = op[1];
144
- op = [0];
145
- continue;
146
- case 7:
147
- op = _.ops.pop();
148
- _.trys.pop();
149
- continue;
150
- default:
151
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
152
- _ = 0;
153
- continue;
154
- }
155
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) {
156
- _.label = op[1];
157
- break;
158
- }
159
- if (op[0] === 6 && _.label < t[1]) {
160
- _.label = t[1];
161
- t = op;
162
- break;
163
- }
164
- if (t && _.label < t[2]) {
165
- _.label = t[2];
166
- _.ops.push(op);
167
- break;
168
- }
169
- if (t[2])
170
- _.ops.pop();
171
- _.trys.pop();
172
- continue;
173
- }
174
- op = body.call(thisArg, _);
175
- }
176
- catch (e) {
177
- op = [6, e];
178
- y = 0;
179
- }
180
- finally {
181
- f = t = 0;
182
- }
183
- if (op[0] & 5)
184
- throw op[1];
185
- return { value: op[0] ? op[1] : void 0, done: true };
186
- }
187
- }
188
- var __createBinding = Object.create ? (function (o, m, k, k2) {
189
- if (k2 === undefined)
190
- k2 = k;
191
- Object.defineProperty(o, k2, { enumerable: true, get: function () { return m[k]; } });
192
- }) : (function (o, m, k, k2) {
193
- if (k2 === undefined)
194
- k2 = k;
195
- o[k2] = m[k];
196
- });
197
- function __exportStar(m, o) {
198
- for (var p in m)
199
- if (p !== "default" && !Object.prototype.hasOwnProperty.call(o, p))
200
- __createBinding(o, m, p);
201
- }
202
- function __values(o) {
203
- var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
204
- if (m)
205
- return m.call(o);
206
- if (o && typeof o.length === "number")
207
- return {
208
- next: function () {
209
- if (o && i >= o.length)
210
- o = void 0;
211
- return { value: o && o[i++], done: !o };
212
- }
213
- };
214
- throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
215
- }
216
- function __read(o, n) {
217
- var m = typeof Symbol === "function" && o[Symbol.iterator];
218
- if (!m)
219
- return o;
220
- var i = m.call(o), r, ar = [], e;
221
- try {
222
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done)
223
- ar.push(r.value);
224
- }
225
- catch (error) {
226
- e = { error: error };
227
- }
228
- finally {
229
- try {
230
- if (r && !r.done && (m = i["return"]))
231
- m.call(i);
232
- }
233
- finally {
234
- if (e)
235
- throw e.error;
236
- }
237
- }
238
- return ar;
239
- }
240
- /** @deprecated */
241
- function __spread() {
242
- for (var ar = [], i = 0; i < arguments.length; i++)
243
- ar = ar.concat(__read(arguments[i]));
244
- return ar;
245
- }
246
- /** @deprecated */
247
- function __spreadArrays() {
248
- for (var s = 0, i = 0, il = arguments.length; i < il; i++)
249
- s += arguments[i].length;
250
- for (var r = Array(s), k = 0, i = 0; i < il; i++)
251
- for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
252
- r[k] = a[j];
253
- return r;
254
- }
255
- function __spreadArray(to, from, pack) {
256
- if (pack || arguments.length === 2)
257
- for (var i = 0, l = from.length, ar; i < l; i++) {
258
- if (ar || !(i in from)) {
259
- if (!ar)
260
- ar = Array.prototype.slice.call(from, 0, i);
261
- ar[i] = from[i];
262
- }
263
- }
264
- return to.concat(ar || from);
265
- }
266
- function __await(v) {
267
- return this instanceof __await ? (this.v = v, this) : new __await(v);
268
- }
269
- function __asyncGenerator(thisArg, _arguments, generator) {
270
- if (!Symbol.asyncIterator)
271
- throw new TypeError("Symbol.asyncIterator is not defined.");
272
- var g = generator.apply(thisArg, _arguments || []), i, q = [];
273
- return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
274
- function verb(n) { if (g[n])
275
- i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
276
- function resume(n, v) { try {
277
- step(g[n](v));
278
- }
279
- catch (e) {
280
- settle(q[0][3], e);
281
- } }
282
- function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
283
- function fulfill(value) { resume("next", value); }
284
- function reject(value) { resume("throw", value); }
285
- function settle(f, v) { if (f(v), q.shift(), q.length)
286
- resume(q[0][0], q[0][1]); }
287
- }
288
- function __asyncDelegator(o) {
289
- var i, p;
290
- return i = {}, verb("next"), verb("throw", function (e) { throw e; }), verb("return"), i[Symbol.iterator] = function () { return this; }, i;
291
- function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === "return" } : f ? f(v) : v; } : f; }
292
- }
293
- function __asyncValues(o) {
294
- if (!Symbol.asyncIterator)
295
- throw new TypeError("Symbol.asyncIterator is not defined.");
296
- var m = o[Symbol.asyncIterator], i;
297
- return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
298
- function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
299
- function settle(resolve, reject, d, v) { Promise.resolve(v).then(function (v) { resolve({ value: v, done: d }); }, reject); }
300
- }
301
- function __makeTemplateObject(cooked, raw) {
302
- if (Object.defineProperty) {
303
- Object.defineProperty(cooked, "raw", { value: raw });
304
- }
305
- else {
306
- cooked.raw = raw;
307
- }
308
- return cooked;
309
- }
310
- ;
311
- var __setModuleDefault = Object.create ? (function (o, v) {
312
- Object.defineProperty(o, "default", { enumerable: true, value: v });
313
- }) : function (o, v) {
314
- o["default"] = v;
315
- };
316
- function __importStar(mod) {
317
- if (mod && mod.__esModule)
318
- return mod;
319
- var result = {};
320
- if (mod != null)
321
- for (var k in mod)
322
- if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k))
323
- __createBinding(result, mod, k);
324
- __setModuleDefault(result, mod);
325
- return result;
326
- }
327
- function __importDefault(mod) {
328
- return (mod && mod.__esModule) ? mod : { default: mod };
329
- }
330
- function __classPrivateFieldGet(receiver, state, kind, f) {
331
- if (kind === "a" && !f)
332
- throw new TypeError("Private accessor was defined without a getter");
333
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
334
- throw new TypeError("Cannot read private member from an object whose class did not declare it");
335
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
336
- }
337
- function __classPrivateFieldSet(receiver, state, value, kind, f) {
338
- if (kind === "m")
339
- throw new TypeError("Private method is not writable");
340
- if (kind === "a" && !f)
341
- throw new TypeError("Private accessor was defined without a setter");
342
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
343
- throw new TypeError("Cannot write private member to an object whose class did not declare it");
344
- return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
345
- }
346
-
347
- var MERCHANT_KEY = new i0.InjectionToken('klasha.merchantKey');
348
- var BUSINESS_ID = new i0.InjectionToken('klasha.businessId');
349
- var IS_TEST_MODE = new i0.InjectionToken('klasha.isTestMode');
350
-
351
- /* eslint-disable @typescript-eslint/naming-convention */
352
- var AngularKlashaService = /** @class */ (function () {
353
- function AngularKlashaService(merchantKey, businessId, isTestMode) {
354
- if (isTestMode === void 0) { isTestMode = false; }
355
- this.merchantKey = merchantKey;
356
- this.businessId = businessId;
357
- this.isTestMode = isTestMode;
358
- console.log('here');
359
- var divScript = window.document.createElement('div');
360
- divScript.id = 'ktest';
361
- window.document.body.appendChild(divScript);
362
- var script = window.document.createElement('script');
363
- window.document.head.appendChild(script);
364
- var onLoadFunc = function () {
365
- script.removeEventListener('load', onLoadFunc);
366
- // resolve();
367
- };
368
- script.addEventListener('load', onLoadFunc);
369
- if (this.isTestMode) {
370
- script.setAttribute('src', 'https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js');
371
- }
372
- else {
373
- script.setAttribute('src', 'https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js');
374
- }
375
- console.log('loaded');
376
- }
377
- AngularKlashaService.prototype.loadScript = function () {
378
- var _this = this;
379
- return new Promise(function (resolve) {
380
- if (window.KlashaClient && typeof window.KlashaClient.initialize === 'function') {
381
- resolve();
382
- return;
383
- }
384
- var script1 = window.document.createElement('script');
385
- window.document.head.appendChild(script1);
386
- var onLoadFunc1 = function () {
387
- script1.removeEventListener('load', onLoadFunc1);
388
- resolve();
389
- };
390
- script1.addEventListener('load', onLoadFunc1);
391
- if (_this.isTestMode) {
392
- script1.setAttribute('src', 'https://klastatic.fra1.digitaloceanspaces.com/test/js/klasha-integration.js');
393
- }
394
- else {
395
- script1.setAttribute('src', 'https://klastatic.fra1.digitaloceanspaces.com/prod/js/klasha-integration.js');
396
- }
397
- console.log('loaded1');
398
- });
399
- };
400
- AngularKlashaService.prototype.checkInput = function (obj) {
401
- if (!obj.merchantKey && !this.merchantKey) {
402
- return 'angular-klasha: Please insert a your merchantKey';
403
- }
404
- if (!obj.businessId) {
405
- return 'angular-klasha: Klasha businessId cannot be empty';
406
- }
407
- if (!obj.email) {
408
- return 'angular-klasha: Klasha email cannot be empty';
409
- }
410
- if (!obj.fullname) {
411
- return 'angular-klasha: Klasha name cannot be empty';
412
- }
413
- if (!obj.phone_number) {
414
- return 'angular-klasha: Klasha phone cannot be empty';
415
- }
416
- if (!obj.amount) {
417
- return 'angular-klasha: Klasha amount cannot be empty';
418
- }
419
- if (!obj.tx_ref) {
420
- return 'angular-klasha: Klasha tx_ref cannot be empty';
421
- }
422
- return '';
423
- };
424
- AngularKlashaService.prototype.getKlashaOptions = function (obj) {
425
- var klashaOptions = {
426
- isTestMode: obj.isTestMode || this.isTestMode,
427
- merchantKey: obj.merchantKey || this.merchantKey,
428
- businessId: obj.businessId || this.businessId,
429
- amount: obj.amount,
430
- tx_ref: obj.tx_ref,
431
- sourceCurrency: obj.sourceCurrency || 'NGN',
432
- destinationCurrency: obj.destinationCurrency || 'NGN',
433
- fullname: obj.fullname || '',
434
- email: obj.email || '',
435
- phone_number: obj.phone_number || '',
436
- paymentDescription: obj.paymentDescription || '',
437
- callbackUrl: obj.callbackUrl || '',
438
- metadata: obj.metadata || {},
439
- kit: {
440
- currency: obj.kit.currency || obj.sourceCurrency || 'NGN',
441
- phone_number: obj.kit.phone_number || obj.phone_number || '',
442
- email: obj.kit.email || obj.email || '',
443
- fullname: obj.kit.fullname || obj.fullname || '',
444
- tx_ref: obj.kit.tx_ref || obj.tx_ref || this.makeId(8),
445
- paymentType: obj.kit.paymentType || '',
446
- // callBack : obj.kit.callBack
447
- }
448
- };
449
- return this.clean(klashaOptions);
450
- };
451
- AngularKlashaService.prototype.clean = function (obj) {
452
- // tslint:disable-next-line:prefer-const
453
- for (var propName in obj) {
454
- if (obj[propName] === null || obj[propName] === undefined) {
455
- delete obj[propName];
456
- }
457
- }
458
- return obj;
459
- };
460
- AngularKlashaService.prototype.makeId = function (length) {
461
- if (length === void 0) { length = 8; }
462
- var result = '';
463
- var characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
464
- var charactersLength = characters.length;
465
- for (var i = 0; i < length; i++) {
466
- result += characters.charAt(Math.floor(Math.random() * charactersLength));
467
- }
468
- return result;
469
- };
470
- return AngularKlashaService;
471
- }());
472
- AngularKlashaService.ɵprov = i0__namespace.ɵɵdefineInjectable({ factory: function AngularKlashaService_Factory() { return new AngularKlashaService(i0__namespace.ɵɵinject(MERCHANT_KEY), i0__namespace.ɵɵinject(BUSINESS_ID), i0__namespace.ɵɵinject(IS_TEST_MODE)); }, token: AngularKlashaService, providedIn: "root" });
473
- AngularKlashaService.decorators = [
474
- { type: i0.Injectable, args: [{
475
- providedIn: 'root',
476
- },] }
477
- ];
478
- AngularKlashaService.ctorParameters = function () { return [
479
- { type: String, decorators: [{ type: i0.Inject, args: [MERCHANT_KEY,] }] },
480
- { type: String, decorators: [{ type: i0.Inject, args: [BUSINESS_ID,] }] },
481
- { type: Boolean, decorators: [{ type: i0.Inject, args: [IS_TEST_MODE,] }] }
482
- ]; };
483
-
484
- var AngularKlashaComponent = /** @class */ (function () {
485
- function AngularKlashaComponent(KlashaService) {
486
- this.KlashaService = KlashaService;
487
- this.paymentInit = new i0.EventEmitter();
488
- this.callBack = new i0.EventEmitter(); // tslint:disable-line
489
- this.isPaying = false;
490
- }
491
- AngularKlashaComponent.prototype.pay = function () {
492
- return __awaiter(this, void 0, void 0, function () {
493
- var errorText, payment;
494
- return __generator(this, function (_a) {
495
- switch (_a.label) {
496
- case 0:
497
- errorText = '';
498
- if (this.klashaOptions && Object.keys(this.klashaOptions).length >= 2) {
499
- errorText = this.validateInput(this.klashaOptions);
500
- this.generateOptions(this.klashaOptions);
501
- }
502
- else {
503
- errorText = this.validateInput(this);
504
- this.generateOptions(this);
505
- }
506
- if (errorText) {
507
- console.error(errorText);
508
- return [2 /*return*/, errorText];
509
- }
510
- return [4 /*yield*/, this.KlashaService.loadScript()];
511
- case 1:
512
- _a.sent();
513
- if (this.isPaying) {
514
- return [2 /*return*/];
515
- }
516
- if (this.paymentInit.observers.length) {
517
- this.paymentInit.emit();
518
- }
519
- payment = new window.KlashaClient(this._KlashaOptions.merchantKey, this._KlashaOptions.businessId || 1, this._KlashaOptions.amount, 'ktest', this._KlashaOptions.callbackUrl, this._KlashaOptions.destinationCurrency, this._KlashaOptions.sourceCurrency, this._KlashaOptions.kit);
520
- payment.init();
521
- // const payment = window.KlashaClient.init(this._KlashaOptions);
522
- // payment.loadIframe(this._KlashaOptions);
523
- this.isPaying = true;
524
- return [2 /*return*/];
525
- }
526
- });
527
- });
528
- };
529
- AngularKlashaComponent.prototype.validateInput = function (obj) {
530
- if (!this.callBack.observers.length) {
531
- return 'angular-klasha: Insert a callBack output like so (callBack)=\'PaymentComplete($event)\' to check payment status';
532
- }
533
- return this.KlashaService.checkInput(obj);
534
- };
535
- AngularKlashaComponent.prototype.generateOptions = function (obj) {
536
- var _this = this;
537
- this._KlashaOptions = this.KlashaService.getKlashaOptions(obj);
538
- this._KlashaOptions.kit.callBack = function () {
539
- var _a;
540
- var response = [];
541
- for (var _i = 0; _i < arguments.length; _i++) {
542
- response[_i] = arguments[_i];
543
- }
544
- (_a = _this.callBack).emit.apply(_a, __spreadArray([], __read(response)));
545
- };
546
- this._KlashaOptions.callBack = function () {
547
- var _a;
548
- var response = [];
549
- for (var _i = 0; _i < arguments.length; _i++) {
550
- response[_i] = arguments[_i];
551
- }
552
- (_a = _this.callBack).emit.apply(_a, __spreadArray([], __read(response)));
553
- };
554
- };
555
- return AngularKlashaComponent;
556
- }());
557
- AngularKlashaComponent.decorators = [
558
- { type: i0.Component, args: [{
559
- // tslint:disable-next-line:component-selector
560
- selector: 'angular-klasha',
561
- template: "<button [ngClass]=\"class\" [ngStyle]=\"style\" (click)=\"pay()\"><ng-content></ng-content></button>"
562
- },] }
563
- ];
564
- AngularKlashaComponent.ctorParameters = function () { return [
565
- { type: AngularKlashaService }
566
- ]; };
567
- AngularKlashaComponent.propDecorators = {
568
- merchantKey: [{ type: i0.Input }],
569
- isTestMode: [{ type: i0.Input }],
570
- businessId: [{ type: i0.Input }],
571
- amount: [{ type: i0.Input }],
572
- metadata: [{ type: i0.Input }],
573
- tx_ref: [{ type: i0.Input }],
574
- currency: [{ type: i0.Input }],
575
- fullname: [{ type: i0.Input }],
576
- email: [{ type: i0.Input }],
577
- phone_number: [{ type: i0.Input }],
578
- paymentDescription: [{ type: i0.Input }],
579
- redirectUrl: [{ type: i0.Input }],
580
- klashaOptions: [{ type: i0.Input }],
581
- class: [{ type: i0.Input }],
582
- style: [{ type: i0.Input }],
583
- paymentInit: [{ type: i0.Output }],
584
- callBack: [{ type: i0.Output }]
585
- };
586
-
587
- var AngularKlashaDirective = /** @class */ (function () {
588
- function AngularKlashaDirective(KlashaService) {
589
- this.KlashaService = KlashaService;
590
- this.paymentInit = new i0.EventEmitter();
591
- this.callBack = new i0.EventEmitter(); // tslint:disable-line
592
- this.isPaying = false;
593
- }
594
- AngularKlashaDirective.prototype.pay = function () {
595
- return __awaiter(this, void 0, void 0, function () {
596
- var errorText, payment;
597
- return __generator(this, function (_a) {
598
- switch (_a.label) {
599
- case 0:
600
- errorText = '';
601
- if (this.klashaOptions && Object.keys(this.klashaOptions).length >= 2) {
602
- errorText = this.validateInput(this.klashaOptions);
603
- this.generateOptions(this.klashaOptions);
604
- }
605
- else {
606
- errorText = this.validateInput(this);
607
- this.generateOptions(this);
608
- }
609
- if (errorText) {
610
- console.error(errorText);
611
- return [2 /*return*/, errorText];
612
- }
613
- return [4 /*yield*/, this.KlashaService.loadScript()];
614
- case 1:
615
- _a.sent();
616
- // if (this.isPaying) { return; }
617
- if (this.paymentInit.observers.length) {
618
- this.paymentInit.emit();
619
- }
620
- payment = new window.KlashaClient(this._KlashaOptions.merchantKey, this._KlashaOptions.businessId || 1, this._KlashaOptions.amount, 'ktest', this._KlashaOptions.callbackUrl, this._KlashaOptions.destinationCurrency, this._KlashaOptions.sourceCurrency, this._KlashaOptions.kit);
621
- payment.init();
622
- return [2 /*return*/];
623
- }
624
- });
625
- });
626
- };
627
- AngularKlashaDirective.prototype.validateInput = function (obj) {
628
- if (!this.callBack.observers.length) {
629
- return 'angular-klasha: Insert a callBack output like so (callBack)=\'PaymentComplete($event)\' to check payment status';
630
- }
631
- return this.KlashaService.checkInput(obj);
632
- };
633
- AngularKlashaDirective.prototype.generateOptions = function (obj) {
634
- var _this = this;
635
- this._KlashaOptions = this.KlashaService.getKlashaOptions(obj);
636
- this._KlashaOptions.kit.callBack = function () {
637
- var _a;
638
- var response = [];
639
- for (var _i = 0; _i < arguments.length; _i++) {
640
- response[_i] = arguments[_i];
641
- }
642
- (_a = _this.callBack).emit.apply(_a, __spreadArray([], __read(response)));
643
- };
644
- this._KlashaOptions.callBack = function () {
645
- var _a;
646
- var response = [];
647
- for (var _i = 0; _i < arguments.length; _i++) {
648
- response[_i] = arguments[_i];
649
- }
650
- (_a = _this.callBack).emit.apply(_a, __spreadArray([], __read(response)));
651
- };
652
- };
653
- AngularKlashaDirective.prototype.buttonClick = function () {
654
- return __awaiter(this, void 0, void 0, function () {
655
- return __generator(this, function (_a) {
656
- this.pay();
657
- return [2 /*return*/];
658
- });
659
- });
660
- };
661
- return AngularKlashaDirective;
662
- }());
663
- AngularKlashaDirective.decorators = [
664
- { type: i0.Directive, args: [{
665
- // tslint:disable-next-line:directive-selector
666
- selector: '[angular-klasha]',
667
- },] }
668
- ];
669
- AngularKlashaDirective.ctorParameters = function () { return [
670
- { type: AngularKlashaService }
671
- ]; };
672
- AngularKlashaDirective.propDecorators = {
673
- merchantKey: [{ type: i0.Input }],
674
- isTestMode: [{ type: i0.Input }],
675
- businessId: [{ type: i0.Input }],
676
- amount: [{ type: i0.Input }],
677
- metadata: [{ type: i0.Input }],
678
- tx_ref: [{ type: i0.Input }],
679
- currency: [{ type: i0.Input }],
680
- fullname: [{ type: i0.Input }],
681
- email: [{ type: i0.Input }],
682
- phone_number: [{ type: i0.Input }],
683
- paymentDescription: [{ type: i0.Input }],
684
- redirectUrl: [{ type: i0.Input }],
685
- klashaOptions: [{ type: i0.Input }],
686
- class: [{ type: i0.Input }],
687
- style: [{ type: i0.Input }],
688
- paymentInit: [{ type: i0.Output }],
689
- callBack: [{ type: i0.Output }],
690
- buttonClick: [{ type: i0.HostListener, args: ['click',] }]
691
- };
692
-
693
- var AngularKlashaModule = /** @class */ (function () {
694
- function AngularKlashaModule() {
695
- }
696
- AngularKlashaModule.forRoot = function (merchantKey, businessId, isTestMode) {
697
- if (isTestMode === void 0) { isTestMode = false; }
698
- return {
699
- ngModule: AngularKlashaModule,
700
- providers: [
701
- AngularKlashaService,
702
- { provide: MERCHANT_KEY, useValue: merchantKey },
703
- { provide: IS_TEST_MODE, useValue: isTestMode },
704
- { provide: BUSINESS_ID, useValue: businessId }
705
- ]
706
- };
707
- };
708
- return AngularKlashaModule;
709
- }());
710
- AngularKlashaModule.decorators = [
711
- { type: i0.NgModule, args: [{
712
- imports: [common.CommonModule],
713
- exports: [
714
- AngularKlashaComponent,
715
- AngularKlashaDirective
716
- ],
717
- declarations: [
718
- AngularKlashaComponent,
719
- AngularKlashaDirective
720
- ],
721
- providers: [],
722
- },] }
723
- ];
724
-
725
- /*
726
- * Public API Surface of angular-klasha
727
- */
728
-
729
- /**
730
- * Generated bundle index. Do not edit.
731
- */
732
-
733
- exports.AngularKlashaComponent = AngularKlashaComponent;
734
- exports.AngularKlashaDirective = AngularKlashaDirective;
735
- exports.AngularKlashaModule = AngularKlashaModule;
736
- exports.ɵa = AngularKlashaService;
737
- exports.ɵb = MERCHANT_KEY;
738
- exports.ɵc = BUSINESS_ID;
739
- exports.ɵd = IS_TEST_MODE;
740
-
741
- Object.defineProperty(exports, '__esModule', { value: true });
742
-
743
- })));
744
- //# sourceMappingURL=angular-klasha.umd.js.map