@paypercut/checkout-js 1.0.15 → 1.0.16
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 +9 -4
- package/dist/index.cjs +1 -1
- package/dist/index.mjs +1 -1
- package/dist/paypercut-checkout.iife.min.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -56,12 +56,12 @@ pnpm add @paypercut/checkout-js
|
|
|
56
56
|
|
|
57
57
|
```html
|
|
58
58
|
<!-- jsDelivr (recommended with SRI) -->
|
|
59
|
-
<script src="https://cdn.jsdelivr.net/npm/@paypercut/checkout-js@1.0.
|
|
59
|
+
<script src="https://cdn.jsdelivr.net/npm/@paypercut/checkout-js@1.0.16/dist/paypercut-checkout.iife.min.js"
|
|
60
60
|
integrity="sha384-..."
|
|
61
61
|
crossorigin="anonymous"></script>
|
|
62
62
|
|
|
63
63
|
<!-- or UNPKG -->
|
|
64
|
-
<script src="https://unpkg.com/@paypercut/checkout-js@1.0.
|
|
64
|
+
<script src="https://unpkg.com/@paypercut/checkout-js@1.0.16/dist/paypercut-checkout.iife.min.js"></script>
|
|
65
65
|
```
|
|
66
66
|
|
|
67
67
|
---
|
|
@@ -130,6 +130,8 @@ Creates a new checkout instance.
|
|
|
130
130
|
| `wallet_options` | `string[]` | No | `['apple_pay', 'google_pay']` | Digital wallet options. Pass `[]` to disable all wallets |
|
|
131
131
|
| `form_only` | `boolean` | No | `false` | Show only payment form (no Pay Now button - use external button with `submit()`) |
|
|
132
132
|
| `validate_form` | `boolean` | No | `false` | This indicates that Google Pay/Apple Pay flow to proceed you need to confirm form validation. For EMBEDDED checkouts only) |
|
|
133
|
+
| `appearance` | `object` | No | `undefined` | Appearance configuration for the checkout UI |
|
|
134
|
+
| `appearance.preset` | `'modal' \| 'inline'` | No | `undefined` | Controls checkout layout preset. `'modal'` shows the order summary (TotalCard) and header inside the iframe — use when rendering in a modal/dialog. `'inline'` hides the TotalCard — use when the merchant renders their own order summary outside the checkout. |
|
|
133
135
|
|
|
134
136
|
#### Examples
|
|
135
137
|
|
|
@@ -153,7 +155,10 @@ const checkout = PaypercutCheckout({
|
|
|
153
155
|
ui_mode: 'embedded', // 'hosted' | 'embedded'
|
|
154
156
|
wallet_options: ['apple_pay', 'google_pay'], // Can be empty array [] or contain one/both options
|
|
155
157
|
form_only: false, // Set true to hide Pay Now button (use external button),
|
|
156
|
-
validate_form: true
|
|
158
|
+
validate_form: true, // Set true to require form validation before wallet payment
|
|
159
|
+
appearance: {
|
|
160
|
+
preset: 'modal', // 'modal' | 'inline' — 'modal' shows TotalCard + header, 'inline' hides them
|
|
161
|
+
},
|
|
157
162
|
});
|
|
158
163
|
```
|
|
159
164
|
|
|
@@ -738,7 +743,7 @@ Tip: Prefer subscribing with the SdkEvent enum for stronger typing.
|
|
|
738
743
|
<body>
|
|
739
744
|
<div id="checkout"></div>
|
|
740
745
|
|
|
741
|
-
<script src="https://cdn.jsdelivr.net/npm/@paypercut/checkout-js@1.0.
|
|
746
|
+
<script src="https://cdn.jsdelivr.net/npm/@paypercut/checkout-js@1.0.16/dist/paypercut-checkout.iife.min.js"></script>
|
|
742
747
|
<script>
|
|
743
748
|
const checkout = PaypercutCheckout({
|
|
744
749
|
id: '01KB23M9EC960C50G3AH14FTTT',
|
package/dist/index.cjs
CHANGED
package/dist/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var PaypercutCheckout=function(){"use strict";class e{constructor(){this.handlers=new Map}on(e,t){return this.handlers.has(e)||this.handlers.set(e,new Set),this.handlers.get(e).add(t),()=>this.off(e,t)}once(e,t){const s=(...o)=>{t(...o),this.off(e,s)};return this.on(e,s)}off(e,t){this.handlers.get(e)?.delete(t)}emit(e,...t){this.handlers.get(e)?.forEach(s=>{try{s(...t)}catch(t){console.error(`[Emitter] Error in ${e} handler:`,t)}})}clear(){this.handlers.clear()}}const t={version:"1.0.
|
|
1
|
+
var PaypercutCheckout=function(){"use strict";class e{constructor(){this.handlers=new Map}on(e,t){return this.handlers.has(e)||this.handlers.set(e,new Set),this.handlers.get(e).add(t),()=>this.off(e,t)}once(e,t){const s=(...o)=>{t(...o),this.off(e,s)};return this.on(e,s)}off(e,t){this.handlers.get(e)?.delete(t)}emit(e,...t){this.handlers.get(e)?.forEach(s=>{try{s(...t)}catch(t){console.error(`[Emitter] Error in ${e} handler:`,t)}})}clear(){this.handlers.clear()}}const t={version:"1.0.16",defaultCheckoutOrigin:"https://buy.paypercut.io",allowedOrigins:["https://buy.paypercut.io"]};function s(e){return t.defaultCheckoutOrigin}const o=new Set(["bg","bg-BG","en","en-GB","el","el-GR","ro","ro-RO","hr","hr-HR","pl","pl-PL","cs","cs-CZ","sl","sl-SI","sk","sk-SK"]);function i(e){return e&&"auto"!==e?o.has(e)?e:(console.warn(`[PaypercutCheckout] Locale "${e}" is not supported. Falling back to "en".`),"en"):"en"}var r,a,n,h;function c(e){return Object.values(a).includes(e)}function d(e){return Object.values(n).includes(e)}function l(e){var t;if(e)return t=e,Object.values(r).includes(t)?e:void console.warn(`[PaypercutCheckout] Invalid ui_mode: "${e}". Valid options: ${Object.values(r).join(", ")}`)}!function(e){e.EMBEDDED="embedded"}(r||(r={})),function(e){e.CARD="card"}(a||(a={})),function(e){e.APPLE_PAY="apple_pay",e.GOOGLE_PAY="google_pay"}(n||(n={})),function(e){e.Loaded="loaded",e.Success="success",e.Error="error",e.Expired="expired",e.Resize="resize",e.ThreeDSComplete="threeds_complete",e.ThreeDSError="threeds_error",e.ThreeDSCanceled="threeds_canceled",e.ThreeDSStarted="threeds_started",e.FormValidation="form_validation"}(h||(h={}));class m{constructor(t){this.options=t,this.emitter=new e,this.mounted=!1,this.destroyed=!1,this.iframe=null,this.threeDSModal=null,this.threeDSIframe=null,this.messageHandler=this.onMessage.bind(this),window.addEventListener("message",this.messageHandler)}buildSrc(){const e=s(this.options.hostedCheckoutUrl),t=new URL(`/c/${this.options.id}`,e);if(this.options.locale){const e=i(this.options.locale);t.searchParams.set("locale",e)}if(this.options.lang){const e=i(this.options.lang);t.searchParams.set("lang",e)}{const e=l(this.options.ui_mode??r.EMBEDDED);e&&t.searchParams.set("ui_mode",e)}if(this.options.payment_methods&&this.options.payment_methods.length>0){(function(e){const t=[];for(const s of e)c(s)?t.push(s):console.warn(`[PaypercutCheckout] Invalid payment method: "${s}". Skipping.`);return 0===t.length&&(console.warn('[PaypercutCheckout] No valid payment methods provided. Defaulting to "card".'),t.push(a.CARD)),t})(this.options.payment_methods).forEach(e=>{t.searchParams.append("payment_methods",e)})}if(void 0!==this.options.wallet_options)if(0===this.options.wallet_options.length)t.searchParams.set("wallet_options",null);else{(function(e){const t=[];for(const s of e)d(s)?t.push(s):console.warn(`[PaypercutCheckout] Invalid wallet option: "${s}". Skipping.`);return t})(this.options.wallet_options).forEach(e=>{t.searchParams.append("wallet_options",e)})}return this.options.appearance?.preset&&t.searchParams.set("preset",this.options.appearance.preset),void 0!==this.options.form_only&&t.searchParams.set("form_only",String(this.options.form_only)),void 0!==this.options.validate_form&&t.searchParams.set("validate_form",String(this.options.validate_form)),t.toString()}getContainer(){const e="string"==typeof this.options.containerId?document.querySelector(this.options.containerId):this.options.containerId;if(!e)throw new Error(`Container not found: ${this.options.containerId}`);return e}onMessage(e){if(s=e.origin,!t.allowedOrigins.includes(s))return;var s;const o=e.data;if(o&&"object"==typeof o&&"type"in o&&(!o.checkoutId||o.checkoutId===this.options.id))switch(o.type){case"CHECKOUT_LOADED":this.emitter.emit(h.Loaded);break;case"CHECKOUT_SUCCESS":const{payment_method:e={}}=o;this.emitter.emit(h.Success,{payment_method:e});break;case"CHECKOUT_ERROR":this.emitter.emit(h.Error,(o&&o.error)??o);break;case"CHECKOUT_EXPIRED":this.emitter.emit(h.Expired);break;case"CHECKOUT_RESIZE":this.emitter.emit(h.Resize,o.height),this.handleResize(o.height);break;case"THREEDS_START_FLOW":this.show3DSModal(o),this.emitter.emit(h.ThreeDSStarted);break;case"THREEDS_READY":this.handle3DSReady();break;case"THREEDS_COMPLETE":this.postToIframe(o),this.close3DSModal(),this.emitter.emit(h.ThreeDSComplete);break;case"THREEDS_CANCELED":this.postToIframe(o),this.close3DSModal(),this.emitter.emit(h.ThreeDSCanceled);break;case"THREEDS_ERROR":this.postToIframe(o),this.close3DSModal(),this.emitter.emit(h.ThreeDSError,o.error);break;case"FORM_VALIDATION":this.emitter.emit(h.FormValidation,{checkoutId:o.checkoutId,wallet:o.wallet})}}render(){if(!this.mounted)try{const e=this.getContainer();this.iframe=document.createElement("iframe"),this.iframe.id="paypercut-checkout-iframe",this.iframe.src=this.buildSrc(),this.iframe.allow="payment *; clipboard-write",this.iframe.setAttribute("frameborder","0"),this.iframe.setAttribute("allowpaymentrequest","true"),this.iframe.setAttribute("sandbox","allow-scripts allow-forms allow-same-origin allow-popups allow-popups-to-escape-sandbox"),Object.assign(this.iframe.style,{width:"100%",height:"100%",border:"none",display:"block"}),e.appendChild(this.iframe),this.mounted=!0}catch(e){throw console.error("[PaypercutCheckout] Failed to render:",e),e}}submit(){if(this.mounted)try{this.postToIframe({type:"START_PROCESSING",checkoutId:this.options.id})}catch(e){throw console.error("[PaypercutCheckout] Failed to submit payment:",e),e}}postToIframe(e){if(!this.iframe?.contentWindow)return void console.error("[PaypercutCheckout] Cannot post message: iframe not mounted");const t=s(this.options.hostedCheckoutUrl);this.iframe.contentWindow.postMessage(e,t)}handleResize(e){!this.iframe||"number"!=typeof e||e<=0||(this.iframe.style.height=`${e}px`)}show3DSModal(e){this.threeDSModal=document.createElement("div"),this.threeDSModal.id="paypercut-3ds-modal",Object.assign(this.threeDSModal.style,{position:"fixed",top:"0",left:"0",width:"100%",height:"100%",display:"flex",alignItems:"center",justifyContent:"center",zIndex:"999999",background:"rgba(0, 0, 0, 0.4)"}),this.threeDSIframe=document.createElement("iframe");const t=s(this.options.hostedCheckoutUrl),o=new URL(`/c/${this.options.id}/threeds`,t);o.searchParams.set("sessionId",e.sessionId),o.searchParams.set("step",e.step),e.challengeUrl&&o.searchParams.set("challengeUrl",e.challengeUrl),e.acsTransactionId&&o.searchParams.set("acsTransactionId",e.acsTransactionId),e.threeDSVersion&&o.searchParams.set("threeDSVersion",e.threeDSVersion),o.searchParams.set("liveMode",String(e.liveMode??!1)),this.threeDSIframe.src=o.toString(),this.threeDSIframe.allow="payment *",this.threeDSIframe.setAttribute("frameborder","0"),Object.assign(this.threeDSIframe.style,{minWidth:"400px",minHeight:"400px",border:"none",borderRadius:"8px",display:"block",background:"transparent"}),this.threeDSModal.appendChild(this.threeDSIframe),document.body.appendChild(this.threeDSModal),this.pending3DSData=e}handle3DSReady(){if(!this.pending3DSData||!this.threeDSIframe?.contentWindow)return void console.error("[PaypercutCheckout] No pending 3DS data or iframe not ready");const e=s(this.options.hostedCheckoutUrl);this.threeDSIframe.contentWindow.postMessage({type:"THREEDS_INIT",checkoutId:this.options.id},e)}close3DSModal(){this.threeDSModal&&(this.threeDSModal.remove(),this.threeDSModal=null),this.threeDSIframe=null,delete this.pending3DSData}destroy(){if(!this.destroyed){if(this.iframe)try{this.iframe.remove(),this.iframe=null}catch(e){console.error("[PaypercutCheckout] Error removing iframe:",e)}this.close3DSModal(),this.mounted=!1,this.destroyed=!0,window.removeEventListener("message",this.messageHandler),this.emitter.clear()}}on(e,t){return this.emitter.on(e,t)}once(e,t){return this.emitter.once(e,t)}off(e,t){this.emitter.off(e,t)}isMounted(){return this.mounted}completeFormValidation(e){this.mounted?this.postToIframe({type:"FORM_VALIDATION_COMPLETED",checkoutId:this.options.id,wallet:e,status:"success"}):console.warn("[PaypercutCheckout] Cannot complete form validation: not mounted")}failFormValidation(e,t){this.mounted?this.postToIframe({type:"FORM_VALIDATION_COMPLETED",checkoutId:this.options.id,wallet:e,status:"failed",errors:t}):console.warn("[PaypercutCheckout] Cannot fail form validation: not mounted")}}const p=function(e){return new m(e)};return p.version=t.version,p}();
|
|
2
2
|
//# sourceMappingURL=paypercut-checkout.iife.min.js.map
|