@flopay/react 1.9.29 → 1.10.0
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 +72 -4
- package/dist/card-setup-entry.cjs +2 -2
- package/dist/card-setup-entry.mjs +1 -1
- package/dist/{chunk-CSBYK62Y.mjs → chunk-I4TPZWBS.mjs} +1 -1
- package/dist/chunk-M7R46EDF.mjs +1 -0
- package/dist/chunk-OYOJA6FI.mjs +1 -0
- package/dist/chunk-R73QOXY5.mjs +1 -0
- package/dist/chunk-U3PMJDD4.mjs +1 -0
- package/dist/index.cjs +9 -9
- package/dist/index.d.cts +11 -1
- package/dist/index.d.ts +11 -1
- package/dist/index.mjs +8 -8
- package/dist/payment-method-setup-entry.cjs +6 -0
- package/dist/payment-method-setup-entry.d.cts +16 -0
- package/dist/payment-method-setup-entry.d.ts +16 -0
- package/dist/payment-method-setup-entry.mjs +1 -0
- package/dist/payment-method-setup-paypal-MWDJVYVO.mjs +1 -0
- package/dist/payment-method-setup-stripe-NCEEB7GN.mjs +1 -0
- package/dist/payment-method-setup-surface-BQltFPXs.d.cts +45 -0
- package/dist/payment-method-setup-surface-Zf-DUxA0.d.ts +45 -0
- package/package.json +8 -3
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @flopay/react
|
|
2
2
|
|
|
3
|
-
React bindings for the FloPay SDK: a drop-in `FloPayCheckout`, a no-charge `FloPayCardSetup`, a one-click `FloPayAutomaticPaymentButton`, composable checkout components, and hooks. Cards are collected by the billing API's hosted PCI card form; wallets, alternative payment methods, and PayPal render beside it from the session's gateways.
|
|
3
|
+
React bindings for the FloPay SDK: a drop-in `FloPayCheckout`, a no-charge `FloPayCardSetup` and `FloPayPaymentMethodSetup`, a one-click `FloPayAutomaticPaymentButton`, composable checkout components, and hooks. Cards are collected by the billing API's hosted PCI card form; wallets, alternative payment methods, and PayPal render beside it from the session's gateways.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
@@ -199,6 +199,19 @@ It drops only complete exception stacks with no app or `@flopay/*` frame and at
|
|
|
199
199
|
|
|
200
200
|
**`containerStyle` precedence.** Each `containerStyle` property wins over the preset's value for the same property, applied preset-first so a longhand refines a preset shorthand (for example `borderColor` keeps the preset border's width). Any `background*` member replaces the preset background entirely. With `classic` or raw colors, `containerStyle` applies alone.
|
|
201
201
|
|
|
202
|
+
### FloPayPaymentMethodSetup
|
|
203
|
+
|
|
204
|
+
`FloPayPaymentMethodSetup` lets a customer save any payment method the setup session offers, not only a card, without a purchase or charge. It takes the same `sessionId` and `nonce` as `FloPayCardSetup`, and the same callbacks, `theme` and `containerStyle`.
|
|
205
|
+
|
|
206
|
+
- **The session decides what renders.** The component renders exactly the methods the setup session advertises, and nothing else. `card` in the Stripe gateway's `enabledPaymentMethods` mounts the hosted card form. Every other entry is a Stripe wallet or alternative method, rendered with Stripe Elements in setup mode. A `paypal` gateway renders the PayPal vault flow. The SDK does no gateway selection, filtering or inference. Each rendered method's wrapper carries `data-flopay-payment-method="<method>"`.
|
|
207
|
+
- **Card-only sessions behave exactly like `FloPayCardSetup`.** They use the same hosted form, overlay wording (`SAVING CARD...`, `CARD SAVED`, `CARD NOT SAVED`) and callbacks, and never request Stripe.js. Stripe.js loads lazily, only when the session advertises a Stripe wallet or alternative method. A PayPal-only session never loads Stripe either.
|
|
208
|
+
- **Success is the backend's call.** `onComplete` fires once, only after the billing API reports the setup verified. For a wallet, alternative method or PayPal, provider approval alone is not success: the component re-reads the session until it completes. A decline, cancel or failure leaves previously saved methods unchanged; the component never lists, replaces or deletes saved methods.
|
|
209
|
+
- **Redirect methods return to the same page.** When the buyer comes back from a bank or wallet redirect (Stripe's `setup_intent` and `redirect_status` query parameters), the component re-reads the session. A completed session reports `onComplete`, and `redirect_status=failed` reports `onDecline`. Anything else waits for verification. The query parameters are removed once read. The hosted card path never posts `/3ds/complete`.
|
|
210
|
+
- **Wording.** Outcomes for non-card methods read `SAVING PAYMENT METHOD...`, `PAYMENT METHOD SAVED` and `PAYMENT METHOD NOT SAVED`.
|
|
211
|
+
- Import it from `@flopay/react/payment-method-setup` to keep Stripe off card-only and PayPal-only pages. The main entry re-exports it, but its module graph eagerly loads Stripe.js.
|
|
212
|
+
|
|
213
|
+
`FloPayCardSetup` is unchanged. Keep using it, and `@flopay/react/card-setup`, for card-only integrations.
|
|
214
|
+
|
|
202
215
|
### FloPayAutomaticPaymentButton
|
|
203
216
|
|
|
204
217
|
`FloPayAutomaticPaymentButton` is a single reusable button that creates an `auto` checkout session inline (or reuses a `sessionId`), lets the billing API charge the customer's most recently saved payment method across providers, and shows the shared processing, success, and failure modal. It accepts either `sessionId` and `nonce`, or the session-creation props `clientId`, `items`, `subscriptions`, `products`, `account`, `successUrl`, `cancelUrl`, `couponCodes`, `tagsData`, and `utmMetadata`. `children` render inside the button.
|
|
@@ -348,6 +361,30 @@ export function AddCard({ sessionId, nonce }: { sessionId: string; nonce: string
|
|
|
348
361
|
}
|
|
349
362
|
```
|
|
350
363
|
|
|
364
|
+
Save any payment method the setup session offers, without charging it:
|
|
365
|
+
|
|
366
|
+
```tsx
|
|
367
|
+
import { FloPayPaymentMethodSetup } from '@flopay/react/payment-method-setup';
|
|
368
|
+
|
|
369
|
+
export function AddPaymentMethod({ sessionId, nonce }: { sessionId: string; nonce: string }) {
|
|
370
|
+
return (
|
|
371
|
+
<FloPayPaymentMethodSetup
|
|
372
|
+
sessionId={sessionId}
|
|
373
|
+
nonce={nonce}
|
|
374
|
+
theme="modern-dark"
|
|
375
|
+
onComplete={({ paymentMethod }) => {
|
|
376
|
+
// Verified by the billing API. `paymentMethod` is present for cards; re-list methods from
|
|
377
|
+
// your server for the rest.
|
|
378
|
+
console.log('Saved', paymentMethod?.brand ?? 'payment method');
|
|
379
|
+
}}
|
|
380
|
+
onDecline={({ message }) => console.warn(message)}
|
|
381
|
+
onError={(error) => console.error(error.code, error.retryable ? 'retry' : 'do not retry')}
|
|
382
|
+
onCancel={() => console.log('Setup closed before it finished')}
|
|
383
|
+
/>
|
|
384
|
+
);
|
|
385
|
+
}
|
|
386
|
+
```
|
|
387
|
+
|
|
351
388
|
Charge a saved payment method with one button:
|
|
352
389
|
|
|
353
390
|
```tsx
|
|
@@ -431,6 +468,7 @@ export function ComposedCheckout({ session, nonce }: { session: CheckoutSession;
|
|
|
431
468
|
|-----------|-------------|
|
|
432
469
|
| `FloPayCheckout` | Recommended self-contained checkout. Resolves gateways, mounts the hosted card form, and renders wallets, alternative methods, PayPal, and saved-payment flows. |
|
|
433
470
|
| `FloPayCardSetup` | No-charge card verification for a merchant-server-created setup session. Also exported from `@flopay/react/card-setup`. |
|
|
471
|
+
| `FloPayPaymentMethodSetup` | No-charge setup of every payment method a setup session advertises: card, Stripe wallets and alternative methods, and PayPal. Also exported from `@flopay/react/payment-method-setup`. |
|
|
434
472
|
| `FloPayAutomaticPaymentButton` | One-click button that charges the customer's saved payment method, falling back to `FloPayCheckout` |
|
|
435
473
|
| `FloPayProvider` | Context provider for composed checkouts |
|
|
436
474
|
| `SplitCardForm` | Checkout surface combining the hosted card form with wallets, alternative methods, and PayPal |
|
|
@@ -487,7 +525,7 @@ export function ComposedCheckout({ session, nonce }: { session: CheckoutSession;
|
|
|
487
525
|
| `children` | `ReactNode?` | Custom layout rendered instead of the default `SplitCardForm` |
|
|
488
526
|
| `telemetry` | `boolean?` | Set `false` to opt out of operational telemetry |
|
|
489
527
|
| `onComplete` | `(result: PaymentResult) => void` | Payment succeeded or was authorized |
|
|
490
|
-
| `onDecline` | `(decline: DeclineEvent) => void` | A payment was declined or authentication failed |
|
|
528
|
+
| `onDecline` | `(decline: DeclineEvent) => void` | A payment was declined or authentication failed. The event carries `sessionId` when a session exists |
|
|
491
529
|
| `onError` | `(error: FloPayError) => void` | A checkout error occurred |
|
|
492
530
|
| `onSessionCompleted` | `(successUrl: string) => void` | The session was already completed |
|
|
493
531
|
| `onButtonClick` | `(method: CheckoutButtonMethod) => void` | A payment method button was clicked |
|
|
@@ -524,6 +562,19 @@ export function ComposedCheckout({ session, nonce }: { session: CheckoutSession;
|
|
|
524
562
|
| `onError` | `(error: FloPayCardSetupError) => void` | Validation or technical failure with `code` and `retryable` |
|
|
525
563
|
| `onCancel` | `(event: FloPayCardSetupCancelEvent) => void` | Unmounted before a terminal outcome |
|
|
526
564
|
|
|
565
|
+
### FloPayPaymentMethodSetupProps
|
|
566
|
+
|
|
567
|
+
The same props as `FloPayCardSetupProps`. `theme`, `containerStyle`, `onReady` and `onValidation` apply to the hosted card form as they do there; `theme` also styles the Stripe Elements of advertised wallets and alternative methods.
|
|
568
|
+
|
|
569
|
+
| Prop | Type | Description |
|
|
570
|
+
|------|------|-------------|
|
|
571
|
+
| `sessionId` | `string` | Opaque id from the merchant-authenticated setup-session endpoint |
|
|
572
|
+
| `nonce` | `string` | Session-bound token returned with `sessionId` |
|
|
573
|
+
| `onComplete` | `(event: FloPayPaymentMethodSetupCompleteEvent) => void` | The billing API verified the method; it is usable |
|
|
574
|
+
| `onDecline` | `(event: FloPayPaymentMethodSetupDeclineEvent) => void` | The method was declined, including a failed redirect return |
|
|
575
|
+
| `onError` | `(error: FloPayCardSetupError) => void` | Validation or technical failure with `code` and `retryable` |
|
|
576
|
+
| `onCancel` | `(event: FloPayPaymentMethodSetupCancelEvent) => void` | Unmounted before a terminal outcome, exactly once |
|
|
577
|
+
|
|
527
578
|
### FloPayAutomaticPaymentButtonProps
|
|
528
579
|
|
|
529
580
|
Also accepts every standard `button` attribute, such as `onClick`, `disabled`, and `className`.
|
|
@@ -543,8 +594,8 @@ Also accepts every standard `button` attribute, such as `onClick`, `disabled`, a
|
|
|
543
594
|
| `theme` | `ThemeId?` | Theme for the button and its fallback checkout |
|
|
544
595
|
| `appearance` / `buttonsStyles` | objects | Appearance overrides |
|
|
545
596
|
| `onSuccess` | `(event: FloPayAutomaticPaymentSuccessEvent) => void` | Payment completed |
|
|
546
|
-
| `onDecline` | `(decline: DeclineEvent) => void` | Payment declined |
|
|
547
|
-
| `onError` | `(error: FloPayError) => void` | Payment or setup error |
|
|
597
|
+
| `onDecline` | `(decline: DeclineEvent) => void` | Payment declined. Carries the failed session's `sessionId` |
|
|
598
|
+
| `onError` | `(error: FloPayError) => void` | Payment or setup error. Carries `sessionId` when the failure happened after the session was created |
|
|
548
599
|
| `children` | `ReactNode?` | Button content |
|
|
549
600
|
|
|
550
601
|
### SplitCardFormProps
|
|
@@ -597,6 +648,10 @@ Also accepts every standard `button` attribute, such as `onClick`, `disabled`, a
|
|
|
597
648
|
| `FloPayCardSetupCompleteEvent` | Verified setup: `status`, `sessionId`, and optional display-only `paymentMethod` |
|
|
598
649
|
| `FloPayCardSetupDeclineEvent` | Declined setup: `status`, `sessionId`, `reason?`, `message?` |
|
|
599
650
|
| `FloPayCardSetupCancelEvent` | Unmounted before a terminal outcome: `status`, `sessionId` |
|
|
651
|
+
| `FloPayPaymentMethodSetupProps` | Props for `FloPayPaymentMethodSetup` |
|
|
652
|
+
| `FloPayPaymentMethodSetupCompleteEvent` | Same shape as `FloPayCardSetupCompleteEvent` |
|
|
653
|
+
| `FloPayPaymentMethodSetupDeclineEvent` | Same shape as `FloPayCardSetupDeclineEvent` |
|
|
654
|
+
| `FloPayPaymentMethodSetupCancelEvent` | Same shape as `FloPayCardSetupCancelEvent` |
|
|
600
655
|
| `FloPayAutomaticPaymentButtonProps` | Props for `FloPayAutomaticPaymentButton` |
|
|
601
656
|
| `FloPayAutomaticPaymentSuccessEvent` | `result`, `session`, `sessionId`, and `autoCompleted` |
|
|
602
657
|
| `SplitCardFormProps` | Props for `SplitCardForm` |
|
|
@@ -651,3 +706,16 @@ A `validation_error` is also reported when both `showStripe` and `showPayPal` ar
|
|
|
651
706
|
| `UnsupportedBackendVaultCapability` | The setup session has no hosted card capability |
|
|
652
707
|
| `card_setup_widget_failed` | The hosted card form failed at runtime (retryable) |
|
|
653
708
|
| `card_setup_load_failed` | Loading the session or card form failed for another reason |
|
|
709
|
+
|
|
710
|
+
`FloPayPaymentMethodSetup` reports the codes above, plus:
|
|
711
|
+
|
|
712
|
+
| Code | When |
|
|
713
|
+
|------|------|
|
|
714
|
+
| `InvalidPaymentMethodSetupSession` | The session is not a zero-amount, product-free setup session |
|
|
715
|
+
| `NoAdvertisedPaymentMethods` | The setup session advertises no payment method |
|
|
716
|
+
| `payment_method_setup_unverified` | The provider accepted the method but the billing API had not verified it in time (retryable) |
|
|
717
|
+
| `payment_method_setup_expired` | The setup session expired before the method was verified |
|
|
718
|
+
| `payment_method_setup_failed` | A wallet or alternative method failed technically (retryable) |
|
|
719
|
+
| `payment_method_setup_load_failed` | The code for a wallet, alternative method or PayPal could not be loaded; that method stays hidden and the other advertised methods remain usable. Not retryable: only a page reload can load it again |
|
|
720
|
+
| `paypal_setup_failed` | The PayPal vault flow failed technically (retryable) |
|
|
721
|
+
| `popup_blocked` | PayPal could not open its approval window; allow pop-ups and retry (retryable) |
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
"use strict";var Q=Object.defineProperty;var ve=Object.getOwnPropertyDescriptor;var Fe=Object.getOwnPropertyNames;var Ee=Object.prototype.hasOwnProperty;var Pe=(e,r)=>{for(var t in r)Q(e,t,{get:r[t],enumerable:!0})},Te=(e,r,t,n)=>{if(r&&typeof r=="object"||typeof r=="function")for(let o of Fe(r))!Ee.call(e,o)&&o!==t&&Q(e,o,{get:()=>r[o],enumerable:!(n=ve(r,o))||n.enumerable});return e};var Ve=e=>Te(Q({},"__esModule",{value:!0}),e);var Qe={};Pe(Qe,{FloPayCardSetup:()=>
|
|
1
|
+
"use strict";var Q=Object.defineProperty;var ve=Object.getOwnPropertyDescriptor;var Fe=Object.getOwnPropertyNames;var Ee=Object.prototype.hasOwnProperty;var Pe=(e,r)=>{for(var t in r)Q(e,t,{get:r[t],enumerable:!0})},Te=(e,r,t,n)=>{if(r&&typeof r=="object"||typeof r=="function")for(let o of Fe(r))!Ee.call(e,o)&&o!==t&&Q(e,o,{get:()=>r[o],enumerable:!(n=ve(r,o))||n.enumerable});return e};var Ve=e=>Te(Q({},"__esModule",{value:!0}),e);var Qe={};Pe(Qe,{FloPayCardSetup:()=>Re,FloPayCardSetupError:()=>$});module.exports=Ve(Qe);var X=require("@flopay/js/card-setup"),b=require("@flopay/shared"),u=require("react");function ie(e,r){if(!e)return r;let t=r??{},n=Object.keys(t),o=n.some(i=>i.startsWith("background")),a={};for(let[i,l]of Object.entries(e))i in t||o&&i.startsWith("background")||(a[i]=l);for(let i of n)a[i]=t[i];return a}var Ae=new Set(["animationIterationCount","aspectRatio","borderImageOutset","borderImageSlice","borderImageWidth","boxFlex","boxFlexGroup","boxOrdinalGroup","columnCount","columns","flex","flexGrow","flexPositive","flexShrink","flexNegative","flexOrder","gridArea","gridRow","gridRowEnd","gridRowSpan","gridRowStart","gridColumn","gridColumnEnd","gridColumnSpan","gridColumnStart","fontWeight","lineClamp","lineHeight","opacity","order","orphans","scale","tabSize","widows","zIndex","zoom","fillOpacity","floodOpacity","stopOpacity","strokeDasharray","strokeDashoffset","strokeMiterlimit","strokeOpacity","strokeWidth"]);function Le(e){let r=e.replace(/^(Webkit|Moz|ms)(?=[A-Z])/,"");return Ae.has(r.charAt(0).toLowerCase()+r.slice(1))}function Be(e,r){return typeof r=="number"&&r!==0&&!Le(e)?`${r}px`:String(r).trim()}function se(e,r){if(e.style.cssText="",!!r){for(let[t,n]of Object.entries(r))if(!(n==null||n==="")){if(t.startsWith("--")){e.style.setProperty(t,String(n));continue}e.style[t]=Be(t,n)}}}var ue={light:{success:"#166534",error:"#991B1B"},dark:{success:"#4ADE80",error:"#FCA5A5"}};function le(e){let r=e.appearance.variables??{},t=e.buttonsLayout.cardFormContainer??{},n=e.appearance.theme==="night",o=n?ue.dark:ue.light,a=r.colorText??(n?"#F1F5F9":"#262833"),i=e.appearance.rules?.[".Label"];return{panel:{...t.background===void 0?{}:{background:t.background},...t.backgroundColor===void 0?{}:{backgroundColor:t.backgroundColor},...t.border===void 0?{}:{border:t.border},...t.borderRadius===void 0?{}:{borderRadius:t.borderRadius},...t.boxShadow===void 0?{}:{boxShadow:t.boxShadow},color:a,...r.fontFamily?{fontFamily:r.fontFamily}:{}},spinnerTrackColor:e.buttonsLayout.cardInputBorder??(n?"#374151":"#e5e7eb"),spinnerAccentColor:r.colorPrimary??"#4A49FF",labelColors:{processing:a,success:o.success,error:o.error},noteColor:i?.color??a}}function T(e){if(!e)return;let r=t=>{console.error("[FloPay] Merchant callback failed; checkout continued.",t)};try{Promise.resolve(e()).catch(r)}catch(t){r(t)}}var d=require("react/jsx-runtime");var Oe={panel:{background:"white"},spinnerTrackColor:"#e5e7eb",spinnerAccentColor:"#4A49FF",labelColors:{processing:"#374151",success:"#16a34a",error:"#dc2626"},noteColor:"#6b7280"};function ce({status:e,errorMessage:r,authorized:t=!1,processingLabel:n="PROCESSING...",successLabel:o,errorLabel:a="PAYMENT FAILED",successNote:i="You will be automatically redirected, do not close or navigate away from this window.",theme:l=Oe}){let s={fontSize:13,color:l.noteColor,fontWeight:400,maxWidth:260,lineHeight:1.4,margin:0};return(0,d.jsx)("div",{"data-testid":"flopay-processing-overlay","data-status":e,role:"dialog","aria-modal":"true",style:{position:"fixed",inset:0,background:"rgba(0,0,0,0.35)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3,backdropFilter:"blur(2px)"},children:(0,d.jsxs)("div",{"data-testid":"flopay-processing-overlay-panel",style:{borderRadius:12,boxShadow:"0 8px 32px rgba(0,0,0,0.18)",...l.panel,padding:"2rem 2.5rem",textAlign:"center",minWidth:240,display:"flex",flexDirection:"column",alignItems:"center",gap:16},children:[(0,d.jsxs)("div",{style:{width:48,height:48,position:"relative"},children:[e==="processing"&&(0,d.jsxs)("svg",{"aria-hidden":"true",width:"48",height:"48",viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",style:{animation:"flopay-spin 0.8s linear infinite"},children:[(0,d.jsx)("circle",{cx:"12",cy:"12",r:"10",stroke:l.spinnerTrackColor,strokeWidth:"3"}),(0,d.jsx)("path",{d:"M4 12a8 8 0 018-8v3a5 5 0 00-5 5H4z",fill:l.spinnerAccentColor})]}),e==="success"&&(0,d.jsx)("div",{style:{animation:"flopay-pop 0.4s cubic-bezier(0.34,1.56,0.64,1)"},children:(0,d.jsxs)("svg",{"aria-hidden":"true",width:"48",height:"48",viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[(0,d.jsx)("circle",{cx:"12",cy:"12",r:"11",fill:"#22c55e"}),(0,d.jsx)("path",{d:"M7 12.5l3 3 7-7",stroke:"white",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",style:{strokeDasharray:20,strokeDashoffset:20,animation:"flopay-draw 0.4s 0.15s ease forwards"}})]})}),e==="error"&&(0,d.jsx)("div",{style:{animation:"flopay-shake 0.4s ease"},children:(0,d.jsxs)("svg",{"aria-hidden":"true",width:"48",height:"48",viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[(0,d.jsx)("circle",{cx:"12",cy:"12",r:"11",fill:"#ef4444"}),(0,d.jsx)("path",{d:"M8 8l8 8M16 8l-8 8",stroke:"white",strokeWidth:"2.5",strokeLinecap:"round",style:{strokeDasharray:12,strokeDashoffset:12,animation:"flopay-draw 0.3s 0.1s ease forwards"}})]})})]}),(0,d.jsxs)("span",{style:{fontSize:14,fontWeight:600,letterSpacing:"0.05em",color:l.labelColors[e]},children:[e==="processing"&&n,e==="success"&&(o??(t?"PAYMENT AUTHORISED":"PAYMENT SUCCESSFUL")),e==="error"&&a]}),e==="success"&&i!==null&&(0,d.jsx)("p",{style:s,children:i}),e==="error"&&r&&(0,d.jsx)("p",{style:s,children:r}),(0,d.jsx)("style",{children:`
|
|
2
2
|
@keyframes flopay-spin { to { transform: rotate(360deg); } }
|
|
3
3
|
@keyframes flopay-pop { 0% { transform: scale(0); } 100% { transform: scale(1); } }
|
|
4
4
|
@keyframes flopay-draw { to { stroke-dashoffset: 0; } }
|
|
5
5
|
@keyframes flopay-shake { 0%,100% { transform: translateX(0); } 20%,60% { transform: translateX(-4px); } 40%,80% { transform: translateX(4px); } }
|
|
6
|
-
`})]})})}var y=require("react");var Y=require("react"),de=typeof window>"u"?Y.useEffect:Y.useLayoutEffect;var pe=require("react/jsx-runtime"),ee=new WeakSet;function fe({capture:e,html:r,messageToken:t,expectedOrigin:n,theme:o,submitLabel:a,containerStyle:i,onReady:l,onError:s,onValidation:f}){let c=(0,y.useRef)(null),m=(0,y.useRef)(l),C=(0,y.useRef)(s),g=(0,y.useRef)(f);m.current=l,C.current=s,g.current=f;let V=(0,y.useRef)(o);V.current=o;let x=(0,y.useRef)(null),k=a??void 0,A=(0,y.useRef)(k);A.current=k;let O=(0,y.useRef)(void 0);return(0,y.useEffect)(()=>{let v=c.current;if(!v)return;let h=!0,G=!1,I=()=>{!h||G||(G=!0,m.current?.())},F=e.on("ready",()=>{I()}),_=e.on("error",R=>{C.current?.(R.message??"There was a problem loading the secure card form.")}),S=e.on("validation",R=>{g.current?.(R.message??null)}),H=A.current??(ee.has(e)?null:void 0),j={html:r,...t?{messageToken:t}:{},...n?{expectedOrigin:n}:{},...V.current?{theme:V.current}:{},...H===void 0?{}:{submitLabel:H}};return x.current=V.current??null,O.current=A.current,A.current!==void 0&&ee.add(e),e.mount(v,j).then(()=>{I()}).catch(R=>{h&&C.current?.(R instanceof Error?R.message:"Failed to load the secure card form.")}),()=>{h=!1,F(),_(),S(),e.unmount()}},[e,r,t,n]),de(()=>{let v=c.current;v&&se(v,i)},[i]),(0,y.useEffect)(()=>{o!==void 0&&(o===null&&x.current===null||(x.current=o,e.applyTheme?.(o)))},[e,o]),(0,y.useEffect)(()=>{k!==O.current&&(O.current=k,k!==void 0&&ee.add(e),e.setSubmitLabel?.(k??null))},[e,k]),(0,pe.jsx)("div",{ref:c,"data-testid":"flopay-vault-card-fields"})}var ge=/^#([0-9a-f]{6})$/i,Ie=/^#([0-9a-f]{3})$/i,ye=/^rgb\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*\)$/i,be=/^rgba\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(0|1|0?\.\d+|1\.0+)\s*\)$/i,Me=/^linear-gradient\(\s*(-?\d+(?:\.\d+)?)deg\s*,\s*(.+)\)$/i,_e=/^(-?\d+(?:\.\d+)?)(?:px)?$/,Ne=/^(-?\d+(?:\.\d+)?)em$/,De=/^blur\(\s*(\d+(?:\.\d+)?)(?:px)?\s*\)$/i,ze=/^[a-z][a-z0-9 -]{0,31}$/i,We=new Set(["none","uppercase","lowercase","capitalize"]);function he(e){if(typeof e!="string")return null;let r=e.trim(),t=ge.exec(r);if(t){let c=Number.parseInt(t[1],16);return{r:c>>16&255,g:c>>8&255,b:c&255,a:null}}let n=Ie.exec(r);if(n){let[c,m,C]=n[1].split("").map(g=>Number.parseInt(g+g,16));return{r:c,g:m,b:C,a:null}}let o=ye.exec(r),a=o?null:be.exec(r),i=o??a;if(!i)return null;let l=Number(i[1]),s=Number(i[2]),f=Number(i[3]);return l>255||s>255||f>255?null:{r:l,g:s,b:f,a:a?Number(a[4]):null}}function Ce({r:e,g:r,b:t,a:n}){return n===null?`#${(1<<24|e<<16|r<<8|t).toString(16).slice(1)}`:`rgba(${e},${r},${t},${n})`}function z(e){if(typeof e!="string")return;let r=e.trim();if(ge.test(r)||ye.test(r))return r;let t=be.exec(r);if(t&&/^\d/.test(t[4]))return r;let n=he(r);return n?Ce(n):void 0}function U(e,r=.12){let t=he(e);if(!t)return e;let n=Math.max(0,Math.min(1,1-r));return Ce({r:Math.round(t.r*n),g:Math.round(t.g*n),b:Math.round(t.b*n),a:t.a})}function W(e,r){let t=[],n=0,o="";for(let a of e){if(a==="("&&(n+=1),a===")"&&(n-=1),a===r&&n===0){o.trim()&&t.push(o.trim()),o="";continue}o+=a}return o.trim()&&t.push(o.trim()),t}function B(e,r,t){if(typeof e!="number"&&typeof e!="string")return;let n=_e.exec(String(e).trim());if(!n)return;let o=Number(n[1]);return Number.isFinite(o)&&o>=r&&o<=t?o:void 0}function $e(e,r,t){if(typeof e!="string")return;let n=Ne.exec(e.trim());if(!n)return;let o=Number(n[1]);return Number.isFinite(o)&&o>=r&&o<=t?o:void 0}function Ge(e){let r=W(e,",");if(r.length<2||r.length>5)return;let t=[];for(let[n,o]of r.entries()){let a=W(o," "),i=z(a[0]);if(!i)return;let l=n/(r.length-1)*100,s=a[1]===void 0?l:Number(/^(\d+(?:\.\d+)?)%$/.exec(a[1])?.[1]),f=t[t.length-1]?.position??-1;if(!Number.isFinite(s)||s<0||s>100||s<f)return;t.push({color:i,position:s})}return{type:"linearGradient",angle:0,stops:t}}function He(e){if(typeof e!="string")return;let r=e.trim(),t=z(r);if(t)return{type:"solid",color:t};let n=Me.exec(r);if(!n)return;let o=Number(n[1]);if(!Number.isFinite(o)||o<0||o>360)return;let a=Ge(n[2]);return a&&a.type==="linearGradient"?{...a,angle:o}:void 0}function Ye(e){return e.type==="solid"?{type:"solid",color:U(e.color)}:{...e,stops:e.stops.map(r=>({...r,color:U(r.color)}))}}function Ue(e){let r=!1,t,n=[];for(let s of W(e," ")){if(s.toLowerCase()==="inset"){r=!0;continue}let f=z(s);if(f){t=f;continue}let c=B(s,-128,128);if(c===void 0)return;n.push(c)}if(!t||n.length<2||n.length>4)return;let[o,a,i=0,l=0]=n;if(!(Math.abs(o)>64||Math.abs(a)>64||i>128||Math.abs(l)>32))return{color:t,inset:r,offsetX:o,offsetY:a,blur:i,spread:l}}function Xe(e){if(typeof e!="string")return;let r=e.trim();if(r.toLowerCase()==="none")return[];let t=W(r,",").map(Ue);if(!(t.length===0||t.length>4))return t.every(n=>n!==void 0)?t:void 0}function me(e){if(typeof e!="string")return;let r=W(e,",").map(t=>t.replace(/^['"]|['"]$/g,"").trim()).filter(t=>ze.test(t)).slice(0,4);return r.length>0?r:void 0}function je(e){let r=typeof e=="string"?e.trim().split(/\s+/):[e],t=B(r[0],0,64),n=B(r[1]??r[0],0,64);if(!(t===void 0||n===void 0))return{paddingBlock:t,paddingInline:n}}function qe(e){if(e==="bold")return 700;if(e==="normal")return 400;let r=Number(e);return Number.isInteger(r)&&r>=100&&r<=900?r:void 0}function Se({appearance:e,buttonsStyles:r,fontFamily:t}){let n=r.submitButton;if(!n)return;let o=e?.variables,a=He(n.background??n.backgroundColor),i=z(o?.colorPrimaryHover),l=i?{type:"solid",color:i}:a&&Ye(a),s={fontFamilies:me(n.fontFamily)??me(t),fontSize:B(n.fontSize??r.submitButtonFontSize,10,32)??16,fontWeight:qe(n.fontWeight)??600,letterSpacing:$e(n.letterSpacing,-.1,.5)??.01,lineHeight:B(n.lineHeight,.8,2)??1,textTransform:We.has(String(n.textTransform))?n.textTransform:"uppercase"},f=je(n.padding),c=Xe(n.boxShadow),m=B(n.borderRadius,0,9999),C=typeof n.backdropFilter=="string"?B(De.exec(n.backdropFilter.trim())?.[1],0,40):void 0;return{foregroundColor:z(n.color)??"#FFFFFF",...a?{background:a,disabledBackground:a}:{},...l?{hoverBackground:l}:{},typography:s,...f?{spacing:f}:{},...c?{shadow:c}:{},...m===void 0?{}:{borderRadius:m},disabledOpacity:e?.theme==="night"?.8:.6,...C===void 0?{}:{backdropBlur:C}}}function Ke(e,r=.12){let t=e.trim(),n=/^[0-9a-fA-F]{6}$/.test(t)?`#${t}`:t;return/^#[0-9a-fA-F]{6}$/.test(n)?U(n,r):e}function Ze(e){if(typeof e=="number"||typeof e=="string")return e}function ke({appearance:e,buttonsStyles:r,layout:t="default"}){let n=e?.variables,o=m=>typeof m=="string"&&m?m:void 0,a=r.submitButton,i=o(n?.colorPrimary)??o(a?.backgroundColor)??"#4A49FF",l=t==="buttons",s=r.nameInput,f=o(s?.fontFamily)??o(n?.fontFamily)??"Poppins, sans-serif",c=Se({appearance:e,buttonsStyles:r,fontFamily:f});return{primaryColor:i,primaryHoverColor:o(n?.colorPrimaryHover)??Ke(i,.12),inputBackgroundColor:o(r.cardInputBackground)??o(n?.colorBackground)??"#ffffff",textColor:o(r.cardInputColor)??o(s?.color)??o(n?.colorText)??"#262833",borderColor:o(r.cardInputBorder)??(l?"#e5e7eb":"#A4A4FF"),placeholderColor:o(r.cardInputPlaceholderColor)??"#9ca3af",errorColor:o(n?.colorDanger)??"#dc2626",successColor:"#16a34a",fontFamily:f,fontSize:o(r.cardInputFontSize)??o(n?.fontSizeBase)??"16px",fontWeight:String(Ze(s?.fontWeight)??400),borderRadius:o(n?.borderRadius)??"8px",...c?{submitButton:c}:{}}}var w=require("react/jsx-runtime"),$=class extends b.FloPayError{constructor(r,t,n){super(r,t,n),this.name="FloPayCardSetupError",this.retryable=n.retryable}};function Re(e,r={}){let t=e instanceof b.FloPayError?e:void 0,n=t?.statusCode,o=r.retryable??(t?.type==="network_error"||t?.type==="rate_limit_error"||typeof n=="number"&&n>=500||t?.code==="vault_capture_timeout"||!t);return new $(t?.message??(e instanceof Error?e.message:"Failed to load the secure card form."),t?.type??"api_error",{code:r.code??t?.code??"card_setup_load_failed",retryable:o,...t?.param?{param:t.param}:{},...n===void 0?{}:{statusCode:n}})}function xe({sessionId:e,nonce:r,billingApiUrl:t,telemetry:n,theme:o="modern-light",containerStyle:a,loading:i=null,onReady:l,onComplete:s,onDecline:f,onCancel:c,onValidation:m,onError:C}){let[g,V]=(0,u.useState)(null),[x,k]=(0,u.useState)(null),[A,O]=(0,u.useState)(null),[v,h]=(0,u.useState)(null),[G,I]=(0,u.useState)(null),F=(0,u.useRef)(!1),_=(0,u.useRef)(!1),S=(0,u.useMemo)(()=>typeof o=="object"?void 0:(0,b.resolveTheme)(o),[o]),H=(0,u.useMemo)(()=>typeof o=="object"?o:S?ke({appearance:S.appearance,buttonsStyles:S.buttonsLayout,layout:"default"}):null,[S,o]),j=(0,u.useMemo)(()=>ie(S?.buttonsLayout.cardFormContainer,a),[S,a]),R=(0,u.useMemo)(()=>S?le(S):void 0,[S]),re=(0,u.useRef)(l),q=(0,u.useRef)(C),te=(0,u.useRef)(s),ne=(0,u.useRef)(f),oe=(0,u.useRef)(c),ae=(0,u.useRef)(m),N=(0,u.useRef)(!1),K=(0,u.useRef)(!1),Z=(0,u.useRef)(0);return re.current=l,q.current=C,te.current=s,ne.current=f,oe.current=c,ae.current=m,(0,u.useEffect)(()=>{let p=Z.current+1;return Z.current=p,()=>{queueMicrotask(()=>{Z.current===p&&(N.current||K.current||(K.current=!0,T(()=>{oe.current?.({status:"cancelled",sessionId:e})})))})}},[e]),(0,u.useEffect)(()=>{let p=!0,L=new X.PaymentAPI((0,b.resolveBillingApiUrl)(t),{telemetry:n});return V(null),k(null),O(null),N.current=!1,K.current=!1,(async()=>{try{if(!e.trim())throw new b.FloPayError("FloPayCardSetup requires a sessionId.","validation_error",{code:"MissingCheckoutSessionId",param:"sessionId"});if(!r.trim())throw new b.FloPayError("FloPayCardSetup requires a session nonce.","validation_error",{code:"MissingCheckoutSessionToken",param:"nonce"});let D=await L.getUnifiedCheckoutSession(e,r);if(!p)return;let E=D.data.session;if(!E||!(0,b.isCardSetupCheckoutSession)(E))throw new b.FloPayError("FloPayCardSetup only accepts a zero-amount, productless setup session.","validation_error",{code:"InvalidCardSetupSession",param:"sessionId"});let M=E.vault;if(M?.html?.trim()||(M=await L.getVaultCapture(e,r)),!M.html?.trim())throw new b.FloPayError("FloPay: this setup session has no vault card capability. Upgrade the billing backend integration.","api_error",{code:"UnsupportedBackendVaultCapability"});if(!p)return;k(M),V(new X.PciVaultCardCapture({sessionId:e,operation:"card_setup",telemetry:n}))}catch(D){if(!p)return;let E=Re(D);N.current=!0,O(E),T(()=>q.current?.(E))}})(),()=>{p=!1,L.destroy()}},[t,r,e,n]),(0,u.useEffect)(()=>{if(!g)return;let p=!1;_.current=!1,F.current=!1;let L=g.on("submitting",()=>{F.current=!0,I(null),h("processing")}),D=g.on("complete",P=>{N.current=!0,F.current=!1,h("success"),(async()=>(await new Promise(J=>setTimeout(J,600)),!_.current&&(_.current=!0,T(()=>{te.current?.({status:"succeeded",sessionId:e,...P.paymentMethod?{paymentMethod:P.paymentMethod}:{}})}),p||h(null))))()}),E=g.on("decline",P=>{N.current=!0,F.current=!1,I(P.message??null),h("error"),T(()=>{ne.current?.({status:"declined",sessionId:e,...P.declineReason?{reason:P.declineReason}:{},...P.message?{message:P.message}:{}})}),(async()=>(await new Promise(J=>setTimeout(J,400)),p||h(null)))()}),M=g.on("challenge_dismissed",()=>{h(null)});return()=>{p=!0,L(),D(),E(),M()}},[g,e]),A?(0,w.jsx)("div",{role:"alert",children:A.message}):!g||!x?.html?(0,w.jsx)(w.Fragment,{children:i}):(0,w.jsxs)(w.Fragment,{children:[v&&(0,w.jsx)(ce,{status:v,errorMessage:G,processingLabel:"SAVING CARD...",successLabel:"CARD SAVED",errorLabel:"CARD NOT SAVED",successNote:null,...R?{theme:R}:{}}),(0,w.jsx)(fe,{capture:g,html:x.html,messageToken:x.messageToken,expectedOrigin:x.expectedOrigin,theme:H,containerStyle:j,onReady:()=>{T(()=>re.current?.())},onValidation:p=>{T(()=>ae.current?.(p))},onError:p=>{if(!p)return;F.current&&(F.current=!1,I(p),h("error"),setTimeout(()=>h(null),400));let L=Re(new Error(p),{code:"card_setup_widget_failed",retryable:!0});T(()=>q.current?.(L))}})]})}0&&(module.exports={FloPayCardSetup,FloPayCardSetupError});
|
|
6
|
+
`})]})})}var y=require("react");var Y=require("react"),de=typeof window>"u"?Y.useEffect:Y.useLayoutEffect;var pe=require("react/jsx-runtime"),ee=new WeakSet;function fe({capture:e,html:r,messageToken:t,expectedOrigin:n,theme:o,submitLabel:a,containerStyle:i,onReady:l,onError:s,onValidation:f}){let c=(0,y.useRef)(null),m=(0,y.useRef)(l),C=(0,y.useRef)(s),g=(0,y.useRef)(f);m.current=l,C.current=s,g.current=f;let V=(0,y.useRef)(o);V.current=o;let R=(0,y.useRef)(null),k=a??void 0,A=(0,y.useRef)(k);A.current=k;let O=(0,y.useRef)(void 0);return(0,y.useEffect)(()=>{let v=c.current;if(!v)return;let h=!0,G=!1,I=()=>{!h||G||(G=!0,m.current?.())},F=e.on("ready",()=>{I()}),_=e.on("error",x=>{C.current?.(x.message??"There was a problem loading the secure card form.")}),S=e.on("validation",x=>{g.current?.(x.message??null)}),H=A.current??(ee.has(e)?null:void 0),j={html:r,...t?{messageToken:t}:{},...n?{expectedOrigin:n}:{},...V.current?{theme:V.current}:{},...H===void 0?{}:{submitLabel:H}};return R.current=V.current??null,O.current=A.current,A.current!==void 0&&ee.add(e),e.mount(v,j).then(()=>{I()}).catch(x=>{h&&C.current?.(x instanceof Error?x.message:"Failed to load the secure card form.")}),()=>{h=!1,F(),_(),S(),e.unmount()}},[e,r,t,n]),de(()=>{let v=c.current;v&&se(v,i)},[i]),(0,y.useEffect)(()=>{o!==void 0&&(o===null&&R.current===null||(R.current=o,e.applyTheme?.(o)))},[e,o]),(0,y.useEffect)(()=>{k!==O.current&&(O.current=k,k!==void 0&&ee.add(e),e.setSubmitLabel?.(k??null))},[e,k]),(0,pe.jsx)("div",{ref:c,"data-testid":"flopay-vault-card-fields"})}var ge=/^#([0-9a-f]{6})$/i,Ie=/^#([0-9a-f]{3})$/i,ye=/^rgb\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*\)$/i,be=/^rgba\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(0|1|0?\.\d+|1\.0+)\s*\)$/i,Me=/^linear-gradient\(\s*(-?\d+(?:\.\d+)?)deg\s*,\s*(.+)\)$/i,_e=/^(-?\d+(?:\.\d+)?)(?:px)?$/,Ne=/^(-?\d+(?:\.\d+)?)em$/,De=/^blur\(\s*(\d+(?:\.\d+)?)(?:px)?\s*\)$/i,ze=/^[a-z][a-z0-9 -]{0,31}$/i,We=new Set(["none","uppercase","lowercase","capitalize"]);function he(e){if(typeof e!="string")return null;let r=e.trim(),t=ge.exec(r);if(t){let c=Number.parseInt(t[1],16);return{r:c>>16&255,g:c>>8&255,b:c&255,a:null}}let n=Ie.exec(r);if(n){let[c,m,C]=n[1].split("").map(g=>Number.parseInt(g+g,16));return{r:c,g:m,b:C,a:null}}let o=ye.exec(r),a=o?null:be.exec(r),i=o??a;if(!i)return null;let l=Number(i[1]),s=Number(i[2]),f=Number(i[3]);return l>255||s>255||f>255?null:{r:l,g:s,b:f,a:a?Number(a[4]):null}}function Ce({r:e,g:r,b:t,a:n}){return n===null?`#${(1<<24|e<<16|r<<8|t).toString(16).slice(1)}`:`rgba(${e},${r},${t},${n})`}function z(e){if(typeof e!="string")return;let r=e.trim();if(ge.test(r)||ye.test(r))return r;let t=be.exec(r);if(t&&/^\d/.test(t[4]))return r;let n=he(r);return n?Ce(n):void 0}function U(e,r=.12){let t=he(e);if(!t)return e;let n=Math.max(0,Math.min(1,1-r));return Ce({r:Math.round(t.r*n),g:Math.round(t.g*n),b:Math.round(t.b*n),a:t.a})}function W(e,r){let t=[],n=0,o="";for(let a of e){if(a==="("&&(n+=1),a===")"&&(n-=1),a===r&&n===0){o.trim()&&t.push(o.trim()),o="";continue}o+=a}return o.trim()&&t.push(o.trim()),t}function B(e,r,t){if(typeof e!="number"&&typeof e!="string")return;let n=_e.exec(String(e).trim());if(!n)return;let o=Number(n[1]);return Number.isFinite(o)&&o>=r&&o<=t?o:void 0}function $e(e,r,t){if(typeof e!="string")return;let n=Ne.exec(e.trim());if(!n)return;let o=Number(n[1]);return Number.isFinite(o)&&o>=r&&o<=t?o:void 0}function Ge(e){let r=W(e,",");if(r.length<2||r.length>5)return;let t=[];for(let[n,o]of r.entries()){let a=W(o," "),i=z(a[0]);if(!i)return;let l=n/(r.length-1)*100,s=a[1]===void 0?l:Number(/^(\d+(?:\.\d+)?)%$/.exec(a[1])?.[1]),f=t[t.length-1]?.position??-1;if(!Number.isFinite(s)||s<0||s>100||s<f)return;t.push({color:i,position:s})}return{type:"linearGradient",angle:0,stops:t}}function He(e){if(typeof e!="string")return;let r=e.trim(),t=z(r);if(t)return{type:"solid",color:t};let n=Me.exec(r);if(!n)return;let o=Number(n[1]);if(!Number.isFinite(o)||o<0||o>360)return;let a=Ge(n[2]);return a&&a.type==="linearGradient"?{...a,angle:o}:void 0}function Ye(e){return e.type==="solid"?{type:"solid",color:U(e.color)}:{...e,stops:e.stops.map(r=>({...r,color:U(r.color)}))}}function Ue(e){let r=!1,t,n=[];for(let s of W(e," ")){if(s.toLowerCase()==="inset"){r=!0;continue}let f=z(s);if(f){t=f;continue}let c=B(s,-128,128);if(c===void 0)return;n.push(c)}if(!t||n.length<2||n.length>4)return;let[o,a,i=0,l=0]=n;if(!(Math.abs(o)>64||Math.abs(a)>64||i>128||Math.abs(l)>32))return{color:t,inset:r,offsetX:o,offsetY:a,blur:i,spread:l}}function Xe(e){if(typeof e!="string")return;let r=e.trim();if(r.toLowerCase()==="none")return[];let t=W(r,",").map(Ue);if(!(t.length===0||t.length>4))return t.every(n=>n!==void 0)?t:void 0}function me(e){if(typeof e!="string")return;let r=W(e,",").map(t=>t.replace(/^['"]|['"]$/g,"").trim()).filter(t=>ze.test(t)).slice(0,4);return r.length>0?r:void 0}function je(e){let r=typeof e=="string"?e.trim().split(/\s+/):[e],t=B(r[0],0,64),n=B(r[1]??r[0],0,64);if(!(t===void 0||n===void 0))return{paddingBlock:t,paddingInline:n}}function qe(e){if(e==="bold")return 700;if(e==="normal")return 400;let r=Number(e);return Number.isInteger(r)&&r>=100&&r<=900?r:void 0}function Se({appearance:e,buttonsStyles:r,fontFamily:t}){let n=r.submitButton;if(!n)return;let o=e?.variables,a=He(n.background??n.backgroundColor),i=z(o?.colorPrimaryHover),l=i?{type:"solid",color:i}:a&&Ye(a),s={fontFamilies:me(n.fontFamily)??me(t),fontSize:B(n.fontSize??r.submitButtonFontSize,10,32)??16,fontWeight:qe(n.fontWeight)??600,letterSpacing:$e(n.letterSpacing,-.1,.5)??.01,lineHeight:B(n.lineHeight,.8,2)??1,textTransform:We.has(String(n.textTransform))?n.textTransform:"uppercase"},f=je(n.padding),c=Xe(n.boxShadow),m=B(n.borderRadius,0,9999),C=typeof n.backdropFilter=="string"?B(De.exec(n.backdropFilter.trim())?.[1],0,40):void 0;return{foregroundColor:z(n.color)??"#FFFFFF",...a?{background:a,disabledBackground:a}:{},...l?{hoverBackground:l}:{},typography:s,...f?{spacing:f}:{},...c?{shadow:c}:{},...m===void 0?{}:{borderRadius:m},disabledOpacity:e?.theme==="night"?.8:.6,...C===void 0?{}:{backdropBlur:C}}}function Ke(e,r=.12){let t=e.trim(),n=/^[0-9a-fA-F]{6}$/.test(t)?`#${t}`:t;return/^#[0-9a-fA-F]{6}$/.test(n)?U(n,r):e}function Ze(e){if(typeof e=="number"||typeof e=="string")return e}function ke({appearance:e,buttonsStyles:r,layout:t="default"}){let n=e?.variables,o=m=>typeof m=="string"&&m?m:void 0,a=r.submitButton,i=o(n?.colorPrimary)??o(a?.backgroundColor)??"#4A49FF",l=t==="buttons",s=r.nameInput,f=o(s?.fontFamily)??o(n?.fontFamily)??"Poppins, sans-serif",c=Se({appearance:e,buttonsStyles:r,fontFamily:f});return{primaryColor:i,primaryHoverColor:o(n?.colorPrimaryHover)??Ke(i,.12),inputBackgroundColor:o(r.cardInputBackground)??o(n?.colorBackground)??"#ffffff",textColor:o(r.cardInputColor)??o(s?.color)??o(n?.colorText)??"#262833",borderColor:o(r.cardInputBorder)??(l?"#e5e7eb":"#A4A4FF"),placeholderColor:o(r.cardInputPlaceholderColor)??"#9ca3af",errorColor:o(n?.colorDanger)??"#dc2626",successColor:"#16a34a",fontFamily:f,fontSize:o(r.cardInputFontSize)??o(n?.fontSizeBase)??"16px",fontWeight:String(Ze(s?.fontWeight)??400),borderRadius:o(n?.borderRadius)??"8px",...c?{submitButton:c}:{}}}var w=require("react/jsx-runtime"),$=class extends b.FloPayError{constructor(r,t,n){super(r,t,n),this.name="FloPayCardSetupError",this.retryable=n.retryable}};function xe(e,r={}){let t=e instanceof b.FloPayError?e:void 0,n=t?.statusCode,o=r.retryable??(t?.type==="network_error"||t?.type==="rate_limit_error"||typeof n=="number"&&n>=500||t?.code==="vault_capture_timeout"||!t);return new $(t?.message??(e instanceof Error?e.message:"Failed to load the secure card form."),t?.type??"api_error",{code:r.code??t?.code??"card_setup_load_failed",retryable:o,...t?.param?{param:t.param}:{},...n===void 0?{}:{statusCode:n}})}function Re({sessionId:e,nonce:r,billingApiUrl:t,telemetry:n,theme:o="modern-light",containerStyle:a,loading:i=null,onReady:l,onComplete:s,onDecline:f,onCancel:c,onValidation:m,onError:C}){let[g,V]=(0,u.useState)(null),[R,k]=(0,u.useState)(null),[A,O]=(0,u.useState)(null),[v,h]=(0,u.useState)(null),[G,I]=(0,u.useState)(null),F=(0,u.useRef)(!1),_=(0,u.useRef)(!1),S=(0,u.useMemo)(()=>typeof o=="object"?void 0:(0,b.resolveTheme)(o),[o]),H=(0,u.useMemo)(()=>typeof o=="object"?o:S?ke({appearance:S.appearance,buttonsStyles:S.buttonsLayout,layout:"default"}):null,[S,o]),j=(0,u.useMemo)(()=>ie(S?.buttonsLayout.cardFormContainer,a),[S,a]),x=(0,u.useMemo)(()=>S?le(S):void 0,[S]),re=(0,u.useRef)(l),q=(0,u.useRef)(C),te=(0,u.useRef)(s),ne=(0,u.useRef)(f),oe=(0,u.useRef)(c),ae=(0,u.useRef)(m),N=(0,u.useRef)(!1),K=(0,u.useRef)(!1),Z=(0,u.useRef)(0);return re.current=l,q.current=C,te.current=s,ne.current=f,oe.current=c,ae.current=m,(0,u.useEffect)(()=>{let p=Z.current+1;return Z.current=p,()=>{queueMicrotask(()=>{Z.current===p&&(N.current||K.current||(K.current=!0,T(()=>{oe.current?.({status:"cancelled",sessionId:e})})))})}},[e]),(0,u.useEffect)(()=>{let p=!0,L=new X.PaymentAPI((0,b.resolveBillingApiUrl)(t),{telemetry:n});return V(null),k(null),O(null),N.current=!1,K.current=!1,(async()=>{try{if(!e.trim())throw new b.FloPayError("FloPayCardSetup requires a sessionId.","validation_error",{code:"MissingCheckoutSessionId",param:"sessionId"});if(!r.trim())throw new b.FloPayError("FloPayCardSetup requires a session nonce.","validation_error",{code:"MissingCheckoutSessionToken",param:"nonce"});let D=await L.getUnifiedCheckoutSession(e,r);if(!p)return;let E=D.data.session;if(!E||!(0,b.isCardSetupCheckoutSession)(E))throw new b.FloPayError("FloPayCardSetup only accepts a zero-amount, productless setup session.","validation_error",{code:"InvalidCardSetupSession",param:"sessionId"});let M=E.vault;if(M?.html?.trim()||(M=await L.getVaultCapture(e,r)),!M.html?.trim())throw new b.FloPayError("FloPay: this setup session has no vault card capability. Upgrade the billing backend integration.","api_error",{code:"UnsupportedBackendVaultCapability"});if(!p)return;k(M),V(new X.PciVaultCardCapture({sessionId:e,operation:"card_setup",telemetry:n}))}catch(D){if(!p)return;let E=xe(D);N.current=!0,O(E),T(()=>q.current?.(E))}})(),()=>{p=!1,L.destroy()}},[t,r,e,n]),(0,u.useEffect)(()=>{if(!g)return;let p=!1;_.current=!1,F.current=!1;let L=g.on("submitting",()=>{F.current=!0,I(null),h("processing")}),D=g.on("complete",P=>{N.current=!0,F.current=!1,h("success"),(async()=>(await new Promise(J=>setTimeout(J,600)),!_.current&&(_.current=!0,T(()=>{te.current?.({status:"succeeded",sessionId:e,...P.paymentMethod?{paymentMethod:P.paymentMethod}:{}})}),p||h(null))))()}),E=g.on("decline",P=>{N.current=!0,F.current=!1,I(P.message??null),h("error"),T(()=>{ne.current?.({status:"declined",sessionId:e,...P.declineReason?{reason:P.declineReason}:{},...P.message?{message:P.message}:{}})}),(async()=>(await new Promise(J=>setTimeout(J,400)),p||h(null)))()}),M=g.on("challenge_dismissed",()=>{h(null)});return()=>{p=!0,L(),D(),E(),M()}},[g,e]),A?(0,w.jsx)("div",{role:"alert",children:A.message}):!g||!R?.html?(0,w.jsx)(w.Fragment,{children:i}):(0,w.jsxs)(w.Fragment,{children:[v&&(0,w.jsx)(ce,{status:v,errorMessage:G,processingLabel:"SAVING CARD...",successLabel:"CARD SAVED",errorLabel:"CARD NOT SAVED",successNote:null,...x?{theme:x}:{}}),(0,w.jsx)(fe,{capture:g,html:R.html,messageToken:R.messageToken,expectedOrigin:R.expectedOrigin,theme:H,containerStyle:j,onReady:()=>{T(()=>re.current?.())},onValidation:p=>{T(()=>ae.current?.(p))},onError:p=>{if(!p)return;F.current&&(F.current=!1,I(p),h("error"),setTimeout(()=>h(null),400));let L=xe(new Error(p),{code:"card_setup_widget_failed",retryable:!0});T(()=>q.current?.(L))}})]})}0&&(module.exports={FloPayCardSetup,FloPayCardSetupError});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{j as e,l as t}from"./chunk-I4TPZWBS.mjs";export{t as FloPayCardSetup,e as FloPayCardSetupError};
|
|
@@ -3,4 +3,4 @@ import{useEffect as Q,useRef as F}from"react";function ue(e,r){if(!e)return r;le
|
|
|
3
3
|
@keyframes flopay-pop { 0% { transform: scale(0); } 100% { transform: scale(1); } }
|
|
4
4
|
@keyframes flopay-draw { to { stroke-dashoffset: 0; } }
|
|
5
5
|
@keyframes flopay-shake { 0%,100% { transform: translateX(0); } 20%,60% { transform: translateX(-4px); } 40%,80% { transform: translateX(4px); } }
|
|
6
|
-
`})]})})}var ye=/^#([0-9a-f]{6})$/i,Be=/^#([0-9a-f]{3})$/i,be=/^rgb\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*\)$/i,he=/^rgba\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(0|1|0?\.\d+|1\.0+)\s*\)$/i,Oe=/^linear-gradient\(\s*(-?\d+(?:\.\d+)?)deg\s*,\s*(.+)\)$/i,Ie=/^(-?\d+(?:\.\d+)?)(?:px)?$/,Me=/^(-?\d+(?:\.\d+)?)em$/,_e=/^blur\(\s*(\d+(?:\.\d+)?)(?:px)?\s*\)$/i,Ne=/^[a-z][a-z0-9 -]{0,31}$/i,De=new Set(["none","uppercase","lowercase","capitalize"]);function Ce(e){if(typeof e!="string")return null;let r=e.trim(),t=ye.exec(r);if(t){let l=Number.parseInt(t[1],16);return{r:l>>16&255,g:l>>8&255,b:l&255,a:null}}let n=Be.exec(r);if(n){let[l,f,y]=n[1].split("").map(p=>Number.parseInt(p+p,16));return{r:l,g:f,b:y,a:null}}let o=be.exec(r),i=o?null:he.exec(r),a=o??i;if(!a)return null;let u=Number(a[1]),s=Number(a[2]),c=Number(a[3]);return u>255||s>255||c>255?null:{r:u,g:s,b:c,a:i?Number(i[4]):null}}function Se({r:e,g:r,b:t,a:n}){return n===null?`#${(1<<24|e<<16|r<<8|t).toString(16).slice(1)}`:`rgba(${e},${r},${t},${n})`}function z(e){if(typeof e!="string")return;let r=e.trim();if(ye.test(r)||be.test(r))return r;let t=he.exec(r);if(t&&/^\d/.test(t[4]))return r;let n=Ce(r);return n?Se(n):void 0}function Y(e,r=.12){let t=Ce(e);if(!t)return e;let n=Math.max(0,Math.min(1,1-r));return Se({r:Math.round(t.r*n),g:Math.round(t.g*n),b:Math.round(t.b*n),a:t.a})}function W(e,r){let t=[],n=0,o="";for(let i of e){if(i==="("&&(n+=1),i===")"&&(n-=1),i===r&&n===0){o.trim()&&t.push(o.trim()),o="";continue}o+=i}return o.trim()&&t.push(o.trim()),t}function A(e,r,t){if(typeof e!="number"&&typeof e!="string")return;let n=Ie.exec(String(e).trim());if(!n)return;let o=Number(n[1]);return Number.isFinite(o)&&o>=r&&o<=t?o:void 0}function ze(e,r,t){if(typeof e!="string")return;let n=Me.exec(e.trim());if(!n)return;let o=Number(n[1]);return Number.isFinite(o)&&o>=r&&o<=t?o:void 0}function We(e){let r=W(e,",");if(r.length<2||r.length>5)return;let t=[];for(let[n,o]of r.entries()){let i=W(o," "),a=z(i[0]);if(!a)return;let u=n/(r.length-1)*100,s=i[1]===void 0?u:Number(/^(\d+(?:\.\d+)?)%$/.exec(i[1])?.[1]),c=t[t.length-1]?.position??-1;if(!Number.isFinite(s)||s<0||s>100||s<c)return;t.push({color:a,position:s})}return{type:"linearGradient",angle:0,stops:t}}function $e(e){if(typeof e!="string")return;let r=e.trim(),t=z(r);if(t)return{type:"solid",color:t};let n=Oe.exec(r);if(!n)return;let o=Number(n[1]);if(!Number.isFinite(o)||o<0||o>360)return;let i=We(n[2]);return i&&i.type==="linearGradient"?{...i,angle:o}:void 0}function Ge(e){return e.type==="solid"?{type:"solid",color:Y(e.color)}:{...e,stops:e.stops.map(r=>({...r,color:Y(r.color)}))}}function He(e){let r=!1,t,n=[];for(let s of W(e," ")){if(s.toLowerCase()==="inset"){r=!0;continue}let c=z(s);if(c){t=c;continue}let l=A(s,-128,128);if(l===void 0)return;n.push(l)}if(!t||n.length<2||n.length>4)return;let[o,i,a=0,u=0]=n;if(!(Math.abs(o)>64||Math.abs(i)>64||a>128||Math.abs(u)>32))return{color:t,inset:r,offsetX:o,offsetY:i,blur:a,spread:u}}function Ye(e){if(typeof e!="string")return;let r=e.trim();if(r.toLowerCase()==="none")return[];let t=W(r,",").map(He);if(!(t.length===0||t.length>4))return t.every(n=>n!==void 0)?t:void 0}function ge(e){if(typeof e!="string")return;let r=W(e,",").map(t=>t.replace(/^['"]|['"]$/g,"").trim()).filter(t=>Ne.test(t)).slice(0,4);return r.length>0?r:void 0}function Ue(e){let r=typeof e=="string"?e.trim().split(/\s+/):[e],t=A(r[0],0,64),n=A(r[1]??r[0],0,64);if(!(t===void 0||n===void 0))return{paddingBlock:t,paddingInline:n}}function Xe(e){if(e==="bold")return 700;if(e==="normal")return 400;let r=Number(e);return Number.isInteger(r)&&r>=100&&r<=900?r:void 0}function ke({appearance:e,buttonsStyles:r,fontFamily:t}){let n=r.submitButton;if(!n)return;let o=e?.variables,i=$e(n.background??n.backgroundColor),a=z(o?.colorPrimaryHover),u=a?{type:"solid",color:a}:i&&Ge(i),s={fontFamilies:ge(n.fontFamily)??ge(t),fontSize:A(n.fontSize??r.submitButtonFontSize,10,32)??16,fontWeight:Xe(n.fontWeight)??600,letterSpacing:ze(n.letterSpacing,-.1,.5)??.01,lineHeight:A(n.lineHeight,.8,2)??1,textTransform:De.has(String(n.textTransform))?n.textTransform:"uppercase"},c=Ue(n.padding),l=Ye(n.boxShadow),f=A(n.borderRadius,0,9999),y=typeof n.backdropFilter=="string"?A(_e.exec(n.backdropFilter.trim())?.[1],0,40):void 0;return{foregroundColor:z(n.color)??"#FFFFFF",...i?{background:i,disabledBackground:i}:{},...u?{hoverBackground:u}:{},typography:s,...c?{spacing:c}:{},...l?{shadow:l}:{},...f===void 0?{}:{borderRadius:f},disabledOpacity:e?.theme==="night"?.8:.6,...y===void 0?{}:{backdropBlur:y}}}function je(e,r=.12){let t=e.trim(),n=/^[0-9a-fA-F]{6}$/.test(t)?`#${t}`:t;return/^#[0-9a-fA-F]{6}$/.test(n)?Y(n,r):e}function qe(e){if(typeof e=="number"||typeof e=="string")return e}function we({appearance:e,buttonsStyles:r,layout:t="default"}){let n=e?.variables,o=f=>typeof f=="string"&&f?f:void 0,i=r.submitButton,a=o(n?.colorPrimary)??o(i?.backgroundColor)??"#4A49FF",u=t==="buttons",s=r.nameInput,c=o(s?.fontFamily)??o(n?.fontFamily)??"Poppins, sans-serif",l=ke({appearance:e,buttonsStyles:r,fontFamily:c});return{primaryColor:a,primaryHoverColor:o(n?.colorPrimaryHover)??je(a,.12),inputBackgroundColor:o(r.cardInputBackground)??o(n?.colorBackground)??"#ffffff",textColor:o(r.cardInputColor)??o(s?.color)??o(n?.colorText)??"#262833",borderColor:o(r.cardInputBorder)??(u?"#e5e7eb":"#A4A4FF"),placeholderColor:o(r.cardInputPlaceholderColor)??"#9ca3af",errorColor:o(n?.colorDanger)??"#dc2626",successColor:"#16a34a",fontFamily:c,fontSize:o(r.cardInputFontSize)??o(n?.fontSizeBase)??"16px",fontWeight:String(qe(s?.fontWeight)??400),borderRadius:o(n?.borderRadius)??"8px",...l?{submitButton:l}:{}}}import{Fragment as ve,jsx as X,jsxs as tr}from"react/jsx-runtime";var te=class extends M{constructor(r,t,n){super(r,t,n),this.name="FloPayCardSetupError",this.retryable=n.retryable}};function xe(e,r={}){let t=e instanceof M?e:void 0,n=t?.statusCode,o=r.retryable??(t?.type==="network_error"||t?.type==="rate_limit_error"||typeof n=="number"&&n>=500||t?.code==="vault_capture_timeout"||!t);return new te(t?.message??(e instanceof Error?e.message:"Failed to load the secure card form."),t?.type??"api_error",{code:r.code??t?.code??"card_setup_load_failed",retryable:o,...t?.param?{param:t.param}:{},...n===void 0?{}:{statusCode:n}})}function Er({sessionId:e,nonce:r,billingApiUrl:t,telemetry:n,theme:o="modern-light",containerStyle:i,loading:a=null,onReady:u,onComplete:s,onDecline:c,onCancel:l,onValidation:f,onError:y}){let[p,T]=$(null),[k,C]=$(null),[P,L]=$(null),[w,m]=$(null),[G,B]=$(null),R=h(!1),_=h(!1),b=U(()=>typeof o=="object"?void 0:rr(o),[o]),H=U(()=>typeof o=="object"?o:b?we({appearance:b.appearance,buttonsStyles:b.buttonsLayout,layout:"default"}):null,[b,o]),j=U(()=>ue(b?.buttonsLayout.cardFormContainer,i),[b,i]),S=U(()=>b?pe(b):void 0,[b]),ne=h(u),q=h(y),oe=h(s),ie=h(c),ae=h(l),se=h(f),N=h(!1),K=h(!1),Z=h(0);return ne.current=u,q.current=y,oe.current=s,ie.current=c,ae.current=l,se.current=f,re(()=>{let d=Z.current+1;return Z.current=d,()=>{queueMicrotask(()=>{Z.current===d&&(N.current||K.current||(K.current=!0,E(()=>{ae.current?.({status:"cancelled",sessionId:e})})))})}},[e]),re(()=>{let d=!0,V=new Ze(er(t),{telemetry:n});return T(null),C(null),L(null),N.current=!1,K.current=!1,(async()=>{try{if(!e.trim())throw new M("FloPayCardSetup requires a sessionId.","validation_error",{code:"MissingCheckoutSessionId",param:"sessionId"});if(!r.trim())throw new M("FloPayCardSetup requires a session nonce.","validation_error",{code:"MissingCheckoutSessionToken",param:"nonce"});let D=await V.getUnifiedCheckoutSession(e,r);if(!d)return;let x=D.data.session;if(!x||!Qe(x))throw new M("FloPayCardSetup only accepts a zero-amount, productless setup session.","validation_error",{code:"InvalidCardSetupSession",param:"sessionId"});let O=x.vault;if(O?.html?.trim()||(O=await V.getVaultCapture(e,r)),!O.html?.trim())throw new M("FloPay: this setup session has no vault card capability. Upgrade the billing backend integration.","api_error",{code:"UnsupportedBackendVaultCapability"});if(!d)return;C(O),T(new Je({sessionId:e,operation:"card_setup",telemetry:n}))}catch(D){if(!d)return;let x=xe(D);N.current=!0,L(x),E(()=>q.current?.(x))}})(),()=>{d=!1,V.destroy()}},[t,r,e,n]),re(()=>{if(!p)return;let d=!1;_.current=!1,R.current=!1;let V=p.on("submitting",()=>{R.current=!0,B(null),m("processing")}),D=p.on("complete",v=>{N.current=!0,R.current=!1,m("success"),(async()=>(await new Promise(J=>setTimeout(J,600)),!_.current&&(_.current=!0,E(()=>{oe.current?.({status:"succeeded",sessionId:e,...v.paymentMethod?{paymentMethod:v.paymentMethod}:{}})}),d||m(null))))()}),x=p.on("decline",v=>{N.current=!0,R.current=!1,B(v.message??null),m("error"),E(()=>{ie.current?.({status:"declined",sessionId:e,...v.declineReason?{reason:v.declineReason}:{},...v.message?{message:v.message}:{}})}),(async()=>(await new Promise(J=>setTimeout(J,400)),d||m(null)))()}),O=p.on("challenge_dismissed",()=>{m(null)});return()=>{d=!0,V(),D(),x(),O()}},[p,e]),P?X("div",{role:"alert",children:P.message}):!p||!k?.html?X(ve,{children:a}):tr(ve,{children:[w&&X(me,{status:w,errorMessage:G,processingLabel:"SAVING CARD...",successLabel:"CARD SAVED",errorLabel:"CARD NOT SAVED",successNote:null,...S?{theme:S}:{}}),X(de,{capture:p,html:k.html,messageToken:k.messageToken,expectedOrigin:k.expectedOrigin,theme:H,containerStyle:j,onReady:()=>{E(()=>ne.current?.())},onValidation:d=>{E(()=>se.current?.(d))},onError:d=>{if(!d)return;R.current&&(R.current=!1,B(d),m("error"),setTimeout(()=>m(null),400));let V=xe(new Error(d),{code:"card_setup_widget_failed",retryable:!0});E(()=>q.current?.(V))}})]})}export{
|
|
6
|
+
`})]})})}var ye=/^#([0-9a-f]{6})$/i,Be=/^#([0-9a-f]{3})$/i,be=/^rgb\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*\)$/i,he=/^rgba\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(0|1|0?\.\d+|1\.0+)\s*\)$/i,Oe=/^linear-gradient\(\s*(-?\d+(?:\.\d+)?)deg\s*,\s*(.+)\)$/i,Ie=/^(-?\d+(?:\.\d+)?)(?:px)?$/,Me=/^(-?\d+(?:\.\d+)?)em$/,_e=/^blur\(\s*(\d+(?:\.\d+)?)(?:px)?\s*\)$/i,Ne=/^[a-z][a-z0-9 -]{0,31}$/i,De=new Set(["none","uppercase","lowercase","capitalize"]);function Ce(e){if(typeof e!="string")return null;let r=e.trim(),t=ye.exec(r);if(t){let l=Number.parseInt(t[1],16);return{r:l>>16&255,g:l>>8&255,b:l&255,a:null}}let n=Be.exec(r);if(n){let[l,f,y]=n[1].split("").map(p=>Number.parseInt(p+p,16));return{r:l,g:f,b:y,a:null}}let o=be.exec(r),i=o?null:he.exec(r),a=o??i;if(!a)return null;let u=Number(a[1]),s=Number(a[2]),c=Number(a[3]);return u>255||s>255||c>255?null:{r:u,g:s,b:c,a:i?Number(i[4]):null}}function Se({r:e,g:r,b:t,a:n}){return n===null?`#${(1<<24|e<<16|r<<8|t).toString(16).slice(1)}`:`rgba(${e},${r},${t},${n})`}function z(e){if(typeof e!="string")return;let r=e.trim();if(ye.test(r)||be.test(r))return r;let t=he.exec(r);if(t&&/^\d/.test(t[4]))return r;let n=Ce(r);return n?Se(n):void 0}function Y(e,r=.12){let t=Ce(e);if(!t)return e;let n=Math.max(0,Math.min(1,1-r));return Se({r:Math.round(t.r*n),g:Math.round(t.g*n),b:Math.round(t.b*n),a:t.a})}function W(e,r){let t=[],n=0,o="";for(let i of e){if(i==="("&&(n+=1),i===")"&&(n-=1),i===r&&n===0){o.trim()&&t.push(o.trim()),o="";continue}o+=i}return o.trim()&&t.push(o.trim()),t}function A(e,r,t){if(typeof e!="number"&&typeof e!="string")return;let n=Ie.exec(String(e).trim());if(!n)return;let o=Number(n[1]);return Number.isFinite(o)&&o>=r&&o<=t?o:void 0}function ze(e,r,t){if(typeof e!="string")return;let n=Me.exec(e.trim());if(!n)return;let o=Number(n[1]);return Number.isFinite(o)&&o>=r&&o<=t?o:void 0}function We(e){let r=W(e,",");if(r.length<2||r.length>5)return;let t=[];for(let[n,o]of r.entries()){let i=W(o," "),a=z(i[0]);if(!a)return;let u=n/(r.length-1)*100,s=i[1]===void 0?u:Number(/^(\d+(?:\.\d+)?)%$/.exec(i[1])?.[1]),c=t[t.length-1]?.position??-1;if(!Number.isFinite(s)||s<0||s>100||s<c)return;t.push({color:a,position:s})}return{type:"linearGradient",angle:0,stops:t}}function $e(e){if(typeof e!="string")return;let r=e.trim(),t=z(r);if(t)return{type:"solid",color:t};let n=Oe.exec(r);if(!n)return;let o=Number(n[1]);if(!Number.isFinite(o)||o<0||o>360)return;let i=We(n[2]);return i&&i.type==="linearGradient"?{...i,angle:o}:void 0}function Ge(e){return e.type==="solid"?{type:"solid",color:Y(e.color)}:{...e,stops:e.stops.map(r=>({...r,color:Y(r.color)}))}}function He(e){let r=!1,t,n=[];for(let s of W(e," ")){if(s.toLowerCase()==="inset"){r=!0;continue}let c=z(s);if(c){t=c;continue}let l=A(s,-128,128);if(l===void 0)return;n.push(l)}if(!t||n.length<2||n.length>4)return;let[o,i,a=0,u=0]=n;if(!(Math.abs(o)>64||Math.abs(i)>64||a>128||Math.abs(u)>32))return{color:t,inset:r,offsetX:o,offsetY:i,blur:a,spread:u}}function Ye(e){if(typeof e!="string")return;let r=e.trim();if(r.toLowerCase()==="none")return[];let t=W(r,",").map(He);if(!(t.length===0||t.length>4))return t.every(n=>n!==void 0)?t:void 0}function ge(e){if(typeof e!="string")return;let r=W(e,",").map(t=>t.replace(/^['"]|['"]$/g,"").trim()).filter(t=>Ne.test(t)).slice(0,4);return r.length>0?r:void 0}function Ue(e){let r=typeof e=="string"?e.trim().split(/\s+/):[e],t=A(r[0],0,64),n=A(r[1]??r[0],0,64);if(!(t===void 0||n===void 0))return{paddingBlock:t,paddingInline:n}}function Xe(e){if(e==="bold")return 700;if(e==="normal")return 400;let r=Number(e);return Number.isInteger(r)&&r>=100&&r<=900?r:void 0}function ke({appearance:e,buttonsStyles:r,fontFamily:t}){let n=r.submitButton;if(!n)return;let o=e?.variables,i=$e(n.background??n.backgroundColor),a=z(o?.colorPrimaryHover),u=a?{type:"solid",color:a}:i&&Ge(i),s={fontFamilies:ge(n.fontFamily)??ge(t),fontSize:A(n.fontSize??r.submitButtonFontSize,10,32)??16,fontWeight:Xe(n.fontWeight)??600,letterSpacing:ze(n.letterSpacing,-.1,.5)??.01,lineHeight:A(n.lineHeight,.8,2)??1,textTransform:De.has(String(n.textTransform))?n.textTransform:"uppercase"},c=Ue(n.padding),l=Ye(n.boxShadow),f=A(n.borderRadius,0,9999),y=typeof n.backdropFilter=="string"?A(_e.exec(n.backdropFilter.trim())?.[1],0,40):void 0;return{foregroundColor:z(n.color)??"#FFFFFF",...i?{background:i,disabledBackground:i}:{},...u?{hoverBackground:u}:{},typography:s,...c?{spacing:c}:{},...l?{shadow:l}:{},...f===void 0?{}:{borderRadius:f},disabledOpacity:e?.theme==="night"?.8:.6,...y===void 0?{}:{backdropBlur:y}}}function je(e,r=.12){let t=e.trim(),n=/^[0-9a-fA-F]{6}$/.test(t)?`#${t}`:t;return/^#[0-9a-fA-F]{6}$/.test(n)?Y(n,r):e}function qe(e){if(typeof e=="number"||typeof e=="string")return e}function we({appearance:e,buttonsStyles:r,layout:t="default"}){let n=e?.variables,o=f=>typeof f=="string"&&f?f:void 0,i=r.submitButton,a=o(n?.colorPrimary)??o(i?.backgroundColor)??"#4A49FF",u=t==="buttons",s=r.nameInput,c=o(s?.fontFamily)??o(n?.fontFamily)??"Poppins, sans-serif",l=ke({appearance:e,buttonsStyles:r,fontFamily:c});return{primaryColor:a,primaryHoverColor:o(n?.colorPrimaryHover)??je(a,.12),inputBackgroundColor:o(r.cardInputBackground)??o(n?.colorBackground)??"#ffffff",textColor:o(r.cardInputColor)??o(s?.color)??o(n?.colorText)??"#262833",borderColor:o(r.cardInputBorder)??(u?"#e5e7eb":"#A4A4FF"),placeholderColor:o(r.cardInputPlaceholderColor)??"#9ca3af",errorColor:o(n?.colorDanger)??"#dc2626",successColor:"#16a34a",fontFamily:c,fontSize:o(r.cardInputFontSize)??o(n?.fontSizeBase)??"16px",fontWeight:String(qe(s?.fontWeight)??400),borderRadius:o(n?.borderRadius)??"8px",...l?{submitButton:l}:{}}}import{Fragment as ve,jsx as X,jsxs as tr}from"react/jsx-runtime";var te=class extends M{constructor(r,t,n){super(r,t,n),this.name="FloPayCardSetupError",this.retryable=n.retryable}};function xe(e,r={}){let t=e instanceof M?e:void 0,n=t?.statusCode,o=r.retryable??(t?.type==="network_error"||t?.type==="rate_limit_error"||typeof n=="number"&&n>=500||t?.code==="vault_capture_timeout"||!t);return new te(t?.message??(e instanceof Error?e.message:"Failed to load the secure card form."),t?.type??"api_error",{code:r.code??t?.code??"card_setup_load_failed",retryable:o,...t?.param?{param:t.param}:{},...n===void 0?{}:{statusCode:n}})}function Er({sessionId:e,nonce:r,billingApiUrl:t,telemetry:n,theme:o="modern-light",containerStyle:i,loading:a=null,onReady:u,onComplete:s,onDecline:c,onCancel:l,onValidation:f,onError:y}){let[p,T]=$(null),[k,C]=$(null),[P,L]=$(null),[w,m]=$(null),[G,B]=$(null),R=h(!1),_=h(!1),b=U(()=>typeof o=="object"?void 0:rr(o),[o]),H=U(()=>typeof o=="object"?o:b?we({appearance:b.appearance,buttonsStyles:b.buttonsLayout,layout:"default"}):null,[b,o]),j=U(()=>ue(b?.buttonsLayout.cardFormContainer,i),[b,i]),S=U(()=>b?pe(b):void 0,[b]),ne=h(u),q=h(y),oe=h(s),ie=h(c),ae=h(l),se=h(f),N=h(!1),K=h(!1),Z=h(0);return ne.current=u,q.current=y,oe.current=s,ie.current=c,ae.current=l,se.current=f,re(()=>{let d=Z.current+1;return Z.current=d,()=>{queueMicrotask(()=>{Z.current===d&&(N.current||K.current||(K.current=!0,E(()=>{ae.current?.({status:"cancelled",sessionId:e})})))})}},[e]),re(()=>{let d=!0,V=new Ze(er(t),{telemetry:n});return T(null),C(null),L(null),N.current=!1,K.current=!1,(async()=>{try{if(!e.trim())throw new M("FloPayCardSetup requires a sessionId.","validation_error",{code:"MissingCheckoutSessionId",param:"sessionId"});if(!r.trim())throw new M("FloPayCardSetup requires a session nonce.","validation_error",{code:"MissingCheckoutSessionToken",param:"nonce"});let D=await V.getUnifiedCheckoutSession(e,r);if(!d)return;let x=D.data.session;if(!x||!Qe(x))throw new M("FloPayCardSetup only accepts a zero-amount, productless setup session.","validation_error",{code:"InvalidCardSetupSession",param:"sessionId"});let O=x.vault;if(O?.html?.trim()||(O=await V.getVaultCapture(e,r)),!O.html?.trim())throw new M("FloPay: this setup session has no vault card capability. Upgrade the billing backend integration.","api_error",{code:"UnsupportedBackendVaultCapability"});if(!d)return;C(O),T(new Je({sessionId:e,operation:"card_setup",telemetry:n}))}catch(D){if(!d)return;let x=xe(D);N.current=!0,L(x),E(()=>q.current?.(x))}})(),()=>{d=!1,V.destroy()}},[t,r,e,n]),re(()=>{if(!p)return;let d=!1;_.current=!1,R.current=!1;let V=p.on("submitting",()=>{R.current=!0,B(null),m("processing")}),D=p.on("complete",v=>{N.current=!0,R.current=!1,m("success"),(async()=>(await new Promise(J=>setTimeout(J,600)),!_.current&&(_.current=!0,E(()=>{oe.current?.({status:"succeeded",sessionId:e,...v.paymentMethod?{paymentMethod:v.paymentMethod}:{}})}),d||m(null))))()}),x=p.on("decline",v=>{N.current=!0,R.current=!1,B(v.message??null),m("error"),E(()=>{ie.current?.({status:"declined",sessionId:e,...v.declineReason?{reason:v.declineReason}:{},...v.message?{message:v.message}:{}})}),(async()=>(await new Promise(J=>setTimeout(J,400)),d||m(null)))()}),O=p.on("challenge_dismissed",()=>{m(null)});return()=>{d=!0,V(),D(),x(),O()}},[p,e]),P?X("div",{role:"alert",children:P.message}):!p||!k?.html?X(ve,{children:a}):tr(ve,{children:[w&&X(me,{status:w,errorMessage:G,processingLabel:"SAVING CARD...",successLabel:"CARD SAVED",errorLabel:"CARD NOT SAVED",successNote:null,...S?{theme:S}:{}}),X(de,{capture:p,html:k.html,messageToken:k.messageToken,expectedOrigin:k.expectedOrigin,theme:H,containerStyle:j,onReady:()=>{E(()=>ne.current?.())},onValidation:d=>{E(()=>se.current?.(d))},onError:d=>{if(!d)return;R.current&&(R.current=!1,B(d),m("error"),setTimeout(()=>m(null),400));let V=xe(new Error(d),{code:"card_setup_widget_failed",retryable:!0});E(()=>q.current?.(V))}})]})}export{ue as a,pe as b,E as c,me as d,ce as e,de as f,je as g,qe as h,we as i,te as j,xe as k,Er as l};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var a=new Set(["err_blocked_by_client","notallowederror","popup_blocked","popupblocked"]),s=["https://www.paypal.com","https://www.sandbox.paypal.com"];function y(e,n,o){let t=`We couldn't open ${e}. Try again or choose another payment method.`;return n?o?`${t} Open this page in your system browser, then try again.`:`${t} Allow pop-ups for this site, then try again.`:t}function i(e){if(e instanceof Error)return e.message;if(typeof e=="object"&&e!==null){let n=e.message;return typeof n=="string"?n:void 0}return typeof e=="string"?e:void 0}function r(e){if(typeof e!="string")return;let n=e.trim();return/^[a-z0-9_.-]{1,64}$/i.test(n)?n:void 0}function p(e){if(typeof e!="object"||e===null)return;let n=e;return r(n.code)??r(n.type)??r(n.name)}function l(e){if(!(typeof e!="object"||e===null))return r(e.decline_code)}function u(e){return typeof e!="object"||e===null?!1:r(e.type)?.toLowerCase()==="card_error"||l(e)!==void 0}function d(e){let n=i(e)?.toLowerCase()??"",o=p(e)?.toLowerCase()??"";return a.has(o)?!0:/(?:popup|pop-up).{0,40}(?:block|denied|prevent)/i.test(n)||/(?:block|denied|prevent).{0,40}(?:popup|pop-up)/i.test(n)}function c(e){if(p(e)?.toLowerCase()==="paypal_init_timeout")return!0;let o=i(e)??"";return o.includes("No ack for postMessage init()")&&s.some(t=>o.includes(t))&&o.includes("10000ms")}function f(e,n){if(u(e))return{errorCode:"PROVIDER_RUNTIME_FAILED",popupBlocked:!1,providerDeclined:!0,terminalReason:"provider_declined"};let t=d(e)||n.inAppBrowser&&!n.handoffObserved&&c(e);return{errorCode:t?"POPUP_BLOCKED":"PROVIDER_RUNTIME_FAILED",popupBlocked:t,providerDeclined:!1,terminalReason:t?"popup_blocked":"provider_error"}}function P(e){return f(e,{inAppBrowser:!1,handoffObserved:!1}).popupBlocked}function m(e){let n=e??(typeof navigator>"u"?"":navigator.userAgent),o=t=>({inAppBrowser:t!=="none",appFamily:t,popupCapability:"unknown"});return n?/FBAN|FBAV|FB_IAB|FBIOS/i.test(n)?o("facebook"):/Instagram/i.test(n)?o("instagram"):/musical_ly|BytedanceWebview|TikTok/i.test(n)?o("tiktok"):/Twitter|Snapchat|Pinterest|LinkedInApp|Line\/|MicroMessenger|GSA\//i.test(n)?o("other_in_app"):/Android.*;\s?wv\)/.test(n)||/(iPhone|iPad|iPod).*AppleWebKit(?!.*Safari)/.test(n)?o("generic_webview"):o("none"):o("none")}function b(e,n,o=e.popupCapability){return e.inAppBrowser||o==="blocked"||n==="prefer_redirect"?"redirect":"popup"}function g(e,n,o){return!e.inAppBrowser||o!=="order"?"popup":n==="app_switch"||n==="redirect"?n:"popup"}export{y as a,r as b,p as c,l as d,u as e,c as f,f as g,P as h,m as i,b as j,g as k};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as M,e as k,g as A,i as R,j as B}from"./chunk-M7R46EDF.mjs";import{PaymentAPI as L}from"@flopay/js/card-setup";import{FloPayError as W,getStripeMethodDisplayName as D}from"@flopay/shared";import{Elements as N,ExpressCheckoutElement as j,PaymentElement as q,useElements as H,useStripe as K}from"@stripe/react-stripe-js";import{loadStripe as O}from"@stripe/stripe-js";import{useCallback as C,useMemo as U,useRef as X,useState as f}from"react";import{Fragment as ee,jsx as u,jsxs as te}from"react/jsx-runtime";var x={apple_pay:{types:["card"],wallet:"applePay"},google_pay:{types:["card"],wallet:"googlePay"},link:{types:["link"],wallet:"link"},paypal:{types:["paypal"],wallet:"paypal"},amazon_pay:{types:["amazon_pay"],wallet:"amazonPay"}},v=new Map;function G(e){let n=v.get(e);if(n)return n;let o=O(e).catch(a=>{throw v.delete(e),a});return v.set(e,o),o}var J={night:"night",flat:"flat"};function Q(e){return e?{theme:J[e.theme??"default"]??"stripe",...e.variables?{variables:e.variables}:{},...e.rules?{rules:e.rules}:{}}:void 0}function Y(e){return k(e)||e.code==="setup_intent_authentication_failure"||e.code==="payment_method_provider_decline"}function Z(e){return e==="paypal"?"PayPal":D(e)}function $(){return typeof window>"u"?"":window.location.href}function le(e){let{publishableKey:n,method:o,currency:a,appearance:p}=e,[d]=f(()=>G(n)),m=U(()=>{let i=Q(p);return{mode:"setup",currency:a.toLowerCase(),paymentMethodTypes:x[o]?.types??[o],...i?{appearance:i}:{}}},[p,a,o]);return u(N,{stripe:d,options:m,children:u(V,{...e})})}function V({method:e,category:n,sessionId:o,nonce:a,billingApiUrl:p,telemetry:d,onSubmitting:m,onConfirmed:i,onDeclined:E,onFailed:g,onValidation:h}){let y=K(),l=H(),[I,_]=f(!1),P=X(!1),[c]=f(()=>R()),[T,F]=f(!1),S=C((t,s)=>{if(A(t,{inAppBrowser:c.inAppBrowser,handoffObserved:!1}).popupBlocked){F(!0),g(new Error(M(Z(e),!0,c.inAppBrowser)),{code:"popup_blocked",retryable:!0});return}g(s.message===void 0?t:new Error(s.message),{code:s.code,retryable:!0})},[c.inAppBrowser,e,g]),b=C(async()=>{if(!(!y||!l||P.current)){P.current=!0,_(!0);try{let t=await l.submit();if(t.error){h(t.error.message??null);return}m();let s=await new L(p,{telemetry:d}).createSessionIntent(o,a,{provider:"stripe",paymentMethodCategory:n,paymentMethodType:e,paymentMethodId:null,intentKind:"setup"});if(s.provider!=="stripe"||s.intentKind!=="setup")throw new W("The billing API returned a non-setup intent.","api_error",{code:"InvalidSessionIntentResponse"});let r=await y.confirmSetup({elements:l,clientSecret:s.clientSecret,confirmParams:{return_url:$()},redirect:"if_required"});if(r.error){Y(r.error)?E({...r.error.decline_code||r.error.code?{reason:r.error.decline_code??r.error.code}:{},...r.error.message?{message:r.error.message}:{}}):S(r.error,{code:"payment_method_setup_provider_failed",message:r.error.message??"The payment method could not be saved."});return}i()}catch(t){S(t,{code:"payment_method_setup_failed"})}finally{P.current=!1,_(!1)}}},[p,n,l,e,a,i,E,m,h,S,o,y,d]),w=x[e]?.wallet,z=w==="paypal"&&B(c,"auto",T?"blocked":c.popupCapability)==="redirect";if(n==="wallet"&&w&&!z){let t={applePay:"never",googlePay:"never",link:"never",paypal:"never",amazonPay:"never"};return t[w]="auto",u(j,{options:{paymentMethods:t},onConfirm:()=>{b()}})}return te(ee,{children:[u(q,{onChange:t=>{t.complete&&h(null)}}),u("button",{type:"button","data-flopay-payment-method-save":e,disabled:!y||!l||I,onClick:()=>{b()},children:"Save payment method"})]})}export{le as a};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as ce,b as pe,c as h,d as me,f as ye,i as fe,k as F}from"./chunk-I4TPZWBS.mjs";import{PaymentAPI as _e,PciVaultCardCapture as Ie}from"@flopay/js/card-setup";import{FloPayError as P,isCardSetupCheckoutSession as Le,resolveBillingApiUrl as H,resolveTheme as xe}from"@flopay/shared";import Ne,{Suspense as we,useCallback as L,useEffect as j,useMemo as T,useRef as g,useState as b}from"react";var Ve=new Set(["apple_pay","google_pay","link","paypal","amazon_pay"]);function Se(t){let i=t.data.stripe,r=Array.from(new Set(i?.enabledPaymentMethods??[])),a=t.data.paypal,o=a?.publishableKey?{clientId:a.publishableKey,...a.environment?{environment:String(a.environment)}:{}}:null,u=r.filter(f=>f!=="card"&&!(o&&f==="paypal"));return{card:r.includes("card"),stripe:i?.publishableKey&&u.length>0?{publishableKey:i.publishableKey,methods:u}:null,paypal:o}}function he(t){return t.card||t.stripe!==null||t.paypal!==null}function ve(t){return Ve.has(t)?"wallet":"apm"}var Oe=["setup_intent","setup_intent_client_secret","redirect_status"];function ge(){if(typeof window>"u")return null;let t=new URLSearchParams(window.location.search);return!t.has("setup_intent")||!t.has("redirect_status")?null:{failed:t.get("redirect_status")==="failed"}}function Pe(){if(typeof window>"u")return;let t=new URL(window.location.href),i=!1;for(let r of Oe)t.searchParams.has(r)&&(t.searchParams.delete(r),i=!0);i&&window.history.replaceState(window.history.state,"",t.toString())}function Ce(t){return t==="card"?{processingLabel:"SAVING CARD...",successLabel:"CARD SAVED",errorLabel:"CARD NOT SAVED"}:{processingLabel:"SAVING PAYMENT METHOD...",successLabel:"PAYMENT METHOD SAVED",errorLabel:"PAYMENT METHOD NOT SAVED"}}import{Fragment as Ee,jsx as p,jsxs as Re}from"react/jsx-runtime";var Be=15,Ue=2e3;function Ye(t){return{userId:t.customer?.id??"",email:t.customer?.email??""}}function q(t){return new Promise(i=>setTimeout(i,t))}async function Ge(t,i,r){if(!i.trim())throw new P("FloPayPaymentMethodSetup requires a sessionId.","validation_error",{code:"MissingCheckoutSessionId",param:"sessionId"});if(!r.trim())throw new P("FloPayPaymentMethodSetup requires a session nonce.","validation_error",{code:"MissingCheckoutSessionToken",param:"nonce"});let a=await t.getUnifiedCheckoutSession(i,r),o=a.data.session;if(!o||!Le(o))throw new P("FloPayPaymentMethodSetup only accepts a zero-amount, productless setup session.","validation_error",{code:"InvalidPaymentMethodSetupSession",param:"sessionId"});let u=Se(a);if(!he(u))throw new P("FloPay: this setup session advertises no payment method.","validation_error",{code:"NoAdvertisedPaymentMethods",param:"sessionId"});return{session:o,advertisement:u}}async function Ke(t,i,r,a){let o=i.vault??null;if(o?.html?.trim()||(o=await t.getVaultCapture(r,a)),!o.html?.trim())throw new P("FloPay: this setup session has no vault card capability. Upgrade the billing backend integration.","api_error",{code:"UnsupportedBackendVaultCapability"});return o}var x=class extends Ne.Component{constructor(){super(...arguments);this.state={failed:!1}}static getDerivedStateFromError(){return{failed:!0}}componentDidCatch(r){this.props.onFailed(r,{code:"payment_method_setup_load_failed",retryable:!1})}render(){return this.state.failed?null:this.props.children}};function rt({branches:{StripeSetupMethod:t,PayPalSetupMethod:i},sessionId:r,nonce:a,billingApiUrl:o,telemetry:u,theme:f="modern-light",containerStyle:z,loading:Me=null,onReady:J,onComplete:Q,onDecline:X,onCancel:Z,onValidation:$,onError:ee}){let[N]=b(ge),[B,U]=b(null),[Ae,Y]=b(!1),[v,te]=b(null),[k,re]=b(null),[ne,ae]=b(null),[V,d]=b(null),S=g(!1),G=g(!1),M=g(!1),K=g(!1),W=g(0),O=g(0),_=g(!1),m=T(()=>typeof f=="object"?void 0:xe(f),[f]),Fe=T(()=>typeof f=="object"?f:m?fe({appearance:m.appearance,buttonsStyles:m.buttonsLayout,layout:"default"}):null,[m,f]),Te=T(()=>ce(m?.buttonsLayout.cardFormContainer,z),[m,z]),oe=T(()=>m?pe(m):void 0,[m]),l=g({sessionId:r,nonce:a,billingApiUrl:o,telemetry:u,onReady:J,onComplete:Q,onDecline:X,onCancel:Z,onValidation:$,onError:ee});l.current={sessionId:r,nonce:a,billingApiUrl:o,telemetry:u,onReady:J,onComplete:Q,onDecline:X,onCancel:Z,onValidation:$,onError:ee},j(()=>{_.current=!0;let e=W.current+1;return W.current=e,()=>{_.current=!1,O.current+=1,queueMicrotask(()=>{W.current===e&&(M.current||K.current||(K.current=!0,h(()=>{l.current.onCancel?.({status:"cancelled",sessionId:r})})))})}},[r]);let w=L((e,n)=>{M.current=!0,S.current=!1,d({status:"success",wording:e,message:null}),(async()=>(await q(600),!G.current&&(G.current=!0,h(()=>{l.current.onComplete?.({status:"succeeded",sessionId:l.current.sessionId,...n?{paymentMethod:n}:{}})}),_.current&&d(null))))()},[]),E=L((e,n)=>{M.current=!0,S.current=!1,d({status:"error",wording:e,message:n.message??null}),h(()=>{l.current.onDecline?.({status:"declined",sessionId:l.current.sessionId,...n.reason?{reason:n.reason}:{},...n.message?{message:n.message}:{}})}),(async()=>(await q(400),_.current&&d(null)))()},[]),A=L((e,n)=>{S.current?(S.current=!1,d({status:"error",wording:e,message:n.message}),setTimeout(()=>{_.current&&d(null)},400)):d(null),h(()=>l.current.onError?.(n))},[]),D=L(async e=>{let n=O.current+1;O.current=n;let c=()=>!_.current||n!==O.current;S.current=!0,d({status:"processing",wording:"payment_method",message:null});let y=new _e(H(l.current.billingApiUrl),{telemetry:l.current.telemetry});try{for(let s=0;s<Be;s+=1){if((s>0||e.waitFirst)&&await q(Ue),c())return;let R=await y.getUnifiedCheckoutSession(l.current.sessionId,l.current.nonce);if(c())return;let de=R.data.session?.status;if(de==="complete"){Y(!0),w("payment_method");return}if(de==="expired")throw new P("This setup session expired before the payment method was saved.","validation_error",{code:"payment_method_setup_expired"})}throw new P("The payment method could not be confirmed yet. Please try again.","api_error",{code:"payment_method_setup_unverified"})}catch(s){if(c())return;let R=s instanceof P&&s.code==="payment_method_setup_unverified";A("payment_method",F(s,R?{retryable:!0}:{}))}finally{y.destroy()}},[A,w]);j(()=>{let e=!0,n=new _e(H(o),{telemetry:u});return U(null),Y(!1),te(null),re(null),ae(null),M.current=!1,K.current=!1,G.current=!1,(async()=>{try{let{session:c,advertisement:y}=await Ge(n,r,a);if(!e)return;let s={advertisement:y,currency:c.currency,customer:Ye(c)};if(N){if(Pe(),c.status==="complete"){Y(!0),U(s),w("payment_method");return}N.failed?E("payment_method",{reason:"redirect_failed"}):D({waitFirst:!0})}let R=y.card?await Ke(n,c,r,a):null;if(!e)return;U(s),R&&(re(R),te(new Ie({sessionId:r,operation:"card_setup",telemetry:u})))}catch(c){if(!e)return;let y=F(c);M.current=!0,ae(y),h(()=>l.current.onError?.(y))}})(),()=>{e=!1,n.destroy()}},[o,a,N,E,w,r,u,D]),j(()=>{if(!v)return;S.current=!1;let e=v.on("submitting",()=>{S.current=!0,d({status:"processing",wording:"card",message:null})}),n=v.on("complete",s=>{w("card",s.paymentMethod)}),c=v.on("decline",s=>{E("card",{...s.declineReason?{reason:s.declineReason}:{},...s.message?{message:s.message}:{}})}),y=v.on("challenge_dismissed",()=>{d(null)});return()=>{e(),n(),c(),y()}},[v,E,w]);let I=T(()=>({onSubmitting:()=>{S.current=!0,d({status:"processing",wording:"payment_method",message:null})},onConfirmed:()=>{D({waitFirst:!1})},onDeclined:e=>E("payment_method",e),onFailed:(e,n)=>{A("payment_method",F(e,n))},onValidation:e=>{h(()=>l.current.onValidation?.(e))},onAbandoned:()=>{S.current=!1,d(null)}}),[E,A,D]),se=V?p(me,{status:V.status,errorMessage:V.message,...Ce(V.wording),successNote:null,...oe?{theme:oe}:{}}):null;if(ne)return p("div",{role:"alert",children:ne.message});if(!B||Ae)return Re(Ee,{children:[se,B?null:Me]});let{advertisement:C,currency:ie,customer:ke}=B,le=H(o),ue=u===void 0?{}:{telemetry:u};return Re(Ee,{children:[se,C.card&&v&&k?.html?p("div",{"data-flopay-payment-method":"card",children:p(ye,{capture:v,html:k.html,messageToken:k.messageToken,expectedOrigin:k.expectedOrigin,theme:Fe,containerStyle:Te,onReady:()=>{h(()=>l.current.onReady?.())},onValidation:e=>{h(()=>l.current.onValidation?.(e))},onError:e=>{e&&A("card",F(new Error(e),{code:"card_setup_widget_failed",retryable:!0}))}})}):null,C.stripe?.methods.map(e=>p("div",{"data-flopay-payment-method":e,children:p(x,{onFailed:I.onFailed,children:p(we,{fallback:null,children:p(t,{method:e,category:ve(e),publishableKey:C.stripe?.publishableKey??"",currency:ie,sessionId:r,nonce:a,billingApiUrl:le,...ue,...m?{appearance:m.appearance}:{},...I})})})},e)),C.paypal?p("div",{"data-flopay-payment-method":"paypal",children:p(x,{onFailed:I.onFailed,children:p(we,{fallback:null,children:p(i,{clientId:C.paypal.clientId,...C.paypal.environment?{environment:C.paypal.environment}:{},currency:ie,sessionId:r,nonce:a,billingApiUrl:le,customer:ke,...ue,...I})})})}):null]})}export{rt as a};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as T,g as A,i as R}from"./chunk-M7R46EDF.mjs";import{PaymentAPI as I}from"@flopay/js/card-setup";import{FloPayError as p,PAYPAL_VAULTED_PAYMENT_METHOD_TYPE as B}from"@flopay/shared";import{loadScript as x}from"@paypal/paypal-js";import{useEffect as D,useRef as C,useState as O}from"react";import{jsx as F}from"react/jsx-runtime";function z({clientId:u,environment:o,currency:d,sessionId:s,nonce:i,billingApiUrl:y,telemetry:f,customer:{userId:m,email:P},onSubmitting:h,onConfirmed:_,onFailed:v,onAbandoned:b}){let w=C(null),t=C({onSubmitting:h,onConfirmed:_,onFailed:v,onAbandoned:b});t.current={onSubmitting:h,onConfirmed:_,onFailed:v,onAbandoned:b};let[l]=O(()=>R().inAppBrowser);return D(()=>{let a=!0,k,c=new I(y,{telemetry:f}),g={userId:m,email:P};return(async()=>{try{let n=await x({clientId:u,currency:d.toUpperCase(),components:"buttons",...o==="sandbox"||o==="production"?{environment:o}:{}}),M=w.current;if(!a||!M)return;if(!n?.Buttons)throw new p("PayPal could not be loaded.","api_error",{code:"paypal_unavailable"});let E=n.Buttons({createVaultSetupToken:async()=>{t.current.onSubmitting();let e=await c.createSessionIntent(s,i,{provider:"paypal",paymentMethodCategory:"wallet",paymentMethodType:B,paymentMethodId:null,intentKind:"setup"});if(e.provider!=="paypal"||e.providerObjectType!=="setup_token")throw new p("The billing API did not return a PayPal setup token.","api_error",{code:"InvalidSessionIntentResponse"});return e.providerObjectId},onApprove:async e=>{let r=e.vaultSetupToken;if(!r)throw new p("PayPal approved without a setup token.","api_error",{code:"paypal_setup_token_missing"});let S=await c.processPayment(g.userId,{sessionId:s,nonce:i,paymentMethodCategory:"paypal",tokenizedData:{id:r,type:"paypal_setup_token",isPaypal:!0,gateway:"paypal",paymentMethodType:B},accountData:g});if(!S.ok)throw new p("PayPal could not be saved.","api_error",{code:"paypal_setup_failed",statusCode:S.status});a&&t.current.onConfirmed()},onCancel:()=>{a&&t.current.onAbandoned()},onError:e=>{if(!a)return;let{popupBlocked:r}=A(e,{inAppBrowser:l,handoffObserved:!1});t.current.onFailed(r?new Error(T("PayPal",!0,l)):e,{code:r?"popup_blocked":"paypal_setup_failed",retryable:!0})}});k=()=>E.close(),await E.render(M)}catch(n){if(!a)return;t.current.onFailed(n,{code:"paypal_unavailable",retryable:!0})}})(),()=>{a=!1,k?.().catch(()=>{}),c.destroy()}},[y,u,d,P,o,l,i,s,f,m]),F("div",{ref:w,"data-flopay-paypal-setup":""})}export{z as a};
|