@commercelayer/react-components 3.6.0 → 3.6.1

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.
@@ -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,{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,paymentSource,currentPaymentMethodType,setPaymentSource}=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):{};(!paymentSource||paymentSource.type!==paymentResource)&&(setPaymentSource({paymentResource,order,attributes}),getCustomerPaymentSources&&getCustomerPaymentSources()),setLoading(!1)}return()=>{setLoading(!0)}},[(_b=order==null?void 0:order.payment_method)===null||_b===void 0?void 0:_b.payment_source_type,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
+ 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{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,paymentSource,currentPaymentMethodType,setPaymentSource}=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):{};(!(order==null?void 0:order.payment_source)||!(order==null?void 0:order.payment_source)&&paymentSource)&&show&&(setPaymentSource({paymentResource,order,attributes}),getCustomerPaymentSources&&getCustomerPaymentSources()),setLoading(!1)}return()=>{setLoading(!0)}},[order==null?void 0:order.payment_method,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);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&&getPaymentMethods({order,dispatch}),credentials&&(order==null?void 0:order.payment_source)&&dispatch({type:"setPaymentSource",payload:{paymentSource:order==null?void 0:order.payment_source}})},[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=>defaultPaymentMethodContext.setPaymentSource(Object.assign(Object.assign(Object.assign({},state),args),{config:credentials,dispatch,getOrder,updateOrder,order})),updatePaymentSource:async args=>defaultPaymentMethodContext.updatePaymentSource(Object.assign(Object.assign({},args),{config:credentials,dispatch})),destroyPaymentSource:async args=>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);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||getPaymentMethods({order,dispatch}),(order==null?void 0:order.payment_source)&&dispatch({type:"setPaymentSource",payload:{paymentSource:order==null?void 0:order.payment_source}}))},[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=>defaultPaymentMethodContext.setPaymentSource(Object.assign(Object.assign(Object.assign({},state),args),{config:credentials,dispatch,getOrder,updateOrder,order})),updatePaymentSource:async args=>defaultPaymentMethodContext.updatePaymentSource(Object.assign(Object.assign({},args),{config:credentials,dispatch})),destroyPaymentSource:async args=>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 +1 @@
1
- import{FunctionComponent}from'react';import{PriceProps}from'../Price';export declare type PTemplateProps={formattedAmount?:string;formattedCompare?:string;}&Omit<PriceProps,'children'>;declare const PriceTemplate:FunctionComponent<PTemplateProps>;export default PriceTemplate;
1
+ import React from'react';import{PriceProps}from'../Price';export declare type PTemplateProps={formattedAmount?:string;formattedCompare?:string;}&Omit<PriceProps,'children'>;declare const PriceTemplate:React.FunctionComponent<PTemplateProps>;export default PriceTemplate;
@@ -1 +1 @@
1
- import{__rest}from"tslib";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";import{Fragment}from"react";import PropTypes from"prop-types";const propTypes={formattedAmount:PropTypes.string,formattedCompare:PropTypes.string},defaultProps={formattedAmount:"",formattedCompare:""},PriceTemplate=props=>{const{showCompare,formattedCompare,compareClassName,className,formattedAmount,skuCode}=props,p=__rest(props,["showCompare","formattedCompare","compareClassName","className","formattedAmount","skuCode"]);return _jsxs(Fragment,{children:[_jsx("span",Object.assign({className},p,{children:formattedAmount})),showCompare&&_jsx("span",Object.assign({className:compareClassName||""},p,{children:formattedCompare}))]})};PriceTemplate.propTypes=propTypes,PriceTemplate.defaultProps=defaultProps;export default PriceTemplate;
1
+ import{__rest}from"tslib";import{jsx as _jsx,Fragment as _Fragment,jsxs as _jsxs}from"react/jsx-runtime";import PropTypes from"prop-types";const propTypes={formattedAmount:PropTypes.string,formattedCompare:PropTypes.string},defaultProps={formattedAmount:"",formattedCompare:""},PriceTemplate=props=>{const{showCompare,formattedCompare,compareClassName,className,formattedAmount}=props,p=__rest(props,["showCompare","formattedCompare","compareClassName","className","formattedAmount"]);return _jsxs(_Fragment,{children:[_jsx("span",Object.assign({className},p,{children:formattedAmount})),showCompare&&_jsx("span",Object.assign({className:compareClassName||""},p,{children:formattedCompare}))]})};PriceTemplate.propTypes=propTypes,PriceTemplate.defaultProps=defaultProps;export default PriceTemplate;
@@ -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;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>;})=>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 +1 @@
1
- import baseReducer from"../utils/baseReducer";import getErrors,{setErrors}from"../utils/getErrors";import getSdk from"../utils/getSdk";import camelCase from"lodash/camelCase";import has from"lodash/has";import isEmpty from"lodash/isEmpty";export function setLoading({loading,dispatch}){dispatch&&dispatch({type:"setLoading",payload:{loading}})}export const setPaymentRef=({ref,dispatch})=>{ref&&dispatch&&dispatch({type:"setPaymentRef",payload:{currentPaymentMethodRef:ref}})},paymentMethodInitialState={errors:[]},setPaymentMethodErrors=(errors,dispatch)=>{dispatch&&dispatch({type:"setErrors",payload:{errors}})},getPaymentMethods=async({order,dispatch})=>{const paymentMethods=order.available_payment_methods,paymentMethod=order.payment_method,paymentSource=order.payment_source;dispatch({type:"setPaymentMethods",payload:{paymentMethods,currentPaymentMethodId:paymentMethod==null?void 0:paymentMethod.id,currentPaymentMethodType:paymentMethod==null?void 0:paymentMethod.payment_source_type,paymentSource}})},setPaymentMethod=async({config,dispatch,order,paymentMethodId,updateOrder,setOrderErrors,paymentResource})=>{try{if(config&&order&&dispatch&&paymentResource){localStorage.removeItem("_save_payment_source_to_customer_wallet");const attributes={payment_method:getSdk(config).payment_methods.relationship(paymentMethodId)};dispatch({type:"setPaymentMethods",payload:{currentPaymentMethodId:paymentMethodId,currentPaymentMethodType:paymentResource,errors:[]}}),updateOrder&&await updateOrder({id:order.id,attributes}),setOrderErrors&&setOrderErrors([])}}catch(error){const errors=getErrors(error,"orders");console.error("Set payment method",errors)}},setPaymentSource=async({config,dispatch,getOrder,attributes={},order,paymentResource,customerPaymentSourceId,paymentSourceId,updateOrder,errors:currentErrors})=>{try{if(config&&order){let paymentSource;const sdk=getSdk(config);if(customerPaymentSourceId)updateOrder&&await updateOrder({id:order.id,attributes:{_customer_payment_source_id:customerPaymentSourceId}});else{if(paymentSourceId){const attrs=Object.assign({id:paymentSourceId},attributes);paymentSource=await sdk[paymentResource].update(attrs)}else{const attrs=Object.assign(Object.assign({},attributes),{order:sdk.orders.relationship(order.id)});paymentSource=await sdk[paymentResource].create(attrs)}return dispatch&&dispatch({type:"setPaymentSource",payload:{paymentSource,errors:[]}}),getOrder&&await getOrder(order.id),paymentSource}}}catch(error){const errors=getErrors(error,"payment_methods");console.error("Set payment source:",errors),dispatch&&setErrors({currentErrors,newErrors:errors,dispatch})}},updatePaymentSource=async({id,attributes,config,dispatch,paymentResource})=>{if(config)try{const paymentSource=await getSdk(config)[paymentResource].update(Object.assign({id},attributes));dispatch&&dispatch({type:"setPaymentSource",payload:{paymentSource}})}catch(err){console.error("Update payment source:",err)}},destroyPaymentSource=async({paymentSourceId,paymentResource,dispatch})=>{paymentSourceId&&paymentResource&&dispatch&&dispatch({type:"setPaymentSource",payload:{paymentSource:void 0}})},setPaymentMethodConfig=(config,dispatch)=>{dispatch({type:"setPaymentMethodConfig",payload:{config}})};export function getPaymentConfig(paymentResource,config){const resource=camelCase(paymentResource).replace("Payments","Payment").replace("Transfers","Transfer");return!isEmpty(config)&&has(config,resource)?config[resource]:void 0}const type=["setErrors","setPaymentMethodConfig","setPaymentMethods","setPaymentSource","setPaymentRef","setLoading"],paymentMethodReducer=(state,reducer)=>baseReducer(state,reducer,type);export default paymentMethodReducer;
1
+ import baseReducer from"../utils/baseReducer";import getErrors,{setErrors}from"../utils/getErrors";import getSdk from"../utils/getSdk";import camelCase from"lodash/camelCase";import has from"lodash/has";import isEmpty from"lodash/isEmpty";export function setLoading({loading,dispatch}){dispatch&&dispatch({type:"setLoading",payload:{loading}})}export const setPaymentRef=({ref,dispatch})=>{ref&&dispatch&&dispatch({type:"setPaymentRef",payload:{currentPaymentMethodRef:ref}})},paymentMethodInitialState={errors:[]},setPaymentMethodErrors=(errors,dispatch)=>{dispatch&&dispatch({type:"setErrors",payload:{errors}})},getPaymentMethods=async({order,dispatch})=>{const paymentMethods=order.available_payment_methods,paymentMethod=order.payment_method,paymentSource=order.payment_source;dispatch({type:"setPaymentMethods",payload:{paymentMethods,currentPaymentMethodId:paymentMethod==null?void 0:paymentMethod.id,currentPaymentMethodType:paymentMethod==null?void 0:paymentMethod.payment_source_type,paymentSource}})},setPaymentMethod=async({config,dispatch,order,paymentMethodId,updateOrder,setOrderErrors,paymentResource})=>{try{if(config&&order&&dispatch&&paymentResource){localStorage.removeItem("_save_payment_source_to_customer_wallet");const attributes={payment_method:getSdk(config).payment_methods.relationship(paymentMethodId)};updateOrder&&await updateOrder({id:order.id,attributes}),dispatch({type:"setPaymentMethods",payload:{currentPaymentMethodId:paymentMethodId,currentPaymentMethodType:paymentResource,errors:[]}}),setOrderErrors&&setOrderErrors([])}}catch(error){const errors=getErrors(error,"orders");console.error("Set payment method",errors)}},setPaymentSource=async({config,dispatch,getOrder,attributes={},order,paymentResource,customerPaymentSourceId,paymentSourceId,updateOrder,errors:currentErrors})=>{try{if(config&&order){let paymentSource;const sdk=getSdk(config);if(customerPaymentSourceId)updateOrder&&await updateOrder({id:order.id,attributes:{_customer_payment_source_id:customerPaymentSourceId}});else{if(paymentSourceId){const attrs=Object.assign({id:paymentSourceId},attributes);paymentSource=await sdk[paymentResource].update(attrs)}else{const attrs=Object.assign(Object.assign({},attributes),{order:sdk.orders.relationship(order.id)});paymentSource=await sdk[paymentResource].create(attrs)}return getOrder&&await getOrder(order.id),dispatch&&dispatch({type:"setPaymentSource",payload:{paymentSource,errors:[]}}),paymentSource}}}catch(error){const errors=getErrors(error,"payment_methods");console.error("Set payment source:",errors),dispatch&&setErrors({currentErrors,newErrors:errors,dispatch})}},updatePaymentSource=async({id,attributes,config,dispatch,paymentResource})=>{if(config)try{const paymentSource=await getSdk(config)[paymentResource].update(Object.assign({id},attributes));dispatch&&dispatch({type:"setPaymentSource",payload:{paymentSource}})}catch(err){console.error("Update payment source:",err)}},destroyPaymentSource=async({paymentSourceId,paymentResource,dispatch})=>{paymentSourceId&&paymentResource&&dispatch&&dispatch({type:"setPaymentSource",payload:{paymentSource:void 0}})},setPaymentMethodConfig=(config,dispatch)=>{dispatch({type:"setPaymentMethodConfig",payload:{config}})};export function getPaymentConfig(paymentResource,config){const resource=camelCase(paymentResource).replace("Payments","Payment").replace("Transfers","Transfer");return!isEmpty(config)&&has(config,resource)?config[resource]:void 0}const type=["setErrors","setPaymentMethodConfig","setPaymentMethods","setPaymentSource","setPaymentRef","setLoading"],paymentMethodReducer=(state,reducer)=>baseReducer(state,reducer,type);export default paymentMethodReducer;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@commercelayer/react-components",
3
- "version": "3.6.0",
3
+ "version": "3.6.1",
4
4
  "description": "The Official Commerce Layer React Components",
