@commercelayer/react-components 3.9.1 → 3.9.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/components/BraintreePayment.js +1 -1
- package/lib/components/GiftCardOrCouponForm.d.ts +1 -1
- package/lib/components/GiftCardOrCouponForm.js +1 -1
- package/lib/components/PaymentGateway.js +1 -1
- package/lib/components/PaymentMethodsContainer.js +1 -1
- package/lib/components/PaymentSource.js +1 -1
- package/lib/components/PlaceOrderButton.js +1 -1
- package/lib/components/StripePayment.js +1 -1
- package/lib/components/gateways/AdyenGateway.js +1 -1
- package/lib/components/gateways/BraintreeGateway.js +1 -1
- package/lib/components/gateways/CheckoutComGateway.js +1 -1
- package/lib/components/gateways/StripeGateway.js +1 -1
- package/lib/reducers/PaymentMethodReducer.d.ts +1 -1
- package/package.json +10 -10
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";import{useContext,useEffect,useRef,useState}from"react";import PaymentMethodContext from"../context/PaymentMethodContext";import isEmpty from"lodash/isEmpty";import OrderContext from"../context/OrderContext";import Parent from"./utils/Parent";import{setCustomerOrderParam}from"../utils/localStorage";import promisify from"../utils/promisify";const defaultConfig={styles:{input:{"font-size":"16px",color:"#3A3A3A"},".number":{"font-family":"monospace"},":focus":{color:"blue"},".valid":{color:"green"},".invalid":{color:"red"},"@media screen and (max-width: 700px)":{input:{"font-size":"14px"}}},fields:{number:{label:"Card Number",selector:"#card-number",placeholder:"4111 1111 1111 1111"},cvv:{label:"CVV",selector:"#cvv",placeholder:"123"},expirationDate:{label:"Expiration Date",selector:"#expiration-date",placeholder:"10/2022"}},submitLabel:"Set payment method"},BraintreePayment=({authorization,config,templateCustomerSaveToWallet})=>{var _a,_b,_c;const{fields,styles,containerClassName,cardContainerClassName,fieldsContainerClassName,expDateContainerClassName,fieldLabelClassName,cvvContainerClassName,inputWrapperClassName,cardDetailsContainerClassName}=Object.assign(Object.assign({},defaultConfig),config),[loadBraintree,setLoadBraintree]=useState(!1),{setPaymentSource,paymentSource,setPaymentMethodErrors,currentPaymentMethodType,setPaymentRef}=useContext(PaymentMethodContext),{order}=useContext(OrderContext),ref=useRef(null),handleSubmitForm=async(event,hostedFieldsInstance,threeDSInstance)=>{var _a2,_b2;const savePaymentSourceToCustomerWallet=(_b2=(_a2=event==null?void 0:event.elements)===null||_a2===void 0?void 0:_a2.save_payment_source_to_customer_wallet)===null||_b2===void 0?void 0:_b2.checked;if(savePaymentSourceToCustomerWallet&&setCustomerOrderParam("_save_payment_source_to_customer_wallet",savePaymentSourceToCustomerWallet),hostedFieldsInstance)try{const payload=await promisify(hostedFieldsInstance).then(payload2=>payload2),billingAddress=order==null?void 0:order.billing_address,verifyCardOptions={nonce:payload.nonce,bin:payload.details.bin,amount:order==null?void 0:order.total_amount_with_taxes_float,email:order==null?void 0:order.customer_email,billingAddress:{givenName:billingAddress==null?void 0:billingAddress.first_name,surname:billingAddress==null?void 0:billingAddress.last_name,phoneNumber:billingAddress==null?void 0:billingAddress.phone,streetAddress:billingAddress==null?void 0:billingAddress.line_1,countryCodeAlpha2:billingAddress==null?void 0:billingAddress.country_code,postalCode:billingAddress==null?void 0:billingAddress.zip_code,region:billingAddress==null?void 0:billingAddress.state_code,locality:billingAddress==null?void 0:billingAddress.city},onLookupComplete:(_data,next)=>{next()}},response=await threeDSInstance.verifyCard(verifyCardOptions);return response.rawCardinalSDKVerificationData.Validated&&paymentSource?(paymentSource&&await setPaymentSource({paymentSourceId:paymentSource.id,paymentResource:"braintree_payments",attributes:{payment_method_nonce:response.nonce,options:{id:response.nonce,card:{last4:response.details.lastFour,exp_year:response.details.expirationYear,exp_month:response.details.expirationMonth,brand:response.details.cardType.toLowerCase()}}}}),!0):!1}catch(error){return console.error(error),setPaymentMethodErrors([{code:"PAYMENT_INTENT_AUTHENTICATION_FAILURE",resource:"payment_methods",field:currentPaymentMethodType,message:error.message}]),!1}return!1};return useEffect(()=>{if(!ref&&authorization&&setCustomerOrderParam("_save_payment_source_to_customer_wallet","false"),authorization&&!loadBraintree&&!isEmpty(window)){const braintreeClient=require("braintree-web/client"),hostedFields=require("braintree-web/hosted-fields"),threeDSecure=require("braintree-web/three-d-secure");braintreeClient.create({authorization},(clientErr,clientInstance)=>{if(clientErr){console.error(clientErr);return}hostedFields.create({client:clientInstance,fields,styles},(hostedFieldsErr,hostedFieldsInstance)=>{if(hostedFieldsErr){console.error(hostedFieldsErr);return}setLoadBraintree(!0),threeDSecure.create({authorization,version:2},(threeDSecureErr,
|
|
1
|
+
import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";import{useContext,useEffect,useRef,useState}from"react";import PaymentMethodContext from"../context/PaymentMethodContext";import isEmpty from"lodash/isEmpty";import OrderContext from"../context/OrderContext";import Parent from"./utils/Parent";import{setCustomerOrderParam}from"../utils/localStorage";import promisify from"../utils/promisify";const defaultConfig={styles:{input:{"font-size":"16px",color:"#3A3A3A"},".number":{"font-family":"monospace"},":focus":{color:"blue"},".valid":{color:"green"},".invalid":{color:"red"},"@media screen and (max-width: 700px)":{input:{"font-size":"14px"}}},fields:{number:{label:"Card Number",selector:"#card-number",placeholder:"4111 1111 1111 1111"},cvv:{label:"CVV",selector:"#cvv",placeholder:"123"},expirationDate:{label:"Expiration Date",selector:"#expiration-date",placeholder:"10/2022"}},submitLabel:"Set payment method"},BraintreePayment=({authorization,config,templateCustomerSaveToWallet})=>{var _a,_b,_c;const{fields,styles,containerClassName,cardContainerClassName,fieldsContainerClassName,expDateContainerClassName,fieldLabelClassName,cvvContainerClassName,inputWrapperClassName,cardDetailsContainerClassName}=Object.assign(Object.assign({},defaultConfig),config),[loadBraintree,setLoadBraintree]=useState(!1),{setPaymentSource,paymentSource,setPaymentMethodErrors,currentPaymentMethodType,setPaymentRef}=useContext(PaymentMethodContext),{order}=useContext(OrderContext),ref=useRef(null),handleSubmitForm=async({event,hostedFieldsInstance,threeDSInstance})=>{var _a2,_b2;const savePaymentSourceToCustomerWallet=(_b2=(_a2=event==null?void 0:event.elements)===null||_a2===void 0?void 0:_a2.save_payment_source_to_customer_wallet)===null||_b2===void 0?void 0:_b2.checked;if(savePaymentSourceToCustomerWallet&&setCustomerOrderParam("_save_payment_source_to_customer_wallet",savePaymentSourceToCustomerWallet),hostedFieldsInstance)try{const payload=await promisify(hostedFieldsInstance).then(payload2=>payload2),billingAddress=order==null?void 0:order.billing_address,verifyCardOptions={nonce:payload.nonce,bin:payload.details.bin,amount:order==null?void 0:order.total_amount_with_taxes_float,email:order==null?void 0:order.customer_email,billingAddress:{givenName:billingAddress==null?void 0:billingAddress.first_name,surname:billingAddress==null?void 0:billingAddress.last_name,phoneNumber:billingAddress==null?void 0:billingAddress.phone,streetAddress:billingAddress==null?void 0:billingAddress.line_1,countryCodeAlpha2:billingAddress==null?void 0:billingAddress.country_code,postalCode:billingAddress==null?void 0:billingAddress.zip_code,region:billingAddress==null?void 0:billingAddress.state_code,locality:billingAddress==null?void 0:billingAddress.city},onLookupComplete:(_data,next)=>{next()}},response=await threeDSInstance.verifyCard(verifyCardOptions);return response.rawCardinalSDKVerificationData.Validated&&paymentSource?(paymentSource&&await setPaymentSource({paymentSourceId:paymentSource.id,paymentResource:"braintree_payments",attributes:{payment_method_nonce:response.nonce,options:{id:response.nonce,card:{last4:response.details.lastFour,exp_year:response.details.expirationYear,exp_month:response.details.expirationMonth,brand:response.details.cardType.toLowerCase()}}}}),!0):!1}catch(error){return console.error(error),setPaymentMethodErrors([{code:"PAYMENT_INTENT_AUTHENTICATION_FAILURE",resource:"payment_methods",field:currentPaymentMethodType,message:error.message}]),!1}return!1};return useEffect(()=>{if(!ref&&authorization&&setCustomerOrderParam("_save_payment_source_to_customer_wallet","false"),authorization&&!loadBraintree&&!isEmpty(window)){const braintreeClient=require("braintree-web/client"),hostedFields=require("braintree-web/hosted-fields"),threeDSecure=require("braintree-web/three-d-secure");braintreeClient.create({authorization},(clientErr,clientInstance)=>{if(clientErr){console.error(clientErr);return}hostedFields.create({client:clientInstance,fields,styles},(hostedFieldsErr,hostedFieldsInstance)=>{if(hostedFieldsErr){console.error(hostedFieldsErr);return}setLoadBraintree(!0),threeDSecure.create({authorization,version:2},(threeDSecureErr,threeDSInstance)=>{threeDSecureErr&&(console.error("3DSecure error",threeDSecureErr),setPaymentMethodErrors([{code:"PAYMENT_INTENT_AUTHENTICATION_FAILURE",resource:"payment_methods",field:currentPaymentMethodType,message:threeDSecureErr.message}])),ref.current&&(ref.current.onsubmit=paymentSource2=>handleSubmitForm({event:ref.current,hostedFieldsInstance,threeDSInstance,paymentSource:paymentSource2}),setPaymentRef({ref}))})})})}return()=>{setPaymentRef({ref:{current:null}}),setLoadBraintree(!1)}},[authorization,ref]),!authorization&&!loadBraintree?null:_jsx("div",Object.assign({className:containerClassName},{children:_jsxs("form",Object.assign({ref,id:"braintree-form",onSubmit:handleSubmitForm,className:containerClassName},{children:[_jsxs("div",Object.assign({className:fieldsContainerClassName},{children:[_jsxs("div",Object.assign({className:cardContainerClassName},{children:[_jsx("label",Object.assign({className:fieldLabelClassName,htmlFor:"card-number"},{children:(_a=fields==null?void 0:fields.number)===null||_a===void 0?void 0:_a.label})),_jsx("div",{className:inputWrapperClassName,id:"card-number"})]})),_jsxs("div",Object.assign({className:cardDetailsContainerClassName},{children:[_jsxs("div",Object.assign({className:expDateContainerClassName},{children:[_jsx("label",Object.assign({className:fieldLabelClassName,htmlFor:"expiration-date"},{children:(_b=fields==null?void 0:fields.expirationDate)===null||_b===void 0?void 0:_b.label})),_jsx("div",{className:inputWrapperClassName,id:"expiration-date"})]})),_jsxs("div",Object.assign({className:cvvContainerClassName},{children:[_jsx("label",Object.assign({className:fieldLabelClassName,htmlFor:"cvv"},{children:(_c=fields==null?void 0:fields.cvv)===null||_c===void 0?void 0:_c.label})),_jsx("div",{className:inputWrapperClassName,id:"cvv"})]}))]}))]})),_jsx("div",Object.assign({className:fieldsContainerClassName},{children:templateCustomerSaveToWallet&&_jsx(Parent,Object.assign({},{name:"save_payment_source_to_customer_wallet"},{children:templateCustomerSaveToWallet}))}))]}))}))};export default BraintreePayment;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{FunctionComponent,ReactNode}from'react';declare type GiftCardOrCouponFormProps={children:ReactNode;onSubmit?:(response:{success:boolean;})=>void;}&Omit<JSX.IntrinsicElements['form'],'onSubmit'>;declare const GiftCardOrCouponForm:FunctionComponent<GiftCardOrCouponFormProps>;export default GiftCardOrCouponForm;
|
|
1
|
+
import{FunctionComponent,ReactNode}from'react';declare type GiftCardOrCouponFormProps={children:ReactNode;onSubmit?:(response:{success:boolean;value:string;})=>void;}&Omit<JSX.IntrinsicElements['form'],'onSubmit'>;declare const GiftCardOrCouponForm:FunctionComponent<GiftCardOrCouponFormProps>;export default GiftCardOrCouponForm;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{__rest}from"tslib";import{jsx as _jsx}from"react/jsx-runtime";import useRapidForm from"rapid-form";import{useContext,useEffect,useRef,useState}from"react";import CouponAndGiftCardFormContext from"../context/CouponAndGiftCardFormContext";import OrderContext from"../context/OrderContext";import isEmpty from"lodash/isEmpty";import components from"../config/components";import camelCase from"lodash/camelCase";import dropWhile from"lodash/dropWhile";import has from"lodash/has";import{findIndex}from"lodash";const propTypes=components.GiftCardOrCouponForm.propTypes,GiftCardOrCouponForm=props=>{const{children,autoComplete="on",onSubmit}=props,p=__rest(props,["children","autoComplete","onSubmit"]),{validation,values}=useRapidForm(),[codeType,setCodeType]=useState("gift_card_or_coupon_code"),{setGiftCardOrCouponCode,order,errors,setOrderErrors}=useContext(OrderContext),ref=useRef(null),inputName="gift_card_or_coupon_code";useEffect(()=>{var _a;if(((_a=values[inputName])===null||_a===void 0?void 0:_a.value)===""&&findIndex(errors,{field:camelCase(inputName)})!==-1){const err=dropWhile(errors,i=>i.field===camelCase(inputName));setOrderErrors({errors:err}),onSubmit&&onSubmit({success:!0})}},[values]),useEffect(()=>{(order==null?void 0:order.gift_card_code)&&!(order==null?void 0:order.coupon_code)&&setCodeType("coupon_code"),!(order==null?void 0:order.gift_card_code)&&(order==null?void 0:order.coupon_code)&&setCodeType("gift_card_code"),!(order==null?void 0:order.gift_card_code)&&!(order==null?void 0:order.coupon_code)&&setCodeType("gift_card_or_coupon_code")},[order]);const handleSubmit=async e=>{e.preventDefault();const code=has(values,inputName)?values[inputName].value:void 0;if(code){const{success}=await setGiftCardOrCouponCode({code,codeType});onSubmit&&onSubmit({success}),success&&
|
|
1
|
+
import{__rest}from"tslib";import{jsx as _jsx}from"react/jsx-runtime";import useRapidForm from"rapid-form";import{useContext,useEffect,useRef,useState}from"react";import CouponAndGiftCardFormContext from"../context/CouponAndGiftCardFormContext";import OrderContext from"../context/OrderContext";import isEmpty from"lodash/isEmpty";import components from"../config/components";import camelCase from"lodash/camelCase";import dropWhile from"lodash/dropWhile";import has from"lodash/has";import{findIndex}from"lodash";const propTypes=components.GiftCardOrCouponForm.propTypes,GiftCardOrCouponForm=props=>{const{children,autoComplete="on",onSubmit}=props,p=__rest(props,["children","autoComplete","onSubmit"]),{validation,values,reset}=useRapidForm(),[codeType,setCodeType]=useState("gift_card_or_coupon_code"),{setGiftCardOrCouponCode,order,errors,setOrderErrors}=useContext(OrderContext),ref=useRef(null),inputName="gift_card_or_coupon_code";useEffect(()=>{var _a,_b,_c,_d;if(((_a=values[inputName])===null||_a===void 0?void 0:_a.value)===""&&findIndex(errors,{field:camelCase(inputName)})!==-1){const err=dropWhile(errors,i=>i.field===camelCase(inputName));setOrderErrors({errors:err}),onSubmit&&onSubmit({value:(_b=values[inputName])===null||_b===void 0?void 0:_b.value,success:!0})}((_c=values[inputName])===null||_c===void 0?void 0:_c.value)===""&&onSubmit&&onSubmit({value:(_d=values[inputName])===null||_d===void 0?void 0:_d.value,success:!1})},[values]),useEffect(()=>{(order==null?void 0:order.gift_card_code)&&!(order==null?void 0:order.coupon_code)&&setCodeType("coupon_code"),!(order==null?void 0:order.gift_card_code)&&(order==null?void 0:order.coupon_code)&&setCodeType("gift_card_code"),!(order==null?void 0:order.gift_card_code)&&!(order==null?void 0:order.coupon_code)&&setCodeType("gift_card_or_coupon_code")},[order]);const handleSubmit=async e=>{var _a;e.preventDefault();const code=has(values,inputName)?values[inputName].value:void 0;if(code){const{success}=await setGiftCardOrCouponCode({code,codeType}),value=(_a=values[inputName])===null||_a===void 0?void 0:_a.value;onSubmit&&onSubmit({success,value}),success&&reset(e)}};return(order==null?void 0:order.gift_card_code)&&(order==null?void 0:order.coupon_code)||isEmpty(order)?null:_jsx(CouponAndGiftCardFormContext.Provider,Object.assign({value:{validation,codeType}},{children:_jsx("form",Object.assign({ref,autoComplete,onSubmit:handleSubmit},p,{children}))}))};GiftCardOrCouponForm.propTypes=propTypes;export default GiftCardOrCouponForm;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{__rest}from"tslib";import{jsx as _jsx}from"react/jsx-runtime";import OrderContext from"../context/OrderContext";import PaymentMethodChildrenContext from"../context/PaymentMethodChildrenContext";import PaymentMethodContext from"../context/PaymentMethodContext";import getPaypalConfig from"../utils/paypalPayment";import{useContext,useEffect,useState}from"react";import getLoaderComponent from"../utils/getLoaderComponent";import AdyenGateway from"./gateways/AdyenGateway";import StripeGateway from"./gateways/StripeGateway";import BraintreeGateway from"./gateways/BraintreeGateway";import PaypalGateway from"./gateways/PaypalGateway";import WireTransferGateway from"./gateways/WireTransferGateway";import CustomerContext from"../context/CustomerContext";import CheckoutComGateway from"./gateways/CheckoutComGateway";const PaymentGateway=_a=>{var _b,
|
|
1
|
+
import{__rest}from"tslib";import{jsx as _jsx}from"react/jsx-runtime";import OrderContext from"../context/OrderContext";import PaymentMethodChildrenContext from"../context/PaymentMethodChildrenContext";import PaymentMethodContext from"../context/PaymentMethodContext";import getPaypalConfig from"../utils/paypalPayment";import{useContext,useEffect,useState}from"react";import getLoaderComponent from"../utils/getLoaderComponent";import AdyenGateway from"./gateways/AdyenGateway";import StripeGateway from"./gateways/StripeGateway";import BraintreeGateway from"./gateways/BraintreeGateway";import PaypalGateway from"./gateways/PaypalGateway";import WireTransferGateway from"./gateways/WireTransferGateway";import CustomerContext from"../context/CustomerContext";import CheckoutComGateway from"./gateways/CheckoutComGateway";const PaymentGateway=_a=>{var _b,{readonly,showCard,handleEditClick,children,templateCustomerCards,templateCustomerSaveToWallet,onClickCustomerCards,show,loader="Loading..."}=_a,p=__rest(_a,["readonly","showCard","handleEditClick","children","templateCustomerCards","templateCustomerSaveToWallet","onClickCustomerCards","show","loader"]);const loaderComponent=getLoaderComponent(loader),[loading,setLoading]=useState(!0),{payment}=useContext(PaymentMethodChildrenContext),{order}=useContext(OrderContext),{getCustomerPaymentSources}=useContext(CustomerContext),{currentPaymentMethodId,config,currentPaymentMethodType,setPaymentSource,paymentSource}=useContext(PaymentMethodContext),paymentResource=readonly?currentPaymentMethodType:payment==null?void 0:payment.payment_source_type;useEffect(()=>{var _a2;if((payment==null?void 0:payment.id)===currentPaymentMethodId&&paymentResource&&((_a2=order==null?void 0:order.payment_method)===null||_a2===void 0?void 0:_a2.payment_source_type)===paymentResource){const attributes=config&&paymentResource==="paypal_payments"?getPaypalConfig(paymentResource,config):{},setPaymentSources=async()=>{await setPaymentSource({paymentResource,order,attributes}),getCustomerPaymentSources&&await getCustomerPaymentSources()};!paymentSource&&(order==null?void 0:order.payment_method.id)&&show&&setPaymentSources(),(paymentSource==null?void 0:paymentSource.mismatched_amounts)&&show&&setPaymentSources(),(!paymentSource||paymentSource.type!==paymentResource)&&setPaymentSources(),setLoading(!1)}return()=>{setLoading(!0)}},[(_b=order==null?void 0:order.payment_method)===null||_b===void 0?void 0:_b.id,show,paymentSource]);const gatewayConfig=Object.assign({readonly,showCard,handleEditClick,children,templateCustomerCards,show,loading,onClickCustomerCards,loaderComponent,templateCustomerSaveToWallet},p);switch(paymentResource){case"stripe_payments":return _jsx(StripeGateway,Object.assign({},gatewayConfig,{children}));case"adyen_payments":return _jsx(AdyenGateway,Object.assign({},gatewayConfig,{children}));case"braintree_payments":return _jsx(BraintreeGateway,Object.assign({},gatewayConfig,{children}));case"wire_transfers":return _jsx(WireTransferGateway,Object.assign({},gatewayConfig,{children}));case"paypal_payments":return _jsx(PaypalGateway,Object.assign({},gatewayConfig,{children}));case"checkout_com_payments":return _jsx(CheckoutComGateway,Object.assign({},gatewayConfig,{children}));default:return null}};export default PaymentGateway;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsx as _jsx}from"react/jsx-runtime";import PaymentMethodContext,{defaultPaymentMethodContext}from"../context/PaymentMethodContext";import{useContext,useEffect,useReducer,useMemo}from"react";import paymentMethodReducer,{paymentMethodInitialState,getPaymentMethods,setPaymentMethodConfig}from"../reducers/PaymentMethodReducer";import OrderContext from"../context/OrderContext";import CommerceLayerContext from"../context/CommerceLayerContext";import components from"../config/components";import{isEmpty}from"lodash";import{setPaymentRef}from"../reducers/PaymentMethodReducer";const propTypes=components.PaymentMethodsContainer.propTypes,displayName=components.PaymentMethodsContainer.displayName,PaymentMethodsContainer=props=>{const{children,config}=props,[state,dispatch]=useReducer(paymentMethodReducer,paymentMethodInitialState),{order,getOrder,setOrderErrors,include,addResourceToInclude,updateOrder,includeLoaded}=useContext(OrderContext),credentials=useContext(CommerceLayerContext);async function getPayMethods(){order&&await getPaymentMethods({order,dispatch})}useEffect(()=>{(include==null?void 0:include.includes("available_payment_methods"))?(includeLoaded==null?void 0:includeLoaded.available_payment_methods)||addResourceToInclude({newResourceLoaded:{available_payment_methods:!0,payment_source:!0,payment_method:!0}}):addResourceToInclude({newResource:["available_payment_methods","payment_source","payment_method"]}),config&&isEmpty(state.config)&&setPaymentMethodConfig(config,dispatch),credentials&&order&&(state.paymentMethods||getPayMethods())},[order,credentials,include,includeLoaded]);const contextValue=useMemo(()=>Object.assign(Object.assign({},state),{setLoading:({loading})=>defaultPaymentMethodContext.setLoading({loading,dispatch}),setPaymentRef:({ref})=>setPaymentRef({ref,dispatch}),setPaymentMethodErrors:errors=>defaultPaymentMethodContext.setPaymentMethodErrors(errors,dispatch),setPaymentMethod:async args=>await defaultPaymentMethodContext.setPaymentMethod(Object.assign(Object.assign({},args),{config:credentials,updateOrder,order,dispatch,setOrderErrors})),setPaymentSource:async args=>await defaultPaymentMethodContext.setPaymentSource(Object.assign(Object.assign(Object.assign({},state),args),{config:credentials,dispatch,getOrder,updateOrder,order})),updatePaymentSource:async args=>await defaultPaymentMethodContext.updatePaymentSource(Object.assign(Object.assign({},args),{config:credentials,dispatch})),destroyPaymentSource:async args=>await defaultPaymentMethodContext.destroyPaymentSource(Object.assign(Object.assign({},args),{dispatch,config:credentials}))}),[state]);return _jsx(PaymentMethodContext.Provider,Object.assign({value:contextValue},{children}))};PaymentMethodsContainer.propTypes=propTypes,PaymentMethodsContainer.displayName=displayName;export default PaymentMethodsContainer;
|
|
1
|
+
import{jsx as _jsx}from"react/jsx-runtime";import PaymentMethodContext,{defaultPaymentMethodContext}from"../context/PaymentMethodContext";import{useContext,useEffect,useReducer,useMemo}from"react";import paymentMethodReducer,{paymentMethodInitialState,getPaymentMethods,setPaymentMethodConfig}from"../reducers/PaymentMethodReducer";import OrderContext from"../context/OrderContext";import CommerceLayerContext from"../context/CommerceLayerContext";import components from"../config/components";import{isEmpty}from"lodash";import{setPaymentRef}from"../reducers/PaymentMethodReducer";const propTypes=components.PaymentMethodsContainer.propTypes,displayName=components.PaymentMethodsContainer.displayName,PaymentMethodsContainer=props=>{const{children,config}=props,[state,dispatch]=useReducer(paymentMethodReducer,paymentMethodInitialState),{order,getOrder,setOrderErrors,include,addResourceToInclude,updateOrder,includeLoaded}=useContext(OrderContext),credentials=useContext(CommerceLayerContext);async function getPayMethods(){order&&await getPaymentMethods({order,dispatch})}useEffect(()=>{(include==null?void 0:include.includes("available_payment_methods"))?(includeLoaded==null?void 0:includeLoaded.available_payment_methods)||addResourceToInclude({newResourceLoaded:{available_payment_methods:!0,payment_source:!0,payment_method:!0}}):addResourceToInclude({newResource:["available_payment_methods","payment_source","payment_method"]}),config&&isEmpty(state.config)&&setPaymentMethodConfig(config,dispatch),credentials&&order&&(state.paymentMethods||getPayMethods()),(order==null?void 0:order.payment_source)&&dispatch({type:"setPaymentSource",payload:{paymentSource:order==null?void 0:order.payment_source}}),(order==null?void 0:order.payment_source)===null&&dispatch({type:"setPaymentSource",payload:{paymentSource:void 0}})},[order,credentials,include,includeLoaded]);const contextValue=useMemo(()=>Object.assign(Object.assign({},state),{setLoading:({loading})=>defaultPaymentMethodContext.setLoading({loading,dispatch}),setPaymentRef:({ref})=>setPaymentRef({ref,dispatch}),setPaymentMethodErrors:errors=>defaultPaymentMethodContext.setPaymentMethodErrors(errors,dispatch),setPaymentMethod:async args=>await defaultPaymentMethodContext.setPaymentMethod(Object.assign(Object.assign({},args),{config:credentials,updateOrder,order,dispatch,setOrderErrors})),setPaymentSource:async args=>await defaultPaymentMethodContext.setPaymentSource(Object.assign(Object.assign(Object.assign({},state),args),{config:credentials,dispatch,getOrder,updateOrder,order})),updatePaymentSource:async args=>await defaultPaymentMethodContext.updatePaymentSource(Object.assign(Object.assign({},args),{config:credentials,dispatch})),destroyPaymentSource:async args=>await defaultPaymentMethodContext.destroyPaymentSource(Object.assign(Object.assign({},args),{dispatch,config:credentials,updateOrder,orderId:order==null?void 0:order.id}))}),[state]);return _jsx(PaymentMethodContext.Provider,Object.assign({value:contextValue},{children}))};PaymentMethodsContainer.propTypes=propTypes,PaymentMethodsContainer.displayName=displayName;export default PaymentMethodsContainer;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsx as _jsx}from"react/jsx-runtime";import{useContext,useState,useEffect}from"react";import PaymentMethodChildrenContext from"../context/PaymentMethodChildrenContext";import components from"../config/components";import PaymentMethodContext from"../context/PaymentMethodContext";import CustomerContext from"../context/CustomerContext";import PaymentGateway from"./PaymentGateway";import getCardDetails from"../utils/getCardDetails";import OrderContext from"../context/OrderContext";const propTypes=components.PaymentSource.propTypes,displayName=components.PaymentSource.displayName,PaymentSource=props=>{const{readonly}=props,{payment}=useContext(PaymentMethodChildrenContext),{order}=useContext(OrderContext),{payments}=useContext(CustomerContext),{currentPaymentMethodId,paymentSource,destroyPaymentSource}=useContext(PaymentMethodContext),[show,setShow]=useState(!1),[showCard,setShowCard]=useState(!1);useEffect(()=>(readonly?(setShow(!0),setShowCard(!0)):(payment==null?void 0:payment.id)===currentPaymentMethodId?(setShow(!0),getCardDetails({paymentType:payment==null?void 0:payment.payment_source_type,customerPayment:{payment_source:
|
|
1
|
+
import{jsx as _jsx}from"react/jsx-runtime";import{useContext,useState,useEffect}from"react";import PaymentMethodChildrenContext from"../context/PaymentMethodChildrenContext";import components from"../config/components";import PaymentMethodContext from"../context/PaymentMethodContext";import CustomerContext from"../context/CustomerContext";import PaymentGateway from"./PaymentGateway";import getCardDetails from"../utils/getCardDetails";import OrderContext from"../context/OrderContext";const propTypes=components.PaymentSource.propTypes,displayName=components.PaymentSource.displayName,PaymentSource=props=>{const{readonly}=props,{payment}=useContext(PaymentMethodChildrenContext),{order}=useContext(OrderContext),{payments}=useContext(CustomerContext),{currentPaymentMethodId,paymentSource,destroyPaymentSource}=useContext(PaymentMethodContext),[show,setShow]=useState(!1),[showCard,setShowCard]=useState(!1);useEffect(()=>(readonly?(setShow(!0),setShowCard(!0)):(payment==null?void 0:payment.id)===currentPaymentMethodId?(setShow(!0),getCardDetails({paymentType:payment==null?void 0:payment.payment_source_type,customerPayment:{payment_source:paymentSource}}).brand&&setShowCard(!0)):setShow(!1),()=>{setShow(!1),setShowCard(!1)}),[currentPaymentMethodId,paymentSource,payments,payment,readonly,order]);const handleEditClick=async e=>{if(e.stopPropagation(),paymentSource){const paymentSourceId=paymentSource==null?void 0:paymentSource.id;await destroyPaymentSource({paymentSourceId,paymentResource:payment==null?void 0:payment.payment_source_type})}setShowCard(!showCard),setShow(!0)},gatewayProps=Object.assign(Object.assign({},props),{show,showCard,handleEditClick,readonly});return _jsx(PaymentGateway,Object.assign({},gatewayProps))};PaymentSource.propTypes=propTypes,PaymentSource.displayName=displayName;export default PaymentSource;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{__rest}from"tslib";import{jsx as _jsx}from"react/jsx-runtime";import{useContext,useEffect,useState}from"react";import Parent from"./utils/Parent";import components from"../config/components";import PlaceOrderContext from"../context/PlaceOrderContext";import isFunction from"lodash/isFunction";import PaymentMethodContext from"../context/PaymentMethodContext";import OrderContext from"../context/OrderContext";import getCardDetails from"../utils/getCardDetails";const propTypes=components.PlaceOrderButton.propTypes,defaultProps=components.PlaceOrderButton.defaultProps,displayName=components.PlaceOrderButton.displayName,PlaceOrderButton=props=>{var _a;const{children,label="Place order",disabled,onClick}=props,p=__rest(props,["children","label","disabled","onClick"]),{isPermitted,setPlaceOrder,options,paymentType}=useContext(PlaceOrderContext),[notPermitted,setNotPermitted]=useState(!0),[forceDisable,setForceDisable]=useState(disabled),{currentPaymentMethodRef,loading,currentPaymentMethodType}=useContext(PaymentMethodContext),{order}=useContext(OrderContext),isFree=(order==null?void 0:order.total_amount_with_taxes_cents)===0;useEffect(()=>{var _a2;if(loading)setNotPermitted(loading);else if(paymentType===currentPaymentMethodType&&paymentType){const card=getCardDetails({customerPayment:{payment_source:
|
|
1
|
+
import{__rest}from"tslib";import{jsx as _jsx}from"react/jsx-runtime";import{useContext,useEffect,useState}from"react";import Parent from"./utils/Parent";import components from"../config/components";import PlaceOrderContext from"../context/PlaceOrderContext";import isFunction from"lodash/isFunction";import PaymentMethodContext from"../context/PaymentMethodContext";import OrderContext from"../context/OrderContext";import getCardDetails from"../utils/getCardDetails";const propTypes=components.PlaceOrderButton.propTypes,defaultProps=components.PlaceOrderButton.defaultProps,displayName=components.PlaceOrderButton.displayName,PlaceOrderButton=props=>{var _a;const{children,label="Place order",disabled,onClick}=props,p=__rest(props,["children","label","disabled","onClick"]),{isPermitted,setPlaceOrder,options,paymentType}=useContext(PlaceOrderContext),[notPermitted,setNotPermitted]=useState(!0),[forceDisable,setForceDisable]=useState(disabled),{currentPaymentMethodRef,loading,currentPaymentMethodType,paymentSource}=useContext(PaymentMethodContext),{order}=useContext(OrderContext),isFree=(order==null?void 0:order.total_amount_with_taxes_cents)===0;useEffect(()=>{var _a2;if(loading)setNotPermitted(loading);else if(paymentType===currentPaymentMethodType&&paymentType){const card=getCardDetails({customerPayment:{payment_source:paymentSource},paymentType});(isFree||((_a2=currentPaymentMethodRef==null?void 0:currentPaymentMethodRef.current)===null||_a2===void 0?void 0:_a2.onsubmit)||card.brand)&&isPermitted&&setNotPermitted(!1)}else setNotPermitted(!isFree);return()=>{setNotPermitted(!0)}},[isPermitted,paymentType,(_a=currentPaymentMethodRef==null?void 0:currentPaymentMethodRef.current)===null||_a===void 0?void 0:_a.onsubmit,loading,currentPaymentMethodType,order,paymentSource]),useEffect(()=>{paymentType==="paypal_payments"&&(options==null?void 0:options.paypalPayerId)&&(order==null?void 0:order.status)&&["draft","pending"].includes(order==null?void 0:order.status)&&handleClick()},[options==null?void 0:options.paypalPayerId,paymentType]),useEffect(()=>{var _a2,_b;paymentType==="adyen_payments"&&((_a2=options==null?void 0:options.adyen)===null||_a2===void 0?void 0:_a2.MD)&&((_b=options==null?void 0:options.adyen)===null||_b===void 0?void 0:_b.PaRes)&&(order==null?void 0:order.status)&&["draft","pending"].includes(order==null?void 0:order.status)&&handleClick()},[options==null?void 0:options.adyen,paymentType]),useEffect(()=>{var _a2;paymentType==="checkout_com_payments"&&((_a2=options==null?void 0:options.checkoutCom)===null||_a2===void 0?void 0:_a2.session_id)&&(order==null?void 0:order.status)&&["draft","pending"].includes(order==null?void 0:order.status)&&handleClick()},[options==null?void 0:options.checkoutCom,paymentType]);const handleClick=async()=>{var _a2,_b,_c,_d;let isValid=!0;setForceDisable(!0);const card=paymentType&&getCardDetails({paymentType,customerPayment:{payment_source:paymentSource}});((_a2=currentPaymentMethodRef==null?void 0:currentPaymentMethodRef.current)===null||_a2===void 0?void 0:_a2.onsubmit)&&[!(options==null?void 0:options.paypalPayerId),!((_b=options==null?void 0:options.adyen)===null||_b===void 0?void 0:_b.MD),!((_c=options==null?void 0:options.checkoutCom)===null||_c===void 0?void 0:_c.session_id)].every(Boolean)?isValid=await((_d=currentPaymentMethodRef.current)===null||_d===void 0?void 0:_d.onsubmit(paymentSource)):(card==null?void 0:card.brand)&&(isValid=!0);const placed=isValid&&setPlaceOrder&&(paymentSource||isFree)&&await setPlaceOrder({paymentSource});setForceDisable(!1),onClick&&placed&&onClick(placed)},disabledButton=disabled!==void 0?disabled:notPermitted,parentProps=Object.assign(Object.assign({},p),{label,disabled:disabledButton,handleClick});return children?_jsx(Parent,Object.assign({},parentProps,{children})):_jsx("button",Object.assign({type:"button",disabled:disabledButton||forceDisable,onClick:handleClick},p,{children:isFunction(label)?label():label}))};PlaceOrderButton.propTypes=propTypes,PlaceOrderButton.defaultProps=defaultProps,PlaceOrderButton.displayName=displayName;export default PlaceOrderButton;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{__rest}from"tslib";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";import{useContext,useEffect,useRef,useState}from"react";import PaymentMethodContext from"../context/PaymentMethodContext";import{CardElement,Elements,useElements,useStripe}from"@stripe/react-stripe-js";import Parent from"./utils/Parent";import OrderContext from"../context/OrderContext";import{setCustomerOrderParam}from"../utils/localStorage";const defaultOptions={style:{base:{fontSize:"16px",color:"#424770","::placeholder":{color:"#aab7c4"}},invalid:{color:"#9e2146"}},hidePostalCode:!0},StripePaymentForm=({options=defaultOptions,templateCustomerSaveToWallet})=>{
|
|
1
|
+
import{__rest}from"tslib";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";import{useContext,useEffect,useRef,useState}from"react";import PaymentMethodContext from"../context/PaymentMethodContext";import{CardElement,Elements,useElements,useStripe}from"@stripe/react-stripe-js";import Parent from"./utils/Parent";import OrderContext from"../context/OrderContext";import{setCustomerOrderParam}from"../utils/localStorage";const defaultOptions={style:{base:{fontSize:"16px",color:"#424770","::placeholder":{color:"#aab7c4"}},invalid:{color:"#9e2146"}},hidePostalCode:!0},StripePaymentForm=({options=defaultOptions,templateCustomerSaveToWallet})=>{const ref=useRef(null),{setPaymentSource,currentPaymentMethodType,setPaymentMethodErrors,setPaymentRef,paymentSource}=useContext(PaymentMethodContext),{order}=useContext(OrderContext),stripe=useStripe(),elements=useElements();useEffect(()=>(ref.current&&stripe&&elements&&paymentSource&&(ref.current.onsubmit=paymentSource2=>onSubmit({event:ref.current,stripe,elements,paymentSource:paymentSource2}),setPaymentRef({ref})),()=>{setPaymentRef({ref:{current:null}})}),[ref,stripe,elements,paymentSource]);const onSubmit=async({event,stripe:stripe2,elements:elements2,paymentSource:ps})=>{var _a,_b;if(!stripe2)return!1;const savePaymentSourceToCustomerWallet=(_b=(_a=event==null?void 0:event.elements)===null||_a===void 0?void 0:_a.save_payment_source_to_customer_wallet)===null||_b===void 0?void 0:_b.checked;savePaymentSourceToCustomerWallet&&setCustomerOrderParam("_save_payment_source_to_customer_wallet",savePaymentSourceToCustomerWallet);const cardElement=elements2&&elements2.getElement(CardElement);if(cardElement){const billingInfo=order==null?void 0:order.billing_address,email=order==null?void 0:order.customer_email,billing_details={name:billingInfo==null?void 0:billingInfo.full_name,email,phone:billingInfo==null?void 0:billingInfo.phone,address:{city:billingInfo==null?void 0:billingInfo.city,country:billingInfo==null?void 0:billingInfo.country_code,line1:billingInfo==null?void 0:billingInfo.line_1,postal_code:billingInfo==null?void 0:billingInfo.zip_code,state:billingInfo==null?void 0:billingInfo.state_code}},{paymentMethod}=await stripe2.createPaymentMethod({type:"card",card:cardElement,billing_details}),clientSecret=ps==null?void 0:ps.client_secret,paymentSourceId=ps==null?void 0:ps.id;if(clientSecret){const{error,paymentIntent}=await stripe2.confirmCardPayment(clientSecret,{payment_method:{card:cardElement,billing_details}});if(error)return console.error(error),setPaymentMethodErrors([{code:"PAYMENT_INTENT_AUTHENTICATION_FAILURE",resource:"payment_methods",field:currentPaymentMethodType,message:error.message}]),!1;if(paymentIntent&&paymentMethod&&paymentSourceId&¤tPaymentMethodType)try{return await setPaymentSource({paymentSourceId,paymentResource:currentPaymentMethodType,attributes:{options:Object.assign(Object.assign({},paymentMethod),{setup_future_usage:"off_session"})}}),!0}catch{return!1}}}return!1};return _jsxs("form",Object.assign({ref},{children:[_jsx(CardElement,{options:Object.assign(Object.assign({},defaultOptions),options)}),templateCustomerSaveToWallet&&_jsx(Parent,Object.assign({},{name:"save_payment_source_to_customer_wallet"},{children:templateCustomerSaveToWallet}))]}))},StripePayment=_a=>{var{publishableKey,show,options,locale="auto"}=_a,p=__rest(_a,["publishableKey","show","options","locale"]);const[isLoaded,setIsLoaded]=useState(!1),[stripe,setStripe]=useState(null),{containerClassName,templateCustomerSaveToWallet,fonts=[]}=p,divProps=__rest(p,["containerClassName","templateCustomerSaveToWallet","fonts"]);return useEffect(()=>{if(show&&publishableKey){const{loadStripe}=require("@stripe/stripe-js");(async()=>{const res=await loadStripe(publishableKey,{locale});setStripe(res),setIsLoaded(!0)})()}return()=>{setIsLoaded(!1)}},[show,publishableKey]),isLoaded&&stripe?_jsx("div",Object.assign({className:containerClassName},divProps,{children:_jsx(Elements,Object.assign({stripe,options:{fonts}},{children:_jsx(StripePaymentForm,{options,templateCustomerSaveToWallet})}))})):null};export default StripePayment;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{__rest}from"tslib";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";import CommerceLayerContext from"../../context/CommerceLayerContext";import CustomerContext from"../../context/CustomerContext";import OrderContext from"../../context/OrderContext";import PaymentMethodChildrenContext from"../../context/PaymentMethodChildrenContext";import PaymentMethodContext from"../../context/PaymentMethodContext";import PaymentSourceContext from"../../context/PaymentSourceContext";import{getPaymentConfig}from"../../reducers/PaymentMethodReducer";import isEmpty from"lodash/isEmpty";import{Fragment,useContext}from"react";import AdyenPayment from"../AdyenPayment";import PaymentCardsTemplate from"../utils/PaymentCardsTemplate";import jwt from"../../utils/jwt";import getCardDetails from"../../utils/getCardDetails";export default function AdyenGateway(props){
|
|
1
|
+
import{__rest}from"tslib";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";import CommerceLayerContext from"../../context/CommerceLayerContext";import CustomerContext from"../../context/CustomerContext";import OrderContext from"../../context/OrderContext";import PaymentMethodChildrenContext from"../../context/PaymentMethodChildrenContext";import PaymentMethodContext from"../../context/PaymentMethodContext";import PaymentSourceContext from"../../context/PaymentSourceContext";import{getPaymentConfig}from"../../reducers/PaymentMethodReducer";import isEmpty from"lodash/isEmpty";import{Fragment,useContext}from"react";import AdyenPayment from"../AdyenPayment";import PaymentCardsTemplate from"../utils/PaymentCardsTemplate";import jwt from"../../utils/jwt";import getCardDetails from"../../utils/getCardDetails";export default function AdyenGateway(props){const{readonly,showCard,handleEditClick,children,templateCustomerCards,loading,loaderComponent,templateCustomerSaveToWallet}=props,p=__rest(props,["readonly","showCard","handleEditClick","children","templateCustomerCards","loading","loaderComponent","templateCustomerSaveToWallet"]),{order}=useContext(OrderContext),{accessToken}=useContext(CommerceLayerContext),{payment}=useContext(PaymentMethodChildrenContext),{payments,isGuest}=useContext(CustomerContext),{currentPaymentMethodId,config,paymentSource}=useContext(PaymentMethodContext),paymentResource="adyen_payments",locale=order==null?void 0:order.language_code,paymentMethods=paymentSource==null?void 0:paymentSource.payment_methods;if(!readonly&&(payment==null?void 0:payment.id)!==currentPaymentMethodId)return null;const clientKey=paymentSource==null?void 0:paymentSource.public_key,environment=jwt(accessToken).test?"test":"live",adyenConfig=config?getPaymentConfig(paymentResource,config):{},customerPayments=!isEmpty(payments)&&payments?payments.filter(customerPayment=>{var _a;return((_a=customerPayment.payment_source)===null||_a===void 0?void 0:_a.type)==="adyen_payments"}):[];if(readonly||showCard){const card=getCardDetails({customerPayment:{payment_source:paymentSource},paymentType:paymentResource}),value=Object.assign(Object.assign({},card),{showCard,handleEditClick,readonly});return isEmpty(card)?null:_jsx(PaymentSourceContext.Provider,Object.assign({value},{children}))}return!isGuest&&templateCustomerCards?clientKey&&!loading&&paymentMethods?_jsxs(Fragment,{children:[isEmpty(customerPayments)?null:_jsx("div",Object.assign({className:p.className},{children:_jsx(PaymentCardsTemplate,Object.assign({},{paymentResource,customerPayments},{children:templateCustomerCards}))})),_jsx(AdyenPayment,{templateCustomerSaveToWallet,clientKey,locale,environment,config:adyenConfig})]}):loaderComponent:clientKey&&!loading&&paymentMethods?_jsx(AdyenPayment,{clientKey,locale,config:adyenConfig}):loaderComponent}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{__rest}from"tslib";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";import BraintreePayment from"../BraintreePayment";import CustomerContext from"../../context/CustomerContext";import OrderContext from"../../context/OrderContext";import PaymentMethodChildrenContext from"../../context/PaymentMethodChildrenContext";import PaymentMethodContext from"../../context/PaymentMethodContext";import PaymentSourceContext from"../../context/PaymentSourceContext";import{getPaymentConfig}from"../../reducers/PaymentMethodReducer";import getCardDetails from"../../utils/getCardDetails";import isEmpty from"lodash/isEmpty";import{Fragment,useContext}from"react";import PaymentCardsTemplate from"../utils/PaymentCardsTemplate";export default function BraintreeGateway(props){
|
|
1
|
+
import{__rest}from"tslib";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";import BraintreePayment from"../BraintreePayment";import CustomerContext from"../../context/CustomerContext";import OrderContext from"../../context/OrderContext";import PaymentMethodChildrenContext from"../../context/PaymentMethodChildrenContext";import PaymentMethodContext from"../../context/PaymentMethodContext";import PaymentSourceContext from"../../context/PaymentSourceContext";import{getPaymentConfig}from"../../reducers/PaymentMethodReducer";import getCardDetails from"../../utils/getCardDetails";import isEmpty from"lodash/isEmpty";import{Fragment,useContext}from"react";import PaymentCardsTemplate from"../utils/PaymentCardsTemplate";export default function BraintreeGateway(props){const{readonly,showCard,handleEditClick,children,templateCustomerCards,loading,loaderComponent,templateCustomerSaveToWallet}=props,p=__rest(props,["readonly","showCard","handleEditClick","children","templateCustomerCards","loading","loaderComponent","templateCustomerSaveToWallet"]),{order}=useContext(OrderContext),{payment}=useContext(PaymentMethodChildrenContext),{payments,isGuest}=useContext(CustomerContext),{currentPaymentMethodId,config,paymentSource}=useContext(PaymentMethodContext),paymentResource="braintree_payments",locale=order==null?void 0:order.language_code;if(!readonly&&(payment==null?void 0:payment.id)!==currentPaymentMethodId)return null;const authorization=paymentSource==null?void 0:paymentSource.client_token,braintreeConfig=config?getPaymentConfig(paymentResource,config):{},customerPayments=!isEmpty(payments)&&payments?payments.filter(customerPayment=>{var _a;return((_a=customerPayment.payment_source)===null||_a===void 0?void 0:_a.type)==="braintree_payments"}):[];if(readonly||showCard){const card=getCardDetails({customerPayment:{payment_source:paymentSource},paymentType:paymentResource}),value=Object.assign(Object.assign({},card),{showCard,handleEditClick,readonly});return isEmpty(card)?null:_jsx(PaymentSourceContext.Provider,Object.assign({value},{children}))}return!isGuest&&templateCustomerCards?authorization&&!loading?_jsxs(Fragment,{children:[isEmpty(customerPayments)?null:_jsx("div",Object.assign({className:p.className},{children:_jsx(PaymentCardsTemplate,Object.assign({},{paymentResource,customerPayments},{children:templateCustomerCards}))})),_jsx(BraintreePayment,{templateCustomerSaveToWallet,authorization,locale,config:braintreeConfig})]}):loaderComponent:authorization&&!loading?_jsx(BraintreePayment,{locale,authorization,config:braintreeConfig}):loaderComponent}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{__rest}from"tslib";import{jsx as _jsx,Fragment as _Fragment,jsxs as _jsxs}from"react/jsx-runtime";import CheckoutComPayment from"../CheckoutComPayment";import CustomerContext from"../../context/CustomerContext";import OrderContext from"../../context/OrderContext";import PaymentMethodChildrenContext from"../../context/PaymentMethodChildrenContext";import PaymentMethodContext from"../../context/PaymentMethodContext";import PaymentSourceContext from"../../context/PaymentSourceContext";import{getPaymentConfig}from"../../reducers/PaymentMethodReducer";import isEmpty from"lodash/isEmpty";import React from"react";import PaymentCardsTemplate from"../utils/PaymentCardsTemplate";import getCardDetails from"../../utils/getCardDetails";export default function CheckoutComGateway(props){
|
|
1
|
+
import{__rest}from"tslib";import{jsx as _jsx,Fragment as _Fragment,jsxs as _jsxs}from"react/jsx-runtime";import CheckoutComPayment from"../CheckoutComPayment";import CustomerContext from"../../context/CustomerContext";import OrderContext from"../../context/OrderContext";import PaymentMethodChildrenContext from"../../context/PaymentMethodChildrenContext";import PaymentMethodContext from"../../context/PaymentMethodContext";import PaymentSourceContext from"../../context/PaymentSourceContext";import{getPaymentConfig}from"../../reducers/PaymentMethodReducer";import isEmpty from"lodash/isEmpty";import React from"react";import PaymentCardsTemplate from"../utils/PaymentCardsTemplate";import getCardDetails from"../../utils/getCardDetails";export default function CheckoutComGateway(props){const{readonly,showCard,handleEditClick,children,templateCustomerCards,show,loading,loaderComponent,templateCustomerSaveToWallet}=props,p=__rest(props,["readonly","showCard","handleEditClick","children","templateCustomerCards","show","loading","loaderComponent","templateCustomerSaveToWallet"]),{order}=React.useContext(OrderContext),{payment}=React.useContext(PaymentMethodChildrenContext),{payments,isGuest}=React.useContext(CustomerContext),{currentPaymentMethodId,config,paymentSource}=React.useContext(PaymentMethodContext),paymentResource="checkout_com_payments",locale=order==null?void 0:order.language_code;if(!readonly&&(payment==null?void 0:payment.id)!==currentPaymentMethodId)return null;const publicKey=paymentSource==null?void 0:paymentSource.public_key,paymentConfig=config?getPaymentConfig(paymentResource,config):{},customerPayments=!isEmpty(payments)&&payments?payments.filter(customerPayment=>{var _a;return((_a=customerPayment.payment_source)===null||_a===void 0?void 0:_a.type)===paymentResource}):[];if(readonly||showCard){const card=getCardDetails({customerPayment:{payment_source:paymentSource},paymentType:paymentResource}),value=Object.assign(Object.assign({},card),{showCard,handleEditClick,readonly});return card.brand?_jsx(PaymentSourceContext.Provider,Object.assign({value},{children})):null}return!isGuest&&templateCustomerCards?publicKey&&!loading?_jsxs(_Fragment,{children:[isEmpty(customerPayments)?null:_jsx("div",Object.assign({className:p.className},{children:_jsx(PaymentCardsTemplate,Object.assign({},{paymentResource,customerPayments},{children:templateCustomerCards}))})),_jsx(CheckoutComPayment,Object.assign({show,templateCustomerSaveToWallet,publicKey,locale},paymentConfig))]}):loaderComponent:publicKey&&!loading?_jsx(CheckoutComPayment,Object.assign({show,publicKey,locale},paymentConfig)):loaderComponent}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{__rest}from"tslib";import{jsx as _jsx,Fragment as _Fragment,jsxs as _jsxs}from"react/jsx-runtime";import StripePayment from"../StripePayment";import CustomerContext from"../../context/CustomerContext";import OrderContext from"../../context/OrderContext";import PaymentMethodChildrenContext from"../../context/PaymentMethodChildrenContext";import PaymentMethodContext from"../../context/PaymentMethodContext";import PaymentSourceContext from"../../context/PaymentSourceContext";import{getPaymentConfig}from"../../reducers/PaymentMethodReducer";import getCardDetails from"../../utils/getCardDetails";import isEmpty from"lodash/isEmpty";import React from"react";import PaymentCardsTemplate from"../utils/PaymentCardsTemplate";export default function StripeGateway(props){var _a
|
|
1
|
+
import{__rest}from"tslib";import{jsx as _jsx,Fragment as _Fragment,jsxs as _jsxs}from"react/jsx-runtime";import StripePayment from"../StripePayment";import CustomerContext from"../../context/CustomerContext";import OrderContext from"../../context/OrderContext";import PaymentMethodChildrenContext from"../../context/PaymentMethodChildrenContext";import PaymentMethodContext from"../../context/PaymentMethodContext";import PaymentSourceContext from"../../context/PaymentSourceContext";import{getPaymentConfig}from"../../reducers/PaymentMethodReducer";import getCardDetails from"../../utils/getCardDetails";import isEmpty from"lodash/isEmpty";import React from"react";import PaymentCardsTemplate from"../utils/PaymentCardsTemplate";export default function StripeGateway(props){var _a;const{readonly,showCard,handleEditClick,children,templateCustomerCards,show,loading,loaderComponent,templateCustomerSaveToWallet}=props,p=__rest(props,["readonly","showCard","handleEditClick","children","templateCustomerCards","show","loading","loaderComponent","templateCustomerSaveToWallet"]),{order}=React.useContext(OrderContext),{payment}=React.useContext(PaymentMethodChildrenContext),{payments,isGuest}=React.useContext(CustomerContext),{currentPaymentMethodId,config,paymentSource}=React.useContext(PaymentMethodContext),paymentResource="stripe_payments",locale=order==null?void 0:order.language_code;if(!readonly&&(payment==null?void 0:payment.id)!==currentPaymentMethodId)return null;const publishableKey=paymentSource==null?void 0:paymentSource.publishable_key,paymentSourceId=((_a=order==null?void 0:order.payment_source)===null||_a===void 0?void 0:_a.id)||(paymentSource==null?void 0:paymentSource.id),stripeConfig=config?getPaymentConfig(paymentResource,config):{},customerPayments=!isEmpty(payments)&&payments?payments.filter(customerPayment=>{var _a2;return((_a2=customerPayment.payment_source)===null||_a2===void 0?void 0:_a2.type)==="stripe_payments"}):[];if(readonly||showCard){const card=getCardDetails({customerPayment:{payment_source:paymentSource},paymentType:paymentResource}),value=Object.assign(Object.assign({},card),{showCard,handleEditClick,readonly});return isEmpty(card)?null:_jsx(PaymentSourceContext.Provider,Object.assign({value},{children}))}return!isGuest&&templateCustomerCards?_jsxs(_Fragment,{children:[isEmpty(customerPayments)?null:_jsx("div",Object.assign({className:p.className},{children:_jsx(PaymentCardsTemplate,Object.assign({},{paymentResource,customerPayments},{children:templateCustomerCards}))})),_jsx(StripePayment,Object.assign({show,templateCustomerSaveToWallet,publishableKey,locale},stripeConfig))]}):publishableKey&&!loading&&paymentSourceId?_jsx(StripePayment,Object.assign({show,publishableKey,locale},stripeConfig)):loaderComponent}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{AdyenPaymentConfig}from'../components/AdyenPayment';import{BraintreeConfig}from'../components/BraintreePayment';import{PaypalConfig}from'../components/PaypalPayment';import{StripeConfig}from'../components/StripePayment';import{WireTransferConfig}from'../components/WireTransferPayment';import{CommerceLayerConfig}from'../context/CommerceLayerContext';import{getOrderContext,updateOrder}from'./OrderReducer';import{BaseError}from'../typings/errors';import{Order,PaymentMethod,StripePayment,WireTransfer,AdyenPayment,BraintreePayment,CheckoutComPayment,ExternalPayment,PaypalPayment}from'@commercelayer/sdk';import{Dispatch,MutableRefObject}from'react';import{CheckoutComConfig}from'../components/CheckoutComPayment';export declare type PaymentSourceType=AdyenPayment|BraintreePayment|CheckoutComPayment|ExternalPayment|PaypalPayment|StripePayment|WireTransfer;declare type Card={brand:string;last4:string;exp_year:number;exp_month:number;};export declare type PaymentSourceObject={adyen_payments:AdyenPayment&{payment_request_data?:{payment_method?:Card;};payment_response?:{resultCode?:'Authorised';};};braintree_payments:BraintreePayment&{options?:{card:Card;};};external_payments:ExternalPayment&{payment_source_token?:string;};paypal_payments:PaypalPayment;stripe_payments:StripePayment&{options?:{card:Card;};};wire_transfers:WireTransfer;checkout_com_payments:CheckoutComPayment&{payment_response:{source?:Pick<Card,'last4'>&{scheme:string;expiry_year:number;expiry_month:number;};};};};export declare type PaymentMethodActionType='setErrors'|'setPaymentMethods'|'setPaymentMethodConfig'|'setPaymentSource'|'setPaymentRef'|'setLoading';export declare type PaymentRef=MutableRefObject<null|HTMLFormElement>;export interface PaymentMethodActionPayload{errors:BaseError[];paymentMethods:PaymentMethod[];currentPaymentMethodType:PaymentResource;currentPaymentMethodId:string;currentPaymentMethodRef:PaymentRef;config:PaymentMethodConfig;paymentSource:PaymentSourceTypes;loading:boolean;}export declare function setLoading({loading,dispatch,}:{loading:boolean;dispatch?:Dispatch<PaymentMethodAction>;}):void;export declare type SetPaymentRef=(args:{ref:PaymentRef;dispatch?:Dispatch<PaymentMethodAction>;})=>void;export declare const setPaymentRef:SetPaymentRef;export declare type PaymentMethodState=Partial<PaymentMethodActionPayload>;export interface PaymentMethodAction{type:PaymentMethodActionType;payload:Partial<PaymentMethodActionPayload>;}export declare const paymentMethodInitialState:PaymentMethodState;export interface SetPaymentMethodErrors{<V extends BaseError[]>(errors:V,dispatch?:Dispatch<PaymentMethodAction>):void;}export declare const setPaymentMethodErrors:SetPaymentMethodErrors;declare type GetPaymentMethods=(args:{order:Order;dispatch:Dispatch<PaymentMethodAction>;})=>Promise<void>;export declare const getPaymentMethods:GetPaymentMethods;export declare type PaymentResource=keyof PaymentSourceObject;export declare type PaymentResourceKey='braintreePayment'|'stripePayment'|'wireTransfer'|'paypalPayment'|'adyenPayment'|'checkoutComPayment';export declare type SDKPaymentResource='AdyenPayment'|'BraintreePayment'|'ExternalPayment'|'PaypalPayment'|'StripePayment'|'WireTransfer'|'CheckoutComPayment';export declare type SetPaymentMethod=(args:{config?:CommerceLayerConfig;dispatch?:Dispatch<PaymentMethodAction>;updateOrder?:typeof updateOrder;setOrderErrors?:(collection:any)=>{success:boolean;};order?:Order;paymentMethodId:string;paymentResource?:PaymentResource;})=>Promise<void>;export declare const setPaymentMethod:SetPaymentMethod;declare type PaymentSourceTypes=(StripePayment&WireTransfer)|(StripePayment|WireTransfer);export declare type SetPaymentSourceResponse={order:Order;paymentSource:PaymentSourceTypes;}|null;export declare type SetPaymentSource=(args:{config?:CommerceLayerConfig;dispatch?:Dispatch<PaymentMethodAction>;getOrder?:getOrderContext;attributes?:Record<string,unknown>;order?:Order;paymentResource:PaymentResource;paymentSourceId?:string;customerPaymentSourceId?:string;updateOrder?:typeof updateOrder;}&PaymentMethodState)=>Promise<PaymentSourceType|void>;export declare const setPaymentSource:SetPaymentSource;export declare type UpdatePaymentSource=(args:{id:string;attributes:Record<string,any>;paymentResource:PaymentResource;config?:CommerceLayerConfig;dispatch?:Dispatch<PaymentMethodAction>;})=>Promise<void>;export declare const updatePaymentSource:UpdatePaymentSource;export declare type DestroyPaymentSource=(args:{paymentSourceId:string;paymentResource:PaymentResource;dispatch?:Dispatch<PaymentMethodAction>;})=>Promise<void>;export declare const destroyPaymentSource:DestroyPaymentSource;export declare type PaymentMethodConfig={stripePayment?:StripeConfig;braintreePayment?:BraintreeConfig;wireTransfer?:Partial<WireTransferConfig>;paypalPayment?:PaypalConfig;adyenPayment?:AdyenPaymentConfig;checkoutComPayment?:CheckoutComConfig;};declare type SetPaymentMethodConfig=(config:PaymentMethodConfig,dispatch:Dispatch<PaymentMethodAction>)=>void;export declare const setPaymentMethodConfig:SetPaymentMethodConfig;export declare function getPaymentConfig<K extends PaymentResourceKey>(paymentResource:PaymentResource,config:PaymentMethodConfig):PaymentMethodConfig[K];declare const paymentMethodReducer:(state:PaymentMethodState,reducer:PaymentMethodAction)=>PaymentMethodState;export default paymentMethodReducer;
|
|
1
|
+
import{AdyenPaymentConfig}from'../components/AdyenPayment';import{BraintreeConfig}from'../components/BraintreePayment';import{PaypalConfig}from'../components/PaypalPayment';import{StripeConfig}from'../components/StripePayment';import{WireTransferConfig}from'../components/WireTransferPayment';import{CommerceLayerConfig}from'../context/CommerceLayerContext';import{getOrderContext,updateOrder}from'./OrderReducer';import{BaseError}from'../typings/errors';import{Order,PaymentMethod,StripePayment,WireTransfer,AdyenPayment,BraintreePayment,CheckoutComPayment,ExternalPayment,PaypalPayment}from'@commercelayer/sdk';import{Dispatch,MutableRefObject}from'react';import{CheckoutComConfig}from'../components/CheckoutComPayment';export declare type PaymentSourceType=AdyenPayment|BraintreePayment|CheckoutComPayment|ExternalPayment|PaypalPayment|StripePayment|WireTransfer;declare type Card={brand:string;last4:string;exp_year:number;exp_month:number;};export declare type PaymentSourceObject={adyen_payments:AdyenPayment&{payment_request_data?:{payment_method?:Card;};payment_response?:{resultCode?:'Authorised';};};braintree_payments:BraintreePayment&{options?:{card:Card;};};external_payments:ExternalPayment&{payment_source_token?:string;};paypal_payments:PaypalPayment;stripe_payments:StripePayment&{options?:{card:Card;};};wire_transfers:WireTransfer;checkout_com_payments:CheckoutComPayment&{payment_response:{source?:Pick<Card,'last4'>&{scheme:string;expiry_year:number;expiry_month:number;};};};};export declare type PaymentMethodActionType='setErrors'|'setPaymentMethods'|'setPaymentMethodConfig'|'setPaymentSource'|'setPaymentRef'|'setLoading';export declare type PaymentRef=MutableRefObject<null|HTMLFormElement>;export interface PaymentMethodActionPayload{errors:BaseError[];paymentMethods:PaymentMethod[];currentPaymentMethodType:PaymentResource;currentPaymentMethodId:string;currentPaymentMethodRef:PaymentRef;config:PaymentMethodConfig;paymentSource:PaymentSourceTypes;loading:boolean;}export declare function setLoading({loading,dispatch,}:{loading:boolean;dispatch?:Dispatch<PaymentMethodAction>;}):void;export declare type SetPaymentRef=(args:{ref:PaymentRef;dispatch?:Dispatch<PaymentMethodAction>;})=>void;export declare const setPaymentRef:SetPaymentRef;export declare type PaymentMethodState=Partial<PaymentMethodActionPayload>;export interface PaymentMethodAction{type:PaymentMethodActionType;payload:Partial<PaymentMethodActionPayload>;}export declare const paymentMethodInitialState:PaymentMethodState;export interface SetPaymentMethodErrors{<V extends BaseError[]>(errors:V,dispatch?:Dispatch<PaymentMethodAction>):void;}export declare const setPaymentMethodErrors:SetPaymentMethodErrors;declare type GetPaymentMethods=(args:{order:Order;dispatch:Dispatch<PaymentMethodAction>;})=>Promise<void>;export declare const getPaymentMethods:GetPaymentMethods;export declare type PaymentResource=keyof PaymentSourceObject;export declare type PaymentResourceKey='braintreePayment'|'stripePayment'|'wireTransfer'|'paypalPayment'|'adyenPayment'|'checkoutComPayment';export declare type SDKPaymentResource='AdyenPayment'|'BraintreePayment'|'ExternalPayment'|'PaypalPayment'|'StripePayment'|'WireTransfer'|'CheckoutComPayment';export declare type SetPaymentMethod=(args:{config?:CommerceLayerConfig;dispatch?:Dispatch<PaymentMethodAction>;updateOrder?:typeof updateOrder;setOrderErrors?:(collection:any)=>{success:boolean;};order?:Order;paymentMethodId:string;paymentResource?:PaymentResource;})=>Promise<void>;export declare const setPaymentMethod:SetPaymentMethod;declare type PaymentSourceTypes=(StripePayment&WireTransfer)|(StripePayment|WireTransfer);export declare type SetPaymentSourceResponse={order:Order;paymentSource:PaymentSourceTypes;}|null;export declare type SetPaymentSource=(args:{config?:CommerceLayerConfig;dispatch?:Dispatch<PaymentMethodAction>;getOrder?:getOrderContext;attributes?:Record<string,unknown>;order?:Order;paymentResource:PaymentResource;paymentSourceId?:string;customerPaymentSourceId?:string;updateOrder?:typeof updateOrder;}&PaymentMethodState)=>Promise<PaymentSourceType|void>;export declare const setPaymentSource:SetPaymentSource;export declare type UpdatePaymentSource=(args:{id:string;attributes:Record<string,any>;paymentResource:PaymentResource;config?:CommerceLayerConfig;dispatch?:Dispatch<PaymentMethodAction>;})=>Promise<void>;export declare const updatePaymentSource:UpdatePaymentSource;export declare type DestroyPaymentSource=(args:{paymentSourceId:string;paymentResource:PaymentResource;dispatch?:Dispatch<PaymentMethodAction>;updateOrder?:typeof updateOrder;orderId?:string;})=>Promise<void>;export declare const destroyPaymentSource:DestroyPaymentSource;export declare type PaymentMethodConfig={stripePayment?:StripeConfig;braintreePayment?:BraintreeConfig;wireTransfer?:Partial<WireTransferConfig>;paypalPayment?:PaypalConfig;adyenPayment?:AdyenPaymentConfig;checkoutComPayment?:CheckoutComConfig;};declare type SetPaymentMethodConfig=(config:PaymentMethodConfig,dispatch:Dispatch<PaymentMethodAction>)=>void;export declare const setPaymentMethodConfig:SetPaymentMethodConfig;export declare function getPaymentConfig<K extends PaymentResourceKey>(paymentResource:PaymentResource,config:PaymentMethodConfig):PaymentMethodConfig[K];declare const paymentMethodReducer:(state:PaymentMethodState,reducer:PaymentMethodAction)=>PaymentMethodState;export default paymentMethodReducer;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@commercelayer/react-components",
|
|
3
|
-
"version": "3.9.
|
|
3
|
+
"version": "3.9.2",
|
|
4
4
|
"description": "The Official Commerce Layer React Components",
|
|
5
5
|
"module": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -102,11 +102,11 @@
|
|
|
102
102
|
"@babel/preset-env": "^7.16.11",
|
|
103
103
|
"@babel/preset-react": "^7.16.7",
|
|
104
104
|
"@babel/preset-typescript": "^7.16.7",
|
|
105
|
-
"@playwright/test": "^1.20.
|
|
105
|
+
"@playwright/test": "^1.20.2",
|
|
106
106
|
"@semantic-release/changelog": "^6.0.1",
|
|
107
107
|
"@semantic-release/commit-analyzer": "^9.0.2",
|
|
108
108
|
"@semantic-release/git": "^10.0.1",
|
|
109
|
-
"@semantic-release/github": "^8.0.
|
|
109
|
+
"@semantic-release/github": "^8.0.4",
|
|
110
110
|
"@semantic-release/npm": "^9.0.1",
|
|
111
111
|
"@semantic-release/release-notes-generator": "^10.0.3",
|
|
112
112
|
"@tailwindcss/aspect-ratio": "^0.4.0",
|
|
@@ -115,13 +115,13 @@
|
|
|
115
115
|
"@tailwindcss/typography": "^0.5.2",
|
|
116
116
|
"@types/braintree-web": "^3.75.19",
|
|
117
117
|
"@types/jest": "^27.4.1",
|
|
118
|
-
"@types/lodash": "^4.14.
|
|
118
|
+
"@types/lodash": "^4.14.181",
|
|
119
119
|
"@types/node": "^17.0.23",
|
|
120
120
|
"@types/prop-types": "^15.7.4",
|
|
121
121
|
"@types/react": "^17.0.43",
|
|
122
122
|
"@types/react-test-renderer": "^17.0.1",
|
|
123
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
124
|
-
"@typescript-eslint/parser": "^5.
|
|
123
|
+
"@typescript-eslint/eslint-plugin": "^5.18.0",
|
|
124
|
+
"@typescript-eslint/parser": "^5.18.0",
|
|
125
125
|
"@zeit/next-css": "^1.0.1",
|
|
126
126
|
"@zerollup/ts-transform-paths": "^1.7.18",
|
|
127
127
|
"autoprefixer": "^10.4.4",
|
|
@@ -133,15 +133,15 @@
|
|
|
133
133
|
"eslint-config-prettier": "^8.5.0",
|
|
134
134
|
"eslint-config-react-app": "^7.0.0",
|
|
135
135
|
"eslint-plugin-react": "^7.29.4",
|
|
136
|
-
"eslint-plugin-react-hooks": "^4.
|
|
136
|
+
"eslint-plugin-react-hooks": "^4.4.0",
|
|
137
137
|
"jest": "^27.5.1",
|
|
138
138
|
"minimize-js": "^1.3.0",
|
|
139
|
-
"next": "^12.1.
|
|
139
|
+
"next": "^12.1.4",
|
|
140
140
|
"nyc": "^15.1.0",
|
|
141
|
-
"playwright": "^1.20.
|
|
141
|
+
"playwright": "^1.20.2",
|
|
142
142
|
"postcss": "^8.4.12",
|
|
143
143
|
"postcss-loader": "^6.2.1",
|
|
144
|
-
"prettier": "^2.6.
|
|
144
|
+
"prettier": "^2.6.2",
|
|
145
145
|
"prop-types": "^15.8.1",
|
|
146
146
|
"react": "^17.0.2",
|
|
147
147
|
"react-dom": "^17.0.2",
|