@juspay-tech/react-native-hyperswitch 1.3.3 → 1.3.4
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/ios/hyperswitchSDK/Core/NativeModule/RNHeadlessManager.swift +13 -7
- package/lib/commonjs/index.bundle.js +2 -2
- package/lib/commonjs/index.bundle.js.map +1 -1
- package/lib/module/index.bundle.js +2 -2
- package/lib/module/index.bundle.js.map +1 -1
- package/lib/typescript/src/views/ApplePayButton.d.ts +3 -1
- package/lib/typescript/src/views/ApplePayButton.d.ts.map +1 -1
- package/lib/typescript/src/views/GooglePayButton.d.ts +3 -1
- package/lib/typescript/src/views/GooglePayButton.d.ts.map +1 -1
- package/lib/typescript/src/views/useWalletReady.d.ts +22 -0
- package/lib/typescript/src/views/useWalletReady.d.ts.map +1 -0
- package/package.json +1 -1
- package/src/views/ApplePayButton.tsx +13 -0
- package/src/views/GooglePayButton.tsx +13 -0
- package/src/views/useWalletReady.ts +109 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{TurboModuleRegistry as e,NativeModules as t,requireNativeComponent as n,findNodeHandle as r,UIManager as o,Platform as a,useColorScheme as i,Pressable as s,StyleSheet as l}from"react-native";import u,{createContext as c,useContext as y,useState as d,useCallback as p,useEffect as f,forwardRef as m,useRef as g,useMemo as h,useImperativeHandle as b}from"react";const v=e.get("NativeHyperswitchModule")??t.NativeHyperswitchModule,w=e.get("NativeWidgetHelperModule")??t.NativeWidgetHelperModule;function S(e){switch(e){case"succeeded":case"completed":case"requires_capture":case"success":return"completed";case"cancelled":case"canceled":return"canceled";default:return"failed"}}function P(e){const t=function(e){if("object"==typeof e&&null!==e)return e;try{return JSON.parse(e)}catch{return{status:"failed",message:String(e)}}}(e);return{status:S(t.status),type:t.type??t.code??S(t.status)??"",message:t.message??t.code??""}}const E=new Map;function
|
|
1
|
+
import{TurboModuleRegistry as e,NativeModules as t,requireNativeComponent as n,findNodeHandle as r,UIManager as o,Platform as a,useColorScheme as i,Pressable as s,StyleSheet as l}from"react-native";import u,{createContext as c,useContext as y,useState as d,useCallback as p,useEffect as f,forwardRef as m,useRef as g,useMemo as h,useImperativeHandle as b}from"react";const v=e.get("NativeHyperswitchModule")??t.NativeHyperswitchModule,w=e.get("NativeWidgetHelperModule")??t.NativeWidgetHelperModule;function S(e){switch(e){case"succeeded":case"completed":case"requires_capture":case"success":return"completed";case"cancelled":case"canceled":return"canceled";default:return"failed"}}function P(e){const t=function(e){if("object"==typeof e&&null!==e)return e;try{return JSON.parse(e)}catch{return{status:"failed",message:String(e)}}}(e);return{status:S(t.status),type:t.type??t.code??S(t.status)??"",message:t.message??t.code??""}}const E=new Map;function _(e,t){E.set(e,t)}function C(e){E.delete(e)}function k(e){const t=[...E.values()].map(t=>new Promise(n=>{w.updateIntentCompleteForWidget(t,e,e=>n(P(e)))}));return Promise.all(t)}let O=!1;function N(e){O=e}let R=!1;function A(e){R=e}async function T(e){if(O)return{status:"failed",type:"initialization_in_progress",message:"SDK is reloading. Please wait for initialisation to complete before presenting the payment sheet."};if(R)return{status:"canceled",type:"sheet_already_presented",message:"A payment sheet is already presented."};A(!0);try{return P(await v.presentPaymentSheet({hyperswitchConfig:e.hyperswitchConfig,paymentSessionConfig:e.paymentSessionConfig,configuration:e.configuration}))}finally{A(!1)}}function j(e){if(!e)throw new Error("A widgetId is required to confirm a saved payment method");const t=function(e){return E.get(e)}(e);if(void 0===t)throw new Error(`Widget ${e} not found or not mounted`);return t}function M(e){if(null==e||"string"!=typeof e)return e??null;try{return JSON.parse(e)}catch{return null}}function W(e){try{const t=JSON.parse(e);return{...t,billing:M(t.billing)}}catch{return null}}async function D(e,t,n){const r={hyperswitchConfig:e,paymentSessionConfig:t,configuration:{...n,paymentMethodLayout:{savedMethodCustomization:{hiddenPaymentMethods:n?.hiddenPaymentMethods??[]}}}};return await v.getCustomerSavedPaymentMethods(r),{getCustomerLastUsedPaymentMethodData:async()=>W(await v.getCustomerLastUsedPaymentMethodData()),getCustomerDefaultSavedPaymentMethodData:async()=>W(await v.getCustomerDefaultSavedPaymentMethodData()),getCustomerSavedPaymentMethodData:async()=>W(await v.getCustomerSavedPaymentMethodData()),confirmWithCustomerLastUsedPaymentMethod:async e=>P(await v.confirmWithCustomerLastUsedPaymentMethod(j(e?.id))),confirmWithCustomerDefaultPaymentMethod:async e=>P(await v.confirmWithCustomerDefaultPaymentMethod(j(e?.id)))}}async function x(e,t){const n=await(r=v.getWalletSession({hyperswitchConfig:e,paymentSessionConfig:t}),o="getWalletSession",new Promise((e,t)=>{const n=setTimeout(()=>{t(new Error(`${o} timed out after 15000ms`))},15e3);r.then(t=>{clearTimeout(n),e(t)},e=>{clearTimeout(n),t(e)})}));var r,o;let a,i;try{const e=JSON.parse(n);a=e.status,i=e.message}catch{a=void 0}if("failed"===a)throw new Error(i??"Failed to initialise the wallet session");return{isWalletEligible:e=>v.isWalletEligible(e).catch(()=>!1),isGooglePayEligible:()=>v.isWalletEligible("google_pay").catch(()=>!1),isApplePayEligible:()=>v.isWalletEligible("apple_pay").catch(()=>!1),launchWallet:async e=>P(await v.launchWallet(e)),launchGooglePay:async()=>P(await v.launchWallet("google_pay")),launchApplePay:async()=>P(await v.launchWallet("apple_pay"))}}function I(e){return async function(t){const n=function(e,t,n){const r={...e};return delete r.platformPublishableKey,{hyperswitchConfig:r,paymentSessionConfig:t,configuration:n??{}}}(e.hyperswitchConfig,e.paymentSessionConfig,t);return T(n)}}function L(e){return function(t){return D(e.hyperswitchConfig,e.paymentSessionConfig,t)}}function U(e){return function(){return x(e.hyperswitchConfig,e.paymentSessionConfig)}}async function $(e){let t;try{await function(){const e=[...E.values()].map(e=>new Promise(t=>{w.updateIntentInitForWidget(e,e=>t(P(e)))}));return Promise.all(e)}(),t=await e(),await k(t.sdkAuthorization)}catch{return void await k("")}}function z(e,t){const n={hyperswitchConfig:e,paymentSessionConfig:t};return{presentPaymentSheet:I(n),async confirmPayment(e,t){if("string"==typeof e){return P(await function(e){const t=E.get(e);return void 0===t?Promise.resolve(JSON.stringify({status:"failed",message:`Widget ${e} not found or not mounted`,type:void 0})):new Promise(e=>{w.confirmPayment(t,e)})}(e))}const n=e.current;if(!n)throw new Error("PaymentElement reference is not mounted");return n.confirmPayment(t)},getCustomerSavedPaymentMethods:L(n),getWalletSession:U(n),updateIntent:$}}var F,H={exports:{}},B={};var K,G,J={};
|
|
2
2
|
/**
|
|
3
3
|
* @license React
|
|
4
4
|
* react-jsx-runtime.development.js
|
|
@@ -7,5 +7,5 @@ import{TurboModuleRegistry as e,NativeModules as t,requireNativeComponent as n,f
|
|
|
7
7
|
*
|
|
8
8
|
* This source code is licensed under the MIT license found in the
|
|
9
9
|
* LICENSE file in the root directory of this source tree.
|
|
10
|
-
*/function V(){return K||(K=1,"production"!==process.env.NODE_ENV&&function(){function e(t){if(null==t)return null;if("function"==typeof t)return t.$$typeof===_?null:t.displayName||t.name||null;if("string"==typeof t)return t;switch(t){case f:return"Fragment";case g:return"Profiler";case m:return"StrictMode";case w:return"Suspense";case S:return"SuspenseList";case C:return"Activity"}if("object"==typeof t)switch("number"==typeof t.tag&&console.error("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),t.$$typeof){case p:return"Portal";case b:return t.displayName||"Context";case h:return(t._context.displayName||"Context")+".Consumer";case v:var n=t.render;return(t=t.displayName)||(t=""!==(t=n.displayName||n.name||"")?"ForwardRef("+t+")":"ForwardRef"),t;case P:return null!==(n=t.displayName||null)?n:e(t.type)||"Memo";case E:n=t._payload,t=t._init;try{return e(t(n))}catch(e){}}return null}function t(e){return""+e}function n(e){try{t(e);var n=!1}catch(e){n=!0}if(n){var r=(n=console).error,o="function"==typeof Symbol&&Symbol.toStringTag&&e[Symbol.toStringTag]||e.constructor.name||"Object";return r.call(n,"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",o),t(e)}}function r(t){if(t===f)return"<>";if("object"==typeof t&&null!==t&&t.$$typeof===E)return"<...>";try{var n=e(t);return n?"<"+n+">":"<...>"}catch(e){return"<...>"}}function o(){return Error("react-stack-top-frame")}function a(){var t=e(this.type);return R[t]||(R[t]=!0,console.error("Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release.")),void 0!==(t=this.props.ref)?t:null}function i(t,r,o,i,l,u){var y,p=r.children;if(void 0!==p)if(i)if(N(p)){for(i=0;i<p.length;i++)s(p[i]);Object.freeze&&Object.freeze(p)}else console.error("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else s(p);if(O.call(r,"key")){p=e(t);var f=Object.keys(r).filter(function(e){return"key"!==e});i=0<f.length?"{key: someKey, "+f.join(": ..., ")+": ...}":"{key: someKey}",M[p+i]||(f=0<f.length?"{"+f.join(": ..., ")+": ...}":"{}",console.error('A props object containing a "key" prop is being spread into JSX:\n let props = %s;\n <%s {...props} />\nReact keys must be passed directly to JSX without using spread:\n let props = %s;\n <%s key={someKey} {...props} />',i,p,f,p),M[p+i]=!0)}if(p=null,void 0!==o&&(n(o),p=""+o),function(e){if(O.call(e,"key")){var t=Object.getOwnPropertyDescriptor(e,"key").get;if(t&&t.isReactWarning)return!1}return void 0!==e.key}(r)&&(n(r.key),p=""+r.key),"key"in r)for(var m in o={},r)"key"!==m&&(o[m]=r[m]);else o=r;return p&&function(e,t){function n(){c||(c=!0,console.error("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",t))}n.isReactWarning=!0,Object.defineProperty(e,"key",{get:n,configurable:!0})}(o,"function"==typeof t?t.displayName||t.name||"Unknown":t),function(e,t,n,r,o,i){var s=n.ref;return e={$$typeof:d,type:e,key:t,props:n,_owner:r},null!==(void 0!==s?s:null)?Object.defineProperty(e,"ref",{enumerable:!1,get:a}):Object.defineProperty(e,"ref",{enumerable:!1,value:null}),e._store={},Object.defineProperty(e._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:0}),Object.defineProperty(e,"_debugInfo",{configurable:!1,enumerable:!1,writable:!0,value:null}),Object.defineProperty(e,"_debugStack",{configurable:!1,enumerable:!1,writable:!0,value:o}),Object.defineProperty(e,"_debugTask",{configurable:!1,enumerable:!1,writable:!0,value:i}),Object.freeze&&(Object.freeze(e.props),Object.freeze(e)),e}(t,p,o,null===(y=k.A)?null:y.getOwner(),l,u)}function s(e){l(e)?e._store&&(e._store.validated=1):"object"==typeof e&&null!==e&&e.$$typeof===E&&("fulfilled"===e._payload.status?l(e._payload.value)&&e._payload.value._store&&(e._payload.value._store.validated=1):e._store&&(e._store.validated=1))}function l(e){return"object"==typeof e&&null!==e&&e.$$typeof===d}var c,y=u,d=Symbol.for("react.transitional.element"),p=Symbol.for("react.portal"),f=Symbol.for("react.fragment"),m=Symbol.for("react.strict_mode"),g=Symbol.for("react.profiler"),h=Symbol.for("react.consumer"),b=Symbol.for("react.context"),v=Symbol.for("react.forward_ref"),w=Symbol.for("react.suspense"),S=Symbol.for("react.suspense_list"),P=Symbol.for("react.memo"),E=Symbol.for("react.lazy"),C=Symbol.for("react.activity"),_=Symbol.for("react.client.reference"),k=y.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,O=Object.prototype.hasOwnProperty,N=Array.isArray,A=console.createTask?console.createTask:function(){return null},R={},T=(y={react_stack_bottom_frame:function(e){return e()}}).react_stack_bottom_frame.bind(y,o)(),j=A(r(o)),M={};J.Fragment=f,J.jsx=function(e,t,n){var o=1e4>k.recentlyCreatedOwnerStacks++;return i(e,t,n,!1,o?Error("react-stack-top-frame"):T,o?A(r(e)):j)},J.jsxs=function(e,t,n){var o=1e4>k.recentlyCreatedOwnerStacks++;return i(e,t,n,!0,o?Error("react-stack-top-frame"):T,o?A(r(e)):j)}}()),J}var Y=(G||(G=1,"production"===process.env.NODE_ENV?H.exports=function(){if(L)return B;L=1;var e=Symbol.for("react.transitional.element"),t=Symbol.for("react.fragment");function n(t,n,r){var o=null;if(void 0!==r&&(o=""+r),void 0!==n.key&&(o=""+n.key),"key"in n)for(var a in r={},n)"key"!==a&&(r[a]=n[a]);else r=n;return n=r.ref,{$$typeof:e,type:t,key:o,ref:void 0!==n?n:null,props:r}}return B.Fragment=t,B.jsx=n,B.jsxs=n,B}():H.exports=V()),H.exports);const q=c(void 0);function X({hyper:e,options:t,children:n}){const[r,o]=d(null),[a,i]=d(null),[s,l]=d(null),[u,c]=d(null),[y,m]=d(null),[g,h]=d(null),[b,v]=d(!0),[w,S]=d(null),[P,E]=d(null),[C,_]=d({googlePay:!1,applePay:!1}),[k,O]=d(!1),N=p(async()=>{if(!r)return null;O(!0);try{const e=await r.getWalletSession(),[t,n]=await Promise.all([e.isGooglePayEligible(),e.isApplePayEligible()]);return E(e),_({googlePay:t,applePay:n}),e}catch{return E(null),_({googlePay:!1,applePay:!1}),null}finally{O(!1)}},[r]);return f(()=>{E(null),_({googlePay:!1,applePay:!1})},[r]),f(()=>{if(!e)return;let n=!1;return(async()=>{try{const r=await Promise.resolve(e),a={sdkAuthorization:t.sdkAuthorization},s=await r.elements(a);n||(o({...s}),l(s.hyperswitchConfig),c(a),i(s),m(r.publishableKey??null),h(t.sdkAuthorization??null),v(!1))}catch(e){n||(S(e instanceof Error?e:new Error(String(e))),v(!1))}})(),()=>{n=!0}},[e,t.sdkAuthorization]),Y.jsx(q.Provider,{value:{paymentSession:r,walletSession:P,walletEligibility:C,walletLoading:k,loadWalletSession:N,elements:a,publishableKey:y,sdkAuthorization:g,loading:b,error:w,paymentSessionConfig:u,hyperswitchConfig:s},children:n})}function Q(){const e=y(q);if(void 0===e)throw new Error("useHyperElementsContext must be used inside <HyperElements>");return e}function Z(){const e=Q();return{walletSession:e.walletSession,isGooglePayEligible:e.walletEligibility.googlePay,isApplePayEligible:e.walletEligibility.applePay,loading:e.walletLoading,load:e.loadWalletSession}}function ee(){return Q().paymentSession}function te(){return Q().elements}q.displayName="HyperElementsContext";const ne=null!=global.nativeFabricUIManager?require("../codegen/components/PaymentWidgetNativeComponent").default:n("RCTNativePaymentWidget");function re(e,t){const[n,o]=d(void 0);return f(()=>{if(void 0!==n)return;let a,i=!0;const s=n=>{if(!i)return;if(null==e.current)return void(n<20&&(a=setTimeout(()=>s(n+1),100)));const l=r(e.current)??-1;-1!==l?(t?.(),o(l)):n<20&&(a=setTimeout(()=>s(n+1),100))};return s(0),()=>{i=!1,void 0!==a&&clearTimeout(a)}},[n]),n}const oe=m((e,t)=>{const{id:n,options:r,onChange:o,onFocus:a,onBlur:i,onPaymentResult:s,style:l,onReady:u}=e,{paymentSessionConfig:c,hyperswitchConfig:y}=Q(),d=g(null),p=re(d,u),m=void 0!==n&&void 0!==p;f(()=>{if(!m)return;const e=n;return C(e,p),()=>_(e)},[m]);const b=h(()=>{const e=r,t=e?.paymentMethodLayout;return{...e,paymentMethodLayout:{...t,savedMethodCustomization:{...t?.savedMethodCustomization,cvcIcon:e?.cvcIcon??"shown"}}}},[r]);return Y.jsx(ne,{ref:d,widgetType:"cvcWidget",sdkAuthorization:c?.sdkAuthorization??"",onPaymentEvent:e=>{if(o?.(e.nativeEvent),"CVC_STATUS"===e.nativeEvent.eventName)try{const t=e.nativeEvent.payload,n="string"==typeof t?JSON.parse(t):t;if(!n)return;const r=n.cvcStatus;if(!r)return;const o=Boolean(r.isCvcFocused),s=Boolean(r.isCvcBlur);o&&a?.(),s&&i?.()}catch{}},onPaymentResult:e=>{var t;s?.((t=e.nativeEvent.result??"",JSON.parse(t)))},options:{hyperswitchConfig:y||void 0,paymentSessionConfig:c||void 0,configuration:b},style:l})}),ae=["PAYMENT_METHOD_INFO_CARD","PAYMENT_METHOD_STATUS","FORM_STATUS","PAYMENT_METHOD_INFO_ADDRESS","PAYMENT_METHOD_INFO_BILLING_ADDRESS","CVC_STATUS"];function ie(e){return{message:`Unknown event(s) subscribed: [${e.join(", ")}]. Valid events are: ${ae.join(", ")}`,invalidEvents:e,validEvents:ae}}const se=m((e,t)=>{const{widgetId:n,options:i,onPaymentResult:s,onChange:l,onReady:u,style:c}=e,{paymentSessionConfig:y,hyperswitchConfig:d}=Q(),p=g(null),m=re(p,u);f(()=>{if(void 0!==m)return C(n,m),()=>_(n)},[m,n]),f(()=>{void 0!==m&&o.dispatchViewManagerCommand(m,1,[])},[m]),b(t,()=>({confirmPayment:e=>{if(null==p.current)return Promise.resolve({status:"failed",type:"widget_not_ready",message:"Widget not ready"});const t=r(p.current)??-1;return-1===t?Promise.resolve({status:"failed",type:"widget_not_ready",message:"Unable to find native view handle"}):new Promise(e=>{w.confirmPayment(t,t=>{e(P(t))})})}}),[m]);const h=g(!1);f(()=>{if(!i||!l||h.current)return;const e=function(e){return e?e.filter(e=>!ae.includes(e)):[]}(i.subscribedEvents);if(e.length>0){h.current=!0;const t=ie(e);l({eventName:"UNKNOWN_EVENT_SUBSCRIBED",payload:JSON.stringify({message:t.message,invalidEvents:t.invalidEvents,validEvents:t.validEvents})})}},[i,l]);return Y.jsx(ne,{ref:p,sdkAuthorization:y?.sdkAuthorization??"",widgetType:"widgetPaymentSheet",onPaymentEvent:e=>{l?.(e.nativeEvent)},onPaymentResult:e=>{s(P("ios"===a.OS?e.nativeEvent.result??"":e.nativeEvent.payload??""))},options:{hyperswitchConfig:d||void 0,paymentSessionConfig:y||void 0,configuration:i},style:{...c,flex:1}})});function le(){return v.isGooglePaySupported().catch(()=>!1)}function ue(){return v.isApplePaySupported().catch(()=>!1)}function ce(e){return"google_pay"===e?le():ue()}function ye(){return"ios"===a.OS?ue():"android"===a.OS?le():Promise.resolve(!1)}function de({wallet:e,label:t,session:n,onPaymentResult:r}){const o=function(){const e=y(q);return e?.paymentSession??null}(),{walletSession:a,load:i}=function(){const e=y(q);return{walletSession:e?.walletSession??null,isGooglePayEligible:e?.walletEligibility.googlePay??!1,isApplePayEligible:e?.walletEligibility.applePay??!1,loading:e?.walletLoading??!1,load:e?.loadWalletSession??(async()=>null)}}(),s=g(!1);return async()=>{const l=n??o;if(!l&&!a){const e=new Error(`${t} was pressed without a payment session. Pass a "session" prop or render it inside <HyperElements>.`);if(!r)throw e;return void r({status:"failed",type:"no_session",message:e.message})}if(s.current){const e=new Error(`${t} is already processing a payment. Ignoring this press.`);if(!r)throw e;return void r({status:"failed",type:"already_in_progress",message:e.message})}s.current=!0;try{const n=a??await i()??await l.getWalletSession();if(!await n.isWalletEligible(e)){const e=new Error(`${t} is not eligible for this payment.`);if(!r)throw e;return void r({status:"failed",type:"not_eligible",message:e.message})}const o=await n.launchWallet(e);r?.(o)}catch(e){const t=e instanceof Error?e.message:String(e);if(!r)throw e;r({status:"failed",type:"launch_failed",message:t})}finally{s.current=!1}}}const pe={BUY:1,BOOK:6,CHECKOUT:5,DONATE:4,ORDER:11,PAY:1e3,SUBSCRIBE:7,PLAIN:1001},fe={light:1,dark:2},me={plain:0,buy:1,setUp:2,inStore:3,donate:4,checkout:5,book:6,subscribe:7},ge={white:0,whiteOutline:1,black:2};function he(e){return"hidden"===e?.visibility}function be(e){return e?.appearance?.primaryButton?.shapes?.borderRadius??e?.appearance?.shapes?.borderRadius??4}function ve(e,t){const n=e?.appearance?.theme;return"Dark"===n||"Light"!==n&&"dark"===t}const we=function(){if("android"!==a.OS)return null;try{return null!=globalThis.nativeFabricUIManager?require("../codegen/components/HyperGooglePayNativeComponent").default:n("HyperGooglePayButton")}catch{return null}}();function Se({options:e,session:t,onPaymentResult:n,style:r}){const o=i(),a=de({wallet:"google_pay",label:"Google Pay",session:t,onPaymentResult:n}),{hidden:u,type:c,appearance:y,borderRadius:d}=function(e,t){const n=e?.walletButtonsConfiguration?.googlePay,r=ve(e,t),o=r?n?.buttonStyle?.dark:n?.buttonStyle?.light;return{hidden:he(n),type:pe[n?.buttonType??"PLAIN"],appearance:fe[o??(r?"dark":"light")],borderRadius:be(e)}}(e,"dark"===o?"dark":"light");return u||null==we?null:Y.jsx(s,{focusable:!0,accessible:!0,accessibilityRole:"button",accessibilityLabel:"Google Pay",onPress:a,style:r,children:Y.jsx(we,{type:c,appearance:y,borderRadius:d,style:l.absoluteFill})})}const Pe=function(){if("ios"!==a.OS)return null;try{return null!=globalThis.nativeFabricUIManager?require("../codegen/components/HyperApplePayNativeComponent").default:n("HyperApplePayButton")}catch{return null}}();function Ee({options:e,session:t,onPaymentResult:n,disabled:r=!1,style:o}){const a=i(),u=de({wallet:"apple_pay",label:"Apple Pay",session:t,onPaymentResult:n}),{hidden:c,type:y,buttonStyle:d,borderRadius:p}=function(e,t){const n=e?.walletButtonsConfiguration?.applePay,r=ve(e,t),o=r?n?.buttonStyle?.dark:n?.buttonStyle?.light;return{hidden:he(n),type:me[n?.buttonType??"plain"],buttonStyle:ge[o??(r?"white":"black")],borderRadius:be(e)}}(e,"dark"===a?"dark":"light");return c||null==Pe?null:Y.jsx(s,{focusable:!0,accessible:!0,accessibilityRole:"button",accessibilityLabel:"Apple Pay",onPress:u,disabled:r,style:o,children:Y.jsx(Pe,{type:y,buttonStyle:d,buttonBorderRadius:p,disabled:r,style:l.absoluteFill})})}function Ce(e){return N(!0),v.initialise(e.publishableKey,e.platformPublishableKey??"",e.profileId??"",e.environment??"PROD",e.customEndpoints??{}).then(()=>(N(!1),{publishableKey:e.publishableKey,initPaymentSession:async t=>function(e,t){const n={hyperswitchConfig:e,paymentSessionConfig:t};return{presentPaymentSheet:I(n),getCustomerSavedPaymentMethods:U(n),getWalletSession:$(n),updateIntent:z}}(e,t),async elements(t){return{hyperswitchConfig:n=e,...F(n,t)};var n}})).catch(e=>{throw N(!1),console.error("Error initializing Hyperswitch SDK:",e),e})}const _e={init:Ce};export{Ee as ApplePayButton,oe as CardCVCElement,Se as GooglePayButton,X as HyperElements,_e as Hyperswitch,se as PaymentElement,_e as default,ue as isApplePaySupported,le as isGooglePaySupported,ye as isPlatformPaySupported,ce as isWalletSupported,Ce as loadHyper,te as useElements,ee as usePaymentSession,Z as useWalletSession,te as useWidgets};
|
|
10
|
+
*/function V(){return K||(K=1,"production"!==process.env.NODE_ENV&&function(){function e(t){if(null==t)return null;if("function"==typeof t)return t.$$typeof===C?null:t.displayName||t.name||null;if("string"==typeof t)return t;switch(t){case f:return"Fragment";case g:return"Profiler";case m:return"StrictMode";case w:return"Suspense";case S:return"SuspenseList";case _:return"Activity"}if("object"==typeof t)switch("number"==typeof t.tag&&console.error("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),t.$$typeof){case p:return"Portal";case b:return t.displayName||"Context";case h:return(t._context.displayName||"Context")+".Consumer";case v:var n=t.render;return(t=t.displayName)||(t=""!==(t=n.displayName||n.name||"")?"ForwardRef("+t+")":"ForwardRef"),t;case P:return null!==(n=t.displayName||null)?n:e(t.type)||"Memo";case E:n=t._payload,t=t._init;try{return e(t(n))}catch(e){}}return null}function t(e){return""+e}function n(e){try{t(e);var n=!1}catch(e){n=!0}if(n){var r=(n=console).error,o="function"==typeof Symbol&&Symbol.toStringTag&&e[Symbol.toStringTag]||e.constructor.name||"Object";return r.call(n,"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",o),t(e)}}function r(t){if(t===f)return"<>";if("object"==typeof t&&null!==t&&t.$$typeof===E)return"<...>";try{var n=e(t);return n?"<"+n+">":"<...>"}catch(e){return"<...>"}}function o(){return Error("react-stack-top-frame")}function a(){var t=e(this.type);return A[t]||(A[t]=!0,console.error("Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release.")),void 0!==(t=this.props.ref)?t:null}function i(t,r,o,i,l,u){var y,p=r.children;if(void 0!==p)if(i)if(N(p)){for(i=0;i<p.length;i++)s(p[i]);Object.freeze&&Object.freeze(p)}else console.error("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else s(p);if(O.call(r,"key")){p=e(t);var f=Object.keys(r).filter(function(e){return"key"!==e});i=0<f.length?"{key: someKey, "+f.join(": ..., ")+": ...}":"{key: someKey}",M[p+i]||(f=0<f.length?"{"+f.join(": ..., ")+": ...}":"{}",console.error('A props object containing a "key" prop is being spread into JSX:\n let props = %s;\n <%s {...props} />\nReact keys must be passed directly to JSX without using spread:\n let props = %s;\n <%s key={someKey} {...props} />',i,p,f,p),M[p+i]=!0)}if(p=null,void 0!==o&&(n(o),p=""+o),function(e){if(O.call(e,"key")){var t=Object.getOwnPropertyDescriptor(e,"key").get;if(t&&t.isReactWarning)return!1}return void 0!==e.key}(r)&&(n(r.key),p=""+r.key),"key"in r)for(var m in o={},r)"key"!==m&&(o[m]=r[m]);else o=r;return p&&function(e,t){function n(){c||(c=!0,console.error("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",t))}n.isReactWarning=!0,Object.defineProperty(e,"key",{get:n,configurable:!0})}(o,"function"==typeof t?t.displayName||t.name||"Unknown":t),function(e,t,n,r,o,i){var s=n.ref;return e={$$typeof:d,type:e,key:t,props:n,_owner:r},null!==(void 0!==s?s:null)?Object.defineProperty(e,"ref",{enumerable:!1,get:a}):Object.defineProperty(e,"ref",{enumerable:!1,value:null}),e._store={},Object.defineProperty(e._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:0}),Object.defineProperty(e,"_debugInfo",{configurable:!1,enumerable:!1,writable:!0,value:null}),Object.defineProperty(e,"_debugStack",{configurable:!1,enumerable:!1,writable:!0,value:o}),Object.defineProperty(e,"_debugTask",{configurable:!1,enumerable:!1,writable:!0,value:i}),Object.freeze&&(Object.freeze(e.props),Object.freeze(e)),e}(t,p,o,null===(y=k.A)?null:y.getOwner(),l,u)}function s(e){l(e)?e._store&&(e._store.validated=1):"object"==typeof e&&null!==e&&e.$$typeof===E&&("fulfilled"===e._payload.status?l(e._payload.value)&&e._payload.value._store&&(e._payload.value._store.validated=1):e._store&&(e._store.validated=1))}function l(e){return"object"==typeof e&&null!==e&&e.$$typeof===d}var c,y=u,d=Symbol.for("react.transitional.element"),p=Symbol.for("react.portal"),f=Symbol.for("react.fragment"),m=Symbol.for("react.strict_mode"),g=Symbol.for("react.profiler"),h=Symbol.for("react.consumer"),b=Symbol.for("react.context"),v=Symbol.for("react.forward_ref"),w=Symbol.for("react.suspense"),S=Symbol.for("react.suspense_list"),P=Symbol.for("react.memo"),E=Symbol.for("react.lazy"),_=Symbol.for("react.activity"),C=Symbol.for("react.client.reference"),k=y.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,O=Object.prototype.hasOwnProperty,N=Array.isArray,R=console.createTask?console.createTask:function(){return null},A={},T=(y={react_stack_bottom_frame:function(e){return e()}}).react_stack_bottom_frame.bind(y,o)(),j=R(r(o)),M={};J.Fragment=f,J.jsx=function(e,t,n){var o=1e4>k.recentlyCreatedOwnerStacks++;return i(e,t,n,!1,o?Error("react-stack-top-frame"):T,o?R(r(e)):j)},J.jsxs=function(e,t,n){var o=1e4>k.recentlyCreatedOwnerStacks++;return i(e,t,n,!0,o?Error("react-stack-top-frame"):T,o?R(r(e)):j)}}()),J}var Y=(G||(G=1,"production"===process.env.NODE_ENV?H.exports=function(){if(F)return B;F=1;var e=Symbol.for("react.transitional.element"),t=Symbol.for("react.fragment");function n(t,n,r){var o=null;if(void 0!==r&&(o=""+r),void 0!==n.key&&(o=""+n.key),"key"in n)for(var a in r={},n)"key"!==a&&(r[a]=n[a]);else r=n;return n=r.ref,{$$typeof:e,type:t,key:o,ref:void 0!==n?n:null,props:r}}return B.Fragment=t,B.jsx=n,B.jsxs=n,B}():H.exports=V()),H.exports);const q=c(void 0);function X({hyper:e,options:t,children:n}){const[r,o]=d(null),[a,i]=d(null),[s,l]=d(null),[u,c]=d(null),[y,m]=d(null),[g,h]=d(null),[b,v]=d(!0),[w,S]=d(null),[P,E]=d(null),[_,C]=d({googlePay:!1,applePay:!1}),[k,O]=d(!1),N=p(async()=>{if(!r)return null;O(!0);try{const e=await r.getWalletSession(),[t,n]=await Promise.all([e.isGooglePayEligible(),e.isApplePayEligible()]);return E(e),C({googlePay:t,applePay:n}),e}catch{return E(null),C({googlePay:!1,applePay:!1}),null}finally{O(!1)}},[r]);return f(()=>{E(null),C({googlePay:!1,applePay:!1})},[r]),f(()=>{if(!e)return;let n=!1;return(async()=>{try{const r=await Promise.resolve(e),a={sdkAuthorization:t.sdkAuthorization},s=await r.elements(a);n||(o({...s}),l(s.hyperswitchConfig),c(a),i(s),m(r.publishableKey??null),h(t.sdkAuthorization??null),v(!1))}catch(e){n||(S(e instanceof Error?e:new Error(String(e))),v(!1))}})(),()=>{n=!0}},[e,t.sdkAuthorization]),Y.jsx(q.Provider,{value:{paymentSession:r,walletSession:P,walletEligibility:_,walletLoading:k,loadWalletSession:N,elements:a,publishableKey:y,sdkAuthorization:g,loading:b,error:w,paymentSessionConfig:u,hyperswitchConfig:s},children:n})}function Q(){const e=y(q);if(void 0===e)throw new Error("useHyperElementsContext must be used inside <HyperElements>");return e}function Z(){const e=Q();return{walletSession:e.walletSession,isGooglePayEligible:e.walletEligibility.googlePay,isApplePayEligible:e.walletEligibility.applePay,loading:e.walletLoading,load:e.loadWalletSession}}function ee(){const e=y(q);return{walletSession:e?.walletSession??null,isGooglePayEligible:e?.walletEligibility.googlePay??!1,isApplePayEligible:e?.walletEligibility.applePay??!1,loading:e?.walletLoading??!1,load:e?.loadWalletSession??(async()=>null)}}function te(){const e=y(q);return e?.paymentSession??null}function ne(){return Q().paymentSession}function re(){return Q().elements}q.displayName="HyperElementsContext";const oe=null!=global.nativeFabricUIManager?require("../codegen/components/PaymentWidgetNativeComponent").default:n("RCTNativePaymentWidget");function ae(e,t){const[n,o]=d(void 0);return f(()=>{if(void 0!==n)return;let a,i=!0;const s=n=>{if(!i)return;if(null==e.current)return void(n<20&&(a=setTimeout(()=>s(n+1),100)));const l=r(e.current)??-1;-1!==l?(t?.(),o(l)):n<20&&(a=setTimeout(()=>s(n+1),100))};return s(0),()=>{i=!1,void 0!==a&&clearTimeout(a)}},[n]),n}const ie=m((e,t)=>{const{id:n,options:r,onChange:o,onFocus:a,onBlur:i,onPaymentResult:s,style:l,onReady:u}=e,{paymentSessionConfig:c,hyperswitchConfig:y}=Q(),d=g(null),p=ae(d,u),m=void 0!==n&&void 0!==p;f(()=>{if(!m)return;const e=n;return _(e,p),()=>C(e)},[m]);const b=h(()=>{const e=r,t=e?.paymentMethodLayout;return{...e,paymentMethodLayout:{...t,savedMethodCustomization:{...t?.savedMethodCustomization,cvcIcon:e?.cvcIcon??"shown"}}}},[r]);return Y.jsx(oe,{ref:d,widgetType:"cvcWidget",sdkAuthorization:c?.sdkAuthorization??"",onPaymentEvent:e=>{if(o?.(e.nativeEvent),"CVC_STATUS"===e.nativeEvent.eventName)try{const t=e.nativeEvent.payload,n="string"==typeof t?JSON.parse(t):t;if(!n)return;const r=n.cvcStatus;if(!r)return;const o=Boolean(r.isCvcFocused),s=Boolean(r.isCvcBlur);o&&a?.(),s&&i?.()}catch{}},onPaymentResult:e=>{var t;s?.((t=e.nativeEvent.result??"",JSON.parse(t)))},options:{hyperswitchConfig:y||void 0,paymentSessionConfig:c||void 0,configuration:b},style:l})}),se=["PAYMENT_METHOD_INFO_CARD","PAYMENT_METHOD_STATUS","FORM_STATUS","PAYMENT_METHOD_INFO_ADDRESS","PAYMENT_METHOD_INFO_BILLING_ADDRESS","CVC_STATUS"];function le(e){return{message:`Unknown event(s) subscribed: [${e.join(", ")}]. Valid events are: ${se.join(", ")}`,invalidEvents:e,validEvents:se}}const ue=m((e,t)=>{const{widgetId:n,options:i,onPaymentResult:s,onChange:l,onReady:u,style:c}=e,{paymentSessionConfig:y,hyperswitchConfig:d}=Q(),p=g(null),m=ae(p,u);f(()=>{if(void 0!==m)return _(n,m),()=>C(n)},[m,n]),f(()=>{void 0!==m&&o.dispatchViewManagerCommand(m,1,[])},[m]),b(t,()=>({confirmPayment:e=>{if(null==p.current)return Promise.resolve({status:"failed",type:"widget_not_ready",message:"Widget not ready"});const t=r(p.current)??-1;return-1===t?Promise.resolve({status:"failed",type:"widget_not_ready",message:"Unable to find native view handle"}):new Promise(e=>{w.confirmPayment(t,t=>{e(P(t))})})}}),[m]);const h=g(!1);f(()=>{if(!i||!l||h.current)return;const e=function(e){return e?e.filter(e=>!se.includes(e)):[]}(i.subscribedEvents);if(e.length>0){h.current=!0;const t=le(e);l({eventName:"UNKNOWN_EVENT_SUBSCRIBED",payload:JSON.stringify({message:t.message,invalidEvents:t.invalidEvents,validEvents:t.validEvents})})}},[i,l]);return Y.jsx(oe,{ref:p,sdkAuthorization:y?.sdkAuthorization??"",widgetType:"widgetPaymentSheet",onPaymentEvent:e=>{l?.(e.nativeEvent)},onPaymentResult:e=>{s(P("ios"===a.OS?e.nativeEvent.result??"":e.nativeEvent.payload??""))},options:{hyperswitchConfig:d||void 0,paymentSessionConfig:y||void 0,configuration:i},style:{...c,flex:1}})});function ce(){return v.isGooglePaySupported().catch(()=>!1)}function ye(){return v.isApplePaySupported().catch(()=>!1)}function de(e){return"google_pay"===e?ce():ye()}function pe(){return"ios"===a.OS?ye():"android"===a.OS?ce():Promise.resolve(!1)}function fe({wallet:e,label:t,session:n,onPaymentResult:r}){const o=te(),{walletSession:a,load:i}=ee(),s=g(!1);return async()=>{const l=n??o;if(!l&&!a){const e=new Error(`${t} was pressed without a payment session. Pass a "session" prop or render it inside <HyperElements>.`);if(!r)throw e;return void r({status:"failed",type:"no_session",message:e.message})}if(s.current){const e=new Error(`${t} is already processing a payment. Ignoring this press.`);if(!r)throw e;return void r({status:"failed",type:"already_in_progress",message:e.message})}s.current=!0;try{const n=a??await i()??await l.getWalletSession();if(!await n.isWalletEligible(e)){const e=new Error(`${t} is not eligible for this payment.`);if(!r)throw e;return void r({status:"failed",type:"not_eligible",message:e.message})}const o=await n.launchWallet(e);r?.(o)}catch(e){const t=e instanceof Error?e.message:String(e);if(!r)throw e;r({status:"failed",type:"launch_failed",message:t})}finally{s.current=!1}}}function me({wallet:e,label:t,session:n,onReady:r,onLoadError:o}){const a=te(),{walletSession:i,load:s}=ee(),l=g(r),u=g(o),c=g(i),y=g(s);f(()=>{l.current=r,u.current=o,c.current=i,y.current=s},[r,o,i,s]),f(()=>{let r=!1;const o=(e,t)=>{u.current?.({status:"failed",type:e,message:t})};return(async()=>{try{const i=await(async()=>n?n.getWalletSession():c.current?c.current:a?y.current():null)();if(r)return;if(!i)return void o("no_session",`${t} has no payment session. Pass a "session" prop or render it inside <HyperElements>.`);const s=await i.isWalletEligible(e);if(r)return;s?l.current?.():o("not_eligible",`${t} is not eligible for this payment.`)}catch(e){if(r)return;o("launch_failed",e instanceof Error?e.message:String(e))}})(),()=>{r=!0}},[n,a,e,t])}const ge={BUY:1,BOOK:6,CHECKOUT:5,DONATE:4,ORDER:11,PAY:1e3,SUBSCRIBE:7,PLAIN:1001},he={light:1,dark:2},be={plain:0,buy:1,setUp:2,inStore:3,donate:4,checkout:5,book:6,subscribe:7},ve={white:0,whiteOutline:1,black:2};function we(e){return"hidden"===e?.visibility}function Se(e){return e?.appearance?.primaryButton?.shapes?.borderRadius??e?.appearance?.shapes?.borderRadius??4}function Pe(e,t){const n=e?.appearance?.theme;return"Dark"===n||"Light"!==n&&"dark"===t}const Ee=function(){if("android"!==a.OS)return null;try{return null!=globalThis.nativeFabricUIManager?require("../codegen/components/HyperGooglePayNativeComponent").default:n("HyperGooglePayButton")}catch{return null}}();function _e({options:e,session:t,onPaymentResult:n,onReady:r,onLoadError:o,style:a}){const u=i(),c=fe({wallet:"google_pay",label:"Google Pay",session:t,onPaymentResult:n});me({wallet:"google_pay",label:"Google Pay",session:t,onReady:r,onLoadError:o});const{hidden:y,type:d,appearance:p,borderRadius:f}=function(e,t){const n=e?.walletButtonsConfiguration?.googlePay,r=Pe(e,t),o=r?n?.buttonStyle?.dark:n?.buttonStyle?.light;return{hidden:we(n),type:ge[n?.buttonType??"PLAIN"],appearance:he[o??(r?"dark":"light")],borderRadius:Se(e)}}(e,"dark"===u?"dark":"light");return y||null==Ee?null:Y.jsx(s,{focusable:!0,accessible:!0,accessibilityRole:"button",accessibilityLabel:"Google Pay",onPress:c,style:a,children:Y.jsx(Ee,{type:d,appearance:p,borderRadius:f,style:l.absoluteFill})})}const Ce=function(){if("ios"!==a.OS)return null;try{return null!=globalThis.nativeFabricUIManager?require("../codegen/components/HyperApplePayNativeComponent").default:n("HyperApplePayButton")}catch{return null}}();function ke({options:e,session:t,onPaymentResult:n,onReady:r,onLoadError:o,disabled:a=!1,style:u}){const c=i(),y=fe({wallet:"apple_pay",label:"Apple Pay",session:t,onPaymentResult:n});me({wallet:"apple_pay",label:"Apple Pay",session:t,onReady:r,onLoadError:o});const{hidden:d,type:p,buttonStyle:f,borderRadius:m}=function(e,t){const n=e?.walletButtonsConfiguration?.applePay,r=Pe(e,t),o=r?n?.buttonStyle?.dark:n?.buttonStyle?.light;return{hidden:we(n),type:be[n?.buttonType??"plain"],buttonStyle:ve[o??(r?"white":"black")],borderRadius:Se(e)}}(e,"dark"===c?"dark":"light");return d||null==Ce?null:Y.jsx(s,{focusable:!0,accessible:!0,accessibilityRole:"button",accessibilityLabel:"Apple Pay",onPress:y,disabled:a,style:u,children:Y.jsx(Ce,{type:p,buttonStyle:f,buttonBorderRadius:m,disabled:a,style:l.absoluteFill})})}function Oe(e){return N(!0),v.initialise(e.publishableKey,e.platformPublishableKey??"",e.profileId??"",e.environment??"PROD",e.customEndpoints??{}).then(()=>(N(!1),{publishableKey:e.publishableKey,initPaymentSession:async t=>function(e,t){const n={hyperswitchConfig:e,paymentSessionConfig:t};return{presentPaymentSheet:I(n),getCustomerSavedPaymentMethods:L(n),getWalletSession:U(n),updateIntent:$}}(e,t),async elements(t){return{hyperswitchConfig:n=e,...z(n,t)};var n}})).catch(e=>{throw N(!1),console.error("Error initializing Hyperswitch SDK:",e),e})}const Ne={init:Oe};export{ke as ApplePayButton,ie as CardCVCElement,_e as GooglePayButton,X as HyperElements,Ne as Hyperswitch,ue as PaymentElement,Ne as default,ye as isApplePaySupported,ce as isGooglePaySupported,pe as isPlatformPaySupported,de as isWalletSupported,Oe as loadHyper,re as useElements,ne as usePaymentSession,Z as useWalletSession,re as useWidgets};
|
|
11
11
|
//# sourceMappingURL=index.bundle.js.map
|