@commercelayer/react-components 3.2.4 → 3.4.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.
- package/LICENSE +2 -2
- package/lib/components/AvailabilityContainer.js +1 -1
- package/lib/components/CheckoutComPayment.d.ts +21 -0
- package/lib/components/CheckoutComPayment.js +1 -0
- package/lib/components/CheckoutLink.d.ts +2 -0
- package/lib/components/CheckoutLink.js +1 -1
- package/lib/components/CustomerInput.d.ts +1 -1
- package/lib/components/CustomerInput.js +1 -1
- package/lib/components/PaymentGateway.js +1 -1
- package/lib/components/PaymentSource.js +1 -1
- package/lib/components/PaymentSourceBrandIcon.d.ts +2 -2
- package/lib/components/PaymentSourceBrandName.d.ts +2 -2
- package/lib/components/PlaceOrderButton.js +1 -1
- package/lib/components/gateways/CheckoutComGateway.d.ts +5 -0
- package/lib/components/gateways/CheckoutComGateway.js +1 -0
- package/lib/components/utils/PaymentCardsTemplate.d.ts +2 -2
- package/lib/components/utils/PaymentCardsTemplate.js +1 -1
- package/lib/context/OrderContext.d.ts +4 -4
- package/lib/context/OrderContext.js +1 -1
- package/lib/context/PaymentSourceContext.d.ts +4 -4
- package/lib/context/PlaceOrderContext.d.ts +4 -2
- package/lib/reducers/PaymentMethodReducer.d.ts +41 -4
- package/lib/reducers/PlaceOrderReducer.d.ts +7 -2
- package/lib/reducers/PlaceOrderReducer.js +1 -1
- package/lib/utils/getCardDetails.d.ts +15 -0
- package/lib/utils/getCardDetails.js +1 -0
- package/lib/utils/hooks/useExternalScript.d.ts +1 -0
- package/lib/utils/hooks/useExternalScript.js +1 -0
- package/package.json +6 -5
package/LICENSE
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
The MIT License (MIT)
|
|
2
2
|
|
|
3
|
-
Copyright (c) 2020 Commerce Layer
|
|
3
|
+
Copyright (c) 2020 Commerce Layer Inc.
|
|
4
4
|
https://commercelayer.io
|
|
5
5
|
|
|
6
6
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
@@ -19,4 +19,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
19
19
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
20
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
21
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
22
|
-
THE SOFTWARE.
|
|
22
|
+
THE SOFTWARE.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsx as _jsx}from"react/jsx-runtime";import{useContext,useReducer,useEffect}from"react";import availabilityReducer,{availabilityInitialState,getAvailability}from"../reducers/AvailabilityReducer";import AvailabilityContext from"../context/AvailabilityContext";import
|
|
1
|
+
import{jsx as _jsx}from"react/jsx-runtime";import{useContext,useReducer,useEffect}from"react";import availabilityReducer,{availabilityInitialState,getAvailability}from"../reducers/AvailabilityReducer";import AvailabilityContext from"../context/AvailabilityContext";import ItemContext from"../context/ItemContext";import getCurrentItemKey from"../utils/getCurrentItemKey";import components from"../config/components";import CommerceLayerContext from"../context/CommerceLayerContext";import LineItemChildrenContext from"../context/LineItemChildrenContext";const propTypes=components.AvailabilityContainer.propTypes,displayName=components.AvailabilityContainer.displayName,AvailabilityContainer=props=>{const{children,skuCode}=props,{item,skuCode:itemSkuCode,setItem}=useContext(ItemContext),{lineItem}=useContext(LineItemChildrenContext),config=useContext(CommerceLayerContext),[state,dispatch]=useReducer(availabilityReducer,availabilityInitialState),sCode=skuCode||getCurrentItemKey(item)||itemSkuCode||(lineItem==null?void 0:lineItem.sku_code);return useEffect(()=>{var _a,_b,_c,_d,_e,_f,_g;if(sCode){const available=(_b=(_a=item[sCode])===null||_a===void 0?void 0:_a.inventory)===null||_b===void 0?void 0:_b.available,quantity=(_d=(_c=item[sCode])===null||_c===void 0?void 0:_c.inventory)===null||_d===void 0?void 0:_d.quantity,[level]=((_f=(_e=item[sCode])===null||_e===void 0?void 0:_e.inventory)===null||_f===void 0?void 0:_f.levels)||[{quantity:null,delivery_lead_times:[]}];if(level!==void 0&&((_g=level==null?void 0:level.delivery_lead_times)===null||_g===void 0?void 0:_g.length)>0){const[delivery]=level.delivery_lead_times;dispatch({type:"setAvailability",payload:Object.assign(Object.assign({},delivery),{quantity:level==null?void 0:level.quantity})})}else config.accessToken&&!(item==null?void 0:item[sCode])?getAvailability({skuCode:sCode,config,dispatch,setItem}):available||dispatch({type:"setAvailability",payload:{quantity}})}return()=>{dispatch({type:"setAvailability",payload:{}})}},[config.accessToken,item,sCode]),_jsx(AvailabilityContext.Provider,Object.assign({value:Object.assign({},state)},{children}),void 0)};AvailabilityContainer.propTypes=propTypes,AvailabilityContainer.displayName=displayName;export default AvailabilityContainer;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { FunctionComponent } from 'react';
|
|
2
|
+
import { PaymentMethodConfig } from '../reducers/PaymentMethodReducer';
|
|
3
|
+
import { PaymentSourceProps } from './PaymentSource';
|
|
4
|
+
import { FramesStyle } from 'frames-react';
|
|
5
|
+
export declare type CheckoutComConfig = {
|
|
6
|
+
containerClassName?: string;
|
|
7
|
+
hintLabel?: string;
|
|
8
|
+
name?: string;
|
|
9
|
+
options?: {
|
|
10
|
+
style: FramesStyle;
|
|
11
|
+
};
|
|
12
|
+
[key: string]: unknown;
|
|
13
|
+
};
|
|
14
|
+
declare type CheckoutComPaymentProps = PaymentMethodConfig['checkoutComPayment'] & JSX.IntrinsicElements['div'] & {
|
|
15
|
+
show?: boolean;
|
|
16
|
+
publicKey: string;
|
|
17
|
+
locale?: string;
|
|
18
|
+
templateCustomerSaveToWallet?: PaymentSourceProps['templateCustomerSaveToWallet'];
|
|
19
|
+
};
|
|
20
|
+
declare const CheckoutComPayment: FunctionComponent<CheckoutComPaymentProps>;
|
|
21
|
+
export default CheckoutComPayment;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{__rest}from"tslib";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";import{useContext,useRef}from"react";import useExternalScript from"../utils/hooks/useExternalScript";import PaymentMethodContext from"../context/PaymentMethodContext";import{Frames,CardNumber,ExpiryDate,Cvv}from"frames-react";import OrderContext from"../context/OrderContext";import Parent from"./utils/Parent";import{setCustomerOrderParam}from"../utils/localStorage";const scriptUrl="https://cdn.checkout.com/js/framesv2.min.js",systemLanguages=["DE-DE","EN-GB","ES-ES","FR-FR","IT-IT","KR-KR","NL-NL"],defaultOptions={style:{base:{color:"black",fontSize:"18px"},autofill:{backgroundColor:"yellow"},hover:{color:"blue"},focus:{color:"blue"},valid:{color:"green"},invalid:{color:"red"},placeholder:{base:{color:"gray"},focus:{border:"solid 1px blue"}}}},CheckoutComPayment=_a=>{var{publicKey,options=defaultOptions,locale="EN-GB"}=_a,p=__rest(_a,["publicKey","options","locale"]);const ref=useRef(null),loaded=useExternalScript(scriptUrl),{setPaymentRef,currentPaymentMethodType,paymentSource,setPaymentSource,setPaymentMethodErrors}=useContext(PaymentMethodContext),{order}=useContext(OrderContext),{containerClassName,templateCustomerSaveToWallet}=p,divProps=__rest(p,["containerClassName","templateCustomerSaveToWallet"]),handleSubmit=async()=>{var _a2,_b,_c,_d,_e,_f,_g,_h,_j,_k,_l;const savePaymentSourceToCustomerWallet=(_c=(_b=(_a2=ref==null?void 0:ref.current)===null||_a2===void 0?void 0:_a2.elements)===null||_b===void 0?void 0:_b.save_payment_source_to_customer_wallet)===null||_c===void 0?void 0:_c.checked;if(savePaymentSourceToCustomerWallet&&setCustomerOrderParam("_save_payment_source_to_customer_wallet",savePaymentSourceToCustomerWallet),window.Frames){window.Frames.cardholder={name:(_d=order==null?void 0:order.billing_address)===null||_d===void 0?void 0:_d.full_name,billingAddress:{addressLine1:(_e=order==null?void 0:order.billing_address)===null||_e===void 0?void 0:_e.line_1,addressLine2:(_f=order==null?void 0:order.billing_address)===null||_f===void 0?void 0:_f.line_2,zip:(_g=order==null?void 0:order.billing_address)===null||_g===void 0?void 0:_g.zip_code,city:(_h=order==null?void 0:order.billing_address)===null||_h===void 0?void 0:_h.city,state:(_j=order==null?void 0:order.billing_address)===null||_j===void 0?void 0:_j.state_code,country:(_k=order==null?void 0:order.billing_address)===null||_k===void 0?void 0:_k.country_code},phone:(_l=order==null?void 0:order.billing_address)===null||_l===void 0?void 0:_l.phone};try{const data=await window.Frames.submitCard();if(data.token&&paymentSource&¤tPaymentMethodType){const ps=await setPaymentSource({paymentSourceId:paymentSource.id,paymentResource:currentPaymentMethodType,attributes:{token:data.token,payment_type:"token",success_url:window.location.href,failure_url:window.location.href,_authorize:!0}});ps&&ps.redirect_uri&&(window.location.href=ps.redirect_uri)}}catch(error){console.error(error),setPaymentMethodErrors([{code:"PAYMENT_INTENT_AUTHENTICATION_FAILURE",resource:"payment_methods",field:currentPaymentMethodType,message:error==null?void 0:error.message}])}}return!1},lang=`${locale.toUpperCase()}-${locale.toUpperCase()}`,localization=systemLanguages.includes(lang)?lang:"EN-GB";return loaded?_jsxs("form",Object.assign({ref},{children:[_jsx("div",Object.assign({className:containerClassName},divProps,{children:_jsxs(Frames,Object.assign({config:Object.assign({debug:!0,publicKey,localization},options),cardValidationChanged:e=>{e.isValid&&ref.current&&(ref.current.onsubmit=()=>handleSubmit(),setPaymentRef({ref}))},cardTokenized:data=>data},{children:[_jsx(CardNumber,{},void 0),_jsx(ExpiryDate,{},void 0),_jsx(Cvv,{},void 0)]}),void 0)}),void 0),templateCustomerSaveToWallet&&_jsx(Parent,Object.assign({},{name:"save_payment_source_to_customer_wallet"},{children:templateCustomerSaveToWallet}),void 0)]}),void 0):null};export default CheckoutComPayment;
|
|
@@ -2,10 +2,12 @@ import { FunctionComponent } from 'react';
|
|
|
2
2
|
import { FunctionChildren } from '../typings/index';
|
|
3
3
|
declare type CheckoutLinkChildrenProps = FunctionChildren<Omit<CheckoutLinkProps, 'children'> & {
|
|
4
4
|
checkoutUrl: string;
|
|
5
|
+
href: string;
|
|
5
6
|
}>;
|
|
6
7
|
declare type CheckoutLinkProps = {
|
|
7
8
|
children?: CheckoutLinkChildrenProps;
|
|
8
9
|
label?: string;
|
|
10
|
+
hostedCheckout?: boolean;
|
|
9
11
|
} & JSX.IntrinsicElements['a'];
|
|
10
12
|
declare const CheckoutLink: FunctionComponent<CheckoutLinkProps>;
|
|
11
13
|
export default CheckoutLink;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{__rest}from"tslib";import{jsx as _jsx}from"react/jsx-runtime";import{useContext}from"react";import OrderContext from"../context/OrderContext";import components from"../config/components";import Parent from"./utils/Parent";const propTypes=components.CheckoutLink.propTypes,defaultProps=components.CheckoutLink.defaultProps,displayName=components.CheckoutLink.displayName,CheckoutLink=props=>{const{label,children}=props,p=__rest(props,["label","children"]),{order}=useContext(OrderContext),parentProps=Object.assign({checkoutUrl:order==null?void 0:order.checkout_url,label},p);return children?_jsx(Parent,Object.assign({},parentProps,{children}),void 0):_jsx("a",Object.assign({href
|
|
1
|
+
import{__rest}from"tslib";import{jsx as _jsx}from"react/jsx-runtime";import{useContext}from"react";import OrderContext from"../context/OrderContext";import components from"../config/components";import Parent from"./utils/Parent";import CommerceLayerContext from"../context/CommerceLayerContext";const propTypes=components.CheckoutLink.propTypes,defaultProps=components.CheckoutLink.defaultProps,displayName=components.CheckoutLink.displayName,CheckoutLink=props=>{const{label,hostedCheckout=!0,children}=props,p=__rest(props,["label","hostedCheckout","children"]),{order}=useContext(OrderContext),{accessToken,endpoint}=useContext(CommerceLayerContext),[slug]=endpoint.split(".commercelayer"),href=hostedCheckout?`${slug}.checkout.commercelayer.app/${order==null?void 0:order.id}?accessToken=${accessToken}`:order==null?void 0:order.checkout_url,parentProps=Object.assign({checkoutUrl:order==null?void 0:order.checkout_url,hostedCheckout,label,href},p);return children?_jsx(Parent,Object.assign({},parentProps,{children}),void 0):_jsx("a",Object.assign({href},p,{children:label}),void 0)};CheckoutLink.propTypes=propTypes,CheckoutLink.defaultProps=defaultProps,CheckoutLink.displayName=displayName;export default CheckoutLink;
|
|
@@ -4,7 +4,7 @@ declare type CustomerInputProps = {
|
|
|
4
4
|
name?: 'customer_email' | string;
|
|
5
5
|
type?: 'email' | string;
|
|
6
6
|
saveOnBlur?: boolean;
|
|
7
|
-
onBlur?: () => void;
|
|
7
|
+
onBlur?: (email: string) => void;
|
|
8
8
|
errorClassName?: string;
|
|
9
9
|
} & Omit<BaseInputComponentProps, 'name' | 'type' | 'onBlur'> & JSX.IntrinsicElements['input'] & JSX.IntrinsicElements['textarea'];
|
|
10
10
|
declare const CustomerInput: FunctionComponent<CustomerInputProps>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{__rest}from"tslib";import{jsx as _jsx}from"react/jsx-runtime";import{useContext,useEffect,useState}from"react";import BaseInput from"./utils/BaseInput";import components from"../config/components";import useRapidForm from"rapid-form";import CustomerContext from"../context/CustomerContext";import isEmpty from"lodash/isEmpty";const propTypes=components.CustomerInput.propTypes,displayName=components.CustomerInput.displayName,CustomerInput=props=>{const{name="customer_email",placeholder="",required=!0,saveOnBlur=!1,type="email",value,onBlur,className,errorClassName}=props,p=__rest(props,["name","placeholder","required","saveOnBlur","type","value","onBlur","className","errorClassName"]),{validation,values,errors}=useRapidForm({fieldEvent:"blur"}),{saveCustomerUser,setCustomerErrors,setCustomerEmail}=useContext(CustomerContext),[hasError,setHasError]=useState(!1),handleOnBlur=async()=>{saveOnBlur&&isEmpty(errors)&&!isEmpty(values)&&(await saveCustomerUser(values[name].value),onBlur&&onBlur())};useEffect(()=>{if(isEmpty(errors))isEmpty(values)||(setCustomerErrors([]),setCustomerEmail(values[name].value),setHasError(!1));else{const formErrors=[];for(const fieldName in errors){const{code,message}=errors[fieldName];formErrors.push({code,message,resource:"orders",field:fieldName})}isEmpty(formErrors)||(setHasError(!0),setCustomerErrors(formErrors))}return()=>{setHasError(!1)}},[errors]);const classNameComputed=`${className} ${hasError?errorClassName:""}`;return _jsx(BaseInput,Object.assign({name,type,ref:validation,required,placeholder,defaultValue:value,onBlur:handleOnBlur,className:classNameComputed},p),void 0)};CustomerInput.propTypes=propTypes,CustomerInput.displayName=displayName;export default CustomerInput;
|
|
1
|
+
import{__rest}from"tslib";import{jsx as _jsx}from"react/jsx-runtime";import{useContext,useEffect,useState}from"react";import BaseInput from"./utils/BaseInput";import components from"../config/components";import useRapidForm from"rapid-form";import CustomerContext from"../context/CustomerContext";import isEmpty from"lodash/isEmpty";const propTypes=components.CustomerInput.propTypes,displayName=components.CustomerInput.displayName,CustomerInput=props=>{const{name="customer_email",placeholder="",required=!0,saveOnBlur=!1,type="email",value,onBlur,className,errorClassName}=props,p=__rest(props,["name","placeholder","required","saveOnBlur","type","value","onBlur","className","errorClassName"]),{validation,values,errors}=useRapidForm({fieldEvent:"blur"}),{saveCustomerUser,setCustomerErrors,setCustomerEmail}=useContext(CustomerContext),[hasError,setHasError]=useState(!1),handleOnBlur=async()=>{saveOnBlur&&isEmpty(errors)&&!isEmpty(values)&&(await saveCustomerUser(values[name].value),onBlur&&onBlur(values[name].value))};useEffect(()=>{if(isEmpty(errors))isEmpty(values)||(setCustomerErrors([]),setCustomerEmail(values[name].value),setHasError(!1));else{const formErrors=[];for(const fieldName in errors){const{code,message}=errors[fieldName];formErrors.push({code,message,resource:"orders",field:fieldName})}isEmpty(formErrors)||(setHasError(!0),setCustomerErrors(formErrors))}return()=>{setHasError(!1)}},[errors]);const classNameComputed=`${className} ${hasError?errorClassName:""}`;return _jsx(BaseInput,Object.assign({name,type,ref:validation,required,placeholder,defaultValue:value,onBlur:handleOnBlur,className:classNameComputed},p),void 0)};CustomerInput.propTypes=propTypes,CustomerInput.displayName=displayName;export default CustomerInput;
|
|
@@ -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";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}),void 0);case"adyen_payments":return _jsx(AdyenGateway,Object.assign({},gatewayConfig,{children}),void 0);case"braintree_payments":return _jsx(BraintreeGateway,Object.assign({},gatewayConfig,{children}),void 0);case"wire_transfers":return _jsx(WireTransferGateway,Object.assign({},gatewayConfig,{children}),void 0);case"paypal_payments":return _jsx(PaypalGateway,Object.assign({},gatewayConfig,{children}),void 0);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 _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}),void 0);case"adyen_payments":return _jsx(AdyenGateway,Object.assign({},gatewayConfig,{children}),void 0);case"braintree_payments":return _jsx(BraintreeGateway,Object.assign({},gatewayConfig,{children}),void 0);case"wire_transfers":return _jsx(WireTransferGateway,Object.assign({},gatewayConfig,{children}),void 0);case"paypal_payments":return _jsx(PaypalGateway,Object.assign({},gatewayConfig,{children}),void 0);case"checkout_com_payments":return _jsx(CheckoutComGateway,Object.assign({},gatewayConfig,{children}),void 0);default:return null}};export default PaymentGateway;
|
|
@@ -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
|
|
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";const propTypes=components.PaymentSource.propTypes,displayName=components.PaymentSource.displayName,PaymentSource=props=>{const{readonly}=props,{payment}=useContext(PaymentMethodChildrenContext),{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]);const handleEditClick=e=>{e.stopPropagation(),paymentSource&&destroyPaymentSource({paymentSourceId:paymentSource==null?void 0:paymentSource.id,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),void 0)};PaymentSource.propTypes=propTypes,PaymentSource.displayName=displayName;export default PaymentSource;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { IconBrand } from '../context/PaymentSourceContext';
|
|
2
2
|
import { FunctionComponent } from 'react';
|
|
3
3
|
import { FunctionChildren } from '../typings/index';
|
|
4
4
|
declare type CustomComponent = FunctionChildren<Omit<Props & {
|
|
5
|
-
brand:
|
|
5
|
+
brand: IconBrand;
|
|
6
6
|
defaultSrc: string;
|
|
7
7
|
url: string;
|
|
8
8
|
}, 'children'>>;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { IconBrand } from '../context/PaymentSourceContext';
|
|
2
2
|
import { FunctionComponent } from 'react';
|
|
3
3
|
import { FunctionChildren } from '../typings/index';
|
|
4
4
|
declare type CustomComponent = FunctionChildren<Omit<Props & {
|
|
5
|
-
brand:
|
|
5
|
+
brand: IconBrand;
|
|
6
6
|
}, 'children'>>;
|
|
7
7
|
declare type Props = {
|
|
8
8
|
children?: CustomComponent;
|
|
@@ -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";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,paymentSource,loading,currentPaymentMethodType}=useContext(PaymentMethodContext),{order}=useContext(OrderContext);useEffect(()=>{var _a2
|
|
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,paymentSource,loading,currentPaymentMethodType}=useContext(PaymentMethodContext),{order}=useContext(OrderContext);useEffect(()=>{var _a2;if(loading)setNotPermitted(loading);else if(paymentType===currentPaymentMethodType&&paymentType){const card=getCardDetails({customerPayment:{payment_source:paymentSource},paymentType});((order==null?void 0:order.total_amount_with_taxes_cents)===0||((_a2=currentPaymentMethodRef==null?void 0:currentPaymentMethodRef.current)===null||_a2===void 0?void 0:_a2.onsubmit)||card.brand)&&isPermitted&&setNotPermitted(!1)}else(order==null?void 0:order.total_amount_with_taxes_cents)===0?setNotPermitted(!1):setNotPermitted(!0);return()=>{setNotPermitted(!0)}},[isPermitted,paymentType,(_a=currentPaymentMethodRef==null?void 0:currentPaymentMethodRef.current)===null||_a===void 0?void 0:_a.onsubmit,paymentSource,loading,currentPaymentMethodType,order]),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]),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]),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]);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()):(card==null?void 0:card.brand)&&(isValid=!0);const placed=isValid&&setPlaceOrder&&paymentSource&&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}),void 0):_jsx("button",Object.assign({type:"button",disabled:disabledButton||forceDisable,onClick:handleClick},p,{children:isFunction(label)?label():label}),void 0)};PlaceOrderButton.propTypes=propTypes,PlaceOrderButton.defaultProps=defaultProps,PlaceOrderButton.displayName=displayName;export default PlaceOrderButton;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{__rest}from"tslib";import{jsx as _jsx,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{Fragment,useContext}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}=useContext(OrderContext),{payment}=useContext(PaymentMethodChildrenContext),{payments,isGuest}=useContext(CustomerContext),{currentPaymentMethodId,config,paymentSource}=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}),void 0):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}),void 0)}),void 0),_jsx(CheckoutComPayment,Object.assign({show,templateCustomerSaveToWallet,publicKey,locale},paymentConfig),void 0)]},void 0):loaderComponent:publicKey&&!loading?_jsx(CheckoutComPayment,Object.assign({show,publicKey,locale},paymentConfig),void 0):loaderComponent}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { PaymentResource, PaymentSourceType } from '../../reducers/PaymentMethodReducer';
|
|
3
|
-
import PaymentSourceContext, {
|
|
3
|
+
import PaymentSourceContext, { IconBrand } from '../../context/PaymentSourceContext';
|
|
4
4
|
import { FunctionChildren } from '../../typings/index';
|
|
5
5
|
declare type ChildrenProps = Pick<Props, 'customerPayments'> & {
|
|
6
6
|
PaymentSourceProvider: typeof PaymentSourceContext.Provider;
|
|
7
7
|
};
|
|
8
8
|
declare type CustomerPayment = PaymentSourceType & {
|
|
9
9
|
card?: {
|
|
10
|
-
brand?:
|
|
10
|
+
brand?: IconBrand;
|
|
11
11
|
last4?: string;
|
|
12
12
|
};
|
|
13
13
|
handleClick?: () => void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsx as _jsx}from"react/jsx-runtime";import Parent from"../utils/Parent";import{useContext}from"react";import PaymentMethodContext from"../../context/PaymentMethodContext";import PaymentSourceContext from"../../context/PaymentSourceContext";export default function PaymentCardsTemplate({customerPayments,children,paymentResource}){const{setPaymentSource}=useContext(PaymentMethodContext),value={customerPayments:customerPayments.map(customerPayment=>{
|
|
1
|
+
import{jsx as _jsx}from"react/jsx-runtime";import Parent from"../utils/Parent";import{useContext}from"react";import PaymentMethodContext from"../../context/PaymentMethodContext";import PaymentSourceContext from"../../context/PaymentSourceContext";import getCardDetails from"../../utils/getCardDetails";export default function PaymentCardsTemplate({customerPayments,children,paymentResource}){const{setPaymentSource}=useContext(PaymentMethodContext),value={customerPayments:customerPayments.map(customerPayment=>{const attributes=customerPayment,card=getCardDetails({customerPayment,paymentType:paymentResource}),handleClick=async e=>{e.stopPropagation(),await setPaymentSource({paymentResource,customerPaymentSourceId:customerPayment.id})};return Object.assign(Object.assign({},attributes),{card,handleClick})}),PaymentSourceProvider:PaymentSourceContext.Provider};return _jsx(Parent,Object.assign({},value,{children}),void 0)}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import { AddToCart, OrderState, CreateOrder, SetGiftCardOrCouponCode, RemoveGiftCardOrCouponCode, SaveAddressToCustomerAddressBook,
|
|
2
|
+
import { AddToCart, OrderState, CreateOrder, SetGiftCardOrCouponCode, RemoveGiftCardOrCouponCode, SaveAddressToCustomerAddressBook, addResourceToInclude, updateOrder, getOrderContext } from '../reducers/OrderReducer';
|
|
3
3
|
declare type DefaultContext = {
|
|
4
4
|
createOrder: CreateOrder;
|
|
5
5
|
addToCart: AddToCart;
|
|
6
|
-
setOrderErrors:
|
|
6
|
+
setOrderErrors: (errors: unknown) => void;
|
|
7
7
|
setGiftCardOrCouponCode: SetGiftCardOrCouponCode;
|
|
8
8
|
removeGiftCardOrCouponCode: RemoveGiftCardOrCouponCode;
|
|
9
9
|
saveAddressToCustomerAddressBook: SaveAddressToCustomerAddressBook;
|
|
@@ -14,12 +14,12 @@ declare type DefaultContext = {
|
|
|
14
14
|
export declare const defaultOrderContext: {
|
|
15
15
|
addToCart: AddToCart;
|
|
16
16
|
createOrder: CreateOrder;
|
|
17
|
-
setOrderErrors:
|
|
17
|
+
setOrderErrors: () => void;
|
|
18
18
|
setGiftCardOrCouponCode: SetGiftCardOrCouponCode;
|
|
19
19
|
removeGiftCardOrCouponCode: RemoveGiftCardOrCouponCode;
|
|
20
20
|
saveAddressToCustomerAddressBook: SaveAddressToCustomerAddressBook;
|
|
21
21
|
addResourceToInclude: typeof addResourceToInclude;
|
|
22
|
-
getOrder: (
|
|
22
|
+
getOrder: () => Promise<void>;
|
|
23
23
|
updateOrder: typeof updateOrder;
|
|
24
24
|
};
|
|
25
25
|
declare const OrderContext: import("react").Context<DefaultContext>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{createContext}from"react";import{addToCart,
|
|
1
|
+
import{createContext}from"react";import{addToCart,createOrder,setGiftCardOrCouponCode,removeGiftCardOrCouponCode,saveAddressToCustomerAddressBook,addResourceToInclude,updateOrder}from"../reducers/OrderReducer";export const defaultOrderContext={addToCart,createOrder,setOrderErrors:()=>{},setGiftCardOrCouponCode,removeGiftCardOrCouponCode,saveAddressToCustomerAddressBook,addResourceToInclude,getOrder:async()=>{},updateOrder};const OrderContext=createContext(defaultOrderContext);export default OrderContext;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
export declare type
|
|
2
|
+
export declare type IconBrand = 'visa' | 'credit-card' | 'amex' | 'mastercard' | 'jcb' | 'wire-transfer' | 'maestro' | 'cirrus' | 'paypal';
|
|
3
3
|
declare type DefaultContext = {
|
|
4
|
-
brand?:
|
|
5
|
-
exp_month?: number;
|
|
6
|
-
exp_year?: number;
|
|
4
|
+
brand?: IconBrand | string;
|
|
5
|
+
exp_month?: number | string;
|
|
6
|
+
exp_year?: number | string;
|
|
7
7
|
last4?: string;
|
|
8
8
|
showCard?: boolean;
|
|
9
9
|
readonly?: boolean;
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import { PlaceOrderState, SetPlaceOrderErrors } from '../reducers/PlaceOrderReducer';
|
|
2
|
+
import { PlaceOrderOptions, PlaceOrderState, SetPlaceOrderErrors } from '../reducers/PlaceOrderReducer';
|
|
3
|
+
import { PaymentSourceType } from '../reducers/PaymentMethodReducer';
|
|
3
4
|
declare type DefaultContext = {
|
|
4
5
|
setPlaceOrderErrors?: SetPlaceOrderErrors;
|
|
5
6
|
setPlaceOrder?: ({ paymentSource, }: {
|
|
6
|
-
paymentSource:
|
|
7
|
+
paymentSource: PaymentSourceType;
|
|
8
|
+
options?: PlaceOrderOptions;
|
|
7
9
|
}) => Promise<{
|
|
8
10
|
placed: boolean;
|
|
9
11
|
}>;
|
|
@@ -8,7 +8,43 @@ import { getOrderContext, updateOrder } from './OrderReducer';
|
|
|
8
8
|
import { BaseError } from '../typings/errors';
|
|
9
9
|
import { Order, PaymentMethod, StripePayment, WireTransfer, AdyenPayment, BraintreePayment, CheckoutComPayment, ExternalPayment, PaypalPayment } from '@commercelayer/sdk';
|
|
10
10
|
import { Dispatch, MutableRefObject } from 'react';
|
|
11
|
+
import { CheckoutComConfig } from '../components/CheckoutComPayment';
|
|
11
12
|
export declare type PaymentSourceType = AdyenPayment | BraintreePayment | CheckoutComPayment | ExternalPayment | PaypalPayment | StripePayment | WireTransfer;
|
|
13
|
+
declare type Card = {
|
|
14
|
+
brand: string;
|
|
15
|
+
last4: string;
|
|
16
|
+
exp_year: number;
|
|
17
|
+
exp_month: number;
|
|
18
|
+
};
|
|
19
|
+
export declare type PaymentSourceObject = {
|
|
20
|
+
adyen_payments: AdyenPayment & {
|
|
21
|
+
payment_request_data?: {
|
|
22
|
+
payment_method?: Card;
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
braintree_payments: BraintreePayment & {
|
|
26
|
+
options?: {
|
|
27
|
+
card: Card;
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
external_payments: ExternalPayment;
|
|
31
|
+
paypal_payments: PaypalPayment;
|
|
32
|
+
stripe_payments: StripePayment & {
|
|
33
|
+
options?: {
|
|
34
|
+
card: Card;
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
wire_transfers: WireTransfer;
|
|
38
|
+
checkout_com_payments: CheckoutComPayment & {
|
|
39
|
+
payment_response: {
|
|
40
|
+
source?: Pick<Card, 'last4'> & {
|
|
41
|
+
scheme: string;
|
|
42
|
+
expiry_year: number;
|
|
43
|
+
expiry_month: number;
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
};
|
|
12
48
|
export declare type PaymentMethodActionType = 'setErrors' | 'setPaymentMethods' | 'setPaymentMethodConfig' | 'setPaymentSource' | 'setPaymentRef' | 'setLoading';
|
|
13
49
|
export declare type PaymentRef = MutableRefObject<null | HTMLFormElement>;
|
|
14
50
|
export interface PaymentMethodActionPayload {
|
|
@@ -45,9 +81,9 @@ declare type GetPaymentMethods = (args: {
|
|
|
45
81
|
dispatch: Dispatch<PaymentMethodAction>;
|
|
46
82
|
}) => Promise<void>;
|
|
47
83
|
export declare const getPaymentMethods: GetPaymentMethods;
|
|
48
|
-
export declare type PaymentResource =
|
|
49
|
-
export declare type PaymentResourceKey = 'braintreePayment' | 'stripePayment' | 'wireTransfer' | 'paypalPayment' | 'adyenPayment';
|
|
50
|
-
export declare type SDKPaymentResource = 'AdyenPayment' | 'BraintreePayment' | 'ExternalPayment' | 'PaypalPayment' | 'StripePayment' | 'WireTransfer';
|
|
84
|
+
export declare type PaymentResource = keyof PaymentSourceObject;
|
|
85
|
+
export declare type PaymentResourceKey = 'braintreePayment' | 'stripePayment' | 'wireTransfer' | 'paypalPayment' | 'adyenPayment' | 'checkoutComPayment';
|
|
86
|
+
export declare type SDKPaymentResource = 'AdyenPayment' | 'BraintreePayment' | 'ExternalPayment' | 'PaypalPayment' | 'StripePayment' | 'WireTransfer' | 'CheckoutComPayment';
|
|
51
87
|
export declare type SetPaymentMethod = (args: {
|
|
52
88
|
config?: CommerceLayerConfig;
|
|
53
89
|
dispatch?: Dispatch<PaymentMethodAction>;
|
|
@@ -69,7 +105,7 @@ export declare type SetPaymentSource = (args: {
|
|
|
69
105
|
config?: CommerceLayerConfig;
|
|
70
106
|
dispatch?: Dispatch<PaymentMethodAction>;
|
|
71
107
|
getOrder?: getOrderContext;
|
|
72
|
-
attributes?: Record<string,
|
|
108
|
+
attributes?: Record<string, unknown>;
|
|
73
109
|
order?: Order;
|
|
74
110
|
paymentResource: PaymentResource;
|
|
75
111
|
paymentSourceId?: string;
|
|
@@ -97,6 +133,7 @@ export declare type PaymentMethodConfig = {
|
|
|
97
133
|
wireTransfer?: Partial<WireTransferConfig>;
|
|
98
134
|
paypalPayment?: PaypalConfig;
|
|
99
135
|
adyenPayment?: AdyenPaymentConfig;
|
|
136
|
+
checkoutComPayment?: CheckoutComConfig;
|
|
100
137
|
};
|
|
101
138
|
declare type SetPaymentMethodConfig = (config: PaymentMethodConfig, dispatch: Dispatch<PaymentMethodAction>) => void;
|
|
102
139
|
export declare const setPaymentMethodConfig: SetPaymentMethodConfig;
|
|
@@ -11,6 +11,9 @@ export declare type PlaceOrderOptions = {
|
|
|
11
11
|
MD: string;
|
|
12
12
|
PaRes: string;
|
|
13
13
|
};
|
|
14
|
+
checkoutCom?: {
|
|
15
|
+
session_id: string;
|
|
16
|
+
};
|
|
14
17
|
};
|
|
15
18
|
export interface PlaceOrderActionPayload {
|
|
16
19
|
errors: BaseError[];
|
|
@@ -42,8 +45,10 @@ export declare type SetPlaceOrder = (args: {
|
|
|
42
45
|
config?: CommerceLayerConfig;
|
|
43
46
|
order?: Order;
|
|
44
47
|
state?: PlaceOrderState;
|
|
45
|
-
setOrderErrors?: (collection:
|
|
46
|
-
paymentSource?:
|
|
48
|
+
setOrderErrors?: (collection: unknown) => void;
|
|
49
|
+
paymentSource?: PaymentSourceType & {
|
|
50
|
+
approval_url?: string;
|
|
51
|
+
};
|
|
47
52
|
}) => Promise<{
|
|
48
53
|
placed: boolean;
|
|
49
54
|
}>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import baseReducer from"../utils/baseReducer";import isEmpty from"lodash/isEmpty";import{shipmentsFilled}from"../utils/shipments";import{saveBillingAddress,saveShippingAddress,saveToWallet}from"../utils/customerOrderOptions";import getSdk from"../utils/getSdk";import getErrors from"../utils/getErrors";export const placeOrderInitialState={errors:[],isPermitted:!1},setPlaceOrderErrors=(errors,dispatch)=>{dispatch&&dispatch({type:"setErrors",payload:{errors}})},placeOrderPermitted=async({config,order,dispatch,options})=>{var _a;if(order&&config){let isPermitted=!0;order.privacy_url&&order.terms_url&&(isPermitted=localStorage.getItem("privacy-terms")==="true");const billingAddress=order.billing_address;isEmpty(billingAddress)&&(isPermitted=!1);const shippingAddress=order.shipping_address;isEmpty(shippingAddress)&&(isPermitted=!1);const shipments=order.shipments,shipment=shipments&&shipmentsFilled(shipments);!isEmpty(shipments)&&!shipment&&(isPermitted=!1);const paymentMethod=order.payment_method,paymentSource=order.payment_source;order.total_amount_with_taxes_cents!==0&&isEmpty(paymentMethod==null?void 0:paymentMethod.id)&&(isPermitted=!1),dispatch({type:"setPlaceOrderPermitted",payload:{isPermitted,paymentType:paymentMethod==null?void 0:paymentMethod.payment_source_type,paymentSecret:paymentSource==null?void 0:paymentSource.client_secret,paymentId:(_a=paymentSource==null?void 0:paymentSource.options)===null||_a===void 0?void 0:_a.id,paymentSource,options}})}},setPlaceOrder=async({state,order,config,setOrderErrors,paymentSource})=>{const response={placed:!1};try{if(state&&order&&config){const sdk=getSdk(config),{options,paymentType}=state;if(paymentType==="paypal_payments"&&paymentSource){if(!(options==null?void 0:options.paypalPayerId)&&(paymentSource==null?void 0:paymentSource.approval_url))return window.location.href=paymentSource==null?void 0:paymentSource.approval_url,response;await sdk.
|
|
1
|
+
import baseReducer from"../utils/baseReducer";import isEmpty from"lodash/isEmpty";import{shipmentsFilled}from"../utils/shipments";import{saveBillingAddress,saveShippingAddress,saveToWallet}from"../utils/customerOrderOptions";import getSdk from"../utils/getSdk";import getErrors from"../utils/getErrors";export const placeOrderInitialState={errors:[],isPermitted:!1},setPlaceOrderErrors=(errors,dispatch)=>{dispatch&&dispatch({type:"setErrors",payload:{errors}})},placeOrderPermitted=async({config,order,dispatch,options})=>{var _a;if(order&&config){let isPermitted=!0;order.privacy_url&&order.terms_url&&(isPermitted=localStorage.getItem("privacy-terms")==="true");const billingAddress=order.billing_address;isEmpty(billingAddress)&&(isPermitted=!1);const shippingAddress=order.shipping_address;isEmpty(shippingAddress)&&(isPermitted=!1);const shipments=order.shipments,shipment=shipments&&shipmentsFilled(shipments);!isEmpty(shipments)&&!shipment&&(isPermitted=!1);const paymentMethod=order.payment_method,paymentSource=order.payment_source;order.total_amount_with_taxes_cents!==0&&isEmpty(paymentMethod==null?void 0:paymentMethod.id)&&(isPermitted=!1),dispatch({type:"setPlaceOrderPermitted",payload:{isPermitted,paymentType:paymentMethod==null?void 0:paymentMethod.payment_source_type,paymentSecret:paymentSource==null?void 0:paymentSource.client_secret,paymentId:(_a=paymentSource==null?void 0:paymentSource.options)===null||_a===void 0?void 0:_a.id,paymentSource,options}})}},setPlaceOrder=async({state,order,config,setOrderErrors,paymentSource})=>{var _a,_b;const response={placed:!1};try{if(state&&order&&config){const sdk=getSdk(config),{options,paymentType}=state;if(paymentType==="paypal_payments"&&paymentSource){if(!(options==null?void 0:options.paypalPayerId)&&(paymentSource==null?void 0:paymentSource.approval_url))return window.location.href=paymentSource==null?void 0:paymentSource.approval_url,response;await sdk[paymentType].update({id:paymentSource.id,paypal_payer_id:options==null?void 0:options.paypalPayerId})}paymentType==="checkout_com_payments"&&paymentSource&&((_a=options==null?void 0:options.checkoutCom)===null||_a===void 0?void 0:_a.session_id)&&await sdk[paymentType].update({id:paymentSource.id,_details:!0,session_id:(_b=options==null?void 0:options.checkoutCom)===null||_b===void 0?void 0:_b.session_id});const updateAttributes={id:order.id,_place:!0};switch(saveBillingAddress()&&await sdk.orders.update({id:order.id,_save_billing_address_to_customer_address_book:!0}),saveShippingAddress()&&await sdk.orders.update({id:order.id,_save_shipping_address_to_customer_address_book:!0}),paymentType){case"braintree_payments":return saveToWallet()&&await sdk.orders.update({id:order.id,_save_payment_source_to_customer_wallet:!0}),await sdk.orders.update(updateAttributes),setOrderErrors&&setOrderErrors([]),{placed:!0};default:return await sdk.orders.update(updateAttributes),saveToWallet()&&await sdk.orders.update({id:order.id,_save_payment_source_to_customer_wallet:!0}),setOrderErrors&&setOrderErrors([]),{placed:!0}}}return response}catch(error){const errors=getErrors(error,"orders");return setOrderErrors&&setOrderErrors(errors),Object.assign(Object.assign({},response),{errors})}};const type=["setErrors","setPlaceOrderPermitted"],placeOrderReducer=(state,reducer)=>baseReducer(state,reducer,type);export default placeOrderReducer;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { IconBrand } from '../context/PaymentSourceContext';
|
|
2
|
+
import { PaymentResource } from '../reducers/PaymentMethodReducer';
|
|
3
|
+
import { CustomerPaymentSource } from '@commercelayer/sdk';
|
|
4
|
+
declare type CardDetails = {
|
|
5
|
+
brand: IconBrand | string;
|
|
6
|
+
last4: string;
|
|
7
|
+
exp_month: number | string;
|
|
8
|
+
exp_year: number | string;
|
|
9
|
+
};
|
|
10
|
+
declare type Args = {
|
|
11
|
+
paymentType: PaymentResource;
|
|
12
|
+
customerPayment: Partial<CustomerPaymentSource>;
|
|
13
|
+
};
|
|
14
|
+
export default function getCardDetails({ paymentType, customerPayment, }: Args): CardDetails;
|
|
15
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function getCardDetails({paymentType,customerPayment}){var _a,_b,_c,_d;switch(paymentType){case"checkout_com_payments":{const ps=customerPayment.payment_source,source=(_a=ps==null?void 0:ps.payment_response)===null||_a===void 0?void 0:_a.source;if(source)return{brand:source.scheme.toLowerCase(),exp_month:source.expiry_month,exp_year:source.expiry_year,last4:source.last4};break}case"stripe_payments":case"braintree_payments":{const ps=customerPayment.payment_source,source=(_b=ps==null?void 0:ps.options)===null||_b===void 0?void 0:_b.card;if(source)return Object.assign({},source);break}case"adyen_payments":{const ps=customerPayment.payment_source,source=(_c=ps==null?void 0:ps.payment_request_data)===null||_c===void 0?void 0:_c.payment_method;if(source)return Object.assign({},source);break}default:{const ps=customerPayment.payment_source,source=(_d=ps==null?void 0:ps.metadata)===null||_d===void 0?void 0:_d.card;if(source)return Object.assign({},source);break}}return{brand:"",exp_month:"**",exp_year:"**",last4:"****"}}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function useExternalScript(url: string): boolean;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{useEffect,useState}from"react";export default function useExternalScript(url){const[loaded,setLoaded]=useState(!1);return useEffect(()=>{const script=document.createElement("script");return script.src=url,script.async=!0,document.body.appendChild(script),script.onload=()=>{setLoaded(!0)},()=>{document.body.removeChild(script),setLoaded(!1)}},[url]),loaded}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@commercelayer/react-components",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.4.1",
|
|
4
4
|
"description": "The Official Commerce Layer React Components",
|
|
5
5
|
"module": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -84,12 +84,13 @@
|
|
|
84
84
|
"@ac-dev/countries-service": "^1.1.3",
|
|
85
85
|
"@ac-dev/states-service": "^1.0.3",
|
|
86
86
|
"@adyen/adyen-web": "^5.7.0",
|
|
87
|
-
"@commercelayer/js-auth": "^
|
|
87
|
+
"@commercelayer/js-auth": "^3.0.0",
|
|
88
88
|
"@commercelayer/sdk": "^3.5.0",
|
|
89
89
|
"@stripe/react-stripe-js": "^1.7.0",
|
|
90
90
|
"@stripe/stripe-js": "^1.22.0",
|
|
91
91
|
"axios": "^0.25.0",
|
|
92
92
|
"braintree-web": "^3.85.2",
|
|
93
|
+
"frames-react": "^1.0.3",
|
|
93
94
|
"jwt-decode": "^3.1.2",
|
|
94
95
|
"lodash": "^4.17.21",
|
|
95
96
|
"lodash-es": "^4.17.21",
|
|
@@ -114,7 +115,7 @@
|
|
|
114
115
|
"@types/braintree-web": "^3.75.17",
|
|
115
116
|
"@types/jest": "^27.4.0",
|
|
116
117
|
"@types/lodash": "^4.14.178",
|
|
117
|
-
"@types/node": "^17.0.
|
|
118
|
+
"@types/node": "^17.0.17",
|
|
118
119
|
"@types/prop-types": "^15.7.4",
|
|
119
120
|
"@types/react": "^17.0.39",
|
|
120
121
|
"@types/react-test-renderer": "^17.0.1",
|
|
@@ -146,10 +147,10 @@
|
|
|
146
147
|
"react-test-renderer": "^17.0.2",
|
|
147
148
|
"rollup-plugin-babel": "^4.4.0",
|
|
148
149
|
"rollup-plugin-node-resolve": "^5.2.0",
|
|
149
|
-
"tailwindcss": "^3.0.
|
|
150
|
+
"tailwindcss": "^3.0.21",
|
|
150
151
|
"ts-jest": "^27.1.3",
|
|
151
152
|
"ts-loader": "^9.2.6",
|
|
152
|
-
"tsc-alias": "^1.
|
|
153
|
+
"tsc-alias": "^1.6.0",
|
|
153
154
|
"tsconfig-paths-jest": "^0.0.1",
|
|
154
155
|
"ttypescript": "^1.5.13",
|
|
155
156
|
"typescript": "^4.5.5",
|