@adyen/adyen-web
Version:
[](https://www.npmjs.com/package/@adyen/adyen-web)
3 lines (2 loc) • 1.6 kB
JavaScript
import{createElement as t}from"../../../../external/preact/dist/preact.js";import{CtpState as e}from"../services/ClickToPayService.js";import{ClickToPayContext as a}from"./ClickToPayContext.js";import{useState as o,useRef as s,useEffect as n,useCallback as i}from"../../../../external/preact/hooks/dist/hooks.js";const r=({isStandaloneComponent:r=!1,clickToPayService:c,configuration:d,children:l,setClickToPayRef:p,onSubmit:u,onSetStatus:y,onError:S})=>{const[m]=o(c),[C,f]=o(c?.state||e.NotAvailable),[h,k]=o(!0),[I,P]=o("ready"),v=s({}),w=s(!1);n(()=>{p(v.current),v.current.setStatus=P},[]),n(()=>{m?.subscribeOnStateChange(t=>f(t))},[m]);const b=i(()=>{w.current||(d.onReady?.(),w.current=!0)},[d?.onReady]),g=i(async t=>{await(m?.finishIdentityValidation(t))},[m]),E=i(async()=>await(m?.startIdentityValidation()),[m]),V=i(async t=>await(m?.checkout(t)),[m]),R=i(async t=>await(m?.verifyIfShopperIsEnrolled(t)),[m]),j=i(async()=>{await(m?.logout())},[m]),x=i(t=>{m.updateStoreCookiesConsent(t)},[m]);return t(a.Provider,{value:{status:I,onSubmit:u,onError:S,onSetStatus:y,configuration:d,isStoringCookies:m?.storeCookies,isStandaloneComponent:r,isCtpPrimaryPaymentMethod:h,setIsCtpPrimaryPaymentMethod:k,ctpState:C,verifyIfShopperIsEnrolled:R,cards:m?.shopperCards,schemes:m?.schemes,otpMaskedContact:m?.identityValidationData?.maskedShopperContact,otpNetwork:m?.identityValidationData?.selectedNetwork,checkout:V,logoutShopper:j,startIdentityValidation:E,finishIdentityValidation:g,updateStoreCookiesConsent:x,onReady:b}},l)};export{r as default};
//# sourceMappingURL=ClickToPayProvider.js.map