@paypercut/checkout-js 1.4.0 → 1.4.2
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 +36 -1
- package/dist/developer-assistance.cjs +119 -18
- package/dist/developer-assistance.cjs.map +1 -1
- package/dist/developer-assistance.mjs +119 -18
- package/dist/developer-assistance.mjs.map +1 -1
- package/dist/index.cjs +318 -36
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +16 -9
- package/dist/index.d.mts +16 -9
- package/dist/index.d.ts +16 -9
- package/dist/index.mjs +318 -36
- package/dist/index.mjs.map +1 -1
- package/dist/paypercut-checkout.iife.min.js +1 -1
- package/dist/paypercut-checkout.iife.min.js.map +1 -1
- package/dist/paypercut-developer-assistance.iife.min.js +1 -1
- package/dist/paypercut-developer-assistance.iife.min.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -102,6 +102,41 @@ Mounting an Element never creates a Payment Method and never creates or confirms
|
|
|
102
102
|
a payment. The merchant server remains authoritative for the final amount,
|
|
103
103
|
currency, order state, authorization, capture, and fulfillment.
|
|
104
104
|
|
|
105
|
+
### Connected account context
|
|
106
|
+
|
|
107
|
+
Platforms can initialize an Elements client with their platform publishable key
|
|
108
|
+
and the connected account selected for the payment:
|
|
109
|
+
|
|
110
|
+
```ts
|
|
111
|
+
import { Paypercut } from '@paypercut/checkout-js';
|
|
112
|
+
|
|
113
|
+
const paypercut = Paypercut('pk_live_PLATFORM', {
|
|
114
|
+
account: 'acc_merchant_A',
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
// The existing object initializer supports the same option:
|
|
118
|
+
// Paypercut({ publishableKey: 'pk_live_PLATFORM', account: 'acc_merchant_A' });
|
|
119
|
+
|
|
120
|
+
const elements = paypercut.elements({
|
|
121
|
+
mode: 'payment',
|
|
122
|
+
amount: 2500,
|
|
123
|
+
currency: 'EUR',
|
|
124
|
+
});
|
|
125
|
+
const card = elements.create('card');
|
|
126
|
+
card.mount('#card-element');
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
`account` is optional and fixed for the client lifetime. Every Elements group
|
|
130
|
+
created by that client inherits it, including Card, split card fields, and
|
|
131
|
+
Express Checkout Elements. `createPaymentMethod()`, `confirmPayment()`, and
|
|
132
|
+
`handleNextAction()` use that same context. Omit `account` to use the
|
|
133
|
+
credential's default account. To select another merchant, destroy the previous
|
|
134
|
+
groups and initialize a new client; `elements.update()` cannot change accounts.
|
|
135
|
+
|
|
136
|
+
Your server must use the same account context when using the Payment Method or
|
|
137
|
+
creating the payment resource whose client secret is returned to this client.
|
|
138
|
+
Do not reuse objects from another account.
|
|
139
|
+
|
|
105
140
|
### Developer Assistance
|
|
106
141
|
|
|
107
142
|
The Developer Assistant is an optional configuration preview tool for developers
|
|
@@ -1708,7 +1743,7 @@ Tip: Prefer subscribing with the SdkEvent enum for stronger typing.
|
|
|
1708
1743
|
<body>
|
|
1709
1744
|
<div id="checkout"></div>
|
|
1710
1745
|
|
|
1711
|
-
<script src="https://cdn.jsdelivr.net/npm/@paypercut/checkout-js@1.4.
|
|
1746
|
+
<script src="https://cdn.jsdelivr.net/npm/@paypercut/checkout-js@1.4.2/dist/paypercut-checkout.iife.min.js"></script>
|
|
1712
1747
|
<script>
|
|
1713
1748
|
const checkout = PaypercutCheckout({
|
|
1714
1749
|
id: '01KB23M9EC960C50G3AH14FTTT',
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
|
|
4
|
-
const SDK_VERSION = "1.4.
|
|
4
|
+
const SDK_VERSION = "1.4.2";
|
|
5
5
|
|
|
6
6
|
const ELEMENTS_APPEARANCE_VARIABLE_NAMES = [
|
|
7
7
|
'colorPrimary',
|
|
@@ -231,6 +231,7 @@ class DeveloperAssistantCoordinator {
|
|
|
231
231
|
configurationIdentity: active.configurationIdentity,
|
|
232
232
|
appearanceScopeId: active.appearanceScopeId,
|
|
233
233
|
...(presetTarget?.presets ? { presets: presetTarget.presets } : {}),
|
|
234
|
+
isVisible: () => identityTargets.some((target) => target.isVisible()),
|
|
234
235
|
isAvailable: () => presetTarget?.isAvailable() ?? true,
|
|
235
236
|
isAppearanceAvailable: () => appearanceTargets.every((target) => target.isAppearanceAvailable()),
|
|
236
237
|
didLastAppearancePreviewClearTestData: () => this.lastAppearancePreviewClearedTestData,
|
|
@@ -2493,15 +2494,89 @@ function createStyle() {
|
|
|
2493
2494
|
return style;
|
|
2494
2495
|
}
|
|
2495
2496
|
|
|
2497
|
+
const DEVELOPER_ASSISTANCE_BROWSER_ARTIFACT = 'paypercut-developer-assistance.iife.min.js';
|
|
2498
|
+
const DEVELOPER_ASSISTANCE_MODULE_ARTIFACT = 'developer-assistance.mjs';
|
|
2499
|
+
const DEVELOPER_ASSISTANCE_LOAD_DIAGNOSTIC = '[Paypercut Elements] developer_assistance_load_failed: Developer Assistant is unavailable. The SDK and Elements continue to work.';
|
|
2500
|
+
const IIFE_ARTIFACT_PATH = /\/paypercut-checkout(?:-dev)?\.iife\.min\.js$/;
|
|
2496
2501
|
// Rollup rewrites import.meta.url for CommonJS and classic-script bundles, so
|
|
2497
2502
|
// this remains the URL of the exact core artifact that owns the registration
|
|
2498
2503
|
// boundary in every supported format.
|
|
2499
|
-
typeof __filename === 'string' ? fileUrlFor(__filename) : (typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('developer-assistance.cjs', document.baseURI).href));
|
|
2500
|
-
typeof document === 'undefined' ? null : (document.currentScript?.getAttribute('src') ?? null);
|
|
2504
|
+
const coreArtifactUrl = typeof __filename === 'string' ? fileUrlFor(__filename) : (typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('developer-assistance.cjs', document.baseURI).href));
|
|
2505
|
+
const classicScriptUrl = typeof document === 'undefined' ? null : (document.currentScript?.getAttribute('src') ?? null);
|
|
2506
|
+
let loadRequested = false;
|
|
2507
|
+
function requestDeveloperAssistance(isInstalled) {
|
|
2508
|
+
if (loadRequested || isInstalled())
|
|
2509
|
+
return;
|
|
2510
|
+
loadRequested = true;
|
|
2511
|
+
if (!canLoadDeveloperAssistance()) {
|
|
2512
|
+
warnDeveloperAssistanceUnavailable();
|
|
2513
|
+
return;
|
|
2514
|
+
}
|
|
2515
|
+
void Promise.resolve()
|
|
2516
|
+
.then(loadDeveloperAssistance)
|
|
2517
|
+
.then(() => {
|
|
2518
|
+
if (!isInstalled())
|
|
2519
|
+
throw new Error();
|
|
2520
|
+
})
|
|
2521
|
+
.catch(warnDeveloperAssistanceUnavailable);
|
|
2522
|
+
}
|
|
2523
|
+
function warnDeveloperAssistanceUnavailable() {
|
|
2524
|
+
console.warn(DEVELOPER_ASSISTANCE_LOAD_DIAGNOSTIC);
|
|
2525
|
+
}
|
|
2526
|
+
function canLoadDeveloperAssistance() {
|
|
2527
|
+
return (typeof document !== 'undefined' &&
|
|
2528
|
+
typeof document.createElement === 'function' &&
|
|
2529
|
+
Boolean(document.head || document.documentElement));
|
|
2530
|
+
}
|
|
2531
|
+
function loadDeveloperAssistance() {
|
|
2532
|
+
if (classicScriptUrl || isClassicScriptArtifact(coreArtifactUrl)) {
|
|
2533
|
+
return loadClassicScript(resolveBrowserArtifactUrl(coreArtifactUrl));
|
|
2534
|
+
}
|
|
2535
|
+
const moduleUrl = new URL(DEVELOPER_ASSISTANCE_MODULE_ARTIFACT, coreArtifactUrl).href;
|
|
2536
|
+
return import(/* @vite-ignore */ moduleUrl);
|
|
2537
|
+
}
|
|
2501
2538
|
function fileUrlFor(filename) {
|
|
2502
2539
|
const normalized = filename.replace(/\\/g, '/');
|
|
2503
2540
|
return new URL(`file://${normalized.startsWith('/') ? '' : '/'}${normalized}`).href;
|
|
2504
2541
|
}
|
|
2542
|
+
function resolveBrowserArtifactUrl(coreUrl) {
|
|
2543
|
+
const url = new URL(coreUrl);
|
|
2544
|
+
if (IIFE_ARTIFACT_PATH.test(url.pathname)) {
|
|
2545
|
+
const artifactUrl = new URL(DEVELOPER_ASSISTANCE_BROWSER_ARTIFACT, url);
|
|
2546
|
+
artifactUrl.search = url.search;
|
|
2547
|
+
artifactUrl.hash = '';
|
|
2548
|
+
return artifactUrl.href;
|
|
2549
|
+
}
|
|
2550
|
+
if (/\.js$/.test(url.pathname)) {
|
|
2551
|
+
url.pathname = url.pathname.replace(/[^/]+$/, DEVELOPER_ASSISTANCE_BROWSER_ARTIFACT);
|
|
2552
|
+
}
|
|
2553
|
+
else if (/\/cdn\/?$/.test(url.pathname)) {
|
|
2554
|
+
url.pathname = url.pathname.replace(/\/cdn\/?$/, `/dist/${DEVELOPER_ASSISTANCE_BROWSER_ARTIFACT}`);
|
|
2555
|
+
}
|
|
2556
|
+
else {
|
|
2557
|
+
url.pathname = `${url.pathname.replace(/\/$/, '')}/dist/${DEVELOPER_ASSISTANCE_BROWSER_ARTIFACT}`;
|
|
2558
|
+
}
|
|
2559
|
+
url.hash = '';
|
|
2560
|
+
return url.href;
|
|
2561
|
+
}
|
|
2562
|
+
function isClassicScriptArtifact(url) {
|
|
2563
|
+
try {
|
|
2564
|
+
return IIFE_ARTIFACT_PATH.test(new URL(url).pathname);
|
|
2565
|
+
}
|
|
2566
|
+
catch {
|
|
2567
|
+
return false;
|
|
2568
|
+
}
|
|
2569
|
+
}
|
|
2570
|
+
function loadClassicScript(src) {
|
|
2571
|
+
return new Promise((resolve, reject) => {
|
|
2572
|
+
const script = document.createElement('script');
|
|
2573
|
+
script.async = true;
|
|
2574
|
+
script.src = src;
|
|
2575
|
+
script.addEventListener('load', () => resolve(), { once: true });
|
|
2576
|
+
script.addEventListener('error', () => reject(new Error()), { once: true });
|
|
2577
|
+
(document.head || document.documentElement).appendChild(script);
|
|
2578
|
+
});
|
|
2579
|
+
}
|
|
2505
2580
|
|
|
2506
2581
|
const registryKey = Symbol.for('paypercut.checkout-js.developer-assistance');
|
|
2507
2582
|
function getRegistry() {
|
|
@@ -2522,6 +2597,45 @@ function safelyUnregister(entry) {
|
|
|
2522
2597
|
}
|
|
2523
2598
|
entry.delegate = null;
|
|
2524
2599
|
}
|
|
2600
|
+
function safelyAttach(entry, provider) {
|
|
2601
|
+
if (!entry.registered || entry.delegate)
|
|
2602
|
+
return;
|
|
2603
|
+
try {
|
|
2604
|
+
entry.delegate = provider.register(entry.target);
|
|
2605
|
+
}
|
|
2606
|
+
catch {
|
|
2607
|
+
// A target can register before its hosted component is ready. Keep the
|
|
2608
|
+
// provider available for the other targets and retry this one on refresh.
|
|
2609
|
+
}
|
|
2610
|
+
}
|
|
2611
|
+
function isTargetVisible(entry) {
|
|
2612
|
+
try {
|
|
2613
|
+
return entry.target.isVisible?.() ?? true;
|
|
2614
|
+
}
|
|
2615
|
+
catch {
|
|
2616
|
+
// Developer Assistance is optional. A stale owner node must never make the
|
|
2617
|
+
// merchant page fail while its visibility is being reconciled.
|
|
2618
|
+
return false;
|
|
2619
|
+
}
|
|
2620
|
+
}
|
|
2621
|
+
function syncAttachment(entry, registry) {
|
|
2622
|
+
if (!entry.registered)
|
|
2623
|
+
return;
|
|
2624
|
+
if (!isTargetVisible(entry)) {
|
|
2625
|
+
safelyUnregister(entry);
|
|
2626
|
+
return;
|
|
2627
|
+
}
|
|
2628
|
+
if (registry.provider?.version === SDK_VERSION) {
|
|
2629
|
+
safelyAttach(entry, registry.provider);
|
|
2630
|
+
return;
|
|
2631
|
+
}
|
|
2632
|
+
requestDeveloperAssistance(() => hasAttachedDeveloperAssistant(registry));
|
|
2633
|
+
}
|
|
2634
|
+
function hasAttachedDeveloperAssistant(registry) {
|
|
2635
|
+
if (registry.provider?.version !== SDK_VERSION)
|
|
2636
|
+
return false;
|
|
2637
|
+
return Array.from(registry.registrations).some((entry) => entry.registered && entry.delegate !== null);
|
|
2638
|
+
}
|
|
2525
2639
|
function installDeveloperAssistantProvider(provider) {
|
|
2526
2640
|
const registry = getRegistry();
|
|
2527
2641
|
const incompatibleCoreVersion = Array.from(registry.coreVersions).find((version) => version !== provider.version);
|
|
@@ -2534,21 +2648,8 @@ function installDeveloperAssistantProvider(provider) {
|
|
|
2534
2648
|
throw new Error(`[Paypercut Elements] Developer Assistance ${provider.version} cannot replace ${registry.provider.version}.`);
|
|
2535
2649
|
}
|
|
2536
2650
|
registry.provider = provider;
|
|
2537
|
-
const
|
|
2538
|
-
|
|
2539
|
-
for (const entry of registry.registrations) {
|
|
2540
|
-
if (!entry.registered)
|
|
2541
|
-
continue;
|
|
2542
|
-
entry.delegate = provider.register(entry.target);
|
|
2543
|
-
attached.push(entry);
|
|
2544
|
-
}
|
|
2545
|
-
}
|
|
2546
|
-
catch (error) {
|
|
2547
|
-
for (const entry of attached.reverse()) {
|
|
2548
|
-
safelyUnregister(entry);
|
|
2549
|
-
}
|
|
2550
|
-
registry.provider = null;
|
|
2551
|
-
throw error;
|
|
2651
|
+
for (const entry of registry.registrations) {
|
|
2652
|
+
syncAttachment(entry, registry);
|
|
2552
2653
|
}
|
|
2553
2654
|
}
|
|
2554
2655
|
|