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