@pkpayplus/core 1.0.0 → 1.0.1
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 +31 -32
- package/dist/index.cjs +1362 -58
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +77 -1
- package/dist/index.d.ts +77 -1
- package/dist/index.js +1354 -58
- package/dist/index.js.map +1 -1
- package/package.json +20 -1
package/dist/index.cjs
CHANGED
|
@@ -20,6 +20,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/index.ts
|
|
21
21
|
var index_exports = {};
|
|
22
22
|
__export(index_exports, {
|
|
23
|
+
COUNTRIES: () => COUNTRIES,
|
|
23
24
|
HTTPClient: () => HTTPClient,
|
|
24
25
|
PKPayPlusAPIConnectionError: () => PKPayPlusAPIConnectionError,
|
|
25
26
|
PKPayPlusAuthenticationError: () => PKPayPlusAuthenticationError,
|
|
@@ -27,12 +28,19 @@ __export(index_exports, {
|
|
|
27
28
|
PKPayPlusInvalidRequestError: () => PKPayPlusInvalidRequestError,
|
|
28
29
|
PKPayPlusRateLimitError: () => PKPayPlusRateLimitError,
|
|
29
30
|
PKPayPlusSecurityError: () => PKPayPlusSecurityError,
|
|
31
|
+
THEME_STYLE_ID: () => THEME_STYLE_ID,
|
|
30
32
|
Webhooks: () => Webhooks,
|
|
31
33
|
assertClientKey: () => assertClientKey,
|
|
32
34
|
assertServerEnvironment: () => assertServerEnvironment,
|
|
33
35
|
assertServerKey: () => assertServerKey,
|
|
34
36
|
createCheckoutDialog: () => createCheckoutDialog,
|
|
37
|
+
createCountryCombobox: () => createCountryCombobox,
|
|
38
|
+
createCustomerForm: () => createCustomerForm,
|
|
39
|
+
createFormMessage: () => createFormMessage,
|
|
40
|
+
createInput: () => createInput,
|
|
41
|
+
createLabel: () => createLabel,
|
|
35
42
|
detectModeFromKey: () => detectModeFromKey,
|
|
43
|
+
injectThemeStyles: () => injectThemeStyles,
|
|
36
44
|
normalizeUrl: () => normalizeUrl,
|
|
37
45
|
setupPostMessageListener: () => setupPostMessageListener
|
|
38
46
|
});
|
|
@@ -59,14 +67,16 @@ function setupPostMessageListener(handlers) {
|
|
|
59
67
|
switch (eventType) {
|
|
60
68
|
case "pkpayplus:loaded":
|
|
61
69
|
case "pkpay:loaded":
|
|
70
|
+
case "pkplusPaymentIsReady":
|
|
62
71
|
handlers.onLoaded?.();
|
|
63
72
|
break;
|
|
64
73
|
case "pkpayplus:completed":
|
|
65
74
|
case "pkpayplus:success":
|
|
66
75
|
case "pkpay:completed":
|
|
67
76
|
case "payment.succeeded":
|
|
77
|
+
case "paymentSuccess":
|
|
68
78
|
handlers.onSuccess?.({
|
|
69
|
-
sessionId: payload.sessionId || payload.session_id || payload.data?.sessionId || "",
|
|
79
|
+
sessionId: payload.sessionId || payload.session_id || payload.data?.sessionId || payload.data?.session_id || "",
|
|
70
80
|
...payload.data || {}
|
|
71
81
|
});
|
|
72
82
|
break;
|
|
@@ -77,6 +87,7 @@ function setupPostMessageListener(handlers) {
|
|
|
77
87
|
break;
|
|
78
88
|
case "pkpayplus:error":
|
|
79
89
|
case "pkpay:error":
|
|
90
|
+
case "paymentError":
|
|
80
91
|
handlers.onError?.({
|
|
81
92
|
message: payload.message || payload.error?.message || "Payment failed",
|
|
82
93
|
code: payload.code || payload.error?.code,
|
|
@@ -93,134 +104,1405 @@ function setupPostMessageListener(handlers) {
|
|
|
93
104
|
};
|
|
94
105
|
}
|
|
95
106
|
|
|
96
|
-
// src/
|
|
97
|
-
var
|
|
98
|
-
|
|
99
|
-
|
|
107
|
+
// src/ui/countries.ts
|
|
108
|
+
var COUNTRIES = [
|
|
109
|
+
{ code: "US", name: "United States", flag: "\u{1F1FA}\u{1F1F8}" },
|
|
110
|
+
{ code: "PK", name: "Pakistan", flag: "\u{1F1F5}\u{1F1F0}" },
|
|
111
|
+
{ code: "GB", name: "United Kingdom", flag: "\u{1F1EC}\u{1F1E7}" },
|
|
112
|
+
{ code: "CA", name: "Canada", flag: "\u{1F1E8}\u{1F1E6}" },
|
|
113
|
+
{ code: "AU", name: "Australia", flag: "\u{1F1E6}\u{1F1FA}" },
|
|
114
|
+
{ code: "BD", name: "Bangladesh", flag: "\u{1F1E7}\u{1F1E9}" },
|
|
115
|
+
{ code: "AE", name: "United Arab Emirates", flag: "\u{1F1E6}\u{1F1EA}" },
|
|
116
|
+
{ code: "SA", name: "Saudi Arabia", flag: "\u{1F1F8}\u{1F1E6}" },
|
|
117
|
+
{ code: "DE", name: "Germany", flag: "\u{1F1E9}\u{1F1EA}" },
|
|
118
|
+
{ code: "FR", name: "France", flag: "\u{1F1EB}\u{1F1F7}" },
|
|
119
|
+
{ code: "IT", name: "Italy", flag: "\u{1F1EE}\u{1F1F9}" },
|
|
120
|
+
{ code: "ES", name: "Spain", flag: "\u{1F1EA}\u{1F1F8}" },
|
|
121
|
+
{ code: "NL", name: "Netherlands", flag: "\u{1F1F3}\u{1F1F1}" },
|
|
122
|
+
{ code: "SE", name: "Sweden", flag: "\u{1F1F8}\u{1F1EA}" },
|
|
123
|
+
{ code: "CH", name: "Switzerland", flag: "\u{1F1E8}\u{1F1ED}" },
|
|
124
|
+
{ code: "SG", name: "Singapore", flag: "\u{1F1F8}\u{1F1EC}" },
|
|
125
|
+
{ code: "MY", name: "Malaysia", flag: "\u{1F1F2}\u{1F1FE}" },
|
|
126
|
+
{ code: "IN", name: "India", flag: "\u{1F1EE}\u{1F1F3}" },
|
|
127
|
+
{ code: "IE", name: "Ireland", flag: "\u{1F1EE}\u{1F1EA}" },
|
|
128
|
+
{ code: "NZ", name: "New Zealand", flag: "\u{1F1F3}\u{1F1FF}" },
|
|
129
|
+
{ code: "JP", name: "Japan", flag: "\u{1F1EF}\u{1F1F5}" },
|
|
130
|
+
{ code: "KR", name: "South Korea", flag: "\u{1F1F0}\u{1F1F7}" },
|
|
131
|
+
{ code: "BR", name: "Brazil", flag: "\u{1F1E7}\u{1F1F7}" },
|
|
132
|
+
{ code: "MX", name: "Mexico", flag: "\u{1F1F2}\u{1F1FD}" },
|
|
133
|
+
{ code: "ZA", name: "South Africa", flag: "\u{1F1FF}\u{1F1E6}" },
|
|
134
|
+
{ code: "TR", name: "Turkey", flag: "\u{1F1F9}\u{1F1F7}" },
|
|
135
|
+
{ code: "EG", name: "Egypt", flag: "\u{1F1EA}\u{1F1EC}" },
|
|
136
|
+
{ code: "QA", name: "Qatar", flag: "\u{1F1F6}\u{1F1E6}" },
|
|
137
|
+
{ code: "KW", name: "Kuwait", flag: "\u{1F1F0}\u{1F1FC}" },
|
|
138
|
+
{ code: "OM", name: "Oman", flag: "\u{1F1F4}\u{1F1F2}" },
|
|
139
|
+
{ code: "BH", name: "Bahrain", flag: "\u{1F1E7}\u{1F1ED}" },
|
|
140
|
+
{ code: "NG", name: "Nigeria", flag: "\u{1F1F3}\u{1F1EC}" },
|
|
141
|
+
{ code: "KE", name: "Kenya", flag: "\u{1F1F0}\u{1F1EA}" },
|
|
142
|
+
{ code: "GH", name: "Ghana", flag: "\u{1F1EC}\u{1F1ED}" },
|
|
143
|
+
{ code: "PH", name: "Philippines", flag: "\u{1F1F5}\u{1F1ED}" },
|
|
144
|
+
{ code: "TH", name: "Thailand", flag: "\u{1F1F9}\u{1F1ED}" },
|
|
145
|
+
{ code: "VN", name: "Vietnam", flag: "\u{1F1FB}\u{1F1F3}" },
|
|
146
|
+
{ code: "ID", name: "Indonesia", flag: "\u{1F1EE}\u{1F1E9}" },
|
|
147
|
+
{ code: "NO", name: "Norway", flag: "\u{1F1F3}\u{1F1F4}" },
|
|
148
|
+
{ code: "DK", name: "Denmark", flag: "\u{1F1E9}\u{1F1F0}" },
|
|
149
|
+
{ code: "FI", name: "Finland", flag: "\u{1F1EB}\u{1F1EE}" },
|
|
150
|
+
{ code: "PL", name: "Poland", flag: "\u{1F1F5}\u{1F1F1}" },
|
|
151
|
+
{ code: "AT", name: "Austria", flag: "\u{1F1E6}\u{1F1F9}" },
|
|
152
|
+
{ code: "BE", name: "Belgium", flag: "\u{1F1E7}\u{1F1EA}" },
|
|
153
|
+
{ code: "PT", name: "Portugal", flag: "\u{1F1F5}\u{1F1F9}" },
|
|
154
|
+
{ code: "GR", name: "Greece", flag: "\u{1F1EC}\u{1F1F7}" },
|
|
155
|
+
{ code: "CZ", name: "Czech Republic", flag: "\u{1F1E8}\u{1F1FF}" },
|
|
156
|
+
{ code: "RO", name: "Romania", flag: "\u{1F1F7}\u{1F1F4}" },
|
|
157
|
+
{ code: "HU", name: "Hungary", flag: "\u{1F1ED}\u{1F1FA}" },
|
|
158
|
+
{ code: "CL", name: "Chile", flag: "\u{1F1E8}\u{1F1F1}" },
|
|
159
|
+
{ code: "CO", name: "Colombia", flag: "\u{1F1E8}\u{1F1F4}" },
|
|
160
|
+
{ code: "AR", name: "Argentina", flag: "\u{1F1E6}\u{1F1F7}" }
|
|
161
|
+
];
|
|
162
|
+
|
|
163
|
+
// src/ui/label.ts
|
|
164
|
+
function createLabel(options) {
|
|
165
|
+
const label = document.createElement("label");
|
|
166
|
+
label.className = "pkpay-label";
|
|
167
|
+
if (options.htmlFor) {
|
|
168
|
+
label.htmlFor = options.htmlFor;
|
|
169
|
+
}
|
|
170
|
+
label.textContent = options.text;
|
|
171
|
+
if (options.required) {
|
|
172
|
+
const asterisk = document.createElement("span");
|
|
173
|
+
asterisk.className = "pkpay-label-required";
|
|
174
|
+
asterisk.textContent = " *";
|
|
175
|
+
label.appendChild(asterisk);
|
|
176
|
+
}
|
|
177
|
+
return label;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
// src/ui/combobox.ts
|
|
181
|
+
function createCountryCombobox(options) {
|
|
182
|
+
const container = document.createElement("div");
|
|
183
|
+
container.className = "pkpay-form-group";
|
|
184
|
+
const label = createLabel({
|
|
185
|
+
text: options.label,
|
|
186
|
+
htmlFor: options.id,
|
|
187
|
+
required: options.required
|
|
188
|
+
});
|
|
189
|
+
const wrapper = document.createElement("div");
|
|
190
|
+
wrapper.className = "pkpay-combobox-wrapper";
|
|
191
|
+
const countryList = options.countries || COUNTRIES;
|
|
192
|
+
let selected = countryList.find(
|
|
193
|
+
(c) => c.code.toLowerCase() === (options.defaultValue || "US").toLowerCase()
|
|
194
|
+
) || countryList[0];
|
|
195
|
+
const trigger = document.createElement("button");
|
|
196
|
+
trigger.type = "button";
|
|
197
|
+
trigger.id = options.id;
|
|
198
|
+
trigger.className = "pkpay-combobox-trigger";
|
|
199
|
+
trigger.setAttribute("aria-haspopup", "listbox");
|
|
200
|
+
trigger.setAttribute("aria-expanded", "false");
|
|
201
|
+
const triggerValue = document.createElement("span");
|
|
202
|
+
triggerValue.className = "pkpay-combobox-value";
|
|
203
|
+
triggerValue.innerHTML = `<span>${selected.flag}</span> <span>${selected.name} (${selected.code})</span>`;
|
|
204
|
+
const triggerIcon = document.createElement("span");
|
|
205
|
+
triggerIcon.className = "pkpay-combobox-icon";
|
|
206
|
+
triggerIcon.innerHTML = `
|
|
207
|
+
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
|
208
|
+
<polyline points="6 9 12 15 18 9"></polyline>
|
|
209
|
+
</svg>
|
|
210
|
+
`;
|
|
211
|
+
trigger.appendChild(triggerValue);
|
|
212
|
+
trigger.appendChild(triggerIcon);
|
|
213
|
+
const popover = document.createElement("div");
|
|
214
|
+
popover.className = "pkpay-combobox-popover";
|
|
215
|
+
const searchBox = document.createElement("div");
|
|
216
|
+
searchBox.className = "pkpay-combobox-search-box";
|
|
217
|
+
searchBox.innerHTML = `
|
|
218
|
+
<svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="#94a3b8" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
|
219
|
+
<circle cx="11" cy="11" r="8"></circle>
|
|
220
|
+
<line x1="21" y1="21" x2="16.65" y2="16.65"></line>
|
|
221
|
+
</svg>
|
|
222
|
+
`;
|
|
223
|
+
const searchInput = document.createElement("input");
|
|
224
|
+
searchInput.className = "pkpay-combobox-search-input";
|
|
225
|
+
searchInput.placeholder = "Search country...";
|
|
226
|
+
searchBox.appendChild(searchInput);
|
|
227
|
+
const list = document.createElement("ul");
|
|
228
|
+
list.className = "pkpay-combobox-list";
|
|
229
|
+
list.setAttribute("role", "listbox");
|
|
230
|
+
let filteredCountries = [...countryList];
|
|
231
|
+
let highlightedIndex = 0;
|
|
232
|
+
let isOpen = false;
|
|
233
|
+
const renderItems = () => {
|
|
234
|
+
list.innerHTML = "";
|
|
235
|
+
if (filteredCountries.length === 0) {
|
|
236
|
+
const empty = document.createElement("li");
|
|
237
|
+
empty.className = "pkpay-combobox-empty";
|
|
238
|
+
empty.textContent = "No country found.";
|
|
239
|
+
list.appendChild(empty);
|
|
240
|
+
return;
|
|
241
|
+
}
|
|
242
|
+
filteredCountries.forEach((c, index) => {
|
|
243
|
+
const item = document.createElement("li");
|
|
244
|
+
item.className = "pkpay-combobox-item";
|
|
245
|
+
item.setAttribute("role", "option");
|
|
246
|
+
if (c.code === selected.code) {
|
|
247
|
+
item.classList.add("pkpay-selected");
|
|
248
|
+
item.setAttribute("aria-selected", "true");
|
|
249
|
+
}
|
|
250
|
+
if (index === highlightedIndex) {
|
|
251
|
+
item.classList.add("pkpay-highlighted");
|
|
252
|
+
}
|
|
253
|
+
item.innerHTML = `
|
|
254
|
+
<span style="display: flex; align-items: center; gap: 8px;">
|
|
255
|
+
<span>${c.flag}</span>
|
|
256
|
+
<span>${c.name}</span>
|
|
257
|
+
</span>
|
|
258
|
+
<span style="color: #94a3b8; font-size: 11px;">${c.code}</span>
|
|
259
|
+
`;
|
|
260
|
+
item.addEventListener("click", (e) => {
|
|
261
|
+
e.stopPropagation();
|
|
262
|
+
selectCountry(c);
|
|
263
|
+
});
|
|
264
|
+
item.addEventListener("mouseenter", () => {
|
|
265
|
+
highlightedIndex = index;
|
|
266
|
+
updateHighlight();
|
|
267
|
+
});
|
|
268
|
+
list.appendChild(item);
|
|
269
|
+
});
|
|
270
|
+
};
|
|
271
|
+
const updateHighlight = () => {
|
|
272
|
+
const items = list.querySelectorAll(".pkpay-combobox-item");
|
|
273
|
+
items.forEach((item, idx) => {
|
|
274
|
+
if (idx === highlightedIndex) {
|
|
275
|
+
item.classList.add("pkpay-highlighted");
|
|
276
|
+
item.scrollIntoView({ block: "nearest" });
|
|
277
|
+
} else {
|
|
278
|
+
item.classList.remove("pkpay-highlighted");
|
|
279
|
+
}
|
|
280
|
+
});
|
|
281
|
+
};
|
|
282
|
+
const selectCountry = (c) => {
|
|
283
|
+
selected = c;
|
|
284
|
+
triggerValue.innerHTML = `<span>${selected.flag}</span> <span>${selected.name} (${selected.code})</span>`;
|
|
285
|
+
closePopover();
|
|
286
|
+
options.onChange?.(c);
|
|
287
|
+
trigger.focus();
|
|
288
|
+
};
|
|
289
|
+
const openPopover = () => {
|
|
290
|
+
isOpen = true;
|
|
291
|
+
popover.classList.add("pkpay-open");
|
|
292
|
+
trigger.classList.add("pkpay-active");
|
|
293
|
+
trigger.setAttribute("aria-expanded", "true");
|
|
294
|
+
searchInput.value = "";
|
|
295
|
+
filteredCountries = [...countryList];
|
|
296
|
+
highlightedIndex = Math.max(
|
|
297
|
+
0,
|
|
298
|
+
filteredCountries.findIndex((c) => c.code === selected.code)
|
|
299
|
+
);
|
|
300
|
+
renderItems();
|
|
301
|
+
updateHighlight();
|
|
302
|
+
setTimeout(() => searchInput.focus(), 50);
|
|
303
|
+
};
|
|
304
|
+
const closePopover = () => {
|
|
305
|
+
if (!isOpen) return;
|
|
306
|
+
isOpen = false;
|
|
307
|
+
popover.classList.remove("pkpay-open");
|
|
308
|
+
trigger.classList.remove("pkpay-active");
|
|
309
|
+
trigger.setAttribute("aria-expanded", "false");
|
|
310
|
+
};
|
|
311
|
+
trigger.addEventListener("click", (e) => {
|
|
312
|
+
e.stopPropagation();
|
|
313
|
+
if (isOpen) {
|
|
314
|
+
closePopover();
|
|
315
|
+
} else {
|
|
316
|
+
openPopover();
|
|
317
|
+
}
|
|
318
|
+
});
|
|
319
|
+
searchInput.addEventListener("input", () => {
|
|
320
|
+
const q = searchInput.value.toLowerCase().trim();
|
|
321
|
+
filteredCountries = countryList.filter(
|
|
322
|
+
(c) => c.name.toLowerCase().includes(q) || c.code.toLowerCase().includes(q)
|
|
323
|
+
);
|
|
324
|
+
highlightedIndex = 0;
|
|
325
|
+
renderItems();
|
|
326
|
+
});
|
|
327
|
+
searchInput.addEventListener("keydown", (e) => {
|
|
328
|
+
if (e.key === "ArrowDown") {
|
|
329
|
+
e.preventDefault();
|
|
330
|
+
if (highlightedIndex < filteredCountries.length - 1) {
|
|
331
|
+
highlightedIndex++;
|
|
332
|
+
updateHighlight();
|
|
333
|
+
}
|
|
334
|
+
} else if (e.key === "ArrowUp") {
|
|
335
|
+
e.preventDefault();
|
|
336
|
+
if (highlightedIndex > 0) {
|
|
337
|
+
highlightedIndex--;
|
|
338
|
+
updateHighlight();
|
|
339
|
+
}
|
|
340
|
+
} else if (e.key === "Enter") {
|
|
341
|
+
e.preventDefault();
|
|
342
|
+
if (filteredCountries[highlightedIndex]) {
|
|
343
|
+
selectCountry(filteredCountries[highlightedIndex]);
|
|
344
|
+
}
|
|
345
|
+
} else if (e.key === "Escape") {
|
|
346
|
+
e.preventDefault();
|
|
347
|
+
closePopover();
|
|
348
|
+
trigger.focus();
|
|
349
|
+
}
|
|
350
|
+
});
|
|
351
|
+
document.addEventListener("click", (e) => {
|
|
352
|
+
if (isOpen && !wrapper.contains(e.target)) {
|
|
353
|
+
closePopover();
|
|
354
|
+
}
|
|
355
|
+
});
|
|
356
|
+
popover.appendChild(searchBox);
|
|
357
|
+
popover.appendChild(list);
|
|
358
|
+
wrapper.appendChild(trigger);
|
|
359
|
+
wrapper.appendChild(popover);
|
|
360
|
+
container.appendChild(label);
|
|
361
|
+
container.appendChild(wrapper);
|
|
362
|
+
return {
|
|
363
|
+
container,
|
|
364
|
+
getValue: () => selected.code,
|
|
365
|
+
setValue: (code) => {
|
|
366
|
+
const match = countryList.find(
|
|
367
|
+
(c) => c.code.toLowerCase() === code.toLowerCase()
|
|
368
|
+
);
|
|
369
|
+
if (match) {
|
|
370
|
+
selectCountry(match);
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
};
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
// src/ui/form-message.ts
|
|
377
|
+
function createFormMessage() {
|
|
378
|
+
const element = document.createElement("div");
|
|
379
|
+
element.className = "pkpay-form-message";
|
|
380
|
+
element.setAttribute("role", "alert");
|
|
381
|
+
return {
|
|
382
|
+
element,
|
|
383
|
+
show: (message) => {
|
|
384
|
+
element.textContent = message;
|
|
385
|
+
element.classList.add("pkpay-visible");
|
|
386
|
+
},
|
|
387
|
+
hide: () => {
|
|
388
|
+
element.textContent = "";
|
|
389
|
+
element.classList.remove("pkpay-visible");
|
|
390
|
+
}
|
|
391
|
+
};
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
// src/ui/input.ts
|
|
395
|
+
function createInput(options) {
|
|
396
|
+
const container = document.createElement("div");
|
|
397
|
+
container.className = "pkpay-form-group";
|
|
398
|
+
const label = createLabel({
|
|
399
|
+
text: options.label,
|
|
400
|
+
htmlFor: options.id,
|
|
401
|
+
required: options.required
|
|
402
|
+
});
|
|
403
|
+
const input = document.createElement("input");
|
|
404
|
+
input.id = options.id;
|
|
405
|
+
input.name = options.name;
|
|
406
|
+
input.type = options.type || "text";
|
|
407
|
+
input.className = "pkpay-input";
|
|
408
|
+
if (options.placeholder) input.placeholder = options.placeholder;
|
|
409
|
+
if (options.value) input.value = options.value;
|
|
410
|
+
if (options.required) input.required = true;
|
|
411
|
+
const message = createFormMessage();
|
|
412
|
+
const validateInput = () => {
|
|
413
|
+
const val = input.value.trim();
|
|
414
|
+
if (options.required && !val) {
|
|
415
|
+
input.classList.add("pkpay-input-error");
|
|
416
|
+
message.show(`${options.label} is required`);
|
|
417
|
+
return false;
|
|
418
|
+
}
|
|
419
|
+
if (options.validate) {
|
|
420
|
+
const error = options.validate(val);
|
|
421
|
+
if (error) {
|
|
422
|
+
input.classList.add("pkpay-input-error");
|
|
423
|
+
message.show(error);
|
|
424
|
+
return false;
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
input.classList.remove("pkpay-input-error");
|
|
428
|
+
message.hide();
|
|
429
|
+
return true;
|
|
430
|
+
};
|
|
431
|
+
input.addEventListener("input", () => {
|
|
432
|
+
if (input.classList.contains("pkpay-input-error")) {
|
|
433
|
+
validateInput();
|
|
434
|
+
}
|
|
435
|
+
options.onInput?.(input.value);
|
|
436
|
+
});
|
|
437
|
+
input.addEventListener("blur", () => {
|
|
438
|
+
validateInput();
|
|
439
|
+
});
|
|
440
|
+
container.appendChild(label);
|
|
441
|
+
container.appendChild(input);
|
|
442
|
+
container.appendChild(message.element);
|
|
443
|
+
return {
|
|
444
|
+
container,
|
|
445
|
+
input,
|
|
446
|
+
message,
|
|
447
|
+
getValue: () => input.value.trim(),
|
|
448
|
+
setValue: (val) => {
|
|
449
|
+
input.value = val;
|
|
450
|
+
options.onInput?.(val);
|
|
451
|
+
},
|
|
452
|
+
validate: validateInput,
|
|
453
|
+
setError: (msg) => {
|
|
454
|
+
if (msg) {
|
|
455
|
+
input.classList.add("pkpay-input-error");
|
|
456
|
+
message.show(msg);
|
|
457
|
+
} else {
|
|
458
|
+
input.classList.remove("pkpay-input-error");
|
|
459
|
+
message.hide();
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
};
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
// src/ui/customer-form.ts
|
|
466
|
+
function createCustomerForm(options = {}) {
|
|
467
|
+
const container = document.createElement("div");
|
|
468
|
+
container.className = "pkpay-customer-pane";
|
|
469
|
+
const header = document.createElement("div");
|
|
470
|
+
header.className = "pkpay-pane-header";
|
|
471
|
+
header.innerHTML = `
|
|
472
|
+
<h3 class="pkpay-pane-title">
|
|
473
|
+
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="#2563eb" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
|
474
|
+
<path d="M20 21v-2a4 4 0 0 0-4-4H8a4 4 0 0 0-4 4v2"></path>
|
|
475
|
+
<circle cx="12" cy="7" r="4"></circle>
|
|
476
|
+
</svg>
|
|
477
|
+
Customer Information
|
|
478
|
+
</h3>
|
|
479
|
+
<p class="pkpay-pane-subtitle">Enter your billing & contact details for payment receipt.</p>
|
|
480
|
+
`;
|
|
481
|
+
container.appendChild(header);
|
|
482
|
+
const form = document.createElement("div");
|
|
483
|
+
form.className = "pkpay-form";
|
|
484
|
+
const initial = options.initialData || { email: "" };
|
|
485
|
+
let initFirstName = "";
|
|
486
|
+
let initLastName = "";
|
|
487
|
+
if (initial.name) {
|
|
488
|
+
const parts = initial.name.trim().split(" ");
|
|
489
|
+
initFirstName = parts[0] || "";
|
|
490
|
+
initLastName = parts.slice(1).join(" ") || "";
|
|
491
|
+
}
|
|
492
|
+
let debounceTimer = null;
|
|
493
|
+
const triggerChange = () => {
|
|
494
|
+
if (debounceTimer) clearTimeout(debounceTimer);
|
|
495
|
+
debounceTimer = setTimeout(() => {
|
|
496
|
+
options.onChange?.(getCurrentData());
|
|
497
|
+
}, 150);
|
|
498
|
+
};
|
|
499
|
+
const nameRow = document.createElement("div");
|
|
500
|
+
nameRow.className = "pkpay-form-row";
|
|
501
|
+
const firstNameInput = createInput({
|
|
502
|
+
id: "pkpay-first-name",
|
|
503
|
+
name: "firstName",
|
|
504
|
+
label: "First Name",
|
|
505
|
+
placeholder: "Jane",
|
|
506
|
+
required: true,
|
|
507
|
+
value: initFirstName,
|
|
508
|
+
onInput: triggerChange
|
|
509
|
+
});
|
|
510
|
+
const lastNameInput = createInput({
|
|
511
|
+
id: "pkpay-last-name",
|
|
512
|
+
name: "lastName",
|
|
513
|
+
label: "Last Name",
|
|
514
|
+
placeholder: "Doe",
|
|
515
|
+
required: true,
|
|
516
|
+
value: initLastName,
|
|
517
|
+
onInput: triggerChange
|
|
518
|
+
});
|
|
519
|
+
nameRow.appendChild(firstNameInput.container);
|
|
520
|
+
nameRow.appendChild(lastNameInput.container);
|
|
521
|
+
form.appendChild(nameRow);
|
|
522
|
+
const emailInput = createInput({
|
|
523
|
+
id: "pkpay-email",
|
|
524
|
+
name: "email",
|
|
525
|
+
label: "Email Address",
|
|
526
|
+
type: "email",
|
|
527
|
+
placeholder: "jane.doe@example.com",
|
|
528
|
+
required: true,
|
|
529
|
+
value: initial.email || "",
|
|
530
|
+
validate: (val) => {
|
|
531
|
+
if (!val) return "Email is required";
|
|
532
|
+
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
533
|
+
if (!emailRegex.test(val)) return "Please enter a valid email address";
|
|
534
|
+
return null;
|
|
535
|
+
},
|
|
536
|
+
onInput: triggerChange
|
|
537
|
+
});
|
|
538
|
+
form.appendChild(emailInput.container);
|
|
539
|
+
const phoneInput = createInput({
|
|
540
|
+
id: "pkpay-phone",
|
|
541
|
+
name: "phone",
|
|
542
|
+
label: "Phone Number",
|
|
543
|
+
type: "tel",
|
|
544
|
+
placeholder: "+1 (555) 000-0000",
|
|
545
|
+
required: true,
|
|
546
|
+
value: initial.phone || "",
|
|
547
|
+
validate: (val) => {
|
|
548
|
+
if (!val) return "Phone number is required";
|
|
549
|
+
if (val.replace(/\D/g, "").length < 7) return "Please enter a valid phone number";
|
|
550
|
+
return null;
|
|
551
|
+
},
|
|
552
|
+
onInput: triggerChange
|
|
553
|
+
});
|
|
554
|
+
form.appendChild(phoneInput.container);
|
|
555
|
+
const addressInput = createInput({
|
|
556
|
+
id: "pkpay-address",
|
|
557
|
+
name: "address",
|
|
558
|
+
label: "Street Address",
|
|
559
|
+
placeholder: "123 Market St, Suite 400",
|
|
560
|
+
required: true,
|
|
561
|
+
value: initial.billing?.address_1 || "",
|
|
562
|
+
validate: (val) => !val ? "Street address is required" : null,
|
|
563
|
+
onInput: triggerChange
|
|
564
|
+
});
|
|
565
|
+
form.appendChild(addressInput.container);
|
|
566
|
+
const countryCombobox = createCountryCombobox({
|
|
567
|
+
id: "pkpay-country",
|
|
568
|
+
label: "Country / Region",
|
|
569
|
+
required: true,
|
|
570
|
+
defaultValue: initial.billing?.country || "US",
|
|
571
|
+
onChange: () => {
|
|
572
|
+
triggerChange();
|
|
573
|
+
}
|
|
574
|
+
});
|
|
575
|
+
form.appendChild(countryCombobox.container);
|
|
576
|
+
const cityRow = document.createElement("div");
|
|
577
|
+
cityRow.className = "pkpay-form-row";
|
|
578
|
+
const cityInput = createInput({
|
|
579
|
+
id: "pkpay-city",
|
|
580
|
+
name: "city",
|
|
581
|
+
label: "City",
|
|
582
|
+
placeholder: "New York",
|
|
583
|
+
required: true,
|
|
584
|
+
value: initial.billing?.city || "",
|
|
585
|
+
validate: (val) => !val ? "City is required" : null,
|
|
586
|
+
onInput: triggerChange
|
|
587
|
+
});
|
|
588
|
+
const zipInput = createInput({
|
|
589
|
+
id: "pkpay-zip",
|
|
590
|
+
name: "postalCode",
|
|
591
|
+
label: "Postal Code",
|
|
592
|
+
placeholder: "10001",
|
|
593
|
+
value: initial.billing?.postcode || "",
|
|
594
|
+
onInput: triggerChange
|
|
595
|
+
});
|
|
596
|
+
cityRow.appendChild(cityInput.container);
|
|
597
|
+
cityRow.appendChild(zipInput.container);
|
|
598
|
+
form.appendChild(cityRow);
|
|
599
|
+
container.appendChild(form);
|
|
600
|
+
const badge = document.createElement("div");
|
|
601
|
+
badge.className = "pkpay-footer-badge";
|
|
602
|
+
badge.innerHTML = `
|
|
603
|
+
<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="#64748b" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
|
604
|
+
<rect x="3" y="11" width="18" height="11" rx="2" ry="2"></rect>
|
|
605
|
+
<path d="M7 11V7a5 5 0 0 1 10 0v4"></path>
|
|
606
|
+
</svg>
|
|
607
|
+
<span>End-to-end 256-bit SSL encrypted</span>
|
|
608
|
+
`;
|
|
609
|
+
container.appendChild(badge);
|
|
610
|
+
const getCurrentData = () => {
|
|
611
|
+
const fName = firstNameInput.getValue();
|
|
612
|
+
const lName = lastNameInput.getValue();
|
|
613
|
+
const fullName = [fName, lName].filter(Boolean).join(" ");
|
|
614
|
+
return {
|
|
615
|
+
email: emailInput.getValue(),
|
|
616
|
+
name: fullName,
|
|
617
|
+
phone: phoneInput.getValue(),
|
|
618
|
+
billing: {
|
|
619
|
+
address_1: addressInput.getValue(),
|
|
620
|
+
city: cityInput.getValue(),
|
|
621
|
+
postcode: zipInput.getValue(),
|
|
622
|
+
country: countryCombobox.getValue()
|
|
623
|
+
}
|
|
624
|
+
};
|
|
625
|
+
};
|
|
626
|
+
const validateAll = () => {
|
|
627
|
+
const emailValid = emailInput.validate();
|
|
628
|
+
const firstValid = firstNameInput.validate();
|
|
629
|
+
const lastValid = lastNameInput.validate();
|
|
630
|
+
const phoneValid = phoneInput.validate();
|
|
631
|
+
const addressValid = addressInput.validate();
|
|
632
|
+
const cityValid = cityInput.validate();
|
|
633
|
+
return emailValid && firstValid && lastValid && phoneValid && addressValid && cityValid;
|
|
634
|
+
};
|
|
635
|
+
const setValues = (data) => {
|
|
636
|
+
if (data.name) {
|
|
637
|
+
const parts = data.name.trim().split(" ");
|
|
638
|
+
firstNameInput.setValue(parts[0] || "");
|
|
639
|
+
lastNameInput.setValue(parts.slice(1).join(" ") || "");
|
|
640
|
+
}
|
|
641
|
+
if (data.email !== void 0) emailInput.setValue(data.email);
|
|
642
|
+
if (data.phone !== void 0) phoneInput.setValue(data.phone);
|
|
643
|
+
if (data.billing?.address_1 !== void 0) addressInput.setValue(data.billing.address_1);
|
|
644
|
+
if (data.billing?.city !== void 0) cityInput.setValue(data.billing.city);
|
|
645
|
+
if (data.billing?.postcode !== void 0) zipInput.setValue(data.billing.postcode);
|
|
646
|
+
if (data.billing?.country !== void 0) countryCombobox.setValue(data.billing.country);
|
|
647
|
+
};
|
|
648
|
+
return {
|
|
649
|
+
element: container,
|
|
650
|
+
getData: getCurrentData,
|
|
651
|
+
validate: validateAll,
|
|
652
|
+
setValues
|
|
653
|
+
};
|
|
654
|
+
}
|
|
655
|
+
|
|
656
|
+
// src/ui/theme.ts
|
|
657
|
+
var THEME_STYLE_ID = "pkpayplus-ui-theme";
|
|
658
|
+
function injectThemeStyles() {
|
|
659
|
+
if (typeof document === "undefined" || document.getElementById(THEME_STYLE_ID)) {
|
|
100
660
|
return;
|
|
101
661
|
}
|
|
102
662
|
const style = document.createElement("style");
|
|
103
|
-
style.id =
|
|
663
|
+
style.id = THEME_STYLE_ID;
|
|
104
664
|
style.textContent = `
|
|
105
|
-
|
|
665
|
+
/* PKPay+ Modern Split Dialog Theme (shadcn/Radix aesthetics) */
|
|
666
|
+
:root {
|
|
667
|
+
--pkpay-font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
|
|
668
|
+
--pkpay-bg: #ffffff;
|
|
669
|
+
--pkpay-sidebar-bg: #f8fafc;
|
|
670
|
+
--pkpay-fg: #0f172a;
|
|
671
|
+
--pkpay-muted: #64748b;
|
|
672
|
+
--pkpay-muted-light: #94a3b8;
|
|
673
|
+
--pkpay-border: #e2e8f0;
|
|
674
|
+
--pkpay-border-hover: #cbd5e1;
|
|
675
|
+
--pkpay-primary: #2563eb;
|
|
676
|
+
--pkpay-primary-hover: #1d4ed8;
|
|
677
|
+
--pkpay-ring: rgba(37, 99, 235, 0.25);
|
|
678
|
+
--pkpay-destructive: #ef4444;
|
|
679
|
+
--pkpay-radius: 12px;
|
|
680
|
+
--pkpay-radius-sm: 6px;
|
|
681
|
+
}
|
|
682
|
+
|
|
683
|
+
@keyframes pkpay-fade-in {
|
|
684
|
+
from { opacity: 0; }
|
|
685
|
+
to { opacity: 1; }
|
|
686
|
+
}
|
|
687
|
+
|
|
688
|
+
@keyframes pkpay-slide-up {
|
|
689
|
+
from {
|
|
690
|
+
opacity: 0;
|
|
691
|
+
transform: scale(0.96) translateY(14px);
|
|
692
|
+
}
|
|
693
|
+
to {
|
|
694
|
+
opacity: 1;
|
|
695
|
+
transform: scale(1) translateY(0);
|
|
696
|
+
}
|
|
697
|
+
}
|
|
698
|
+
|
|
699
|
+
@keyframes pkpay-error-reveal {
|
|
700
|
+
from {
|
|
701
|
+
opacity: 0;
|
|
702
|
+
transform: translateY(-4px);
|
|
703
|
+
max-height: 0;
|
|
704
|
+
}
|
|
705
|
+
to {
|
|
706
|
+
opacity: 1;
|
|
707
|
+
transform: translateY(0);
|
|
708
|
+
max-height: 32px;
|
|
709
|
+
}
|
|
710
|
+
}
|
|
711
|
+
|
|
712
|
+
.pkpay-overlay {
|
|
106
713
|
position: fixed;
|
|
107
|
-
|
|
108
|
-
left: 0;
|
|
714
|
+
inset: 0;
|
|
109
715
|
width: 100vw;
|
|
110
716
|
height: 100vh;
|
|
111
|
-
background: rgba(15, 23, 42, 0.
|
|
112
|
-
backdrop-filter: blur(
|
|
113
|
-
-webkit-backdrop-filter: blur(
|
|
717
|
+
background: rgba(15, 23, 42, 0.6);
|
|
718
|
+
backdrop-filter: blur(8px);
|
|
719
|
+
-webkit-backdrop-filter: blur(8px);
|
|
114
720
|
z-index: 999999;
|
|
115
721
|
display: flex;
|
|
116
722
|
align-items: center;
|
|
117
723
|
justify-content: center;
|
|
118
|
-
opacity: 0;
|
|
119
|
-
transition: opacity 0.25s cubic-bezier(0.16, 1, 0.3, 1);
|
|
120
|
-
box-sizing: border-box;
|
|
121
724
|
padding: 16px;
|
|
725
|
+
box-sizing: border-box;
|
|
726
|
+
opacity: 0;
|
|
727
|
+
transition: opacity 0.22s cubic-bezier(0.16, 1, 0.3, 1);
|
|
728
|
+
font-family: var(--pkpay-font);
|
|
122
729
|
}
|
|
123
|
-
|
|
730
|
+
|
|
731
|
+
.pkpay-overlay.pkpay-visible {
|
|
124
732
|
opacity: 1;
|
|
125
733
|
}
|
|
126
|
-
|
|
734
|
+
|
|
735
|
+
.pkpay-dialog {
|
|
127
736
|
position: relative;
|
|
128
737
|
width: 100%;
|
|
129
|
-
max-width:
|
|
130
|
-
height:
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
738
|
+
max-width: 920px;
|
|
739
|
+
min-height: 580px;
|
|
740
|
+
height: auto;
|
|
741
|
+
max-height: 94vh;
|
|
742
|
+
background: var(--pkpay-bg);
|
|
743
|
+
border-radius: var(--pkpay-radius);
|
|
744
|
+
box-shadow: 0 25px 50px -12px rgba(15, 23, 42, 0.25), 0 0 0 1px rgba(15, 23, 42, 0.08);
|
|
135
745
|
overflow: hidden;
|
|
136
|
-
|
|
746
|
+
display: grid;
|
|
747
|
+
grid-template-columns: 1.05fr 1fr;
|
|
748
|
+
transform: scale(0.96) translateY(14px);
|
|
137
749
|
transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1);
|
|
750
|
+
box-sizing: border-box;
|
|
751
|
+
}
|
|
752
|
+
|
|
753
|
+
.pkpay-visible .pkpay-dialog {
|
|
754
|
+
transform: scale(1) translateY(0);
|
|
755
|
+
}
|
|
756
|
+
|
|
757
|
+
/* Single column mode when customer form is disabled or pre-filled */
|
|
758
|
+
.pkpay-dialog.pkpay-compact {
|
|
759
|
+
max-width: 460px;
|
|
760
|
+
grid-template-columns: 1fr;
|
|
761
|
+
}
|
|
762
|
+
|
|
763
|
+
/* Left Pane: Customer Information */
|
|
764
|
+
.pkpay-customer-pane {
|
|
138
765
|
display: flex;
|
|
139
766
|
flex-direction: column;
|
|
767
|
+
background: var(--pkpay-sidebar-bg);
|
|
768
|
+
border-right: 1px solid var(--pkpay-border);
|
|
769
|
+
overflow-y: auto;
|
|
770
|
+
scrollbar-width: none;
|
|
771
|
+
-ms-overflow-style: none;
|
|
772
|
+
padding: 24px;
|
|
773
|
+
box-sizing: border-box;
|
|
140
774
|
}
|
|
141
|
-
|
|
142
|
-
|
|
775
|
+
|
|
776
|
+
.pkpay-customer-pane::-webkit-scrollbar {
|
|
777
|
+
display: none;
|
|
778
|
+
}
|
|
779
|
+
|
|
780
|
+
.pkpay-pane-header {
|
|
781
|
+
margin-bottom: 14px;
|
|
782
|
+
}
|
|
783
|
+
|
|
784
|
+
.pkpay-pane-title {
|
|
785
|
+
font-size: 16px;
|
|
786
|
+
font-weight: 600;
|
|
787
|
+
color: var(--pkpay-fg);
|
|
788
|
+
margin: 0 0 3px 0;
|
|
789
|
+
letter-spacing: -0.01em;
|
|
790
|
+
display: flex;
|
|
791
|
+
align-items: center;
|
|
792
|
+
gap: 7px;
|
|
793
|
+
}
|
|
794
|
+
|
|
795
|
+
.pkpay-pane-subtitle {
|
|
796
|
+
font-size: 11px;
|
|
797
|
+
color: var(--pkpay-muted);
|
|
798
|
+
margin: 0;
|
|
799
|
+
line-height: 1.4;
|
|
800
|
+
}
|
|
801
|
+
|
|
802
|
+
.pkpay-form {
|
|
803
|
+
display: flex;
|
|
804
|
+
flex-direction: column;
|
|
805
|
+
gap: 10px;
|
|
806
|
+
width: 100%;
|
|
807
|
+
}
|
|
808
|
+
|
|
809
|
+
.pkpay-form-row {
|
|
810
|
+
display: grid;
|
|
811
|
+
grid-template-columns: 1fr 1fr;
|
|
812
|
+
gap: 10px;
|
|
813
|
+
}
|
|
814
|
+
|
|
815
|
+
.pkpay-form-group {
|
|
816
|
+
display: flex;
|
|
817
|
+
flex-direction: column;
|
|
818
|
+
gap: 4px;
|
|
819
|
+
width: 100%;
|
|
820
|
+
box-sizing: border-box;
|
|
821
|
+
}
|
|
822
|
+
|
|
823
|
+
.pkpay-label {
|
|
824
|
+
font-size: 11.5px;
|
|
825
|
+
font-weight: 500;
|
|
826
|
+
color: var(--pkpay-fg);
|
|
827
|
+
letter-spacing: -0.01em;
|
|
828
|
+
user-select: none;
|
|
829
|
+
}
|
|
830
|
+
|
|
831
|
+
.pkpay-label-required {
|
|
832
|
+
color: var(--pkpay-destructive);
|
|
833
|
+
margin-left: 2px;
|
|
143
834
|
}
|
|
144
|
-
|
|
835
|
+
|
|
836
|
+
.pkpay-input {
|
|
837
|
+
width: 100%;
|
|
838
|
+
height: 36px;
|
|
839
|
+
padding: 0 10px;
|
|
840
|
+
font-size: 13px;
|
|
841
|
+
font-family: inherit;
|
|
842
|
+
color: var(--pkpay-fg);
|
|
843
|
+
background: #ffffff;
|
|
844
|
+
border: 1px solid var(--pkpay-border);
|
|
845
|
+
border-radius: var(--pkpay-radius-sm);
|
|
846
|
+
box-sizing: border-box;
|
|
847
|
+
outline: none;
|
|
848
|
+
transition: border-color 0.15s ease, box-shadow 0.15s ease;
|
|
849
|
+
}
|
|
850
|
+
|
|
851
|
+
.pkpay-input::placeholder {
|
|
852
|
+
color: var(--pkpay-muted-light);
|
|
853
|
+
}
|
|
854
|
+
|
|
855
|
+
.pkpay-input:hover {
|
|
856
|
+
border-color: var(--pkpay-border-hover);
|
|
857
|
+
}
|
|
858
|
+
|
|
859
|
+
.pkpay-input:focus {
|
|
860
|
+
border-color: var(--pkpay-primary);
|
|
861
|
+
box-shadow: 0 0 0 3px var(--pkpay-ring);
|
|
862
|
+
}
|
|
863
|
+
|
|
864
|
+
.pkpay-input.pkpay-input-error {
|
|
865
|
+
border-color: var(--pkpay-destructive);
|
|
866
|
+
}
|
|
867
|
+
|
|
868
|
+
.pkpay-input.pkpay-input-error:focus {
|
|
869
|
+
box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.2);
|
|
870
|
+
}
|
|
871
|
+
|
|
872
|
+
.pkpay-form-message {
|
|
873
|
+
font-size: 11px;
|
|
874
|
+
color: var(--pkpay-destructive);
|
|
875
|
+
line-height: 1.2;
|
|
876
|
+
display: none;
|
|
877
|
+
animation: pkpay-error-reveal 0.15s ease-out;
|
|
878
|
+
}
|
|
879
|
+
|
|
880
|
+
.pkpay-form-message.pkpay-visible {
|
|
881
|
+
display: block;
|
|
882
|
+
}
|
|
883
|
+
|
|
884
|
+
/* Combobox / Country Selector */
|
|
885
|
+
.pkpay-combobox-wrapper {
|
|
886
|
+
position: relative;
|
|
887
|
+
width: 100%;
|
|
888
|
+
}
|
|
889
|
+
|
|
890
|
+
.pkpay-combobox-trigger {
|
|
891
|
+
width: 100%;
|
|
892
|
+
height: 36px;
|
|
893
|
+
padding: 0 10px;
|
|
894
|
+
font-size: 13px;
|
|
895
|
+
font-family: inherit;
|
|
896
|
+
color: var(--pkpay-fg);
|
|
897
|
+
background: #ffffff;
|
|
898
|
+
border: 1px solid var(--pkpay-border);
|
|
899
|
+
border-radius: var(--pkpay-radius-sm);
|
|
900
|
+
box-sizing: border-box;
|
|
901
|
+
display: flex;
|
|
902
|
+
align-items: center;
|
|
903
|
+
justify-content: space-between;
|
|
904
|
+
cursor: pointer;
|
|
905
|
+
user-select: none;
|
|
906
|
+
transition: border-color 0.15s ease, box-shadow 0.15s ease;
|
|
907
|
+
}
|
|
908
|
+
|
|
909
|
+
.pkpay-combobox-trigger:hover {
|
|
910
|
+
border-color: var(--pkpay-border-hover);
|
|
911
|
+
}
|
|
912
|
+
|
|
913
|
+
.pkpay-combobox-trigger:focus,
|
|
914
|
+
.pkpay-combobox-trigger.pkpay-active {
|
|
915
|
+
border-color: var(--pkpay-primary);
|
|
916
|
+
box-shadow: 0 0 0 3px var(--pkpay-ring);
|
|
917
|
+
outline: none;
|
|
918
|
+
}
|
|
919
|
+
|
|
920
|
+
.pkpay-combobox-value {
|
|
921
|
+
display: flex;
|
|
922
|
+
align-items: center;
|
|
923
|
+
gap: 8px;
|
|
924
|
+
overflow: hidden;
|
|
925
|
+
text-overflow: ellipsis;
|
|
926
|
+
white-space: nowrap;
|
|
927
|
+
}
|
|
928
|
+
|
|
929
|
+
.pkpay-combobox-icon {
|
|
930
|
+
color: var(--pkpay-muted);
|
|
931
|
+
flex-shrink: 0;
|
|
932
|
+
transition: transform 0.2s ease;
|
|
933
|
+
}
|
|
934
|
+
|
|
935
|
+
.pkpay-combobox-trigger.pkpay-active .pkpay-combobox-icon {
|
|
936
|
+
transform: rotate(180deg);
|
|
937
|
+
}
|
|
938
|
+
|
|
939
|
+
.pkpay-combobox-popover {
|
|
940
|
+
position: absolute;
|
|
941
|
+
top: calc(100% + 4px);
|
|
942
|
+
left: 0;
|
|
943
|
+
right: 0;
|
|
944
|
+
background: #ffffff;
|
|
945
|
+
border: 1px solid var(--pkpay-border);
|
|
946
|
+
border-radius: var(--pkpay-radius-sm);
|
|
947
|
+
box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.1);
|
|
948
|
+
z-index: 50;
|
|
949
|
+
display: none;
|
|
950
|
+
flex-direction: column;
|
|
951
|
+
overflow: hidden;
|
|
952
|
+
max-height: 220px;
|
|
953
|
+
}
|
|
954
|
+
|
|
955
|
+
.pkpay-combobox-popover.pkpay-open {
|
|
956
|
+
display: flex;
|
|
957
|
+
}
|
|
958
|
+
|
|
959
|
+
.pkpay-combobox-search-box {
|
|
960
|
+
padding: 6px 8px;
|
|
961
|
+
border-bottom: 1px solid var(--pkpay-border);
|
|
962
|
+
display: flex;
|
|
963
|
+
align-items: center;
|
|
964
|
+
gap: 6px;
|
|
965
|
+
background: #fdfdfd;
|
|
966
|
+
}
|
|
967
|
+
|
|
968
|
+
.pkpay-combobox-search-input {
|
|
969
|
+
width: 100%;
|
|
970
|
+
height: 28px;
|
|
971
|
+
border: none;
|
|
972
|
+
outline: none;
|
|
973
|
+
background: transparent;
|
|
974
|
+
font-size: 12px;
|
|
975
|
+
font-family: inherit;
|
|
976
|
+
color: var(--pkpay-fg);
|
|
977
|
+
}
|
|
978
|
+
|
|
979
|
+
.pkpay-combobox-list {
|
|
980
|
+
list-style: none;
|
|
981
|
+
margin: 0;
|
|
982
|
+
padding: 4px;
|
|
983
|
+
overflow-y: auto;
|
|
984
|
+
max-height: 170px;
|
|
985
|
+
scrollbar-width: thin;
|
|
986
|
+
}
|
|
987
|
+
|
|
988
|
+
.pkpay-combobox-item {
|
|
989
|
+
padding: 6px 8px;
|
|
990
|
+
font-size: 12px;
|
|
991
|
+
color: var(--pkpay-fg);
|
|
992
|
+
border-radius: 4px;
|
|
993
|
+
cursor: pointer;
|
|
994
|
+
display: flex;
|
|
995
|
+
align-items: center;
|
|
996
|
+
justify-content: space-between;
|
|
997
|
+
transition: background 0.1s ease;
|
|
998
|
+
}
|
|
999
|
+
|
|
1000
|
+
.pkpay-combobox-item:hover,
|
|
1001
|
+
.pkpay-combobox-item.pkpay-highlighted {
|
|
1002
|
+
background: #f1f5f9;
|
|
1003
|
+
}
|
|
1004
|
+
|
|
1005
|
+
.pkpay-combobox-item.pkpay-selected {
|
|
1006
|
+
font-weight: 600;
|
|
1007
|
+
background: #eff6ff;
|
|
1008
|
+
color: var(--pkpay-primary);
|
|
1009
|
+
}
|
|
1010
|
+
|
|
1011
|
+
.pkpay-combobox-empty {
|
|
1012
|
+
padding: 12px;
|
|
1013
|
+
font-size: 12px;
|
|
1014
|
+
color: var(--pkpay-muted);
|
|
1015
|
+
text-align: center;
|
|
1016
|
+
}
|
|
1017
|
+
|
|
1018
|
+
/* Right Pane: Iframe Checkout */
|
|
1019
|
+
.pkpay-iframe-pane {
|
|
1020
|
+
position: relative;
|
|
1021
|
+
display: flex;
|
|
1022
|
+
flex-direction: column;
|
|
1023
|
+
background: #ffffff;
|
|
145
1024
|
width: 100%;
|
|
146
1025
|
height: 100%;
|
|
1026
|
+
overflow: hidden;
|
|
1027
|
+
padding: 24px;
|
|
1028
|
+
box-sizing: border-box;
|
|
1029
|
+
}
|
|
1030
|
+
|
|
1031
|
+
.pkpay-payment-header {
|
|
1032
|
+
margin-bottom: 12px;
|
|
1033
|
+
padding-right: 32px;
|
|
1034
|
+
}
|
|
1035
|
+
|
|
1036
|
+
.pkpay-payment-title-row {
|
|
1037
|
+
display: flex;
|
|
1038
|
+
align-items: center;
|
|
1039
|
+
justify-content: space-between;
|
|
1040
|
+
gap: 8px;
|
|
1041
|
+
margin-bottom: 3px;
|
|
1042
|
+
}
|
|
1043
|
+
|
|
1044
|
+
.pkpay-payment-title {
|
|
1045
|
+
font-size: 13.5px;
|
|
1046
|
+
font-weight: 600;
|
|
1047
|
+
color: var(--pkpay-fg);
|
|
1048
|
+
display: flex;
|
|
1049
|
+
align-items: center;
|
|
1050
|
+
gap: 6px;
|
|
1051
|
+
letter-spacing: -0.01em;
|
|
1052
|
+
}
|
|
1053
|
+
|
|
1054
|
+
.pkpay-radio-dot {
|
|
1055
|
+
width: 13px;
|
|
1056
|
+
height: 13px;
|
|
1057
|
+
border-radius: 50%;
|
|
1058
|
+
border: 3.5px solid var(--pkpay-primary);
|
|
1059
|
+
background: #ffffff;
|
|
1060
|
+
display: inline-block;
|
|
1061
|
+
box-sizing: border-box;
|
|
1062
|
+
flex-shrink: 0;
|
|
1063
|
+
}
|
|
1064
|
+
|
|
1065
|
+
.pkpay-brand-badges {
|
|
1066
|
+
display: flex;
|
|
1067
|
+
align-items: center;
|
|
1068
|
+
gap: 4px;
|
|
1069
|
+
}
|
|
1070
|
+
|
|
1071
|
+
.pkpay-brand-badge {
|
|
1072
|
+
font-size: 9px;
|
|
1073
|
+
font-weight: 700;
|
|
1074
|
+
padding: 2px 4px;
|
|
1075
|
+
border-radius: 3px;
|
|
1076
|
+
border: 1px solid #cbd5e1;
|
|
1077
|
+
background: #f8fafc;
|
|
1078
|
+
color: #475569;
|
|
1079
|
+
letter-spacing: 0.04em;
|
|
1080
|
+
line-height: 1;
|
|
1081
|
+
}
|
|
1082
|
+
|
|
1083
|
+
.pkpay-payment-subtitle {
|
|
1084
|
+
font-size: 11px;
|
|
1085
|
+
color: var(--pkpay-muted);
|
|
1086
|
+
margin: 0;
|
|
1087
|
+
line-height: 1.4;
|
|
1088
|
+
}
|
|
1089
|
+
|
|
1090
|
+
.pkpay-card-box {
|
|
1091
|
+
position: relative;
|
|
1092
|
+
background: #f8fafc;
|
|
1093
|
+
border: 1px solid #e2e8f0;
|
|
1094
|
+
border-radius: 8px;
|
|
1095
|
+
padding: 4px 6px;
|
|
1096
|
+
margin-bottom: 12px;
|
|
1097
|
+
box-sizing: border-box;
|
|
1098
|
+
overflow: hidden;
|
|
1099
|
+
}
|
|
1100
|
+
|
|
1101
|
+
.pkpay-processing-overlay {
|
|
1102
|
+
position: absolute;
|
|
1103
|
+
inset: 0;
|
|
1104
|
+
background: rgba(255, 255, 255, 0.94);
|
|
1105
|
+
backdrop-filter: blur(4px);
|
|
1106
|
+
-webkit-backdrop-filter: blur(4px);
|
|
1107
|
+
display: flex;
|
|
1108
|
+
flex-direction: column;
|
|
1109
|
+
align-items: center;
|
|
1110
|
+
justify-content: center;
|
|
1111
|
+
gap: 10px;
|
|
1112
|
+
z-index: 10;
|
|
1113
|
+
opacity: 0;
|
|
1114
|
+
pointer-events: none;
|
|
1115
|
+
transition: opacity 0.2s ease;
|
|
1116
|
+
border-radius: 7px;
|
|
1117
|
+
}
|
|
1118
|
+
|
|
1119
|
+
.pkpay-processing-overlay.pkpay-visible {
|
|
1120
|
+
opacity: 1;
|
|
1121
|
+
pointer-events: auto;
|
|
1122
|
+
}
|
|
1123
|
+
|
|
1124
|
+
.pkpay-processing-text {
|
|
1125
|
+
font-size: 13.5px;
|
|
1126
|
+
font-weight: 600;
|
|
1127
|
+
color: #0f172a;
|
|
1128
|
+
margin: 0;
|
|
1129
|
+
letter-spacing: -0.01em;
|
|
1130
|
+
}
|
|
1131
|
+
|
|
1132
|
+
.pkpay-processing-subtext {
|
|
1133
|
+
font-size: 11.5px;
|
|
1134
|
+
color: #64748b;
|
|
1135
|
+
margin: 0;
|
|
1136
|
+
}
|
|
1137
|
+
|
|
1138
|
+
.pkpay-iframe {
|
|
1139
|
+
width: 100%;
|
|
1140
|
+
height: 285px;
|
|
1141
|
+
min-height: 285px;
|
|
147
1142
|
border: none;
|
|
148
|
-
flex: 1;
|
|
149
1143
|
background: transparent;
|
|
1144
|
+
display: block;
|
|
1145
|
+
overflow: hidden;
|
|
1146
|
+
}
|
|
1147
|
+
|
|
1148
|
+
.pkpay-terms-notice {
|
|
1149
|
+
font-size: 10.5px;
|
|
1150
|
+
color: var(--pkpay-muted);
|
|
1151
|
+
line-height: 1.45;
|
|
1152
|
+
margin: 0 0 12px 0;
|
|
150
1153
|
}
|
|
151
|
-
|
|
1154
|
+
|
|
1155
|
+
.pkpay-submit-btn {
|
|
1156
|
+
width: 100%;
|
|
1157
|
+
height: 42px;
|
|
1158
|
+
border: none;
|
|
1159
|
+
border-radius: var(--pkpay-radius-sm);
|
|
1160
|
+
background: #0f172a;
|
|
1161
|
+
color: #ffffff;
|
|
1162
|
+
font-size: 13.5px;
|
|
1163
|
+
font-weight: 600;
|
|
1164
|
+
font-family: inherit;
|
|
1165
|
+
cursor: pointer;
|
|
1166
|
+
display: flex;
|
|
1167
|
+
align-items: center;
|
|
1168
|
+
justify-content: center;
|
|
1169
|
+
gap: 8px;
|
|
1170
|
+
transition: background 0.15s ease, transform 0.1s ease, box-shadow 0.15s ease;
|
|
1171
|
+
box-shadow: 0 4px 12px rgba(15, 23, 42, 0.12);
|
|
1172
|
+
margin-top: auto;
|
|
1173
|
+
}
|
|
1174
|
+
|
|
1175
|
+
.pkpay-submit-btn:hover:not(:disabled) {
|
|
1176
|
+
background: #1e293b;
|
|
1177
|
+
transform: translateY(-1px);
|
|
1178
|
+
box-shadow: 0 6px 16px rgba(15, 23, 42, 0.18);
|
|
1179
|
+
}
|
|
1180
|
+
|
|
1181
|
+
.pkpay-submit-btn:disabled {
|
|
1182
|
+
opacity: 0.55;
|
|
1183
|
+
cursor: not-allowed;
|
|
1184
|
+
transform: none;
|
|
1185
|
+
box-shadow: none;
|
|
1186
|
+
}
|
|
1187
|
+
|
|
1188
|
+
.pkpay-submit-btn.pkpay-loading {
|
|
1189
|
+
cursor: wait;
|
|
1190
|
+
opacity: 0.8;
|
|
1191
|
+
}
|
|
1192
|
+
|
|
1193
|
+
.pkpay-iframe-loader {
|
|
1194
|
+
position: absolute;
|
|
1195
|
+
inset: 0;
|
|
1196
|
+
background: #ffffff;
|
|
1197
|
+
display: flex;
|
|
1198
|
+
flex-direction: column;
|
|
1199
|
+
align-items: center;
|
|
1200
|
+
justify-content: center;
|
|
1201
|
+
gap: 12px;
|
|
1202
|
+
z-index: 5;
|
|
1203
|
+
transition: opacity 0.2s ease;
|
|
1204
|
+
}
|
|
1205
|
+
|
|
1206
|
+
.pkpay-spinner {
|
|
1207
|
+
width: 28px;
|
|
1208
|
+
height: 28px;
|
|
1209
|
+
border: 3px solid rgba(37, 99, 235, 0.15);
|
|
1210
|
+
border-top-color: var(--pkpay-primary);
|
|
1211
|
+
border-radius: 50%;
|
|
1212
|
+
animation: pkpay-spin 0.75s linear infinite;
|
|
1213
|
+
}
|
|
1214
|
+
|
|
1215
|
+
@keyframes pkpay-spin {
|
|
1216
|
+
to { transform: rotate(360deg); }
|
|
1217
|
+
}
|
|
1218
|
+
|
|
1219
|
+
.pkpay-loader-text {
|
|
1220
|
+
font-size: 12px;
|
|
1221
|
+
color: var(--pkpay-muted);
|
|
1222
|
+
font-weight: 500;
|
|
1223
|
+
}
|
|
1224
|
+
|
|
1225
|
+
.pkpay-close-btn {
|
|
152
1226
|
position: absolute;
|
|
153
|
-
top:
|
|
154
|
-
right:
|
|
155
|
-
width:
|
|
156
|
-
height:
|
|
1227
|
+
top: 14px;
|
|
1228
|
+
right: 14px;
|
|
1229
|
+
width: 30px;
|
|
1230
|
+
height: 30px;
|
|
157
1231
|
border-radius: 50%;
|
|
158
|
-
background:
|
|
159
|
-
border: 1px solid
|
|
1232
|
+
background: #f1f5f9;
|
|
1233
|
+
border: 1px solid var(--pkpay-border);
|
|
160
1234
|
cursor: pointer;
|
|
161
1235
|
display: flex;
|
|
162
1236
|
align-items: center;
|
|
163
1237
|
justify-content: center;
|
|
164
|
-
color:
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
z-index: 10;
|
|
168
|
-
transition: background 0.15s ease, transform 0.1s ease;
|
|
1238
|
+
color: var(--pkpay-muted);
|
|
1239
|
+
z-index: 20;
|
|
1240
|
+
transition: background 0.15s ease, color 0.15s ease, transform 0.1s ease;
|
|
169
1241
|
}
|
|
170
|
-
|
|
1242
|
+
|
|
1243
|
+
.pkpay-close-btn:hover {
|
|
171
1244
|
background: #e2e8f0;
|
|
172
|
-
color:
|
|
1245
|
+
color: var(--pkpay-fg);
|
|
173
1246
|
transform: scale(1.05);
|
|
174
1247
|
}
|
|
175
|
-
|
|
176
|
-
|
|
1248
|
+
|
|
1249
|
+
.pkpay-footer-badge {
|
|
1250
|
+
margin-top: auto;
|
|
1251
|
+
padding-top: 16px;
|
|
1252
|
+
display: flex;
|
|
1253
|
+
align-items: center;
|
|
1254
|
+
justify-content: center;
|
|
1255
|
+
gap: 6px;
|
|
1256
|
+
font-size: 11px;
|
|
1257
|
+
color: var(--pkpay-muted);
|
|
1258
|
+
user-select: none;
|
|
1259
|
+
}
|
|
1260
|
+
|
|
1261
|
+
/* Responsive Breakdown */
|
|
1262
|
+
@media (max-width: 768px) {
|
|
1263
|
+
.pkpay-overlay {
|
|
177
1264
|
padding: 0;
|
|
178
1265
|
}
|
|
179
|
-
|
|
1266
|
+
|
|
1267
|
+
.pkpay-dialog {
|
|
180
1268
|
max-width: 100%;
|
|
181
1269
|
height: 100%;
|
|
182
1270
|
max-height: 100vh;
|
|
183
1271
|
border-radius: 0;
|
|
1272
|
+
grid-template-columns: 1fr;
|
|
1273
|
+
grid-template-rows: auto 1fr;
|
|
1274
|
+
}
|
|
1275
|
+
|
|
1276
|
+
.pkpay-customer-pane {
|
|
1277
|
+
border-right: none;
|
|
1278
|
+
border-bottom: 1px solid var(--pkpay-border);
|
|
1279
|
+
padding: 16px;
|
|
1280
|
+
max-height: 40vh;
|
|
1281
|
+
}
|
|
1282
|
+
|
|
1283
|
+
.pkpay-form-row {
|
|
1284
|
+
grid-template-columns: 1fr;
|
|
184
1285
|
}
|
|
185
1286
|
}
|
|
186
1287
|
`;
|
|
187
1288
|
document.head.appendChild(style);
|
|
188
1289
|
}
|
|
1290
|
+
|
|
1291
|
+
// src/dialog.ts
|
|
189
1292
|
function createCheckoutDialog(options) {
|
|
190
1293
|
if (typeof document === "undefined") {
|
|
191
1294
|
throw new Error(
|
|
192
1295
|
"createCheckoutDialog can only be invoked in a browser environment with window and document."
|
|
193
1296
|
);
|
|
194
1297
|
}
|
|
195
|
-
|
|
1298
|
+
injectThemeStyles();
|
|
196
1299
|
const previousOverflow = document.body.style.overflow;
|
|
197
1300
|
document.body.style.overflow = "hidden";
|
|
198
1301
|
const overlay = document.createElement("div");
|
|
199
|
-
overlay.className = "pkpayplus-overlay";
|
|
1302
|
+
overlay.className = "pkpay-overlay pkpayplus-overlay";
|
|
200
1303
|
const dialog = document.createElement("div");
|
|
201
|
-
dialog.className = "
|
|
1304
|
+
dialog.className = "pkpay-dialog";
|
|
1305
|
+
const showCustomer = options.showCustomerForm !== false;
|
|
1306
|
+
if (!showCustomer) {
|
|
1307
|
+
dialog.classList.add("pkpay-compact");
|
|
1308
|
+
}
|
|
1309
|
+
const iframePane = document.createElement("div");
|
|
1310
|
+
iframePane.className = "pkpay-iframe-pane";
|
|
202
1311
|
const closeBtn = document.createElement("button");
|
|
203
|
-
closeBtn.
|
|
1312
|
+
closeBtn.type = "button";
|
|
1313
|
+
closeBtn.className = "pkpay-close-btn";
|
|
204
1314
|
closeBtn.setAttribute("aria-label", "Close PKPay+ Checkout");
|
|
205
|
-
closeBtn.innerHTML =
|
|
1315
|
+
closeBtn.innerHTML = `
|
|
1316
|
+
<svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round">
|
|
1317
|
+
<line x1="18" y1="6" x2="6" y2="18"></line>
|
|
1318
|
+
<line x1="6" y1="6" x2="18" y2="18"></line>
|
|
1319
|
+
</svg>
|
|
1320
|
+
`;
|
|
1321
|
+
const loader = document.createElement("div");
|
|
1322
|
+
loader.className = "pkpay-iframe-loader";
|
|
1323
|
+
loader.innerHTML = `
|
|
1324
|
+
<div class="pkpay-spinner"></div>
|
|
1325
|
+
<span class="pkpay-loader-text">Loading secure payment...</span>
|
|
1326
|
+
`;
|
|
206
1327
|
const iframe = document.createElement("iframe");
|
|
207
|
-
iframe.className = "
|
|
1328
|
+
iframe.className = "pkpay-iframe";
|
|
208
1329
|
iframe.src = options.url;
|
|
209
1330
|
iframe.setAttribute("allow", "payment *; camera *");
|
|
1331
|
+
iframe.setAttribute("scrolling", "no");
|
|
210
1332
|
iframe.setAttribute("title", "PKPay+ Secure Checkout");
|
|
211
|
-
|
|
212
|
-
|
|
1333
|
+
const hideLoader = () => {
|
|
1334
|
+
loader.style.opacity = "0";
|
|
1335
|
+
loader.style.pointerEvents = "none";
|
|
1336
|
+
setTimeout(() => {
|
|
1337
|
+
if (loader.parentNode) {
|
|
1338
|
+
loader.parentNode.removeChild(loader);
|
|
1339
|
+
}
|
|
1340
|
+
}, 200);
|
|
1341
|
+
};
|
|
1342
|
+
iframe.addEventListener("load", hideLoader);
|
|
1343
|
+
const sendCustomerUpdateToIframe = (customer) => {
|
|
1344
|
+
try {
|
|
1345
|
+
const fullName = (customer.name || "").trim();
|
|
1346
|
+
const customerPayload = {
|
|
1347
|
+
type: "pkplus_customer_update",
|
|
1348
|
+
event: "pkplus_customer_update",
|
|
1349
|
+
data: {
|
|
1350
|
+
name: fullName,
|
|
1351
|
+
email: customer.email || "",
|
|
1352
|
+
phone: customer.phone || "",
|
|
1353
|
+
country: customer.billing?.country || "US",
|
|
1354
|
+
address: customer.billing?.address_1 || "",
|
|
1355
|
+
city: customer.billing?.city || "",
|
|
1356
|
+
state: customer.billing?.state || "",
|
|
1357
|
+
postal_code: customer.billing?.postcode || ""
|
|
1358
|
+
}
|
|
1359
|
+
};
|
|
1360
|
+
iframe.contentWindow?.postMessage(customerPayload, "*");
|
|
1361
|
+
} catch {
|
|
1362
|
+
}
|
|
1363
|
+
};
|
|
1364
|
+
let customerForm = null;
|
|
1365
|
+
if (showCustomer) {
|
|
1366
|
+
customerForm = createCustomerForm({
|
|
1367
|
+
initialData: options.customer,
|
|
1368
|
+
onChange: (customer) => {
|
|
1369
|
+
sendCustomerUpdateToIframe(customer);
|
|
1370
|
+
}
|
|
1371
|
+
});
|
|
1372
|
+
dialog.appendChild(customerForm.element);
|
|
1373
|
+
}
|
|
1374
|
+
const paymentHeader = document.createElement("div");
|
|
1375
|
+
paymentHeader.className = "pkpay-payment-header";
|
|
1376
|
+
paymentHeader.innerHTML = `
|
|
1377
|
+
<div class="pkpay-payment-title-row">
|
|
1378
|
+
<span class="pkpay-payment-title">
|
|
1379
|
+
<span class="pkpay-radio-dot"></span>
|
|
1380
|
+
PKPay+ Secured Checkout
|
|
1381
|
+
</span>
|
|
1382
|
+
<div class="pkpay-brand-badges">
|
|
1383
|
+
<span class="pkpay-brand-badge">VISA</span>
|
|
1384
|
+
<span class="pkpay-brand-badge">MC</span>
|
|
1385
|
+
<span class="pkpay-brand-badge">AMEX</span>
|
|
1386
|
+
<span class="pkpay-brand-badge">GPAY</span>
|
|
1387
|
+
</div>
|
|
1388
|
+
</div>
|
|
1389
|
+
<p class="pkpay-payment-subtitle">Pay with your credit or debit card via our secure payment gateway.</p>
|
|
1390
|
+
`;
|
|
1391
|
+
const cardBox = document.createElement("div");
|
|
1392
|
+
cardBox.className = "pkpay-card-box";
|
|
1393
|
+
cardBox.appendChild(loader);
|
|
1394
|
+
cardBox.appendChild(iframe);
|
|
1395
|
+
const processingOverlay = document.createElement("div");
|
|
1396
|
+
processingOverlay.className = "pkpay-processing-overlay";
|
|
1397
|
+
processingOverlay.innerHTML = `
|
|
1398
|
+
<div class="pkpay-spinner" style="width: 26px; height: 26px; border-width: 2.5px; border-color: #cbd5e1; border-top-color: #2563eb;"></div>
|
|
1399
|
+
<p class="pkpay-processing-text">Verifying device & processing...</p>
|
|
1400
|
+
<p class="pkpay-processing-subtext">Please do not close or refresh this window</p>
|
|
1401
|
+
`;
|
|
1402
|
+
cardBox.appendChild(processingOverlay);
|
|
1403
|
+
const termsNotice = document.createElement("p");
|
|
1404
|
+
termsNotice.className = "pkpay-terms-notice";
|
|
1405
|
+
termsNotice.textContent = "Your personal data will be used to process your order, support your experience throughout this website, and for other purposes described in our privacy policy.";
|
|
1406
|
+
const errorAlert = document.createElement("div");
|
|
1407
|
+
errorAlert.className = "pkpay-form-message";
|
|
1408
|
+
errorAlert.style.marginBottom = "10px";
|
|
1409
|
+
errorAlert.style.padding = "8px 12px";
|
|
1410
|
+
errorAlert.style.borderRadius = "6px";
|
|
1411
|
+
errorAlert.style.background = "#fef2f2";
|
|
1412
|
+
errorAlert.style.border = "1px solid #fecaca";
|
|
1413
|
+
const payBtn = document.createElement("button");
|
|
1414
|
+
payBtn.type = "button";
|
|
1415
|
+
payBtn.className = "pkpay-submit-btn";
|
|
1416
|
+
payBtn.innerHTML = `
|
|
1417
|
+
<svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round">
|
|
1418
|
+
<rect x="3" y="11" width="18" height="11" rx="2" ry="2"></rect>
|
|
1419
|
+
<path d="M7 11V7a5 5 0 0 1 10 0v4"></path>
|
|
1420
|
+
</svg>
|
|
1421
|
+
<span>Pay Now</span>
|
|
1422
|
+
`;
|
|
1423
|
+
let isCardReady = false;
|
|
1424
|
+
let paymentTimeout = null;
|
|
1425
|
+
const handleCardReadyMessage = (event) => {
|
|
1426
|
+
if (event.data?.event === "pkplus_card_ready" || event.data?.event === "paydios_card_ready") {
|
|
1427
|
+
isCardReady = Boolean(event.data?.ready);
|
|
1428
|
+
if (isCardReady && errorAlert.style.display === "block") {
|
|
1429
|
+
errorAlert.style.display = "none";
|
|
1430
|
+
}
|
|
1431
|
+
}
|
|
1432
|
+
};
|
|
1433
|
+
window.addEventListener("message", handleCardReadyMessage);
|
|
1434
|
+
const resetPayButton = () => {
|
|
1435
|
+
processingOverlay.classList.remove("pkpay-visible");
|
|
1436
|
+
if (paymentTimeout) {
|
|
1437
|
+
clearTimeout(paymentTimeout);
|
|
1438
|
+
paymentTimeout = null;
|
|
1439
|
+
}
|
|
1440
|
+
payBtn.disabled = false;
|
|
1441
|
+
payBtn.classList.remove("pkpay-loading");
|
|
1442
|
+
payBtn.innerHTML = `
|
|
1443
|
+
<svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round">
|
|
1444
|
+
<rect x="3" y="11" width="18" height="11" rx="2" ry="2"></rect>
|
|
1445
|
+
<path d="M7 11V7a5 5 0 0 1 10 0v4"></path>
|
|
1446
|
+
</svg>
|
|
1447
|
+
<span>Pay Now</span>
|
|
1448
|
+
`;
|
|
1449
|
+
};
|
|
1450
|
+
payBtn.addEventListener("click", () => {
|
|
1451
|
+
errorAlert.style.display = "none";
|
|
1452
|
+
if (customerForm) {
|
|
1453
|
+
const isValid = customerForm.validate();
|
|
1454
|
+
if (!isValid) {
|
|
1455
|
+
const firstInvalid = customerForm.element.querySelector(".pkpay-input-error");
|
|
1456
|
+
firstInvalid?.focus();
|
|
1457
|
+
return;
|
|
1458
|
+
}
|
|
1459
|
+
sendCustomerUpdateToIframe(customerForm.getData());
|
|
1460
|
+
} else if (options.customer) {
|
|
1461
|
+
sendCustomerUpdateToIframe(options.customer);
|
|
1462
|
+
}
|
|
1463
|
+
payBtn.disabled = true;
|
|
1464
|
+
payBtn.classList.add("pkpay-loading");
|
|
1465
|
+
payBtn.innerHTML = `
|
|
1466
|
+
<div class="pkpay-spinner" style="width: 16px; height: 16px; border-width: 2px;"></div>
|
|
1467
|
+
<span>Processing payment...</span>
|
|
1468
|
+
`;
|
|
1469
|
+
processingOverlay.classList.add("pkpay-visible");
|
|
1470
|
+
if (paymentTimeout) clearTimeout(paymentTimeout);
|
|
1471
|
+
paymentTimeout = setTimeout(() => {
|
|
1472
|
+
resetPayButton();
|
|
1473
|
+
errorAlert.textContent = "Payment request timed out. Please check your card details and try again.";
|
|
1474
|
+
errorAlert.style.display = "block";
|
|
1475
|
+
}, 25e3);
|
|
1476
|
+
setTimeout(() => {
|
|
1477
|
+
iframe.contentWindow?.postMessage(
|
|
1478
|
+
{ event: "pkplus_place_order" },
|
|
1479
|
+
"*"
|
|
1480
|
+
);
|
|
1481
|
+
}, 100);
|
|
1482
|
+
});
|
|
1483
|
+
iframePane.appendChild(closeBtn);
|
|
1484
|
+
iframePane.appendChild(paymentHeader);
|
|
1485
|
+
iframePane.appendChild(cardBox);
|
|
1486
|
+
iframePane.appendChild(termsNotice);
|
|
1487
|
+
iframePane.appendChild(errorAlert);
|
|
1488
|
+
iframePane.appendChild(payBtn);
|
|
1489
|
+
dialog.appendChild(iframePane);
|
|
213
1490
|
overlay.appendChild(dialog);
|
|
214
1491
|
document.body.appendChild(overlay);
|
|
215
1492
|
requestAnimationFrame(() => {
|
|
216
|
-
overlay.classList.add("
|
|
1493
|
+
overlay.classList.add("pkpay-visible");
|
|
217
1494
|
});
|
|
218
1495
|
let isClosed = false;
|
|
219
1496
|
const cleanup = () => {
|
|
220
1497
|
if (isClosed) return;
|
|
221
1498
|
isClosed = true;
|
|
222
1499
|
document.body.style.overflow = previousOverflow;
|
|
223
|
-
overlay.classList.remove("
|
|
1500
|
+
overlay.classList.remove("pkpay-visible");
|
|
1501
|
+
if (paymentTimeout) {
|
|
1502
|
+
clearTimeout(paymentTimeout);
|
|
1503
|
+
paymentTimeout = null;
|
|
1504
|
+
}
|
|
1505
|
+
window.removeEventListener("message", handleCardReadyMessage);
|
|
224
1506
|
cleanupEvents();
|
|
225
1507
|
window.removeEventListener("keydown", handleKeyDown);
|
|
226
1508
|
setTimeout(() => {
|
|
@@ -240,9 +1522,18 @@ function createCheckoutDialog(options) {
|
|
|
240
1522
|
};
|
|
241
1523
|
closeBtn.addEventListener("click", handleClose);
|
|
242
1524
|
window.addEventListener("keydown", handleKeyDown);
|
|
1525
|
+
const onReady = () => {
|
|
1526
|
+
hideLoader();
|
|
1527
|
+
if (customerForm) {
|
|
1528
|
+
sendCustomerUpdateToIframe(customerForm.getData());
|
|
1529
|
+
} else if (options.customer) {
|
|
1530
|
+
sendCustomerUpdateToIframe(options.customer);
|
|
1531
|
+
}
|
|
1532
|
+
options.onLoaded?.();
|
|
1533
|
+
};
|
|
243
1534
|
const cleanupEvents = setupPostMessageListener({
|
|
244
1535
|
targetUrl: options.url,
|
|
245
|
-
onLoaded:
|
|
1536
|
+
onLoaded: onReady,
|
|
246
1537
|
onSuccess: (data) => {
|
|
247
1538
|
cleanup();
|
|
248
1539
|
options.onSuccess?.(data);
|
|
@@ -252,14 +1543,19 @@ function createCheckoutDialog(options) {
|
|
|
252
1543
|
options.onCancel?.();
|
|
253
1544
|
},
|
|
254
1545
|
onError: (error) => {
|
|
255
|
-
|
|
1546
|
+
resetPayButton();
|
|
1547
|
+
errorAlert.textContent = error.message || "Payment failed. Please try again.";
|
|
1548
|
+
errorAlert.style.display = "block";
|
|
256
1549
|
options.onError?.(error);
|
|
257
1550
|
}
|
|
258
1551
|
});
|
|
259
1552
|
return {
|
|
260
1553
|
close: cleanup,
|
|
261
1554
|
iframe,
|
|
262
|
-
container: overlay
|
|
1555
|
+
container: overlay,
|
|
1556
|
+
updateCustomer: (data) => {
|
|
1557
|
+
customerForm?.setValues(data);
|
|
1558
|
+
}
|
|
263
1559
|
};
|
|
264
1560
|
}
|
|
265
1561
|
|
|
@@ -503,6 +1799,7 @@ var Webhooks = class {
|
|
|
503
1799
|
};
|
|
504
1800
|
// Annotate the CommonJS export names for ESM import in node:
|
|
505
1801
|
0 && (module.exports = {
|
|
1802
|
+
COUNTRIES,
|
|
506
1803
|
HTTPClient,
|
|
507
1804
|
PKPayPlusAPIConnectionError,
|
|
508
1805
|
PKPayPlusAuthenticationError,
|
|
@@ -510,12 +1807,19 @@ var Webhooks = class {
|
|
|
510
1807
|
PKPayPlusInvalidRequestError,
|
|
511
1808
|
PKPayPlusRateLimitError,
|
|
512
1809
|
PKPayPlusSecurityError,
|
|
1810
|
+
THEME_STYLE_ID,
|
|
513
1811
|
Webhooks,
|
|
514
1812
|
assertClientKey,
|
|
515
1813
|
assertServerEnvironment,
|
|
516
1814
|
assertServerKey,
|
|
517
1815
|
createCheckoutDialog,
|
|
1816
|
+
createCountryCombobox,
|
|
1817
|
+
createCustomerForm,
|
|
1818
|
+
createFormMessage,
|
|
1819
|
+
createInput,
|
|
1820
|
+
createLabel,
|
|
518
1821
|
detectModeFromKey,
|
|
1822
|
+
injectThemeStyles,
|
|
519
1823
|
normalizeUrl,
|
|
520
1824
|
setupPostMessageListener
|
|
521
1825
|
});
|