@proximafortedev/payxy 1.0.9
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.
- package/README.md +127 -0
- package/dist/index.d.ts +53 -0
- package/dist/payxy.esm.js +161 -0
- package/dist/payxy.umd.js +169 -0
- package/package.json +43 -0
package/README.md
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
# Payxy Payment Gateway SDK
|
|
2
|
+
|
|
3
|
+
**Payxy** is a lightweight JavaScript SDK that allows merchants and developers to easily integrate the Payxy payment gateway into their web applications via a seamless iframe experience.
|
|
4
|
+
|
|
5
|
+
## โจ Features
|
|
6
|
+
|
|
7
|
+
- Seamless iframe-based payment experience.
|
|
8
|
+
- Secure communication via `postMessage`.
|
|
9
|
+
- Simple setup and integration.
|
|
10
|
+
- Environment-aware with explicit support for development, staging, and production.
|
|
11
|
+
- Custom callbacks for handling transaction results.
|
|
12
|
+
|
|
13
|
+
---
|
|
14
|
+
|
|
15
|
+
## ๐ฆ Installation
|
|
16
|
+
|
|
17
|
+
### Using npm
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
npm install payxy
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
### Using yarn
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
yarn add payxy
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
---
|
|
30
|
+
|
|
31
|
+
## ๐ ๏ธ Usage
|
|
32
|
+
|
|
33
|
+
### 1. Import and Initialize
|
|
34
|
+
|
|
35
|
+
```ts
|
|
36
|
+
import { Payxy } from "payxy";
|
|
37
|
+
|
|
38
|
+
const payxy = new Payxy({
|
|
39
|
+
accessCode: "YOUR_ACCESS_CODE",
|
|
40
|
+
environment: "staging", // "development" | "staging" | "production"
|
|
41
|
+
onSuccess: (data) => {
|
|
42
|
+
console.log(data)
|
|
43
|
+
},
|
|
44
|
+
onError: (data) => {
|
|
45
|
+
console.log(data)
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
### 1b. Optional URL Overrides
|
|
51
|
+
|
|
52
|
+
Use this when your environments do not use the SDK defaults.
|
|
53
|
+
|
|
54
|
+
```ts
|
|
55
|
+
import { Payxy } from "payxy";
|
|
56
|
+
|
|
57
|
+
const payxy = new Payxy({
|
|
58
|
+
accessCode: "YOUR_ACCESS_CODE",
|
|
59
|
+
environment: "staging",
|
|
60
|
+
environmentUrls: {
|
|
61
|
+
development: "http://localhost:5006",
|
|
62
|
+
staging: "https://staging.your-payxy-domain.com",
|
|
63
|
+
production: "https://payxy.your-domain.com"
|
|
64
|
+
},
|
|
65
|
+
onSuccess: (data) => {
|
|
66
|
+
console.log(data)
|
|
67
|
+
},
|
|
68
|
+
onError: (data) => {
|
|
69
|
+
console.log(data)
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
You can also set a single direct URL with `origin` if needed:
|
|
75
|
+
|
|
76
|
+
```ts
|
|
77
|
+
const payxy = new Payxy({
|
|
78
|
+
accessCode: "YOUR_ACCESS_CODE",
|
|
79
|
+
origin: "https://pg-ip6u.onrender.com",
|
|
80
|
+
onSuccess: (data) => {
|
|
81
|
+
console.log(data)
|
|
82
|
+
},
|
|
83
|
+
onError: (data) => {
|
|
84
|
+
console.log(data)
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
Note: `origin` and `environmentUrls` values must be full `http` or `https` URLs. Invalid values throw a runtime error during SDK initialization.
|
|
90
|
+
|
|
91
|
+
### 2. Launch Payment
|
|
92
|
+
|
|
93
|
+
```ts
|
|
94
|
+
payxy.init();
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
---
|
|
98
|
+
|
|
99
|
+
---
|
|
100
|
+
|
|
101
|
+
## ๐งฑ SDK Options
|
|
102
|
+
|
|
103
|
+
| Option | Type | Required | Description |
|
|
104
|
+
|--------------|----------|----------|-------------|
|
|
105
|
+
| `accessCode` | `string` | โ
| Unique access code generated for the transaction |
|
|
106
|
+
| `environment` | `"development" \| "staging" \| "production"` | โ | Runtime target environment. If omitted, localhost resolves to development; all other hostnames resolve to production |
|
|
107
|
+
| `environmentUrls` | `Partial<{ development: string; staging: string; production: string }>` | โ | Override one or more environment URLs |
|
|
108
|
+
| `origin` | `string` | โ | Direct URL override that takes priority over environment/environmentUrls |
|
|
109
|
+
| `onSuccess` | `callback` | โ
| A callback function to get success data |
|
|
110
|
+
| `onError` | `callback` | โ | A callback funtion to get error data |
|
|
111
|
+
| `onClose` | `callback` | โ | A callback function called when payment modal closes |
|
|
112
|
+
|
|
113
|
+
---
|
|
114
|
+
|
|
115
|
+
## ๐งน Cleanup
|
|
116
|
+
|
|
117
|
+
To close the payment modal or remove the iframe manually:
|
|
118
|
+
|
|
119
|
+
```ts
|
|
120
|
+
payxy.close();
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
---
|
|
124
|
+
|
|
125
|
+
## ๐ License
|
|
126
|
+
|
|
127
|
+
MIT
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
interface ValidatePaymentResponse {
|
|
2
|
+
responseCode: string;
|
|
3
|
+
responseMessage: string;
|
|
4
|
+
orderReference: string;
|
|
5
|
+
chargedAmount: string;
|
|
6
|
+
providerReference: string;
|
|
7
|
+
}
|
|
8
|
+
interface MakePaymentResponse {
|
|
9
|
+
responseCode: string;
|
|
10
|
+
responseMessage: string;
|
|
11
|
+
authenticatePaymentResponseCode: string;
|
|
12
|
+
authenticatePaymentResponseMessage: string;
|
|
13
|
+
transactionId: string;
|
|
14
|
+
providerReference: string;
|
|
15
|
+
transactionNumber: string;
|
|
16
|
+
isWebhookUrlSet: boolean;
|
|
17
|
+
accountNumber: string;
|
|
18
|
+
accountName: string;
|
|
19
|
+
bankName: string;
|
|
20
|
+
}
|
|
21
|
+
type PaymentEnvironment = "development" | "staging" | "production";
|
|
22
|
+
interface EnvironmentUrls {
|
|
23
|
+
development: string;
|
|
24
|
+
staging: string;
|
|
25
|
+
production: string;
|
|
26
|
+
}
|
|
27
|
+
interface PaymentOptions {
|
|
28
|
+
accessCode: string;
|
|
29
|
+
onSuccess: (data: MakePaymentResponse | ValidatePaymentResponse) => void;
|
|
30
|
+
onError: (data: MakePaymentResponse | ValidatePaymentResponse) => void;
|
|
31
|
+
onClose?: () => void;
|
|
32
|
+
environment?: PaymentEnvironment;
|
|
33
|
+
environmentUrls?: Partial<EnvironmentUrls>;
|
|
34
|
+
origin?: string;
|
|
35
|
+
}
|
|
36
|
+
declare class Payxy {
|
|
37
|
+
private options;
|
|
38
|
+
private overlay;
|
|
39
|
+
private iframe;
|
|
40
|
+
private origin;
|
|
41
|
+
constructor(options: PaymentOptions);
|
|
42
|
+
private resolveOrigin;
|
|
43
|
+
private normalizeAndValidateEnvironmentUrls;
|
|
44
|
+
private normalizeAndValidateOrigin;
|
|
45
|
+
private normalizeOrigin;
|
|
46
|
+
private injectStyles;
|
|
47
|
+
init(): void;
|
|
48
|
+
private handleMessage;
|
|
49
|
+
close(): void;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export { Payxy };
|
|
53
|
+
export type { EnvironmentUrls, MakePaymentResponse, PaymentEnvironment, PaymentOptions, ValidatePaymentResponse };
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
/******************************************************************************
|
|
2
|
+
Copyright (c) Microsoft Corporation.
|
|
3
|
+
|
|
4
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
5
|
+
purpose with or without fee is hereby granted.
|
|
6
|
+
|
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
8
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
9
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
10
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
11
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
12
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
13
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
14
|
+
***************************************************************************** */
|
|
15
|
+
/* global Reflect, Promise, SuppressedError, Symbol, Iterator */
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
var __assign = function() {
|
|
19
|
+
__assign = Object.assign || function __assign(t) {
|
|
20
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
21
|
+
s = arguments[i];
|
|
22
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
|
23
|
+
}
|
|
24
|
+
return t;
|
|
25
|
+
};
|
|
26
|
+
return __assign.apply(this, arguments);
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
30
|
+
var e = new Error(message);
|
|
31
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
var DEFAULT_ENVIRONMENT_URLS = {
|
|
35
|
+
development: "http://localhost:5006",
|
|
36
|
+
staging: "https://staging.pg-ip6u.onrender.com",
|
|
37
|
+
production: "https://pg-ip6u.onrender.com",
|
|
38
|
+
};
|
|
39
|
+
var Payxy = /** @class */ (function () {
|
|
40
|
+
function Payxy(options) {
|
|
41
|
+
var _this = this;
|
|
42
|
+
this.overlay = null;
|
|
43
|
+
this.iframe = null;
|
|
44
|
+
this.handleMessage = function (event) {
|
|
45
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
46
|
+
if (event.origin !== _this.origin)
|
|
47
|
+
return;
|
|
48
|
+
var _j = event.data, status = _j.status, data = _j.data, action = _j.action;
|
|
49
|
+
if (action === "close-transaction") {
|
|
50
|
+
(_b = (_a = _this.options).onClose) === null || _b === void 0 ? void 0 : _b.call(_a);
|
|
51
|
+
_this.close();
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
if (status === "SUCCESS") {
|
|
55
|
+
(_d = (_c = _this.options).onSuccess) === null || _d === void 0 ? void 0 : _d.call(_c, data);
|
|
56
|
+
_this.close();
|
|
57
|
+
}
|
|
58
|
+
else if (status === "FAILED") {
|
|
59
|
+
(_f = (_e = _this.options).onError) === null || _f === void 0 ? void 0 : _f.call(_e, data);
|
|
60
|
+
_this.close();
|
|
61
|
+
}
|
|
62
|
+
else if (status === "CLOSED") {
|
|
63
|
+
(_h = (_g = _this.options).onClose) === null || _h === void 0 ? void 0 : _h.call(_g);
|
|
64
|
+
_this.close();
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
this.options = options;
|
|
68
|
+
this.origin = this.resolveOrigin();
|
|
69
|
+
this.injectStyles();
|
|
70
|
+
}
|
|
71
|
+
Payxy.prototype.resolveOrigin = function () {
|
|
72
|
+
var _a;
|
|
73
|
+
var mergedEnvironmentUrls = this.normalizeAndValidateEnvironmentUrls(__assign(__assign({}, DEFAULT_ENVIRONMENT_URLS), ((_a = this.options.environmentUrls) !== null && _a !== void 0 ? _a : {})));
|
|
74
|
+
if (this.options.origin) {
|
|
75
|
+
return this.normalizeAndValidateOrigin(this.options.origin, "origin");
|
|
76
|
+
}
|
|
77
|
+
if (this.options.environment) {
|
|
78
|
+
return this.normalizeOrigin(mergedEnvironmentUrls[this.options.environment]);
|
|
79
|
+
}
|
|
80
|
+
var hostname = window.location.hostname;
|
|
81
|
+
var inferredEnvironment = hostname === "localhost" || hostname === "127.0.0.1"
|
|
82
|
+
? "development"
|
|
83
|
+
: "production";
|
|
84
|
+
return this.normalizeOrigin(mergedEnvironmentUrls[inferredEnvironment]);
|
|
85
|
+
};
|
|
86
|
+
Payxy.prototype.normalizeAndValidateEnvironmentUrls = function (urls) {
|
|
87
|
+
return {
|
|
88
|
+
development: this.normalizeAndValidateOrigin(urls.development, "environmentUrls.development"),
|
|
89
|
+
staging: this.normalizeAndValidateOrigin(urls.staging, "environmentUrls.staging"),
|
|
90
|
+
production: this.normalizeAndValidateOrigin(urls.production, "environmentUrls.production"),
|
|
91
|
+
};
|
|
92
|
+
};
|
|
93
|
+
Payxy.prototype.normalizeAndValidateOrigin = function (url, source) {
|
|
94
|
+
var normalized = this.normalizeOrigin(url.trim());
|
|
95
|
+
var parsedUrl;
|
|
96
|
+
try {
|
|
97
|
+
parsedUrl = new URL(normalized);
|
|
98
|
+
}
|
|
99
|
+
catch (_a) {
|
|
100
|
+
throw new Error("Invalid ".concat(source, " URL: \"").concat(url, "\". Expected a full URL such as https://example.com"));
|
|
101
|
+
}
|
|
102
|
+
if (parsedUrl.protocol !== "http:" && parsedUrl.protocol !== "https:") {
|
|
103
|
+
throw new Error("Invalid ".concat(source, " URL protocol: \"").concat(parsedUrl.protocol, "\". Only http and https are supported"));
|
|
104
|
+
}
|
|
105
|
+
return normalized;
|
|
106
|
+
};
|
|
107
|
+
Payxy.prototype.normalizeOrigin = function (url) {
|
|
108
|
+
return url.replace(/\/+$/, "");
|
|
109
|
+
};
|
|
110
|
+
Payxy.prototype.injectStyles = function () {
|
|
111
|
+
var existingStyle = document.getElementById("payxy-style");
|
|
112
|
+
if (existingStyle)
|
|
113
|
+
return;
|
|
114
|
+
var style = document.createElement("style");
|
|
115
|
+
style.id = "payxy-style";
|
|
116
|
+
style.textContent = "\n .payxy-iframe {\n position: fixed;\n top: 0;\n left: 0;\n width: 100%;\n height: 100svh;\n border: none;\n z-index: 999999;\n }\n .payxy-overlay {\n position: fixed;\n top: 0;\n left: 0;\n width: 100%;\n height: 100%;\n background: rgba(0, 0, 0, 0.6);\n z-index: 999999;\n }\n .payxy-close-btn {\n position: absolute;\n top: 20px;\n right: 30px;\n font-size: 30px;\n background: none;\n color: #fff;\n border: none;\n cursor: pointer;\n z-index: 1000000;\n }\n ";
|
|
117
|
+
document.head.appendChild(style);
|
|
118
|
+
};
|
|
119
|
+
Payxy.prototype.init = function () {
|
|
120
|
+
var _this = this;
|
|
121
|
+
if (this.overlay)
|
|
122
|
+
return;
|
|
123
|
+
var overlay = document.createElement("div");
|
|
124
|
+
overlay.className = "payxy-overlay";
|
|
125
|
+
var iframe = document.createElement("iframe");
|
|
126
|
+
iframe.className = "payxy-iframe";
|
|
127
|
+
iframe.src = "".concat(this.origin, "/").concat(this.options.accessCode);
|
|
128
|
+
iframe.setAttribute("frameborder", "0");
|
|
129
|
+
var closeBtn = document.createElement("button");
|
|
130
|
+
closeBtn.className = "payxy-close-btn";
|
|
131
|
+
closeBtn.innerHTML = "ร";
|
|
132
|
+
closeBtn.onclick = function () { return _this.close(); };
|
|
133
|
+
overlay.appendChild(closeBtn);
|
|
134
|
+
overlay.appendChild(iframe);
|
|
135
|
+
document.body.appendChild(overlay);
|
|
136
|
+
this.overlay = overlay;
|
|
137
|
+
this.iframe = iframe;
|
|
138
|
+
window.addEventListener("message", this.handleMessage);
|
|
139
|
+
iframe.onload = function () {
|
|
140
|
+
var _a;
|
|
141
|
+
// Send only serializable data โ no functions
|
|
142
|
+
(_a = iframe.contentWindow) === null || _a === void 0 ? void 0 : _a.postMessage({
|
|
143
|
+
action: "init",
|
|
144
|
+
data: {
|
|
145
|
+
accessCode: _this.options.accessCode,
|
|
146
|
+
},
|
|
147
|
+
}, _this.origin);
|
|
148
|
+
};
|
|
149
|
+
};
|
|
150
|
+
Payxy.prototype.close = function () {
|
|
151
|
+
if (this.overlay) {
|
|
152
|
+
document.body.removeChild(this.overlay);
|
|
153
|
+
this.overlay = null;
|
|
154
|
+
this.iframe = null;
|
|
155
|
+
window.removeEventListener("message", this.handleMessage);
|
|
156
|
+
}
|
|
157
|
+
};
|
|
158
|
+
return Payxy;
|
|
159
|
+
}());
|
|
160
|
+
|
|
161
|
+
export { Payxy };
|
|
@@ -0,0 +1,169 @@
|
|
|
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.Payxy = {}));
|
|
5
|
+
})(this, (function (exports) { 'use strict';
|
|
6
|
+
|
|
7
|
+
/******************************************************************************
|
|
8
|
+
Copyright (c) Microsoft Corporation.
|
|
9
|
+
|
|
10
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
11
|
+
purpose with or without fee is hereby granted.
|
|
12
|
+
|
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
14
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
15
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
16
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
17
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
18
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
19
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
20
|
+
***************************************************************************** */
|
|
21
|
+
/* global Reflect, Promise, SuppressedError, Symbol, Iterator */
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
var __assign = function() {
|
|
25
|
+
__assign = Object.assign || function __assign(t) {
|
|
26
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
27
|
+
s = arguments[i];
|
|
28
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
|
29
|
+
}
|
|
30
|
+
return t;
|
|
31
|
+
};
|
|
32
|
+
return __assign.apply(this, arguments);
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
36
|
+
var e = new Error(message);
|
|
37
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
var DEFAULT_ENVIRONMENT_URLS = {
|
|
41
|
+
development: "http://localhost:5006",
|
|
42
|
+
staging: "https://staging.pg-ip6u.onrender.com",
|
|
43
|
+
production: "https://pg-ip6u.onrender.com",
|
|
44
|
+
};
|
|
45
|
+
var Payxy = /** @class */ (function () {
|
|
46
|
+
function Payxy(options) {
|
|
47
|
+
var _this = this;
|
|
48
|
+
this.overlay = null;
|
|
49
|
+
this.iframe = null;
|
|
50
|
+
this.handleMessage = function (event) {
|
|
51
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
52
|
+
if (event.origin !== _this.origin)
|
|
53
|
+
return;
|
|
54
|
+
var _j = event.data, status = _j.status, data = _j.data, action = _j.action;
|
|
55
|
+
if (action === "close-transaction") {
|
|
56
|
+
(_b = (_a = _this.options).onClose) === null || _b === void 0 ? void 0 : _b.call(_a);
|
|
57
|
+
_this.close();
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
if (status === "SUCCESS") {
|
|
61
|
+
(_d = (_c = _this.options).onSuccess) === null || _d === void 0 ? void 0 : _d.call(_c, data);
|
|
62
|
+
_this.close();
|
|
63
|
+
}
|
|
64
|
+
else if (status === "FAILED") {
|
|
65
|
+
(_f = (_e = _this.options).onError) === null || _f === void 0 ? void 0 : _f.call(_e, data);
|
|
66
|
+
_this.close();
|
|
67
|
+
}
|
|
68
|
+
else if (status === "CLOSED") {
|
|
69
|
+
(_h = (_g = _this.options).onClose) === null || _h === void 0 ? void 0 : _h.call(_g);
|
|
70
|
+
_this.close();
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
this.options = options;
|
|
74
|
+
this.origin = this.resolveOrigin();
|
|
75
|
+
this.injectStyles();
|
|
76
|
+
}
|
|
77
|
+
Payxy.prototype.resolveOrigin = function () {
|
|
78
|
+
var _a;
|
|
79
|
+
var mergedEnvironmentUrls = this.normalizeAndValidateEnvironmentUrls(__assign(__assign({}, DEFAULT_ENVIRONMENT_URLS), ((_a = this.options.environmentUrls) !== null && _a !== void 0 ? _a : {})));
|
|
80
|
+
if (this.options.origin) {
|
|
81
|
+
return this.normalizeAndValidateOrigin(this.options.origin, "origin");
|
|
82
|
+
}
|
|
83
|
+
if (this.options.environment) {
|
|
84
|
+
return this.normalizeOrigin(mergedEnvironmentUrls[this.options.environment]);
|
|
85
|
+
}
|
|
86
|
+
var hostname = window.location.hostname;
|
|
87
|
+
var inferredEnvironment = hostname === "localhost" || hostname === "127.0.0.1"
|
|
88
|
+
? "development"
|
|
89
|
+
: "production";
|
|
90
|
+
return this.normalizeOrigin(mergedEnvironmentUrls[inferredEnvironment]);
|
|
91
|
+
};
|
|
92
|
+
Payxy.prototype.normalizeAndValidateEnvironmentUrls = function (urls) {
|
|
93
|
+
return {
|
|
94
|
+
development: this.normalizeAndValidateOrigin(urls.development, "environmentUrls.development"),
|
|
95
|
+
staging: this.normalizeAndValidateOrigin(urls.staging, "environmentUrls.staging"),
|
|
96
|
+
production: this.normalizeAndValidateOrigin(urls.production, "environmentUrls.production"),
|
|
97
|
+
};
|
|
98
|
+
};
|
|
99
|
+
Payxy.prototype.normalizeAndValidateOrigin = function (url, source) {
|
|
100
|
+
var normalized = this.normalizeOrigin(url.trim());
|
|
101
|
+
var parsedUrl;
|
|
102
|
+
try {
|
|
103
|
+
parsedUrl = new URL(normalized);
|
|
104
|
+
}
|
|
105
|
+
catch (_a) {
|
|
106
|
+
throw new Error("Invalid ".concat(source, " URL: \"").concat(url, "\". Expected a full URL such as https://example.com"));
|
|
107
|
+
}
|
|
108
|
+
if (parsedUrl.protocol !== "http:" && parsedUrl.protocol !== "https:") {
|
|
109
|
+
throw new Error("Invalid ".concat(source, " URL protocol: \"").concat(parsedUrl.protocol, "\". Only http and https are supported"));
|
|
110
|
+
}
|
|
111
|
+
return normalized;
|
|
112
|
+
};
|
|
113
|
+
Payxy.prototype.normalizeOrigin = function (url) {
|
|
114
|
+
return url.replace(/\/+$/, "");
|
|
115
|
+
};
|
|
116
|
+
Payxy.prototype.injectStyles = function () {
|
|
117
|
+
var existingStyle = document.getElementById("payxy-style");
|
|
118
|
+
if (existingStyle)
|
|
119
|
+
return;
|
|
120
|
+
var style = document.createElement("style");
|
|
121
|
+
style.id = "payxy-style";
|
|
122
|
+
style.textContent = "\n .payxy-iframe {\n position: fixed;\n top: 0;\n left: 0;\n width: 100%;\n height: 100svh;\n border: none;\n z-index: 999999;\n }\n .payxy-overlay {\n position: fixed;\n top: 0;\n left: 0;\n width: 100%;\n height: 100%;\n background: rgba(0, 0, 0, 0.6);\n z-index: 999999;\n }\n .payxy-close-btn {\n position: absolute;\n top: 20px;\n right: 30px;\n font-size: 30px;\n background: none;\n color: #fff;\n border: none;\n cursor: pointer;\n z-index: 1000000;\n }\n ";
|
|
123
|
+
document.head.appendChild(style);
|
|
124
|
+
};
|
|
125
|
+
Payxy.prototype.init = function () {
|
|
126
|
+
var _this = this;
|
|
127
|
+
if (this.overlay)
|
|
128
|
+
return;
|
|
129
|
+
var overlay = document.createElement("div");
|
|
130
|
+
overlay.className = "payxy-overlay";
|
|
131
|
+
var iframe = document.createElement("iframe");
|
|
132
|
+
iframe.className = "payxy-iframe";
|
|
133
|
+
iframe.src = "".concat(this.origin, "/").concat(this.options.accessCode);
|
|
134
|
+
iframe.setAttribute("frameborder", "0");
|
|
135
|
+
var closeBtn = document.createElement("button");
|
|
136
|
+
closeBtn.className = "payxy-close-btn";
|
|
137
|
+
closeBtn.innerHTML = "ร";
|
|
138
|
+
closeBtn.onclick = function () { return _this.close(); };
|
|
139
|
+
overlay.appendChild(closeBtn);
|
|
140
|
+
overlay.appendChild(iframe);
|
|
141
|
+
document.body.appendChild(overlay);
|
|
142
|
+
this.overlay = overlay;
|
|
143
|
+
this.iframe = iframe;
|
|
144
|
+
window.addEventListener("message", this.handleMessage);
|
|
145
|
+
iframe.onload = function () {
|
|
146
|
+
var _a;
|
|
147
|
+
// Send only serializable data โ no functions
|
|
148
|
+
(_a = iframe.contentWindow) === null || _a === void 0 ? void 0 : _a.postMessage({
|
|
149
|
+
action: "init",
|
|
150
|
+
data: {
|
|
151
|
+
accessCode: _this.options.accessCode,
|
|
152
|
+
},
|
|
153
|
+
}, _this.origin);
|
|
154
|
+
};
|
|
155
|
+
};
|
|
156
|
+
Payxy.prototype.close = function () {
|
|
157
|
+
if (this.overlay) {
|
|
158
|
+
document.body.removeChild(this.overlay);
|
|
159
|
+
this.overlay = null;
|
|
160
|
+
this.iframe = null;
|
|
161
|
+
window.removeEventListener("message", this.handleMessage);
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
return Payxy;
|
|
165
|
+
}());
|
|
166
|
+
|
|
167
|
+
exports.Payxy = Payxy;
|
|
168
|
+
|
|
169
|
+
}));
|
package/package.json
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@proximafortedev/payxy",
|
|
3
|
+
"version": "1.0.9",
|
|
4
|
+
"description": "Payxy payment gateway SDK",
|
|
5
|
+
"main": "dist/payxy.umd.js",
|
|
6
|
+
"module": "dist/payxy.esm.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"import": "./dist/payxy.esm.js",
|
|
11
|
+
"require": "./dist/payxy.umd.js",
|
|
12
|
+
"types": "./dist/index.d.ts"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist"
|
|
17
|
+
],
|
|
18
|
+
"keywords": [
|
|
19
|
+
"payment",
|
|
20
|
+
"gateway",
|
|
21
|
+
"sdk",
|
|
22
|
+
"payxy"
|
|
23
|
+
],
|
|
24
|
+
"scripts": {
|
|
25
|
+
"build": "rimraf dist && rollup -c",
|
|
26
|
+
"start": "serve dist"
|
|
27
|
+
},
|
|
28
|
+
"author": "",
|
|
29
|
+
"license": "ISC",
|
|
30
|
+
"type": "commonjs",
|
|
31
|
+
"devDependencies": {
|
|
32
|
+
"@rollup/plugin-commonjs": "^28.0.6",
|
|
33
|
+
"@rollup/plugin-node-resolve": "^16.0.1",
|
|
34
|
+
"@rollup/plugin-typescript": "^12.1.4",
|
|
35
|
+
"rimraf": "^6.0.1",
|
|
36
|
+
"rollup": "^4.45.1",
|
|
37
|
+
"tslib": "^2.8.1",
|
|
38
|
+
"typescript": "^5.8.3"
|
|
39
|
+
},
|
|
40
|
+
"dependencies": {
|
|
41
|
+
"rollup-plugin-dts": "^6.2.1"
|
|
42
|
+
}
|
|
43
|
+
}
|