5
5
  "module": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -49,6 +49,7 @@
49
49
  "coverage:report": "nyc report --reporter=html",
50
50
  "lint": "eslint src",
51
51
  "build": "tsc -b tsconfig.prod.json --verbose",
52
+ "build:dev": "tsc -b tsconfig.prod.json --verbose && tsc-alias -p tsconfig.prod.json",
52
53
  "postbuild": "tsc-alias -p tsconfig.prod.json && minimize-js lib -w -s -d",
53
54
  "start": "NODE_OPTIONS='--inspect' next dev",
54
55
  "version:fix": "npm version patch",
@@ -83,12 +84,12 @@
83
84
  "dependencies": {
84
85
  "@ac-dev/countries-service": "^1.2.0",
85
86
  "@ac-dev/states-service": "^1.0.3",
86
- "@adyen/adyen-web": "^5.9.0",
87
+ "@adyen/adyen-web": "^5.10.0",
87
88
  "@commercelayer/js-auth": "^3.0.0",
88
- "@commercelayer/sdk": "^3.5.0",
89
+ "@commercelayer/sdk": "^3.6.0",
89
90
  "@stripe/react-stripe-js": "^1.7.0",
90
91
  "@stripe/stripe-js": "^1.24.0",
91
- "axios": "^0.26.0",
92
+ "axios": "^0.26.1",
92
93
  "braintree-web": "^3.85.2",
93
94
  "frames-react": "^1.0.3",
94
95
  "jwt-decode": "^3.1.2",
@@ -112,15 +113,15 @@
112
113
  "@tailwindcss/forms": "^0.5.0",
113
114
  "@tailwindcss/line-clamp": "^0.3.1",
114
115
  "@tailwindcss/typography": "^0.5.2",
115
- "@types/braintree-web": "^3.75.18",
116
+ "@types/braintree-web": "^3.75.19",
116
117
  "@types/jest": "^27.4.1",
117
118
  "@types/lodash": "^4.14.179",
118
119
  "@types/node": "^17.0.21",
119
120
  "@types/prop-types": "^15.7.4",
120
- "@types/react": "^17.0.39",
121
+ "@types/react": "^17.0.40",
121
122
  "@types/react-test-renderer": "^17.0.1",
122
- "@typescript-eslint/eslint-plugin": "^5.13.0",
123
- "@typescript-eslint/parser": "^5.13.0",
123
+ "@typescript-eslint/eslint-plugin": "^5.14.0",
124
+ "@typescript-eslint/parser": "^5.14.0",
124
125
  "@zeit/next-css": "^1.0.1",
125
126
  "@zerollup/ts-transform-paths": "^1.7.18",
126
127
  "autoprefixer": "^10.4.2",