mmpay-browser-sdk 1.0.3

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.
@@ -0,0 +1,476 @@
1
+ (function (global, factory) {
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
3
+ typeof define === 'function' && define.amd ? define(['exports'], factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.MMPaySDK = {}));
5
+ })(this, (function (exports) { 'use strict';
6
+
7
+ class MMPaySDK {
8
+ constructor(publishableKey, options = {}) {
9
+ this.pollIntervalId = undefined;
10
+ this.onCompleteCallback = null;
11
+ this.overlayElement = null;
12
+ // Properties to store pending data for re-rendering after cancel attempt
13
+ this.pendingApiResponse = null;
14
+ this.pendingPaymentPayload = null;
15
+ this.QR_SIZE = 300;
16
+ if (!publishableKey) {
17
+ throw new Error("A Publishable Key is required to initialize [MMPaySDK].");
18
+ }
19
+ this.publishableKey = publishableKey;
20
+ this.environment = options.environment || 'production';
21
+ this.baseUrl = options.baseUrl || 'https://api.mm-pay.com';
22
+ this.merchantName = options.merchantName || 'Your Merchant';
23
+ this.POLL_INTERVAL_MS = options.pollInterval || 3000;
24
+ }
25
+ /**
26
+ * _callApi
27
+ * @param endpoint
28
+ * @param data
29
+ * @returns
30
+ */
31
+ async _callApi(endpoint, data = {}) {
32
+ const response = await fetch(`${this.baseUrl}${endpoint}`, {
33
+ method: 'POST',
34
+ headers: {
35
+ 'Content-Type': 'application/json',
36
+ 'Authorization': `Bearer ${this.publishableKey}`
37
+ },
38
+ body: JSON.stringify(data)
39
+ });
40
+ if (!response.ok) {
41
+ const errorText = await response.text();
42
+ throw new Error(`API error (${response.status}): ${response.statusText}. Details: ${errorText}`);
43
+ }
44
+ return response.json();
45
+ }
46
+ /**
47
+ * createPaymentRequest
48
+ * @param {PaymentData} payload
49
+ * @returns
50
+ */
51
+ async createPaymentRequest(payload) {
52
+ try {
53
+ const endpoint = this.environment === 'sandbox'
54
+ ? '/xpayments/sandbox-payment-create'
55
+ : '/xpayments/production-payment-create';
56
+ return await this._callApi(endpoint, payload);
57
+ }
58
+ catch (error) {
59
+ console.error("Payment request failed:", error);
60
+ throw error;
61
+ }
62
+ }
63
+ /**
64
+ * _createAndRenderModal
65
+ * @param {string} contentHtml
66
+ * @param isTerminal
67
+ * @returns
68
+ */
69
+ _createAndRenderModal(contentHtml, isTerminal = false) {
70
+ this._cleanupModal(false);
71
+ const overlay = document.createElement('div');
72
+ overlay.id = 'mmpay-full-modal';
73
+ document.body.appendChild(overlay);
74
+ this.overlayElement = overlay;
75
+ const style = document.createElement('style');
76
+ style.innerHTML = `
77
+ @import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;600;700;800&family=Padauk:wght@400;700&display=swap');
78
+
79
+ #mmpay-full-modal {
80
+ position: fixed;
81
+ top: 0;
82
+ left: 0;
83
+ width: 100vw;
84
+ height: 100vh;
85
+ background-color: rgba(0, 0, 0, 0.85);
86
+ z-index: 9999;
87
+ display: flex;
88
+ align-items: center;
89
+ justify-content: center;
90
+ transition: opacity 0.3s;
91
+ padding: 15px;
92
+ box-sizing: border-box;
93
+ overflow: auto;
94
+ }
95
+ .mmpay-overlay-content {
96
+ display: flex;
97
+ align-items: center;
98
+ justify-content: center;
99
+ min-height: 100%;
100
+ width: 100%;
101
+ padding: 20px 0;
102
+ }
103
+ /* Card Base Styles */
104
+ .mmpay-card {
105
+ background: #ffffff;
106
+ border-radius: 16px;
107
+ box-shadow: 0 20px 40px -10px rgba(0, 0, 0, 0.4);
108
+ text-align: center;
109
+ font-family: 'Inter', 'Padauk', sans-serif;
110
+ border: 1px solid #f3f4f6;
111
+ animation: fadeInScale 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
112
+ box-sizing: border-box;
113
+ position: relative;
114
+ width: min(90vw, 330px);
115
+ margin: auto;
116
+ }
117
+ @keyframes fadeInScale {
118
+ from { opacity: 0; transform: scale(0.9); }
119
+ to { opacity: 1; transform: scale(1); }
120
+ }
121
+ .mmpay-close-btn {
122
+ position: absolute;
123
+ top: 10px;
124
+ right: 10px;
125
+ background: none;
126
+ border: none;
127
+ cursor: pointer;
128
+ padding: 8px;
129
+ color: #9ca3af;
130
+ border-radius: 50%;
131
+ transition: color 0.2s, background-color 0.2s;
132
+ line-height: 1;
133
+ z-index: 10;
134
+ }
135
+ .mmpay-close-btn:hover {
136
+ color: #4b5563;
137
+ background-color: #f3f4f6;
138
+ }
139
+ .mmpay-button {
140
+ background-color: #4f46e5;
141
+ color: white;
142
+ border: none;
143
+ padding: 10px 20px;
144
+ border-radius: 8px;
145
+ font-size: 0.95rem;
146
+ font-weight: 700;
147
+ cursor: pointer;
148
+ margin-top: 15px;
149
+ transition: background-color 0.2s, box-shadow 0.2s, transform 0.1s;
150
+ box-shadow: 0 5px 15px rgba(79, 70, 229, 0.3);
151
+ width: 100%;
152
+ }
153
+ .mmpay-button:hover {
154
+ background-color: #4338ca;
155
+ box-shadow: 0 8px 18px rgba(67, 56, 202, 0.4);
156
+ transform: translateY(-1px);
157
+ }
158
+ .mmpay-button:active {
159
+ transform: translateY(0);
160
+ background-color: #3f35c7;
161
+ }
162
+ .mmpay-text-myanmar { font-family: 'Padauk', sans-serif; }
163
+ `;
164
+ overlay.appendChild(style);
165
+ window.MMPayCloseModal = (forceClose = false) => {
166
+ if (isTerminal || forceClose) {
167
+ this._cleanupModal(true);
168
+ }
169
+ else {
170
+ this._showCancelConfirmationModal();
171
+ }
172
+ };
173
+ window.MMPayReRenderModal = () => this._reRenderPendingModalInstance();
174
+ overlay.innerHTML += `<div class="mmpay-overlay-content">${contentHtml}</div>`;
175
+ document.body.style.overflow = 'hidden'; // FIX: Prevent body scroll when modal is open
176
+ return overlay;
177
+ }
178
+ /**
179
+ * showPaymentModal
180
+ * @param {PaymentData} payload
181
+ * @param {Function} onComplete
182
+ */
183
+ async showPaymentModal(payload, onComplete) {
184
+ const initialContent = `<div class="mmpay-overlay-content"><div style="text-align: center; color: #fff;">ငွေပေးချေမှု စတင်နေသည်...</div></div>`;
185
+ this._createAndRenderModal(initialContent, false);
186
+ this.onCompleteCallback = onComplete;
187
+ try {
188
+ const apiResponse = await this.createPaymentRequest(payload);
189
+ if (apiResponse && apiResponse.qr && apiResponse.transactionId) {
190
+ this.pendingApiResponse = apiResponse;
191
+ this.pendingPaymentPayload = payload;
192
+ this._renderQrModalContent(apiResponse, payload, this.merchantName);
193
+ this._startPolling(apiResponse._id, onComplete);
194
+ }
195
+ else {
196
+ this._showTerminalMessage(apiResponse.orderId || 'N/A', 'FAILED', 'ငွေပေးချေမှု စတင်ရန် မအောင်မြင်ပါ။ QR ဒေတာ မရရှိပါ။');
197
+ }
198
+ }
199
+ catch (error) {
200
+ // Myanmar translation for "Error during payment initiation. See console."
201
+ this._showTerminalMessage(payload.orderId || 'N/A', 'FAILED', 'ငွေပေးချေမှု စတင်စဉ် အမှားအယွင်း ဖြစ်ပွားသည်။ ကွန်ဆိုးလ်တွင် ကြည့်ပါ။');
202
+ }
203
+ }
204
+ /**
205
+ * _renderQrModalContent
206
+ * @param {CreatePaymentResponse} apiResponse
207
+ * @param {PaymentData} payload
208
+ * @param {string} merchantName
209
+ */
210
+ _renderQrModalContent(apiResponse, payload, merchantName) {
211
+ const qrData = apiResponse.qr;
212
+ const amountDisplay = `${apiResponse.amount.toFixed(2)} ${apiResponse.currency}`;
213
+ const qrCanvasId = 'mmpayQrCanvas';
214
+ const orderId = payload.orderId;
215
+ window.MMPayDownloadQR = function () {
216
+ const canvas = document.getElementById(qrCanvasId);
217
+ if (!canvas)
218
+ return;
219
+ try {
220
+ const dataURL = canvas.toDataURL('image/png');
221
+ const link = document.createElement('a');
222
+ link.href = dataURL;
223
+ link.download = `MMPay-QR-${orderId}.png`;
224
+ document.body.appendChild(link);
225
+ link.click();
226
+ document.body.removeChild(link);
227
+ }
228
+ catch (e) {
229
+ console.error("Failed to download QR image:", e);
230
+ }
231
+ };
232
+ const qrContentHtml = `
233
+ <style>
234
+ .mmpay-card { max-width: 350px; padding: 16px; }
235
+ .mmpay-header { color: #1f2937; font-size: 1rem; font-weight: bold; margin-bottom: 8px; }
236
+ .mmpay-qr-container { padding: 0; margin: 10px auto; display: inline-block; line-height: 0; width: 300px; height: 300px; }
237
+ #${qrCanvasId} { display: block; background: white; border-radius: 8px; width: 100%; height: 100%; }
238
+ .mmpay-amount { font-size: 1.2rem; font-weight: 800; color: #1f2937; margin: 0; }
239
+ .mmpay-separator { border-top: 1px solid #f3f4f6; margin: 12px 0; }
240
+ .mmpay-detail { font-size: 0.8rem; color: #6b7280; margin: 3px 0; display: flex; justify-content: space-between; align-items: center; padding: 0 5px; }
241
+ .mmpay-detail strong { color: #374151; font-weight: 600; text-align: right; }
242
+ .mmpay-detail span { text-align: left; }
243
+ .mmpay-secure-text { color: #757575; border-radius: 9999px; font-size: 0.8rem; font-weight: 600; display: inline-flex; align-items: center; justify-content: center; }
244
+ .mmpay-warning { font-size: 0.75rem; color: #9ca3af; font-weight: 500; margin-top: 12px; line-height: 1.5; }
245
+ </style>
246
+
247
+ <div class="mmpay-card">
248
+ <!-- Close Button - Triggers Confirmation Modal -->
249
+ <button class="mmpay-close-btn" onclick="MMPayCloseModal(false)">
250
+ <svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" fill="currentColor" viewBox="0 0 16 16">
251
+ <path d="M4.646 4.646a.5.5 0 0 1 .708 0L8 7.293l2.646-2.647a.5.5 0 0 1 .708.708L8.707 8l2.647 2.646a.5.5 0 0 1-.708.708L8 8.707l-2.646 2.647a.5.5 0 0 1-.708-.708L7.293 8 4.646 5.354a.5.5 0 0 1 0-.708z"/>
252
+ </svg>
253
+ </button>
254
+
255
+ <div style="padding:0px auto 16px auto">
256
+ <img src="https://upload.wikimedia.org/wikipedia/commons/2/2f/MMQR_Logo.svg" style="width:40px">
257
+ </div>
258
+
259
+ <div class="mmpay-header mmpay-text-myanmar">
260
+ ${merchantName} သို့ပေးချေပါ
261
+ </div>
262
+
263
+ <div class="mmpay-amount">${amountDisplay}</div>
264
+
265
+ <div class="mmpay-qr-container">
266
+ <canvas id="${qrCanvasId}" width="${this.QR_SIZE}" height="${this.QR_SIZE}"></canvas>
267
+ </div>
268
+
269
+ <button class="mmpay-button mmpay-text-myanmar" onclick="MMPayDownloadQR()">
270
+ QR ကုဒ်ကို ဒေါင်းလုဒ်လုပ်ပါ
271
+ </button>
272
+
273
+ <div class="mmpay-separator"></div>
274
+
275
+ <div class="mmpay-detail">
276
+ <span class="mmpay-text-myanmar">မှာယူမှုနံပါတ်:</span> <strong>${apiResponse.orderId}</strong>
277
+ </div>
278
+ <div class="mmpay-detail">
279
+ <span class="mmpay-text-myanmar">ငွေပေးငွေယူနံပါတ်:</span> <strong>${apiResponse.transactionId}</strong>
280
+ </div>
281
+
282
+ <p class="mmpay-warning mmpay-text-myanmar">
283
+ ကျေးဇူးပြု၍ သင့်ဖုန်းဖြင့် ငွေပေးချေမှုကို အပြီးသတ်ပေးပါ။
284
+ </p>
285
+
286
+ <div class="mmpay-secure-text">
287
+ လုံခြုံသော ငွေပေးချေမှု
288
+ </div>
289
+ </div>
290
+ `;
291
+ this._cleanupModal(false);
292
+ this._createAndRenderModal(qrContentHtml, false);
293
+ this._injectQrScript(qrData, qrCanvasId);
294
+ }
295
+ /**
296
+ * _showTerminalMessage
297
+ * @param {string} orderId
298
+ * @param {string} status
299
+ * @param {string} message
300
+ */
301
+ _showTerminalMessage(orderId, status, message) {
302
+ this._cleanupModal(true);
303
+ const successColor = '#10b981'; // Tailwind Green 500
304
+ const failureColor = '#ef4444'; // Tailwind Red 500
305
+ const expiredColor = '#f59e0b'; // Tailwind Amber 500
306
+ let color;
307
+ let iconSvg;
308
+ let statusText;
309
+ if (status === 'SUCCESS') {
310
+ color = successColor;
311
+ statusText = 'အောင်မြင်';
312
+ iconSvg = `<svg xmlns="http://www.w3.org/2000/svg" width="48" height="48" fill="${color}" viewBox="0 0 16 16">
313
+ <path d="M16 8A8 8 0 1 1 0 8a8 8 0 0 1 16 0zm-3.97-3.03a.75.75 0 0 0-1.08.022l-3.473 4.425-2.094-2.094a.75.75 0 0 0-1.06 1.06L6.92 10.865l.764.764a.75.75 0 0 0 1.06 0l4.5-5.5a.75.75 0 0 0-.01-1.05z"/>
314
+ </svg>`;
315
+ }
316
+ else {
317
+ // Shared icon for FAILED and EXPIRED (X mark)
318
+ color = status === 'FAILED' ? failureColor : expiredColor;
319
+ statusText = status === 'FAILED' ? 'မအောင်မြင်' : 'သက်တမ်းကုန်';
320
+ iconSvg = `<svg xmlns="http://www.w3.org/2000/svg" width="48" height="48" fill="${color}" viewBox="0 0 16 16">
321
+ <path d="M16 8A8 8 0 1 1 0 8a8 8 0 0 1 16 0zM5.354 4.146a.5.5 0 1 0-.708.708L7.293 8l-2.647 2.646a.5.5 0 0 0 .708.708L8 8.707l2.646 2.647a.5.5 0 0 0 .708-.708L8.707 8l2.647-2.646a.5.5 0 0 0-.708-.708L8 7.293 5.354 4.146z"/>
322
+ </svg>`;
323
+ }
324
+ const content = `
325
+ <div class="mmpay-card mmpay-terminal-card" style="
326
+ background: white; padding: 25px; box-sizing: border-box;
327
+ ">
328
+ <div style="margin-bottom: 20px;">${iconSvg}</div>
329
+
330
+ <h2 style="font-size: 1.5rem; font-weight: 800; color: ${color}; margin-bottom: 10px;">
331
+ ငွေပေးချေမှု ${statusText}
332
+ </h2>
333
+ <p style="color: #4b5563; font-size: 0.95rem; font-weight: 600;">မှာယူမှုနံပါတ်: ${orderId}</p>
334
+ <p style="color: #6b7280; margin-top: 15px; margin-bottom: 25px; font-size: 0.9rem;">${message}</p>
335
+
336
+ <button class="mmpay-button mmpay-text-myanmar" style="background-color: ${color};" onclick="MMPayCloseModal(true)">
337
+ ပိတ်မည်
338
+ </button>
339
+ </div>
340
+ `;
341
+ this._createAndRenderModal(content, true); // Set isTerminal=true so the close button always forces cleanup
342
+ }
343
+ /**
344
+ * _showCancelConfirmationModal
345
+ */
346
+ _showCancelConfirmationModal() {
347
+ if (this.pollIntervalId !== undefined) {
348
+ window.clearInterval(this.pollIntervalId);
349
+ this.pollIntervalId = undefined;
350
+ }
351
+ this._cleanupModal(false);
352
+ const content = `
353
+ <div class="mmpay-card mmpay-terminal-card" style="
354
+ background: white; padding: 25px; box-sizing: border-box;
355
+ ">
356
+ <h2 style="font-size: 1.25rem; font-weight: 800; color: #f59e0b; margin-bottom: 10px;">
357
+ ငွေပေးချေမှုကို ပယ်ဖျက်မည်လား။
358
+ </h2>
359
+ <p style="color: #6b7280; margin-top: 15px; margin-bottom: 25px; font-size: 0.9rem;">
360
+ သင်သည် QR ဖြင့် ငွေပေးချေခြင်း မပြုရသေးကြောင်း သေချာပါသလား။ ပယ်ဖျက်ပြီးပါက ပြန်လည် စတင်ရပါမည်။
361
+ </p>
362
+
363
+ <div style="display: flex; gap: 10px;">
364
+ <button class="mmpay-button mmpay-text-myanmar"
365
+ style="flex-grow: 1; background-color: #f3f4f6; color: #1f2937; box-shadow: none; margin-top: 0;"
366
+ onclick="MMPayCloseModal(true)">
367
+ ပယ်ဖျက်မည်
368
+ </button>
369
+ </div>
370
+ </div>
371
+ `;
372
+ this._createAndRenderModal(content, false); // Set isTerminal=false so the close button calls MMPayCloseModal(true)
373
+ }
374
+ /**
375
+ * _reRenderPendingModalInstance
376
+ */
377
+ _reRenderPendingModalInstance() {
378
+ if (this.pendingApiResponse && this.pendingPaymentPayload && this.onCompleteCallback) {
379
+ this._cleanupModal(true);
380
+ this.showPaymentModal(this.pendingPaymentPayload, this.onCompleteCallback);
381
+ }
382
+ else {
383
+ this._cleanupModal(true);
384
+ }
385
+ }
386
+ /**
387
+ * Cleans up the modal and stops polling.
388
+ * @param restoreBodyScroll
389
+ */
390
+ _cleanupModal(restoreBodyScroll) {
391
+ if (this.pollIntervalId !== undefined) {
392
+ window.clearInterval(this.pollIntervalId);
393
+ this.pollIntervalId = undefined;
394
+ }
395
+ if (this.overlayElement && this.overlayElement.parentNode) {
396
+ this.overlayElement.parentNode.removeChild(this.overlayElement);
397
+ this.overlayElement = null;
398
+ }
399
+ if (restoreBodyScroll) {
400
+ document.body.style.overflow = '';
401
+ }
402
+ delete window.MMPayCloseModal;
403
+ delete window.MMPayReRenderModal;
404
+ }
405
+ /**
406
+ * _injectQrScript
407
+ * @param {string} qrData
408
+ * @param {string} qrCanvasId
409
+ */
410
+ _injectQrScript(qrData, qrCanvasId) {
411
+ const script = document.createElement('script');
412
+ script.src = "https://cdn.jsdelivr.net/npm/qrious@4.0.2/dist/qrious.min.js";
413
+ script.onload = () => {
414
+ setTimeout(() => {
415
+ const canvas = document.getElementById(qrCanvasId);
416
+ if (typeof QRious !== 'undefined' && canvas) {
417
+ new QRious({
418
+ element: canvas,
419
+ value: qrData,
420
+ size: this.QR_SIZE,
421
+ padding: 15,
422
+ level: 'H'
423
+ });
424
+ }
425
+ else {
426
+ console.error('Failed to load QRious or find canvas.');
427
+ }
428
+ }, 10);
429
+ };
430
+ document.head.appendChild(script);
431
+ }
432
+ /**
433
+ * _startPolling
434
+ * @param {string} _id
435
+ * @param {Function} onComplete
436
+ */
437
+ async _startPolling(_id, onComplete) {
438
+ if (this.pollIntervalId !== undefined) {
439
+ window.clearInterval(this.pollIntervalId);
440
+ }
441
+ const checkStatus = async () => {
442
+ try {
443
+ const endpoint = this.environment === 'sandbox'
444
+ ? '/xpayments/sandbox-payment-polling'
445
+ : '/xpayments/production-payment-polling';
446
+ const response = await this._callApi(endpoint, { _id: _id });
447
+ const status = (response.status || '').toUpperCase();
448
+ if (status === 'SUCCESS' || status === 'FAILED' || status === 'EXPIRED') {
449
+ window.clearInterval(this.pollIntervalId);
450
+ this.pollIntervalId = undefined;
451
+ const success = status === 'SUCCESS';
452
+ const message = success ?
453
+ `ငွေပေးချေမှု အောင်မြင်ပါပြီ။ ငွေပေးငွေယူ ရည်ညွှန်းနံပါတ်: ${response.transactionRefId || 'N/A'}` :
454
+ `ငွေပေးချေမှု ${status === 'FAILED' ? 'မအောင်မြင်ပါ' : 'သက်တမ်းကုန်သွားပါပြီ'}.`;
455
+ this._showTerminalMessage(response.orderId || 'N/A', status, message);
456
+ if (onComplete) {
457
+ onComplete({ success: success, transaction: response });
458
+ }
459
+ return;
460
+ }
461
+ }
462
+ catch (error) {
463
+ console.error("Polling error:", error);
464
+ }
465
+ };
466
+ checkStatus();
467
+ this.pollIntervalId = window.setInterval(checkStatus, this.POLL_INTERVAL_MS);
468
+ }
469
+ }
470
+ // Make the SDK class and its instance methods accessible globally
471
+ window.MMPaySDK = MMPaySDK;
472
+
473
+ exports.MMPaySDK = MMPaySDK;
474
+
475
+ }));
476
+ //# sourceMappingURL=mmpay-sdk.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mmpay-sdk.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
package/package.json ADDED
@@ -0,0 +1,51 @@
1
+ {
2
+ "name": "mmpay-browser-sdk",
3
+ "version": "1.0.3",
4
+ "description": "JavaScript SDK for integrating the MMQR Merchant and Redirect payment gateway",
5
+ "keywords": [
6
+ "MMQR",
7
+ "Master",
8
+ "Visa",
9
+ "JCB",
10
+ "MPU"
11
+ ],
12
+ "main": "./dist/cjs/index.js",
13
+ "module": "./dist/esm/index.js",
14
+ "types": "./dist/esm/index.d.ts",
15
+ "exports": {
16
+ ".": {
17
+ "import": "./dist/esm/index.js",
18
+ "require": "./dist/cjs/index.js",
19
+ "types": "./dist/esm/index.d.ts"
20
+ }
21
+ },
22
+ "repository": {
23
+ "type": "git",
24
+ "url": "git+https://github.com/nawing/Myan-Myan-Pay-SDK.git"
25
+ },
26
+ "bugs": {
27
+ "url": "https://github.com/nawing/Myan-Myan-Pay-SDK/issues"
28
+ },
29
+ "homepage": "https://github.com/nawing/Myan-Myan-Pay-SDK#readme",
30
+ "scripts": {
31
+ "build": "npm run clean && tsc && tsc -p tsconfig.cjs.json && rollup -c",
32
+ "clean": "rm -rf dist",
33
+ "dev": "tsc --watch"
34
+ },
35
+ "devDependencies": {
36
+ "@rollup/plugin-commonjs": "^26.0.1",
37
+ "@rollup/plugin-node-resolve": "^15.2.3",
38
+ "@types/crypto-js": "^4.2.2",
39
+ "@types/node": "^20.10.6",
40
+ "rollup": "^4.18.0",
41
+ "rollup-plugin-typescript2": "^0.36.0",
42
+ "typescript": "^5.9.3"
43
+ },
44
+ "author": "Naw Ing",
45
+ "license": "ISC",
46
+ "dependencies": {
47
+ "axios": "^1.13.2",
48
+ "crypto-js": "^4.2.0",
49
+ "dotenv": "^17.2.2"
50
+ }
51
+ }
@@ -0,0 +1,41 @@
1
+ const resolve = require('@rollup/plugin-node-resolve');
2
+ const commonjs = require('@rollup/plugin-commonjs');
3
+ const typescript = require('rollup-plugin-typescript2');
4
+
5
+ module.exports = {
6
+ input: 'src/index.ts',
7
+
8
+ output: {
9
+ file: 'dist/mmpay-sdk.js',
10
+ format: 'umd',
11
+ name: 'MMPaySDK',
12
+ sourcemap: true,
13
+ exports: 'named',
14
+ },
15
+
16
+ // Plugins handle the heavy lifting:
17
+ plugins: [
18
+ // 1. Compile TypeScript to JavaScript
19
+ typescript({
20
+ tsconfig: 'tsconfig.json',
21
+ useTsconfigDeclarationDir: true,
22
+ tsconfigOverride: {
23
+ compilerOptions: {
24
+ module: "esnext",
25
+ declaration: false,
26
+ declarationMap: false,
27
+ }
28
+ }
29
+ }),
30
+
31
+ // 2. Resolve external dependencies (like axios, crypto-js)
32
+ // from node_modules and include them in the bundle.
33
+ resolve({
34
+ browser: true,
35
+ }),
36
+
37
+ // 3. Convert CommonJS modules (like axios, crypto-js)
38
+ // into ES Modules so Rollup can handle them.
39
+ commonjs(),
40
+ ],
41
+ };