@commercelayer/react-components 3.5.0 → 3.6.0
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/AddToCartButton.d.ts +1 -20
- package/lib/components/AddToCartButton.js +1 -1
- package/lib/components/Address.d.ts +1 -13
- package/lib/components/Address.js +1 -1
- package/lib/components/AddressCountrySelector.d.ts +1 -9
- package/lib/components/AddressCountrySelector.js +1 -1
- package/lib/components/AddressField.d.ts +1 -15
- package/lib/components/AddressField.js +1 -1
- package/lib/components/AddressInput.d.ts +1 -7
- package/lib/components/AddressInput.js +1 -1
- package/lib/components/AddressStateSelector.d.ts +1 -11
- package/lib/components/AddressStateSelector.js +1 -1
- package/lib/components/AddressesContainer.d.ts +1 -8
- package/lib/components/AddressesContainer.js +1 -1
- package/lib/components/AdjustmentAmount.d.ts +1 -4
- package/lib/components/AdjustmentAmount.js +1 -1
- package/lib/components/AdyenPayment.d.ts +1 -25
- package/lib/components/AdyenPayment.js +1 -1
- package/lib/components/AvailabilityContainer.d.ts +1 -7
- package/lib/components/AvailabilityContainer.js +1 -1
- package/lib/components/AvailabilityTemplate.d.ts +1 -15
- package/lib/components/AvailabilityTemplate.js +1 -1
- package/lib/components/BillingAddressContainer.d.ts +1 -6
- package/lib/components/BillingAddressContainer.js +1 -1
- package/lib/components/BillingAddressForm.d.ts +1 -8
- package/lib/components/BillingAddressForm.js +1 -1
- package/lib/components/BraintreePayment.d.ts +1 -30
- package/lib/components/BraintreePayment.js +1 -1
- package/lib/components/CheckoutComPayment.d.ts +1 -23
- package/lib/components/CheckoutComPayment.js +1 -1
- package/lib/components/CheckoutLink.d.ts +1 -13
- package/lib/components/CheckoutLink.js +1 -1
- package/lib/components/CommerceLayer.d.ts +1 -8
- package/lib/components/CommerceLayer.js +1 -1
- package/lib/components/CustomerContainer.d.ts +1 -7
- package/lib/components/CustomerContainer.js +1 -1
- package/lib/components/CustomerInput.d.ts +1 -11
- package/lib/components/CustomerInput.js +1 -1
- package/lib/components/DeliveryLeadTime.d.ts +1 -10
- package/lib/components/DeliveryLeadTime.js +1 -1
- package/lib/components/DiscountAmount.d.ts +1 -4
- package/lib/components/DiscountAmount.js +1 -1
- package/lib/components/Errors.d.ts +1 -5
- package/lib/components/Errors.js +1 -1
- package/lib/components/ExternalFunction.d.ts +1 -7
- package/lib/components/ExternalFunction.js +1 -1
- package/lib/components/GiftCard.d.ts +1 -8
- package/lib/components/GiftCard.js +1 -1
- package/lib/components/GiftCardAmount.d.ts +1 -4
- package/lib/components/GiftCardAmount.js +1 -1
- package/lib/components/GiftCardContainer.d.ts +1 -6
- package/lib/components/GiftCardContainer.js +1 -1
- package/lib/components/GiftCardCurrencySelector.d.ts +1 -7
- package/lib/components/GiftCardCurrencySelector.js +1 -1
- package/lib/components/GiftCardInput.d.ts +1 -7
- package/lib/components/GiftCardInput.js +1 -1
- package/lib/components/GiftCardOrCouponCode.d.ts +1 -13
- package/lib/components/GiftCardOrCouponCode.js +1 -1
- package/lib/components/GiftCardOrCouponForm.d.ts +1 -10
- package/lib/components/GiftCardOrCouponForm.js +1 -1
- package/lib/components/GiftCardOrCouponInput.d.ts +1 -8
- package/lib/components/GiftCardOrCouponInput.js +1 -1
- package/lib/components/GiftCardOrCouponRemoveButton.d.ts +1 -16
- package/lib/components/GiftCardOrCouponRemoveButton.js +1 -1
- package/lib/components/GiftCardOrCouponSubmit.d.ts +1 -9
- package/lib/components/GiftCardOrCouponSubmit.js +1 -1
- package/lib/components/ItemContainer.d.ts +1 -11
- package/lib/components/ItemContainer.js +1 -1
- package/lib/components/LineItem.d.ts +1 -8
- package/lib/components/LineItem.js +1 -1
- package/lib/components/LineItemAmount.d.ts +1 -7
- package/lib/components/LineItemAmount.js +1 -1
- package/lib/components/LineItemCode.d.ts +1 -12
- package/lib/components/LineItemCode.js +1 -1
- package/lib/components/LineItemImage.d.ts +1 -16
- package/lib/components/LineItemImage.js +1 -1
- package/lib/components/LineItemName.d.ts +1 -11
- package/lib/components/LineItemName.js +1 -1
- package/lib/components/LineItemOption.d.ts +1 -19
- package/lib/components/LineItemOption.js +1 -1
- package/lib/components/LineItemOptions.d.ts +1 -14
- package/lib/components/LineItemOptions.js +1 -1
- package/lib/components/LineItemQuantity.d.ts +1 -14
- package/lib/components/LineItemQuantity.js +1 -1
- package/lib/components/LineItemRemoveLink.d.ts +1 -12
- package/lib/components/LineItemRemoveLink.js +1 -1
- package/lib/components/LineItemsContainer.d.ts +1 -8
- package/lib/components/LineItemsContainer.js +1 -1
- package/lib/components/LineItemsCount.d.ts +1 -12
- package/lib/components/LineItemsCount.js +1 -1
- package/lib/components/LineItemsEmpty.d.ts +1 -12
- package/lib/components/LineItemsEmpty.js +1 -1
- package/lib/components/MetadataInput.d.ts +1 -5
- package/lib/components/MetadataInput.js +1 -1
- package/lib/components/OrderContainer.d.ts +1 -11
- package/lib/components/OrderContainer.js +1 -1
- package/lib/components/OrderNumber.d.ts +1 -5
- package/lib/components/OrderNumber.js +1 -1
- package/lib/components/OrderStorage.d.ts +1 -8
- package/lib/components/OrderStorage.js +1 -1
- package/lib/components/PaymentGateway.d.ts +1 -16
- package/lib/components/PaymentGateway.js +1 -1
- package/lib/components/PaymentMethod.d.ts +1 -16
- package/lib/components/PaymentMethod.js +1 -1
- package/lib/components/PaymentMethodAmount.d.ts +1 -4
- package/lib/components/PaymentMethodAmount.js +1 -1
- package/lib/components/PaymentMethodName.d.ts +1 -9
- package/lib/components/PaymentMethodName.js +1 -1
- package/lib/components/PaymentMethodPrice.d.ts +1 -9
- package/lib/components/PaymentMethodPrice.js +1 -1
- package/lib/components/PaymentMethodRadioButton.d.ts +1 -11
- package/lib/components/PaymentMethodRadioButton.js +1 -1
- package/lib/components/PaymentMethodsContainer.d.ts +1 -8
- package/lib/components/PaymentMethodsContainer.js +1 -1
- package/lib/components/PaymentSource.d.ts +1 -19
- package/lib/components/PaymentSource.js +1 -1
- package/lib/components/PaymentSourceBrandIcon.d.ts +1 -15
- package/lib/components/PaymentSourceBrandIcon.js +1 -1
- package/lib/components/PaymentSourceBrandName.d.ts +1 -12
- package/lib/components/PaymentSourceBrandName.js +1 -1
- package/lib/components/PaymentSourceDetail.d.ts +1 -12
- package/lib/components/PaymentSourceDetail.js +1 -1
- package/lib/components/PaymentSourceEditButton.d.ts +1 -9
- package/lib/components/PaymentSourceEditButton.js +1 -1
- package/lib/components/PaypalPayment.d.ts +1 -12
- package/lib/components/PaypalPayment.js +1 -1
- package/lib/components/PlaceOrderButton.d.ts +1 -12
- package/lib/components/PlaceOrderButton.js +1 -1
- package/lib/components/PlaceOrderContainer.d.ts +1 -8
- package/lib/components/PlaceOrderContainer.js +1 -1
- package/lib/components/Price.d.ts +1 -16
- package/lib/components/Price.js +1 -1
- package/lib/components/PricesContainer.d.ts +1 -11
- package/lib/components/PricesContainer.js +1 -1
- package/lib/components/PrivacyAndTermsCheckbox.d.ts +1 -4
- package/lib/components/PrivacyAndTermsCheckbox.js +1 -1
- package/lib/components/QuantitySelector.d.ts +1 -17
- package/lib/components/QuantitySelector.js +1 -1
- package/lib/components/SaveAddressesButton.d.ts +1 -10
- package/lib/components/SaveAddressesButton.js +1 -1
- package/lib/components/SaveCustomerButton.d.ts +1 -13
- package/lib/components/SaveCustomerButton.js +1 -1
- package/lib/components/Shipment.d.ts +1 -8
- package/lib/components/Shipment.js +1 -1
- package/lib/components/ShipmentField.d.ts +1 -12
- package/lib/components/ShipmentField.js +1 -1
- package/lib/components/ShipmentsContainer.d.ts +1 -6
- package/lib/components/ShipmentsContainer.js +1 -1
- package/lib/components/ShippingAddressContainer.d.ts +1 -6
- package/lib/components/ShippingAddressContainer.js +1 -1
- package/lib/components/ShippingAddressForm.d.ts +1 -8
- package/lib/components/ShippingAddressForm.js +1 -1
- package/lib/components/ShippingAmount.d.ts +1 -4
- package/lib/components/ShippingAmount.js +1 -1
- package/lib/components/ShippingMethod.d.ts +1 -8
- package/lib/components/ShippingMethod.js +1 -1
- package/lib/components/ShippingMethodName.d.ts +1 -11
- package/lib/components/ShippingMethodName.js +1 -1
- package/lib/components/ShippingMethodPrice.d.ts +1 -13
- package/lib/components/ShippingMethodPrice.js +1 -1
- package/lib/components/ShippingMethodRadioButton.d.ts +1 -13
- package/lib/components/ShippingMethodRadioButton.js +1 -1
- package/lib/components/SkuList.d.ts +1 -7
- package/lib/components/SkuList.js +1 -1
- package/lib/components/SkuListsContainer.d.ts +1 -6
- package/lib/components/SkuListsContainer.js +1 -1
- package/lib/components/SkuOption.d.ts +1 -7
- package/lib/components/SkuOption.js +1 -1
- package/lib/components/SkuOptionInput.d.ts +1 -5
- package/lib/components/SkuOptionInput.js +1 -1
- package/lib/components/SkuOptionsContainer.d.ts +1 -7
- package/lib/components/SkuOptionsContainer.js +1 -1
- package/lib/components/StockTransfer.d.ts +1 -6
- package/lib/components/StockTransfer.js +1 -1
- package/lib/components/StockTransferField.d.ts +1 -9
- package/lib/components/StockTransferField.js +1 -1
- package/lib/components/StripePayment.d.ts +1 -18
- package/lib/components/StripePayment.js +1 -1
- package/lib/components/SubTotalAmount.d.ts +1 -4
- package/lib/components/SubTotalAmount.js +1 -1
- package/lib/components/SubmitButton.d.ts +1 -9
- package/lib/components/SubmitButton.js +1 -1
- package/lib/components/TaxesAmount.d.ts +1 -4
- package/lib/components/TaxesAmount.js +1 -1
- package/lib/components/TotalAmount.d.ts +1 -4
- package/lib/components/TotalAmount.js +1 -1
- package/lib/components/VariantSelector.d.ts +1 -29
- package/lib/components/VariantSelector.js +1 -1
- package/lib/components/VariantsContainer.d.ts +1 -8
- package/lib/components/VariantsContainer.js +1 -1
- package/lib/components/WireTransferPayment.d.ts +1 -10
- package/lib/components/WireTransferPayment.js +1 -1
- package/lib/components/gateways/AdyenGateway.d.ts +1 -4
- package/lib/components/gateways/AdyenGateway.js +1 -1
- package/lib/components/gateways/BraintreeGateway.d.ts +1 -4
- package/lib/components/gateways/BraintreeGateway.js +1 -1
- package/lib/components/gateways/CheckoutComGateway.d.ts +1 -4
- package/lib/components/gateways/CheckoutComGateway.js +1 -1
- package/lib/components/gateways/PaypalGateway.d.ts +1 -4
- package/lib/components/gateways/PaypalGateway.js +1 -1
- package/lib/components/gateways/StripeGateway.d.ts +1 -4
- package/lib/components/gateways/StripeGateway.js +1 -1
- package/lib/components/gateways/WireTransferGateway.d.ts +1 -4
- package/lib/components/gateways/WireTransferGateway.js +1 -1
- package/lib/components/utils/AddressCardsTemplate.d.ts +1 -26
- package/lib/components/utils/AddressCardsTemplate.js +1 -1
- package/lib/components/utils/BaseField.d.ts +1 -8
- package/lib/components/utils/BaseField.js +1 -1
- package/lib/components/utils/BaseInput.d.ts +1 -5
- package/lib/components/utils/BaseInput.js +1 -1
- package/lib/components/utils/BaseOrderPrice.d.ts +1 -6
- package/lib/components/utils/BaseOrderPrice.js +1 -1
- package/lib/components/utils/BaseSelect.d.ts +1 -5
- package/lib/components/utils/BaseSelect.js +1 -1
- package/lib/components/utils/Parent.d.ts +1 -8
- package/lib/components/utils/Parent.js +1 -1
- package/lib/components/utils/PaymentCardsTemplate.d.ts +1 -22
- package/lib/components/utils/PaymentCardsTemplate.js +1 -1
- package/lib/components/utils/PriceTemplate.d.ts +1 -8
- package/lib/components/utils/PriceTemplate.js +1 -1
- package/lib/components/utils/VariantTemplate.d.ts +1 -36
- package/lib/components/utils/VariantTemplate.js +1 -1
- package/lib/components/utils/getAllErrors.d.ts +1 -17
- package/lib/config/components.d.ts +1 -891
- package/lib/config/currency.d.ts +1 -5
- package/lib/context/AddressChildrenContext.d.ts +1 -6
- package/lib/context/AddressContext.d.ts +1 -16
- package/lib/context/AvailabilityContext.d.ts +1 -2
- package/lib/context/BillingAddressContext.d.ts +1 -11
- package/lib/context/BillingAddressFormContext.d.ts +1 -19
- package/lib/context/CommerceLayerContext.d.ts +1 -6
- package/lib/context/CouponAndGiftCardFormContext.d.ts +1 -7
- package/lib/context/CustomerContext.d.ts +1 -15
- package/lib/context/ExternalFunctionContext.d.ts +1 -11
- package/lib/context/GiftCardContext.d.ts +1 -10
- package/lib/context/ItemContext.d.ts +1 -12
- package/lib/context/LineItemChildrenContext.d.ts +1 -8
- package/lib/context/LineItemContext.d.ts +1 -7
- package/lib/context/LineItemOptionChildrenContext.d.ts +1 -7
- package/lib/context/OrderContext.d.ts +1 -25
- package/lib/context/OrderStorageContext.d.ts +1 -10
- package/lib/context/PaymentMethodChildrenContext.d.ts +1 -9
- package/lib/context/PaymentMethodContext.d.ts +1 -22
- package/lib/context/PaymentSourceContext.d.ts +1 -13
- package/lib/context/PlaceOrderContext.d.ts +1 -17
- package/lib/context/PricesContext.d.ts +1 -6
- package/lib/context/ShipmentChildrenContext.d.ts +1 -12
- package/lib/context/ShipmentContext.d.ts +1 -11
- package/lib/context/ShippingAddressContext.d.ts +1 -9
- package/lib/context/ShippingAddressFormContext.d.ts +1 -3
- package/lib/context/ShippingMethodChildrenContext.d.ts +1 -9
- package/lib/context/SkuListsContext.d.ts +1 -5
- package/lib/context/SkuOptionChildrenContext.d.ts +1 -7
- package/lib/context/SkuOptionsContext.d.ts +1 -2
- package/lib/context/StockTransferChildrenContext.d.ts +1 -6
- package/lib/context/VariantsContext.d.ts +1 -2
- package/lib/index.d.ts +1 -99
- package/lib/reducers/AddressReducer.d.ts +1 -59
- package/lib/reducers/AvailabilityReducer.d.ts +1 -53
- package/lib/reducers/BillingAddressReducer.d.ts +1 -31
- package/lib/reducers/CustomerReducer.d.ts +1 -50
- package/lib/reducers/CustomerReducer.js +1 -1
- package/lib/reducers/GiftCardReducer.d.ts +1 -76
- package/lib/reducers/ItemReducer.d.ts +1 -69
- package/lib/reducers/LineItemReducer.d.ts +1 -52
- package/lib/reducers/OrderReducer.d.ts +2 -121
- package/lib/reducers/PaymentMethodReducer.d.ts +1 -145
- package/lib/reducers/PlaceOrderReducer.d.ts +1 -57
- package/lib/reducers/PriceReducer.d.ts +1 -44
- package/lib/reducers/ShipmentReducer.d.ts +1 -40
- package/lib/reducers/ShippingAddressReducer.d.ts +1 -32
- package/lib/reducers/SkuListsReducer.d.ts +1 -21
- package/lib/reducers/SkuOptionsReducer.d.ts +1 -26
- package/lib/reducers/VariantReducer.d.ts +1 -71
- package/lib/typings/errors.d.ts +1 -42
- package/lib/typings/index.d.ts +1 -127
- package/lib/utils/PropsType.d.ts +1 -33
- package/lib/utils/addressesManager.d.ts +1 -28
- package/lib/utils/baseReducer.d.ts +1 -3
- package/lib/utils/browserInfo.d.ts +1 -9
- package/lib/utils/childrenTypes.d.ts +1 -9
- package/lib/utils/countryStateCity.d.ts +1 -9
- package/lib/utils/customMessages.d.ts +1 -8
- package/lib/utils/customerOrderOptions.d.ts +1 -3
- package/lib/utils/getAmount.d.ts +1 -9
- package/lib/utils/getCardDetails.d.ts +1 -15
- package/lib/utils/getCurrentItemKey.d.ts +1 -6
- package/lib/utils/getErrors.d.ts +1 -11
- package/lib/utils/getLineItemsCount.d.ts +1 -12
- package/lib/utils/getLoaderComponent.d.ts +1 -2
- package/lib/utils/getLoaderComponent.js +1 -1
- package/lib/utils/getPrices.d.ts +1 -17
- package/lib/utils/getPrices.js +1 -1
- package/lib/utils/getSdk.d.ts +1 -3
- package/lib/utils/getSkus.d.ts +1 -3
- package/lib/utils/hooks/useExternalScript.d.ts +1 -1
- package/lib/utils/isEmptyStates.d.ts +1 -1
- package/lib/utils/isJSON.d.ts +1 -1
- package/lib/utils/jwt.d.ts +1 -27
- package/lib/utils/localStorage.d.ts +1 -17
- package/lib/utils/organization.d.ts +1 -6
- package/lib/utils/paypalPayment.d.ts +1 -3
- package/lib/utils/promisify.d.ts +1 -1
- package/lib/utils/shipments.d.ts +1 -2
- package/lib/utils/validateFormFields.d.ts +1 -22
- package/package.json +21 -21
|
@@ -1,20 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { FunctionChildren } from '../typings/index';
|
|
3
|
-
import { AddToCartReturn } from '../reducers/OrderReducer';
|
|
4
|
-
import { VariantOption } from './VariantSelector';
|
|
5
|
-
declare type ChildrenProps = {
|
|
6
|
-
handleClick: () => AddToCartReturn;
|
|
7
|
-
} & Omit<AddToCartButtonProps, 'children'>;
|
|
8
|
-
declare type AddToCartButtonChildrenProps = FunctionChildren<ChildrenProps>;
|
|
9
|
-
export declare type AddToCartButtonType = ChildrenProps;
|
|
10
|
-
declare type AddToCartButtonProps = {
|
|
11
|
-
children?: AddToCartButtonChildrenProps;
|
|
12
|
-
label?: string | ReactNode;
|
|
13
|
-
skuCode?: string;
|
|
14
|
-
bundleCode?: string;
|
|
15
|
-
disabled?: boolean;
|
|
16
|
-
skuListId?: string;
|
|
17
|
-
lineItem?: VariantOption['lineItem'];
|
|
18
|
-
} & PropsWithoutRef<JSX.IntrinsicElements['button']>;
|
|
19
|
-
declare const AddToCartButton: FunctionComponent<AddToCartButtonProps>;
|
|
20
|
-
export default AddToCartButton;
|
|
1
|
+
import{FunctionComponent,PropsWithoutRef,ReactNode}from'react';import{FunctionChildren}from'../typings/index';import{AddToCartReturn}from'../reducers/OrderReducer';import{VariantOption}from'./VariantSelector';declare type ChildrenProps={handleClick:()=>AddToCartReturn;}&Omit<AddToCartButtonProps,'children'>;declare type AddToCartButtonChildrenProps=FunctionChildren<ChildrenProps>;export declare type AddToCartButtonType=ChildrenProps;declare type AddToCartButtonProps={children?:AddToCartButtonChildrenProps;label?:string|ReactNode;skuCode?:string;bundleCode?:string;disabled?:boolean;skuListId?:string;lineItem?:VariantOption['lineItem'];}&PropsWithoutRef<JSX.IntrinsicElements['button']>;declare const AddToCartButton:FunctionComponent<AddToCartButtonProps>;export default AddToCartButton;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{__rest}from"tslib";import{jsx as _jsx}from"react/jsx-runtime";import{useContext}from"react";import Parent from"./utils/Parent";import OrderContext from"../context/OrderContext";import{isEmpty,has}from"lodash";import ItemContext from"../context/ItemContext";import getCurrentItemKey from"../utils/getCurrentItemKey";import components from"../config/components";import SkuListsContext from"../context/SkuListsContext";import ExternalFunctionContext from"../context/ExternalFunctionContext";import isFunction from"lodash/isFunction";const propTypes=components.AddToCartButton.propTypes,defaultProps=components.AddToCartButton.defaultProps,displayName=components.AddToCartButton.displayName,AddToCartButton=props=>{var _a,_b,_c;const{label="Add to cart",children,skuCode,bundleCode,disabled,skuListId,lineItem}=props,p=__rest(props,["label","children","skuCode","bundleCode","disabled","skuListId","lineItem"]),{addToCart,orderId,getOrder,setOrderErrors}=useContext(OrderContext),{url,callExternalFunction}=useContext(ExternalFunctionContext),{item,items,quantity,option,prices,lineItems,lineItem:lineItemContext,skuCode:itemSkuCode}=useContext(ItemContext),{skuLists}=useContext(SkuListsContext),sCode=!isEmpty(items)&&skuCode?(_a=items[skuCode])===null||_a===void 0?void 0:_a.code:skuCode||getCurrentItemKey(item)||itemSkuCode,availabilityQuantity=(_c=(_b=item[sCode])===null||_b===void 0?void 0:_b.inventory)===null||_c===void 0?void 0:_c.quantity,handleClick=()=>{var _a2,_b2;const qty=quantity[sCode],opt=option[sCode],customLineItem=isEmpty(lineItem||lineItemContext)?lineItems[sCode]:lineItem||lineItemContext;if(!isEmpty(skuLists)&&skuListId&&url){const slQty=quantity[skuListId]||1;if(has(skuLists,skuListId)){const lineItems2=skuLists&&skuLists[skuListId].map(skuCode2=>({skuCode:skuCode2,quantity:slQty,_update_quantity:1}));return callExternalFunction({url,data:{resourceType:"orders",inputs:[{id:orderId,lineItems:lineItems2}]}}).then(res=>(getOrder&&orderId&&getOrder(orderId),res)).catch(({response})=>(setOrderErrors&&setOrderErrors(response.data),response))}}return url?callExternalFunction({url,data:{bundleCode,skuCode:sCode,skuId:(_b2=item[sCode])===null||_b2===void 0?void 0:_b2.id,quantity:qty,option:opt,lineItem:customLineItem}}).then(res=>(getOrder&&orderId&&getOrder(orderId),res)).catch(({response})=>(setOrderErrors&&setOrderErrors(response.data),response)):addToCart&&addToCart({bundleCode,skuCode:sCode,skuId:(_a2=item[sCode])===null||_a2===void 0?void 0:_a2.id,quantity:qty,option:opt,lineItem:customLineItem})},autoDisabled=!isEmpty(skuLists)||skuListId?!1:disabled||!prices[sCode]||!sCode||availabilityQuantity===0,parentProps=Object.assign({handleClick,disabled:disabled||autoDisabled,label},props);return children?_jsx(Parent,Object.assign({},parentProps,{children})
|
|
1
|
+
import{__rest}from"tslib";import{jsx as _jsx}from"react/jsx-runtime";import{useContext}from"react";import Parent from"./utils/Parent";import OrderContext from"../context/OrderContext";import{isEmpty,has}from"lodash";import ItemContext from"../context/ItemContext";import getCurrentItemKey from"../utils/getCurrentItemKey";import components from"../config/components";import SkuListsContext from"../context/SkuListsContext";import ExternalFunctionContext from"../context/ExternalFunctionContext";import isFunction from"lodash/isFunction";const propTypes=components.AddToCartButton.propTypes,defaultProps=components.AddToCartButton.defaultProps,displayName=components.AddToCartButton.displayName,AddToCartButton=props=>{var _a,_b,_c;const{label="Add to cart",children,skuCode,bundleCode,disabled,skuListId,lineItem}=props,p=__rest(props,["label","children","skuCode","bundleCode","disabled","skuListId","lineItem"]),{addToCart,orderId,getOrder,setOrderErrors}=useContext(OrderContext),{url,callExternalFunction}=useContext(ExternalFunctionContext),{item,items,quantity,option,prices,lineItems,lineItem:lineItemContext,skuCode:itemSkuCode}=useContext(ItemContext),{skuLists}=useContext(SkuListsContext),sCode=!isEmpty(items)&&skuCode?(_a=items[skuCode])===null||_a===void 0?void 0:_a.code:skuCode||getCurrentItemKey(item)||itemSkuCode,availabilityQuantity=(_c=(_b=item[sCode])===null||_b===void 0?void 0:_b.inventory)===null||_c===void 0?void 0:_c.quantity,handleClick=()=>{var _a2,_b2;const qty=quantity[sCode],opt=option[sCode],customLineItem=isEmpty(lineItem||lineItemContext)?lineItems[sCode]:lineItem||lineItemContext;if(!isEmpty(skuLists)&&skuListId&&url){const slQty=quantity[skuListId]||1;if(has(skuLists,skuListId)){const lineItems2=skuLists&&skuLists[skuListId].map(skuCode2=>({skuCode:skuCode2,quantity:slQty,_update_quantity:1}));return callExternalFunction({url,data:{resourceType:"orders",inputs:[{id:orderId,lineItems:lineItems2}]}}).then(res=>(getOrder&&orderId&&getOrder(orderId),res)).catch(({response})=>(setOrderErrors&&setOrderErrors(response.data),response))}}return url?callExternalFunction({url,data:{bundleCode,skuCode:sCode,skuId:(_b2=item[sCode])===null||_b2===void 0?void 0:_b2.id,quantity:qty,option:opt,lineItem:customLineItem}}).then(res=>(getOrder&&orderId&&getOrder(orderId),res)).catch(({response})=>(setOrderErrors&&setOrderErrors(response.data),response)):addToCart&&addToCart({bundleCode,skuCode:sCode,skuId:(_a2=item[sCode])===null||_a2===void 0?void 0:_a2.id,quantity:qty,option:opt,lineItem:customLineItem})},autoDisabled=!isEmpty(skuLists)||skuListId?!1:disabled||!prices[sCode]||!sCode||availabilityQuantity===0,parentProps=Object.assign({handleClick,disabled:disabled||autoDisabled,label},props);return children?_jsx(Parent,Object.assign({},parentProps,{children})):_jsx("button",Object.assign({},p,{disabled:autoDisabled,onClick:handleClick},{children:isFunction(label)?label():label}))};AddToCartButton.propTypes=propTypes,AddToCartButton.defaultProps=defaultProps,AddToCartButton.displayName=displayName;export default AddToCartButton;
|
|
@@ -1,13 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { Address as AddressType } from '@commercelayer/sdk';
|
|
3
|
-
import { AddressCardsTemplateChildren } from './utils/AddressCardsTemplate';
|
|
4
|
-
declare type Props = {
|
|
5
|
-
children: ReactNode | AddressCardsTemplateChildren;
|
|
6
|
-
selectedClassName?: string;
|
|
7
|
-
disabledClassName?: string;
|
|
8
|
-
onSelect?: (address: AddressType) => void;
|
|
9
|
-
addresses?: AddressType[];
|
|
10
|
-
deselect?: boolean;
|
|
11
|
-
} & JSX.IntrinsicElements['div'];
|
|
12
|
-
declare const Address: FunctionComponent<Props>;
|
|
13
|
-
export default Address;
|
|
1
|
+
import{FunctionComponent,ReactNode}from'react';import{Address as AddressType}from'@commercelayer/sdk';import{AddressCardsTemplateChildren}from'./utils/AddressCardsTemplate';declare type Props={children:ReactNode|AddressCardsTemplateChildren;selectedClassName?:string;disabledClassName?:string;onSelect?:(address:AddressType)=>void;addresses?:AddressType[];deselect?:boolean;}&JSX.IntrinsicElements['div'];declare const Address:FunctionComponent<Props>;export default Address;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{__rest}from"tslib";import{jsx as _jsx}from"react/jsx-runtime";import{Fragment,useContext,useState,useEffect}from"react";import AddressChildrenContext from"../context/AddressChildrenContext";import components from"../config/components";import CustomerContext from"../context/CustomerContext";import BillingAddressContext from"../context/BillingAddressContext";import ShippingAddressContext from"../context/ShippingAddressContext";import isEmpty from"lodash/isEmpty";import AddressContext from"../context/AddressContext";import OrderContext from"../context/OrderContext";import AddressCardsTemplate from"./utils/AddressCardsTemplate";const propTypes=components.Address.propTypes,Address=props=>{const{children,className,selectedClassName="",disabledClassName="",onSelect,addresses=[],deselect=!1}=props,p=__rest(props,["children","className","selectedClassName","disabledClassName","onSelect","addresses","deselect"]),{addresses:addressesContext}=useContext(CustomerContext),{setBillingAddress,billingCustomerAddressId}=useContext(BillingAddressContext),{setShippingAddress,shippingCustomerAddressId}=useContext(ShippingAddressContext),{shipToDifferentAddress,billingAddressId,shippingAddressId}=useContext(AddressContext),{order}=useContext(OrderContext),[selected,setSelected]=useState(null),items=isEmpty(addresses)?addressesContext&&addressesContext||[]:addresses;useEffect(()=>{items&&!deselect&&items.map((address,k)=>{billingCustomerAddressId&&address.reference===billingCustomerAddressId&&selected===null&&setSelected(k),!billingAddressId&&k===selected&&setBillingAddress&&setBillingAddress(address.id,{customerAddressId:address.reference}),shippingCustomerAddressId&&address.reference===shippingCustomerAddressId&&selected===null&&setSelected(k),!shippingAddressId&&k===selected&&setShippingAddress&&setShippingAddress(address.id,{customerAddressId:address.reference})}),deselect&&(async()=>{setBillingAddress&&await setBillingAddress(""),setShippingAddress&&await setShippingAddress("")})()},[deselect,billingCustomerAddressId,shippingCustomerAddressId,addressesContext,shipToDifferentAddress]);const handleSelect=async(k,addressId,customerAddressId,disabled,address)=>{!disabled&&setSelected(k),setBillingAddress&&await setBillingAddress(addressId,{customerAddressId}),!disabled&&setShippingAddress&&await setShippingAddress(addressId,{customerAddressId}),onSelect&&onSelect(address)},countryLock=order==null?void 0:order.shipping_country_code_lock,components2=typeof children=="function"?[]:items.filter(address=>!(setShippingAddress&&countryLock&&countryLock!==address.country_code)).map((address,k)=>{const addressProps={address},disabled=setShippingAddress&&countryLock&&countryLock!==address.country_code||!1,addressSelectedClass=selected===k?`${className} ${deselect?"":selectedClassName}`:className,customerAddressId=(address==null?void 0:address.reference)||"",finalClassName=disabled?`${className} ${disabledClassName}`:addressSelectedClass;return _jsx(AddressChildrenContext.Provider,Object.assign({value:addressProps},{children:_jsx("div",Object.assign({className:finalClassName,onClick:()=>handleSelect(k,address.id,customerAddressId,disabled,address),"data-disabled":disabled},p,{children})
|
|
1
|
+
import{__rest}from"tslib";import{jsx as _jsx}from"react/jsx-runtime";import{Fragment,useContext,useState,useEffect}from"react";import AddressChildrenContext from"../context/AddressChildrenContext";import components from"../config/components";import CustomerContext from"../context/CustomerContext";import BillingAddressContext from"../context/BillingAddressContext";import ShippingAddressContext from"../context/ShippingAddressContext";import isEmpty from"lodash/isEmpty";import AddressContext from"../context/AddressContext";import OrderContext from"../context/OrderContext";import AddressCardsTemplate from"./utils/AddressCardsTemplate";const propTypes=components.Address.propTypes,Address=props=>{const{children,className,selectedClassName="",disabledClassName="",onSelect,addresses=[],deselect=!1}=props,p=__rest(props,["children","className","selectedClassName","disabledClassName","onSelect","addresses","deselect"]),{addresses:addressesContext}=useContext(CustomerContext),{setBillingAddress,billingCustomerAddressId}=useContext(BillingAddressContext),{setShippingAddress,shippingCustomerAddressId}=useContext(ShippingAddressContext),{shipToDifferentAddress,billingAddressId,shippingAddressId}=useContext(AddressContext),{order}=useContext(OrderContext),[selected,setSelected]=useState(null),items=isEmpty(addresses)?addressesContext&&addressesContext||[]:addresses;useEffect(()=>{items&&!deselect&&items.map((address,k)=>{billingCustomerAddressId&&address.reference===billingCustomerAddressId&&selected===null&&setSelected(k),!billingAddressId&&k===selected&&setBillingAddress&&setBillingAddress(address.id,{customerAddressId:address.reference}),shippingCustomerAddressId&&address.reference===shippingCustomerAddressId&&selected===null&&setSelected(k),!shippingAddressId&&k===selected&&setShippingAddress&&setShippingAddress(address.id,{customerAddressId:address.reference})}),deselect&&(async()=>{setBillingAddress&&await setBillingAddress(""),setShippingAddress&&await setShippingAddress("")})()},[deselect,billingCustomerAddressId,shippingCustomerAddressId,addressesContext,shipToDifferentAddress]);const handleSelect=async(k,addressId,customerAddressId,disabled,address)=>{!disabled&&setSelected(k),setBillingAddress&&await setBillingAddress(addressId,{customerAddressId}),!disabled&&setShippingAddress&&await setShippingAddress(addressId,{customerAddressId}),onSelect&&onSelect(address)},countryLock=order==null?void 0:order.shipping_country_code_lock,components2=typeof children=="function"?[]:items.filter(address=>!(setShippingAddress&&countryLock&&countryLock!==address.country_code)).map((address,k)=>{const addressProps={address},disabled=setShippingAddress&&countryLock&&countryLock!==address.country_code||!1,addressSelectedClass=selected===k?`${className} ${deselect?"":selectedClassName}`:className,customerAddressId=(address==null?void 0:address.reference)||"",finalClassName=disabled?`${className} ${disabledClassName}`:addressSelectedClass;return _jsx(AddressChildrenContext.Provider,Object.assign({value:addressProps},{children:_jsx("div",Object.assign({className:finalClassName,onClick:()=>handleSelect(k,address.id,customerAddressId,disabled,address),"data-disabled":disabled},p,{children}))}),k)}),parentProps=Object.assign({customerAddresses:items,selected,handleSelect,countryLock},props);return typeof children=="function"?_jsx(AddressCardsTemplate,Object.assign({},parentProps,{children})):_jsx(Fragment,{children:components2})};Address.propTypes=propTypes;export default Address;
|
|
@@ -1,9 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { AddressCountrySelectName, BaseSelectComponentProps } from '../typings/index';
|
|
3
|
-
declare type AddressCountrySelectorProps = Omit<BaseSelectComponentProps, 'options' | 'name'> & {
|
|
4
|
-
name: AddressCountrySelectName;
|
|
5
|
-
required?: boolean;
|
|
6
|
-
disabled?: boolean;
|
|
7
|
-
} & Pick<JSX.IntrinsicElements['select'], 'className' | 'id' | 'style'>;
|
|
8
|
-
declare const AddressCountrySelector: FunctionComponent<AddressCountrySelectorProps>;
|
|
9
|
-
export default AddressCountrySelector;
|
|
1
|
+
import{FunctionComponent}from'react';import{AddressCountrySelectName,BaseSelectComponentProps}from'../typings/index';declare type AddressCountrySelectorProps=Omit<BaseSelectComponentProps,'options'|'name'>&{name:AddressCountrySelectName;required?:boolean;disabled?:boolean;}&Pick<JSX.IntrinsicElements['select'],'className'|'id'|'style'>;declare const AddressCountrySelector:FunctionComponent<AddressCountrySelectorProps>;export default AddressCountrySelector;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{__rest}from"tslib";import{jsx as _jsx}from"react/jsx-runtime";import{useContext,useEffect,useState}from"react";import BaseSelect from"./utils/BaseSelect";import components from"../config/components";import BillingAddressFormContext from"../context/BillingAddressFormContext";import ShippingAddressFormContext from"../context/ShippingAddressFormContext";import isEmpty from"lodash/isEmpty";import{getCountries}from"../utils/countryStateCity";const propTypes=components.AddressCountrySelector.propTypes,defaultProps=components.AddressCountrySelector.defaultProps,displayName=components.AddressCountrySelector.displayName,AddressCountrySelector=props=>{const{required=!0,value,name,className}=props,p=__rest(props,["required","value","name","className"]),billingAddress=useContext(BillingAddressFormContext),shippingAddress=useContext(ShippingAddressFormContext),[hasError,setHasError]=useState(!1);useEffect(()=>{var _a,_b,_c,_d,_e,_f;return value&&(billingAddress==null?void 0:billingAddress.setValue)&&billingAddress.setValue(name,value),value&&(shippingAddress==null?void 0:shippingAddress.setValue)&&shippingAddress.setValue(name,value),!isEmpty(billingAddress.errors)&&((_b=(_a=billingAddress==null?void 0:billingAddress.errors)===null||_a===void 0?void 0:_a[name])===null||_b===void 0?void 0:_b.error)&&setHasError(!0),isEmpty((_c=billingAddress==null?void 0:billingAddress.errors)===null||_c===void 0?void 0:_c[name])&&hasError&&setHasError(!1),!isEmpty(shippingAddress.errors)&&((_e=(_d=shippingAddress==null?void 0:shippingAddress.errors)===null||_d===void 0?void 0:_d[name])===null||_e===void 0?void 0:_e.error)&&setHasError(!0),isEmpty((_f=shippingAddress==null?void 0:shippingAddress.errors)===null||_f===void 0?void 0:_f[name])&&hasError&&setHasError(!1),()=>{setHasError(!1)}},[value,billingAddress==null?void 0:billingAddress.errors,shippingAddress==null?void 0:shippingAddress.errors]);const errorClassName=(billingAddress==null?void 0:billingAddress.errorClassName)||(shippingAddress==null?void 0:shippingAddress.errorClassName),classNameComputed=`${className} ${hasError?errorClassName:""}`;return _jsx(BaseSelect,Object.assign({className:classNameComputed,ref:(billingAddress==null?void 0:billingAddress.validation)||(shippingAddress==null?void 0:shippingAddress.validation),required,options:getCountries(),name,value},p)
|
|
1
|
+
import{__rest}from"tslib";import{jsx as _jsx}from"react/jsx-runtime";import{useContext,useEffect,useState}from"react";import BaseSelect from"./utils/BaseSelect";import components from"../config/components";import BillingAddressFormContext from"../context/BillingAddressFormContext";import ShippingAddressFormContext from"../context/ShippingAddressFormContext";import isEmpty from"lodash/isEmpty";import{getCountries}from"../utils/countryStateCity";const propTypes=components.AddressCountrySelector.propTypes,defaultProps=components.AddressCountrySelector.defaultProps,displayName=components.AddressCountrySelector.displayName,AddressCountrySelector=props=>{const{required=!0,value,name,className}=props,p=__rest(props,["required","value","name","className"]),billingAddress=useContext(BillingAddressFormContext),shippingAddress=useContext(ShippingAddressFormContext),[hasError,setHasError]=useState(!1);useEffect(()=>{var _a,_b,_c,_d,_e,_f;return value&&(billingAddress==null?void 0:billingAddress.setValue)&&billingAddress.setValue(name,value),value&&(shippingAddress==null?void 0:shippingAddress.setValue)&&shippingAddress.setValue(name,value),!isEmpty(billingAddress.errors)&&((_b=(_a=billingAddress==null?void 0:billingAddress.errors)===null||_a===void 0?void 0:_a[name])===null||_b===void 0?void 0:_b.error)&&setHasError(!0),isEmpty((_c=billingAddress==null?void 0:billingAddress.errors)===null||_c===void 0?void 0:_c[name])&&hasError&&setHasError(!1),!isEmpty(shippingAddress.errors)&&((_e=(_d=shippingAddress==null?void 0:shippingAddress.errors)===null||_d===void 0?void 0:_d[name])===null||_e===void 0?void 0:_e.error)&&setHasError(!0),isEmpty((_f=shippingAddress==null?void 0:shippingAddress.errors)===null||_f===void 0?void 0:_f[name])&&hasError&&setHasError(!1),()=>{setHasError(!1)}},[value,billingAddress==null?void 0:billingAddress.errors,shippingAddress==null?void 0:shippingAddress.errors]);const errorClassName=(billingAddress==null?void 0:billingAddress.errorClassName)||(shippingAddress==null?void 0:shippingAddress.errorClassName),classNameComputed=`${className} ${hasError?errorClassName:""}`;return _jsx(BaseSelect,Object.assign({className:classNameComputed,ref:(billingAddress==null?void 0:billingAddress.validation)||(shippingAddress==null?void 0:shippingAddress.validation),required,options:getCountries(),name,value},p))};AddressCountrySelector.propTypes=propTypes,AddressCountrySelector.defaultProps=defaultProps,AddressCountrySelector.displayName=displayName;export default AddressCountrySelector;
|
|
@@ -1,15 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { AddressFieldView } from '../reducers/AddressReducer';
|
|
3
|
-
import { Address } from '@commercelayer/sdk';
|
|
4
|
-
declare type AddressFieldChildrenProps = Omit<AddressFieldProps, 'children' | 'name'> & {
|
|
5
|
-
address: Address;
|
|
6
|
-
};
|
|
7
|
-
declare type AddressFieldProps = ({
|
|
8
|
-
children?: (props: AddressFieldChildrenProps) => ReactNode;
|
|
9
|
-
name: AddressFieldView;
|
|
10
|
-
} | {
|
|
11
|
-
children: (props: AddressFieldChildrenProps) => ReactNode;
|
|
12
|
-
name?: AddressFieldView;
|
|
13
|
-
}) & JSX.IntrinsicElements['p'];
|
|
14
|
-
declare const AddressField: FunctionComponent<AddressFieldProps>;
|
|
15
|
-
export default AddressField;
|
|
1
|
+
import{FunctionComponent,ReactNode}from'react';import{AddressFieldView}from'../reducers/AddressReducer';import{Address}from'@commercelayer/sdk';declare type AddressFieldChildrenProps=Omit<AddressFieldProps,'children'|'name'>&{address:Address;};declare type AddressFieldProps=({children?:(props:AddressFieldChildrenProps)=>ReactNode;name:AddressFieldView;}|{children:(props:AddressFieldChildrenProps)=>ReactNode;name?:AddressFieldView;})&JSX.IntrinsicElements['p'];declare const AddressField:FunctionComponent<AddressFieldProps>;export default AddressField;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsx as _jsx}from"react/jsx-runtime";import{useContext}from"react";import AddressChildrenContext from"../context/AddressChildrenContext";import Parent from"./utils/Parent";import components from"../config/components";import get from"lodash/get";const propTypes=components.AddressField.propTypes,displayName=components.AddressField.displayName,AddressField=props=>{const{name}=props,{address}=useContext(AddressChildrenContext),text=get(address,name),parentProps=Object.assign({address},props);return props.children?_jsx(Parent,Object.assign({},parentProps,{children:props.children})
|
|
1
|
+
import{jsx as _jsx}from"react/jsx-runtime";import{useContext}from"react";import AddressChildrenContext from"../context/AddressChildrenContext";import Parent from"./utils/Parent";import components from"../config/components";import get from"lodash/get";const propTypes=components.AddressField.propTypes,displayName=components.AddressField.displayName,AddressField=props=>{const{name}=props,{address}=useContext(AddressChildrenContext),text=get(address,name),parentProps=Object.assign({address},props);return props.children?_jsx(Parent,Object.assign({},parentProps,{children:props.children})):_jsx("p",Object.assign({},props,{children:text}))};AddressField.propTypes=propTypes,AddressField.displayName=displayName;export default AddressField;
|
|
@@ -1,7 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { BaseInputComponentProps, AddressInputName } from '../typings/index';
|
|
3
|
-
export declare type AddressInputProps = {
|
|
4
|
-
name: AddressInputName;
|
|
5
|
-
} & Omit<BaseInputComponentProps, 'name'> & JSX.IntrinsicElements['input'] & JSX.IntrinsicElements['textarea'];
|
|
6
|
-
declare const AddressInput: FunctionComponent<AddressInputProps>;
|
|
7
|
-
export default AddressInput;
|
|
1
|
+
import{FunctionComponent}from'react';import{BaseInputComponentProps,AddressInputName}from'../typings/index';export declare type AddressInputProps={name:AddressInputName;}&Omit<BaseInputComponentProps,'name'>&JSX.IntrinsicElements['input']&JSX.IntrinsicElements['textarea'];declare const AddressInput:FunctionComponent<AddressInputProps>;export default AddressInput;
|
|
@@ -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 BillingAddressFormContext from"../context/BillingAddressFormContext";import ShippingAddressFormContext from"../context/ShippingAddressFormContext";import isEmpty from"lodash/isEmpty";import{businessMandatoryField}from"../utils/validateFormFields";const propTypes=components.AddressInput.propTypes,displayName=components.AddressInput.displayName,AddressInput=props=>{const{placeholder="",required,value,className}=props,p=__rest(props,["placeholder","required","value","className"]),billingAddress=useContext(BillingAddressFormContext),shippingAddress=useContext(ShippingAddressFormContext),[hasError,setHasError]=useState(!1);useEffect(()=>{var _a,_b,_c,_d,_e,_f;return value&&(billingAddress==null?void 0:billingAddress.setValue)&&billingAddress.setValue(p.name,value),value&&(shippingAddress==null?void 0:shippingAddress.setValue)&&shippingAddress.setValue(p.name,value),!isEmpty(billingAddress.errors)&&((_b=(_a=billingAddress==null?void 0:billingAddress.errors)===null||_a===void 0?void 0:_a[p.name])===null||_b===void 0?void 0:_b.error)&&setHasError(!0),!isEmpty(billingAddress)&&isEmpty((_c=billingAddress==null?void 0:billingAddress.errors)===null||_c===void 0?void 0:_c[p.name])&&hasError&&setHasError(!1),!isEmpty(shippingAddress.errors)&&((_e=(_d=shippingAddress==null?void 0:shippingAddress.errors)===null||_d===void 0?void 0:_d[p.name])===null||_e===void 0?void 0:_e.error)&&setHasError(!0),!isEmpty(shippingAddress)&&isEmpty((_f=shippingAddress==null?void 0:shippingAddress.errors)===null||_f===void 0?void 0:_f[p.name])&&hasError&&setHasError(!1),()=>{setHasError(!1)}},[value,billingAddress==null?void 0:billingAddress.errors,shippingAddress==null?void 0:shippingAddress.errors]);const mandatoryField=(billingAddress==null?void 0:billingAddress.isBusiness)?businessMandatoryField(p.name,billingAddress.isBusiness):businessMandatoryField(p.name,shippingAddress.isBusiness),reqField=required!==void 0?required:mandatoryField,errorClassName=(billingAddress==null?void 0:billingAddress.errorClassName)||(shippingAddress==null?void 0:shippingAddress.errorClassName),classNameComputed=`${className} ${hasError?errorClassName:""}`;return p.name==="billing_address_billing_info"&&!billingAddress.requiresBillingInfo?null:_jsx(BaseInput,Object.assign({ref:(billingAddress==null?void 0:billingAddress.validation)||(shippingAddress==null?void 0:shippingAddress.validation),className:classNameComputed,required:reqField,placeholder,defaultValue:value},p)
|
|
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 BillingAddressFormContext from"../context/BillingAddressFormContext";import ShippingAddressFormContext from"../context/ShippingAddressFormContext";import isEmpty from"lodash/isEmpty";import{businessMandatoryField}from"../utils/validateFormFields";const propTypes=components.AddressInput.propTypes,displayName=components.AddressInput.displayName,AddressInput=props=>{const{placeholder="",required,value,className}=props,p=__rest(props,["placeholder","required","value","className"]),billingAddress=useContext(BillingAddressFormContext),shippingAddress=useContext(ShippingAddressFormContext),[hasError,setHasError]=useState(!1);useEffect(()=>{var _a,_b,_c,_d,_e,_f;return value&&(billingAddress==null?void 0:billingAddress.setValue)&&billingAddress.setValue(p.name,value),value&&(shippingAddress==null?void 0:shippingAddress.setValue)&&shippingAddress.setValue(p.name,value),!isEmpty(billingAddress.errors)&&((_b=(_a=billingAddress==null?void 0:billingAddress.errors)===null||_a===void 0?void 0:_a[p.name])===null||_b===void 0?void 0:_b.error)&&setHasError(!0),!isEmpty(billingAddress)&&isEmpty((_c=billingAddress==null?void 0:billingAddress.errors)===null||_c===void 0?void 0:_c[p.name])&&hasError&&setHasError(!1),!isEmpty(shippingAddress.errors)&&((_e=(_d=shippingAddress==null?void 0:shippingAddress.errors)===null||_d===void 0?void 0:_d[p.name])===null||_e===void 0?void 0:_e.error)&&setHasError(!0),!isEmpty(shippingAddress)&&isEmpty((_f=shippingAddress==null?void 0:shippingAddress.errors)===null||_f===void 0?void 0:_f[p.name])&&hasError&&setHasError(!1),()=>{setHasError(!1)}},[value,billingAddress==null?void 0:billingAddress.errors,shippingAddress==null?void 0:shippingAddress.errors]);const mandatoryField=(billingAddress==null?void 0:billingAddress.isBusiness)?businessMandatoryField(p.name,billingAddress.isBusiness):businessMandatoryField(p.name,shippingAddress.isBusiness),reqField=required!==void 0?required:mandatoryField,errorClassName=(billingAddress==null?void 0:billingAddress.errorClassName)||(shippingAddress==null?void 0:shippingAddress.errorClassName),classNameComputed=`${className} ${hasError?errorClassName:""}`;return p.name==="billing_address_billing_info"&&!billingAddress.requiresBillingInfo?null:_jsx(BaseInput,Object.assign({ref:(billingAddress==null?void 0:billingAddress.validation)||(shippingAddress==null?void 0:shippingAddress.validation),className:classNameComputed,required:reqField,placeholder,defaultValue:value},p))};AddressInput.propTypes=propTypes,AddressInput.displayName=displayName;export default AddressInput;
|
|
@@ -1,11 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { AddressStateSelectName, BaseSelectComponentProps } from '../typings/index';
|
|
3
|
-
declare type AddressStateSelectorProps = Omit<BaseSelectComponentProps, 'options' | 'name'> & {
|
|
4
|
-
name: AddressStateSelectName;
|
|
5
|
-
required?: boolean;
|
|
6
|
-
disabled?: boolean;
|
|
7
|
-
inputClassName?: string;
|
|
8
|
-
selectClassName?: string;
|
|
9
|
-
} & Pick<JSX.IntrinsicElements['select'], 'className' | 'id' | 'style'>;
|
|
10
|
-
declare const AddressStateSelector: FunctionComponent<AddressStateSelectorProps>;
|
|
11
|
-
export default AddressStateSelector;
|
|
1
|
+
import{FunctionComponent}from'react';import{AddressStateSelectName,BaseSelectComponentProps}from'../typings/index';declare type AddressStateSelectorProps=Omit<BaseSelectComponentProps,'options'|'name'>&{name:AddressStateSelectName;required?:boolean;disabled?:boolean;inputClassName?:string;selectClassName?:string;}&Pick<JSX.IntrinsicElements['select'],'className'|'id'|'style'>;declare const AddressStateSelector:FunctionComponent<AddressStateSelectorProps>;export default AddressStateSelector;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{__rest}from"tslib";import{jsx as _jsx}from"react/jsx-runtime";import{useContext,useEffect,useState}from"react";import BaseSelect from"./utils/BaseSelect";import components from"../config/components";import BillingAddressFormContext from"../context/BillingAddressFormContext";import ShippingAddressFormContext from"../context/ShippingAddressFormContext";import isEmpty from"lodash/isEmpty";import{getStateOfCountry,isValidState}from"../utils/countryStateCity";import isEmptyStates from"../utils/isEmptyStates";import AddressesContext from"../context/AddressContext";import BaseInput from"./utils/BaseInput";const propTypes=components.AddressStateSelector.propTypes,defaultProps=components.AddressStateSelector.defaultProps,displayName=components.AddressStateSelector.displayName,AddressStateSelector=props=>{var _a;const{required=!0,value,name,className,inputClassName,selectClassName}=props,p=__rest(props,["required","value","name","className","inputClassName","selectClassName"]),billingAddress=useContext(BillingAddressFormContext),shippingAddress=useContext(ShippingAddressFormContext),{errors:addressErrors}=useContext(AddressesContext),[hasError,setHasError]=useState(!1),[countryCode,setCountryCode]=useState(""),[val,setVal]=useState(value||"");useEffect(()=>{var _a2,_b,_c,_d,_e,_f,_g,_h,_j;const billingCountryCode=((_b=(_a2=billingAddress==null?void 0:billingAddress.values)===null||_a2===void 0?void 0:_a2.billing_address_country_code)===null||_b===void 0?void 0:_b.value)||((_c=billingAddress==null?void 0:billingAddress.values)===null||_c===void 0?void 0:_c.country_code);!isEmpty(billingCountryCode)&&billingCountryCode!==countryCode&&setCountryCode(billingCountryCode);const shippingCountryCode=(_e=(_d=shippingAddress==null?void 0:shippingAddress.values)===null||_d===void 0?void 0:_d.shipping_address_country_code)===null||_e===void 0?void 0:_e.value;if(!isEmpty(shippingCountryCode)&&shippingCountryCode!==countryCode&&setCountryCode(shippingCountryCode),[!isEmpty(billingAddress),billingCountryCode,countryCode!==billingCountryCode].every(Boolean)&&!isValidState(val,billingCountryCode)&&!isEmptyStates(billingCountryCode)&&(billingAddress.resetField&&billingAddress.resetField(name),setVal("")),[!isEmpty(shippingAddress),shippingCountryCode,countryCode!==shippingCountryCode].every(Boolean)&&!isValidState(val,shippingCountryCode)&&!isEmptyStates(shippingCountryCode)&&(shippingAddress.resetField&&shippingAddress.resetField(name),setVal("")),!isEmpty(billingAddress)){const fieldError=(_g=(_f=billingAddress==null?void 0:billingAddress.errors)===null||_f===void 0?void 0:_f[name])===null||_g===void 0?void 0:_g.error;setHasError(!!fieldError)}if(!isEmpty(shippingAddress)){const fieldError=(_j=(_h=shippingAddress==null?void 0:shippingAddress.errors)===null||_h===void 0?void 0:_h[name])===null||_j===void 0?void 0:_j.error;setHasError(!!fieldError)}return()=>{setHasError(!1)}},[value,billingAddress,shippingAddress,addressErrors]);const errorClassName=(billingAddress==null?void 0:billingAddress.errorClassName)||(shippingAddress==null?void 0:shippingAddress.errorClassName),classNameComputed=isEmptyStates(countryCode)?`${className} ${inputClassName} ${hasError?errorClassName:""}`:`${className} ${selectClassName} ${hasError?errorClassName:""}`;return isEmptyStates(countryCode)?_jsx(BaseInput,Object.assign({},p,{name,ref:(billingAddress==null?void 0:billingAddress.validation)||(shippingAddress==null?void 0:shippingAddress.validation),className:classNameComputed,required,placeholder:((_a=p.placeholder)===null||_a===void 0?void 0:_a.label)||"",defaultValue:val,type:"text"})
|
|
1
|
+
import{__rest}from"tslib";import{jsx as _jsx}from"react/jsx-runtime";import{useContext,useEffect,useState}from"react";import BaseSelect from"./utils/BaseSelect";import components from"../config/components";import BillingAddressFormContext from"../context/BillingAddressFormContext";import ShippingAddressFormContext from"../context/ShippingAddressFormContext";import isEmpty from"lodash/isEmpty";import{getStateOfCountry,isValidState}from"../utils/countryStateCity";import isEmptyStates from"../utils/isEmptyStates";import AddressesContext from"../context/AddressContext";import BaseInput from"./utils/BaseInput";const propTypes=components.AddressStateSelector.propTypes,defaultProps=components.AddressStateSelector.defaultProps,displayName=components.AddressStateSelector.displayName,AddressStateSelector=props=>{var _a;const{required=!0,value,name,className,inputClassName,selectClassName}=props,p=__rest(props,["required","value","name","className","inputClassName","selectClassName"]),billingAddress=useContext(BillingAddressFormContext),shippingAddress=useContext(ShippingAddressFormContext),{errors:addressErrors}=useContext(AddressesContext),[hasError,setHasError]=useState(!1),[countryCode,setCountryCode]=useState(""),[val,setVal]=useState(value||"");useEffect(()=>{var _a2,_b,_c,_d,_e,_f,_g,_h,_j;const billingCountryCode=((_b=(_a2=billingAddress==null?void 0:billingAddress.values)===null||_a2===void 0?void 0:_a2.billing_address_country_code)===null||_b===void 0?void 0:_b.value)||((_c=billingAddress==null?void 0:billingAddress.values)===null||_c===void 0?void 0:_c.country_code);!isEmpty(billingCountryCode)&&billingCountryCode!==countryCode&&setCountryCode(billingCountryCode);const shippingCountryCode=(_e=(_d=shippingAddress==null?void 0:shippingAddress.values)===null||_d===void 0?void 0:_d.shipping_address_country_code)===null||_e===void 0?void 0:_e.value;if(!isEmpty(shippingCountryCode)&&shippingCountryCode!==countryCode&&setCountryCode(shippingCountryCode),[!isEmpty(billingAddress),billingCountryCode,countryCode!==billingCountryCode].every(Boolean)&&!isValidState(val,billingCountryCode)&&!isEmptyStates(billingCountryCode)&&(billingAddress.resetField&&billingAddress.resetField(name),setVal("")),[!isEmpty(shippingAddress),shippingCountryCode,countryCode!==shippingCountryCode].every(Boolean)&&!isValidState(val,shippingCountryCode)&&!isEmptyStates(shippingCountryCode)&&(shippingAddress.resetField&&shippingAddress.resetField(name),setVal("")),!isEmpty(billingAddress)){const fieldError=(_g=(_f=billingAddress==null?void 0:billingAddress.errors)===null||_f===void 0?void 0:_f[name])===null||_g===void 0?void 0:_g.error;setHasError(!!fieldError)}if(!isEmpty(shippingAddress)){const fieldError=(_j=(_h=shippingAddress==null?void 0:shippingAddress.errors)===null||_h===void 0?void 0:_h[name])===null||_j===void 0?void 0:_j.error;setHasError(!!fieldError)}return()=>{setHasError(!1)}},[value,billingAddress,shippingAddress,addressErrors]);const errorClassName=(billingAddress==null?void 0:billingAddress.errorClassName)||(shippingAddress==null?void 0:shippingAddress.errorClassName),classNameComputed=isEmptyStates(countryCode)?`${className} ${inputClassName} ${hasError?errorClassName:""}`:`${className} ${selectClassName} ${hasError?errorClassName:""}`;return isEmptyStates(countryCode)?_jsx(BaseInput,Object.assign({},p,{name,ref:(billingAddress==null?void 0:billingAddress.validation)||(shippingAddress==null?void 0:shippingAddress.validation),className:classNameComputed,required,placeholder:((_a=p.placeholder)===null||_a===void 0?void 0:_a.label)||"",defaultValue:val,type:"text"})):_jsx(BaseSelect,Object.assign({},p,{className:classNameComputed,ref:(billingAddress==null?void 0:billingAddress.validation)||(shippingAddress==null?void 0:shippingAddress.validation),required,options:getStateOfCountry(countryCode),name,value:val}))};AddressStateSelector.propTypes=propTypes,AddressStateSelector.defaultProps=defaultProps,AddressStateSelector.displayName=displayName;export default AddressStateSelector;
|
|
@@ -1,8 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
export declare type AddressesContainerProps = {
|
|
3
|
-
children: ReactNode;
|
|
4
|
-
shipToDifferentAddress?: boolean;
|
|
5
|
-
isBusiness?: boolean;
|
|
6
|
-
};
|
|
7
|
-
declare const AddressesContainer: FunctionComponent<AddressesContainerProps>;
|
|
8
|
-
export default AddressesContainer;
|
|
1
|
+
import{FunctionComponent,ReactNode}from'react';export declare type AddressesContainerProps={children:ReactNode;shipToDifferentAddress?:boolean;isBusiness?:boolean;};declare const AddressesContainer:FunctionComponent<AddressesContainerProps>;export default AddressesContainer;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsx as _jsx}from"react/jsx-runtime";import AddressesContext,{defaultAddressContext}from"../context/AddressContext";import{useContext,useEffect,useReducer}from"react";import addressReducer,{addressInitialState,setAddressErrors,setCloneAddress}from"../reducers/AddressReducer";import OrderContext from"../context/OrderContext";import CommerceLayerContext from"../context/CommerceLayerContext";import{saveAddresses}from"../reducers/AddressReducer";import components from"../config/components";const propTypes=components.AddressesContainer.propTypes,displayName=components.AddressesContainer.displayName,AddressesContainer=props=>{const{children,shipToDifferentAddress=!1,isBusiness}=props,[state,dispatch]=useReducer(addressReducer,addressInitialState),{order,orderId,updateOrder}=useContext(OrderContext),config=useContext(CommerceLayerContext);useEffect(()=>(dispatch({type:"setShipToDifferentAddress",payload:{shipToDifferentAddress,isBusiness}}),()=>{dispatch({type:"cleanup",payload:{}})}),[shipToDifferentAddress,isBusiness]);const contextValue=Object.assign(Object.assign({},state),{setAddressErrors:(errors,resource)=>setAddressErrors({errors,resource,dispatch,currentErrors:state.errors}),setAddress:params=>defaultAddressContext.setAddress(Object.assign(Object.assign({},params),{dispatch})),saveAddresses:async()=>await saveAddresses({config,dispatch,updateOrder,order,orderId,state}),setCloneAddress:(id,resource)=>setCloneAddress(id,resource,dispatch)});return _jsx(AddressesContext.Provider,Object.assign({value:contextValue},{children})
|
|
1
|
+
import{jsx as _jsx}from"react/jsx-runtime";import AddressesContext,{defaultAddressContext}from"../context/AddressContext";import{useContext,useEffect,useReducer}from"react";import addressReducer,{addressInitialState,setAddressErrors,setCloneAddress}from"../reducers/AddressReducer";import OrderContext from"../context/OrderContext";import CommerceLayerContext from"../context/CommerceLayerContext";import{saveAddresses}from"../reducers/AddressReducer";import components from"../config/components";const propTypes=components.AddressesContainer.propTypes,displayName=components.AddressesContainer.displayName,AddressesContainer=props=>{const{children,shipToDifferentAddress=!1,isBusiness}=props,[state,dispatch]=useReducer(addressReducer,addressInitialState),{order,orderId,updateOrder}=useContext(OrderContext),config=useContext(CommerceLayerContext);useEffect(()=>(dispatch({type:"setShipToDifferentAddress",payload:{shipToDifferentAddress,isBusiness}}),()=>{dispatch({type:"cleanup",payload:{}})}),[shipToDifferentAddress,isBusiness]);const contextValue=Object.assign(Object.assign({},state),{setAddressErrors:(errors,resource)=>setAddressErrors({errors,resource,dispatch,currentErrors:state.errors}),setAddress:params=>defaultAddressContext.setAddress(Object.assign(Object.assign({},params),{dispatch})),saveAddresses:async()=>await saveAddresses({config,dispatch,updateOrder,order,orderId,state}),setCloneAddress:(id,resource)=>setCloneAddress(id,resource,dispatch)});return _jsx(AddressesContext.Provider,Object.assign({value:contextValue},{children}))};AddressesContainer.propTypes=propTypes,AddressesContainer.displayName=displayName;export default AddressesContainer;
|
|
@@ -1,4 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { BaseAmountComponent } from '../typings/index';
|
|
3
|
-
declare const AdjustmentAmount: FunctionComponent<BaseAmountComponent>;
|
|
4
|
-
export default AdjustmentAmount;
|
|
1
|
+
import{FunctionComponent}from'react';import{BaseAmountComponent}from'../typings/index';declare const AdjustmentAmount:FunctionComponent<BaseAmountComponent>;export default AdjustmentAmount;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsx as _jsx}from"react/jsx-runtime";import BaseOrderPrice from"./utils/BaseOrderPrice";import components from"../config/components";const propTypes=components.AdjustmentAmount.propTypes,defaultProps=components.AdjustmentAmount.defaultProps,displayName=components.AdjustmentAmount.displayName,AdjustmentAmount=props=>_jsx(BaseOrderPrice,Object.assign({base:"amount",type:"adjustment"},props)
|
|
1
|
+
import{jsx as _jsx}from"react/jsx-runtime";import BaseOrderPrice from"./utils/BaseOrderPrice";import components from"../config/components";const propTypes=components.AdjustmentAmount.propTypes,defaultProps=components.AdjustmentAmount.defaultProps,displayName=components.AdjustmentAmount.displayName,AdjustmentAmount=props=>_jsx(BaseOrderPrice,Object.assign({base:"amount",type:"adjustment"},props));AdjustmentAmount.propTypes=propTypes,AdjustmentAmount.defaultProps=defaultProps,AdjustmentAmount.displayName=displayName;export default AdjustmentAmount;
|
|
@@ -1,25 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { PaymentSourceProps } from './PaymentSource';
|
|
3
|
-
declare type Styles = Partial<{
|
|
4
|
-
base: CSSProperties;
|
|
5
|
-
error: CSSProperties;
|
|
6
|
-
placeholder: CSSProperties;
|
|
7
|
-
validated: CSSProperties;
|
|
8
|
-
}>;
|
|
9
|
-
export declare type AdyenPaymentConfig = {
|
|
10
|
-
cardContainerClassName?: string;
|
|
11
|
-
threeDSecureContainerClassName?: string;
|
|
12
|
-
placeOrderCallback?: (response: {
|
|
13
|
-
placed: boolean;
|
|
14
|
-
}) => void;
|
|
15
|
-
styles?: Styles;
|
|
16
|
-
};
|
|
17
|
-
declare type AdyenPaymentProps = {
|
|
18
|
-
clientKey?: string;
|
|
19
|
-
config?: AdyenPaymentConfig;
|
|
20
|
-
templateCustomerSaveToWallet?: PaymentSourceProps['templateCustomerSaveToWallet'];
|
|
21
|
-
locale?: string;
|
|
22
|
-
environment?: string;
|
|
23
|
-
};
|
|
24
|
-
declare const AdyenPayment: FunctionComponent<AdyenPaymentProps>;
|
|
25
|
-
export default AdyenPayment;
|
|
1
|
+
import{CSSProperties,FunctionComponent}from'react';import{PaymentSourceProps}from'./PaymentSource';declare type Styles=Partial<{base:CSSProperties;error:CSSProperties;placeholder:CSSProperties;validated:CSSProperties;}>;export declare type AdyenPaymentConfig={cardContainerClassName?:string;threeDSecureContainerClassName?:string;placeOrderCallback?:(response:{placed:boolean;})=>void;styles?:Styles;};declare type AdyenPaymentProps={clientKey?:string;config?:AdyenPaymentConfig;templateCustomerSaveToWallet?:PaymentSourceProps['templateCustomerSaveToWallet'];locale?:string;environment?:string;};declare const AdyenPayment:FunctionComponent<AdyenPaymentProps>;export default AdyenPayment;
|
|
@@ -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{setCustomerOrderParam}from"../utils/localStorage";import Parent from"./utils/Parent";import getBrowserInfo from"../utils/browserInfo";import PlaceOrderContext from"../context/PlaceOrderContext";const threeDSConfiguration={challengeWindowSize:"05"},defaultConfig={},AdyenPayment=({clientKey,config,templateCustomerSaveToWallet,environment="test",locale="en_US"})=>{const{cardContainerClassName,threeDSecureContainerClassName,placeOrderCallback,styles}=Object.assign(Object.assign({},defaultConfig),config),[loadAdyen,setLoadAdyen]=useState(!1),[checkout,setCheckout]=useState({}),{setPaymentSource,paymentSource,setPaymentMethodErrors,currentPaymentMethodType,setPaymentRef}=useContext(PaymentMethodContext),{setPlaceOrder}=useContext(PlaceOrderContext),ref=useRef(null),handleSubmit=async(e,checkout2)=>{var _a,_b,_c,_d,_e,_f,_g;const savePaymentSourceToCustomerWallet=(_b=(_a=e==null?void 0:e.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 attributes={_authorize:1};try{const pSource=paymentSource&&await setPaymentSource({paymentSourceId:paymentSource.id,paymentResource:"adyen_payments",attributes}),adyenAction=(_c=pSource==null?void 0:pSource.payment_response)===null||_c===void 0?void 0:_c.action,resultCode=(_d=pSource==null?void 0:pSource.payment_response)===null||_d===void 0?void 0:_d.resultCode;if(adyenAction&&["IdentifyShopper","RedirectShopper"].includes(resultCode))checkout2.createFromAction(adyenAction,threeDSConfiguration).mount("#adyen-action");else if(["Authorised","Pending","Received"].includes(resultCode)){const brand=(_f=(_e=pSource==null?void 0:pSource.payment_request_data)===null||_e===void 0?void 0:_e.payment_method)===null||_f===void 0?void 0:_f.brand;if(brand){const attributes2={metadata:{card:{brand}}};await setPaymentSource({paymentSourceId:pSource==null?void 0:pSource.id,paymentResource:"adyen_payments",attributes:attributes2})}return!0}const message=(_g=pSource==null?void 0:pSource.payment_response)===null||_g===void 0?void 0:_g.refusalReason;return setPaymentMethodErrors([{code:"PAYMENT_INTENT_AUTHENTICATION_FAILURE",resource:"payment_methods",field:currentPaymentMethodType,message}]),!1}catch(error){return setPaymentMethodErrors([{code:"PAYMENT_INTENT_AUTHENTICATION_FAILURE",resource:"payment_methods",field:currentPaymentMethodType,message:error.message}]),!1}},handleChange=async(state,_component,config2,paySource)=>{if(state.isValid){if(ref.current){const adyenCheckout=await require("@adyen/adyen-web")(config2);ref.current.onsubmit=()=>handleSubmit(ref.current,adyenCheckout),setPaymentRef({ref})}const browserInfo=getBrowserInfo(),attributes={payment_request_data:{payment_method:state.data.paymentMethod,shopperInteraction:"Ecommerce",recurringProcessingModel:"CardOnFile",origin:window.location.origin,return_url:window.location.href,redirect_from_issuer_method:"GET",browser_info:Object.assign({acceptHeader:"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8"},browserInfo)}};paySource&&await setPaymentSource({paymentSourceId:paySource.id,paymentResource:"adyen_payments",attributes})}},handleOnAdditionalDetails=async(state,_component,config2)=>{var _a,_b;const attributes={payment_request_details:state.data,_details:1};try{const pSource=paymentSource&&await setPaymentSource({paymentSourceId:paymentSource.id,paymentResource:"adyen_payments",attributes}),adyenAction=(_a=pSource==null?void 0:pSource.payment_response)===null||_a===void 0?void 0:_a.action,resultCode=(_b=pSource==null?void 0:pSource.payment_response)===null||_b===void 0?void 0:_b.resultCode,AdyenCheckout=require("@adyen/adyen-web");if(adyenAction&&(await AdyenCheckout(config2)).createFromAction(adyenAction,threeDSConfiguration).mount("#adyen-action"),["Authorised","Pending","Received"].includes(resultCode)){const{placed}=setPlaceOrder&&await setPlaceOrder({paymentSource:pSource})||{placed:!1};placed&&placeOrderCallback&&placeOrderCallback({placed})}}catch(error){console.error("Adyen additional details error:",error)}};return useEffect(()=>{const paymentMethodsResponse=isEmpty(paymentSource==null?void 0:paymentSource.payment_methods)?{}:paymentSource==null?void 0:paymentSource.payment_methods;isEmpty(paymentMethodsResponse)&&console.error("Payment methods are not available. Please, check your Adyen configuration.");const options={locale,environment,clientKey,paymentMethodsResponse};return options.onChange=(s,c)=>handleChange(s,c,options,paymentSource),options.onAdditionalDetails=(s,c)=>handleOnAdditionalDetails(s,c,options),!ref&&clientKey&&setCustomerOrderParam("_save_payment_source_to_customer_wallet","false"),clientKey&&!loadAdyen&&!isEmpty(window)&&require("@adyen/adyen-web")(options).then(adyenCheckout=>{adyenCheckout.create("card",{styles}).mount("#adyen-card")&&(setCheckout(adyenCheckout),setLoadAdyen(!0))}),()=>{setPaymentRef({ref:{current:null}}),setLoadAdyen(!1)}},[clientKey,ref]),!clientKey&&!loadAdyen&&!checkout?null:_jsxs("form",Object.assign({ref,onSubmit:e=>handleSubmit(e,checkout)},{children:[_jsx("div",{className:cardContainerClassName,id:"adyen-card"}
|
|
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{setCustomerOrderParam}from"../utils/localStorage";import Parent from"./utils/Parent";import getBrowserInfo from"../utils/browserInfo";import PlaceOrderContext from"../context/PlaceOrderContext";const threeDSConfiguration={challengeWindowSize:"05"},defaultConfig={},AdyenPayment=({clientKey,config,templateCustomerSaveToWallet,environment="test",locale="en_US"})=>{const{cardContainerClassName,threeDSecureContainerClassName,placeOrderCallback,styles}=Object.assign(Object.assign({},defaultConfig),config),[loadAdyen,setLoadAdyen]=useState(!1),[checkout,setCheckout]=useState({}),{setPaymentSource,paymentSource,setPaymentMethodErrors,currentPaymentMethodType,setPaymentRef}=useContext(PaymentMethodContext),{setPlaceOrder}=useContext(PlaceOrderContext),ref=useRef(null),handleSubmit=async(e,checkout2)=>{var _a,_b,_c,_d,_e,_f,_g;const savePaymentSourceToCustomerWallet=(_b=(_a=e==null?void 0:e.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 attributes={_authorize:1};try{const pSource=paymentSource&&await setPaymentSource({paymentSourceId:paymentSource.id,paymentResource:"adyen_payments",attributes}),adyenAction=(_c=pSource==null?void 0:pSource.payment_response)===null||_c===void 0?void 0:_c.action,resultCode=(_d=pSource==null?void 0:pSource.payment_response)===null||_d===void 0?void 0:_d.resultCode;if(adyenAction&&["IdentifyShopper","RedirectShopper"].includes(resultCode))checkout2.createFromAction(adyenAction,threeDSConfiguration).mount("#adyen-action");else if(["Authorised","Pending","Received"].includes(resultCode)){const brand=(_f=(_e=pSource==null?void 0:pSource.payment_request_data)===null||_e===void 0?void 0:_e.payment_method)===null||_f===void 0?void 0:_f.brand;if(brand){const attributes2={metadata:{card:{brand}}};await setPaymentSource({paymentSourceId:pSource==null?void 0:pSource.id,paymentResource:"adyen_payments",attributes:attributes2})}return!0}const message=(_g=pSource==null?void 0:pSource.payment_response)===null||_g===void 0?void 0:_g.refusalReason;return setPaymentMethodErrors([{code:"PAYMENT_INTENT_AUTHENTICATION_FAILURE",resource:"payment_methods",field:currentPaymentMethodType,message}]),!1}catch(error){return setPaymentMethodErrors([{code:"PAYMENT_INTENT_AUTHENTICATION_FAILURE",resource:"payment_methods",field:currentPaymentMethodType,message:error.message}]),!1}},handleChange=async(state,_component,config2,paySource)=>{if(state.isValid){if(ref.current){const adyenCheckout=await require("@adyen/adyen-web")(config2);ref.current.onsubmit=()=>handleSubmit(ref.current,adyenCheckout),setPaymentRef({ref})}const browserInfo=getBrowserInfo(),attributes={payment_request_data:{payment_method:state.data.paymentMethod,shopperInteraction:"Ecommerce",recurringProcessingModel:"CardOnFile",origin:window.location.origin,return_url:window.location.href,redirect_from_issuer_method:"GET",browser_info:Object.assign({acceptHeader:"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8"},browserInfo)}};paySource&&await setPaymentSource({paymentSourceId:paySource.id,paymentResource:"adyen_payments",attributes})}},handleOnAdditionalDetails=async(state,_component,config2)=>{var _a,_b;const attributes={payment_request_details:state.data,_details:1};try{const pSource=paymentSource&&await setPaymentSource({paymentSourceId:paymentSource.id,paymentResource:"adyen_payments",attributes}),adyenAction=(_a=pSource==null?void 0:pSource.payment_response)===null||_a===void 0?void 0:_a.action,resultCode=(_b=pSource==null?void 0:pSource.payment_response)===null||_b===void 0?void 0:_b.resultCode,AdyenCheckout=require("@adyen/adyen-web");if(adyenAction&&(await AdyenCheckout(config2)).createFromAction(adyenAction,threeDSConfiguration).mount("#adyen-action"),["Authorised","Pending","Received"].includes(resultCode)){const{placed}=setPlaceOrder&&await setPlaceOrder({paymentSource:pSource})||{placed:!1};placed&&placeOrderCallback&&placeOrderCallback({placed})}}catch(error){console.error("Adyen additional details error:",error)}};return useEffect(()=>{const paymentMethodsResponse=isEmpty(paymentSource==null?void 0:paymentSource.payment_methods)?{}:paymentSource==null?void 0:paymentSource.payment_methods;isEmpty(paymentMethodsResponse)&&console.error("Payment methods are not available. Please, check your Adyen configuration.");const options={locale,environment,clientKey,paymentMethodsResponse};return options.onChange=(s,c)=>handleChange(s,c,options,paymentSource),options.onAdditionalDetails=(s,c)=>handleOnAdditionalDetails(s,c,options),!ref&&clientKey&&setCustomerOrderParam("_save_payment_source_to_customer_wallet","false"),clientKey&&!loadAdyen&&!isEmpty(window)&&require("@adyen/adyen-web")(options).then(adyenCheckout=>{adyenCheckout.create("card",{styles}).mount("#adyen-card")&&(setCheckout(adyenCheckout),setLoadAdyen(!0))}),()=>{setPaymentRef({ref:{current:null}}),setLoadAdyen(!1)}},[clientKey,ref]),!clientKey&&!loadAdyen&&!checkout?null:_jsxs("form",Object.assign({ref,onSubmit:e=>handleSubmit(e,checkout)},{children:[_jsx("div",{className:cardContainerClassName,id:"adyen-card"}),templateCustomerSaveToWallet&&_jsx(Parent,Object.assign({},{name:"save_payment_source_to_customer_wallet"},{children:templateCustomerSaveToWallet})),_jsx("div",{className:threeDSecureContainerClassName,id:"adyen-action"})]}))};export default AdyenPayment;
|
|
@@ -1,7 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
declare type AvailabilityContainerProps = {
|
|
3
|
-
children: ReactNode;
|
|
4
|
-
skuCode?: string;
|
|
5
|
-
};
|
|
6
|
-
declare const AvailabilityContainer: FunctionComponent<AvailabilityContainerProps>;
|
|
7
|
-
export default AvailabilityContainer;
|
|
1
|
+
import{FunctionComponent,ReactNode}from'react';declare type AvailabilityContainerProps={children:ReactNode;skuCode?:string;};declare const AvailabilityContainer:FunctionComponent<AvailabilityContainerProps>;export default AvailabilityContainer;
|
|
@@ -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 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})
|
|
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}))};AvailabilityContainer.propTypes=propTypes,AvailabilityContainer.displayName=displayName;export default AvailabilityContainer;
|
|
@@ -1,15 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { TimeFormat, FunctionChildren } from '../typings/index';
|
|
3
|
-
import { DeliveryLeadTime } from '../reducers/AvailabilityReducer';
|
|
4
|
-
declare type AvailabilityTemplateChildrenProps = FunctionChildren<Omit<AvailabilityTemplateProps, 'children'> & DeliveryLeadTime & {
|
|
5
|
-
text: string;
|
|
6
|
-
quantity: number;
|
|
7
|
-
}>;
|
|
8
|
-
declare type AvailabilityTemplateProps = {
|
|
9
|
-
children?: AvailabilityTemplateChildrenProps;
|
|
10
|
-
timeFormat?: TimeFormat;
|
|
11
|
-
showShippingMethodName?: boolean;
|
|
12
|
-
showShippingMethodPrice?: boolean;
|
|
13
|
-
} & JSX.IntrinsicElements['p'];
|
|
14
|
-
declare const AvailabilityTemplate: FunctionComponent<AvailabilityTemplateProps>;
|
|
15
|
-
export default AvailabilityTemplate;
|
|
1
|
+
import{FunctionComponent}from'react';import{TimeFormat,FunctionChildren}from'../typings/index';import{DeliveryLeadTime}from'../reducers/AvailabilityReducer';declare type AvailabilityTemplateChildrenProps=FunctionChildren<Omit<AvailabilityTemplateProps,'children'>&DeliveryLeadTime&{text:string;quantity:number;}>;declare type AvailabilityTemplateProps={children?:AvailabilityTemplateChildrenProps;timeFormat?:TimeFormat;showShippingMethodName?:boolean;showShippingMethodPrice?:boolean;}&JSX.IntrinsicElements['p'];declare const AvailabilityTemplate:FunctionComponent<AvailabilityTemplateProps>;export default AvailabilityTemplate;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{__rest}from"tslib";import{jsx as _jsx}from"react/jsx-runtime";import{useContext}from"react";import AvailabilityContext from"../context/AvailabilityContext";import Parent from"./utils/Parent";import{isEmpty}from"lodash";import components from"../config/components";const propTypes=components.AvailabilityTemplate.propTypes,defaultProps=components.AvailabilityTemplate.defaultProps,displayName=components.AvailabilityTemplate.displayName,AvailabilityTemplate=props=>{const{timeFormat,showShippingMethodName,showShippingMethodPrice,children}=props,p=__rest(props,["timeFormat","showShippingMethodName","showShippingMethodPrice","children"]),{min,max,shipping_method,quantity}=useContext(AvailabilityContext),mn=!isEmpty(min)&&timeFormat?min==null?void 0:min[timeFormat]:"",mx=!isEmpty(max)&&timeFormat?max==null?void 0:max[timeFormat]:"",text=[],shippingMethodPrice=showShippingMethodPrice&&(shipping_method==null?void 0:shipping_method.formatted_price_amount)?`(${shipping_method==null?void 0:shipping_method.formatted_price_amount})`:"",name=showShippingMethodName&&shipping_method?`with ${shipping_method.name}`:"";quantity&&quantity>0?(text.push("Available"),mn&&mx&&text.push(`in ${mn} - ${mx} ${timeFormat} ${name} ${shippingMethodPrice}`)):quantity===0&&text.push("Out of stock");const parentProps=Object.assign({min,max,shipping_method,quantity,text:text.join(" ")},props);return children?_jsx(Parent,Object.assign({},parentProps,{children})
|
|
1
|
+
import{__rest}from"tslib";import{jsx as _jsx}from"react/jsx-runtime";import{useContext}from"react";import AvailabilityContext from"../context/AvailabilityContext";import Parent from"./utils/Parent";import{isEmpty}from"lodash";import components from"../config/components";const propTypes=components.AvailabilityTemplate.propTypes,defaultProps=components.AvailabilityTemplate.defaultProps,displayName=components.AvailabilityTemplate.displayName,AvailabilityTemplate=props=>{const{timeFormat,showShippingMethodName,showShippingMethodPrice,children}=props,p=__rest(props,["timeFormat","showShippingMethodName","showShippingMethodPrice","children"]),{min,max,shipping_method,quantity}=useContext(AvailabilityContext),mn=!isEmpty(min)&&timeFormat?min==null?void 0:min[timeFormat]:"",mx=!isEmpty(max)&&timeFormat?max==null?void 0:max[timeFormat]:"",text=[],shippingMethodPrice=showShippingMethodPrice&&(shipping_method==null?void 0:shipping_method.formatted_price_amount)?`(${shipping_method==null?void 0:shipping_method.formatted_price_amount})`:"",name=showShippingMethodName&&shipping_method?`with ${shipping_method.name}`:"";quantity&&quantity>0?(text.push("Available"),mn&&mx&&text.push(`in ${mn} - ${mx} ${timeFormat} ${name} ${shippingMethodPrice}`)):quantity===0&&text.push("Out of stock");const parentProps=Object.assign({min,max,shipping_method,quantity,text:text.join(" ")},props);return children?_jsx(Parent,Object.assign({},parentProps,{children})):_jsx("p",Object.assign({},p,{children:text.join(" ")}))};AvailabilityTemplate.propTypes=propTypes,AvailabilityTemplate.defaultProps=defaultProps,AvailabilityTemplate.displayName=displayName;export default AvailabilityTemplate;
|
|
@@ -1,6 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
declare type Props = {
|
|
3
|
-
children: ReactNode;
|
|
4
|
-
};
|
|
5
|
-
declare const BillingAddressContainer: FunctionComponent<Props>;
|
|
6
|
-
export default BillingAddressContainer;
|
|
1
|
+
import{FunctionComponent,ReactNode}from'react';declare type Props={children:ReactNode;};declare const BillingAddressContainer:FunctionComponent<Props>;export default BillingAddressContainer;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsx as _jsx}from"react/jsx-runtime";import BillingAddressContext from"../context/BillingAddressContext";import{useContext,useEffect,useReducer}from"react";import billingAddressReducer,{billingAddressInitialState,setBillingAddress,setBillingCustomerAddressId}from"../reducers/BillingAddressReducer";import CommerceLayerContext from"../context/CommerceLayerContext";import components from"../config/components";import OrderContext from"../context/OrderContext";import AddressContext from"../context/AddressContext";const propTypes=components.BillingAddressContainer.propTypes,BillingAddressContainer=props=>{const{children}=props,[state,dispatch]=useReducer(billingAddressReducer,billingAddressInitialState),config=useContext(CommerceLayerContext),{order,include,addResourceToInclude}=useContext(OrderContext),{shipToDifferentAddress,setCloneAddress}=useContext(AddressContext);useEffect(()=>((include==null?void 0:include.includes("billing_address"))||addResourceToInclude({newResource:"billing_address",resourcesIncluded:include}),order&&config&&setBillingCustomerAddressId({dispatch,order,setCloneAddress}),()=>{dispatch({type:"cleanup",payload:{}})}),[order,include]);const contextValue=Object.assign(Object.assign({},state),{setBillingAddress:async(id,options)=>{await setBillingAddress(id,{config,dispatch,order,shipToDifferentAddress,customerAddressId:options==null?void 0:options.customerAddressId}),setCloneAddress(id,"billing_address")}});return _jsx(BillingAddressContext.Provider,Object.assign({value:contextValue},{children})
|
|
1
|
+
import{jsx as _jsx}from"react/jsx-runtime";import BillingAddressContext from"../context/BillingAddressContext";import{useContext,useEffect,useReducer}from"react";import billingAddressReducer,{billingAddressInitialState,setBillingAddress,setBillingCustomerAddressId}from"../reducers/BillingAddressReducer";import CommerceLayerContext from"../context/CommerceLayerContext";import components from"../config/components";import OrderContext from"../context/OrderContext";import AddressContext from"../context/AddressContext";const propTypes=components.BillingAddressContainer.propTypes,BillingAddressContainer=props=>{const{children}=props,[state,dispatch]=useReducer(billingAddressReducer,billingAddressInitialState),config=useContext(CommerceLayerContext),{order,include,addResourceToInclude}=useContext(OrderContext),{shipToDifferentAddress,setCloneAddress}=useContext(AddressContext);useEffect(()=>((include==null?void 0:include.includes("billing_address"))||addResourceToInclude({newResource:"billing_address",resourcesIncluded:include}),order&&config&&setBillingCustomerAddressId({dispatch,order,setCloneAddress}),()=>{dispatch({type:"cleanup",payload:{}})}),[order,include]);const contextValue=Object.assign(Object.assign({},state),{setBillingAddress:async(id,options)=>{await setBillingAddress(id,{config,dispatch,order,shipToDifferentAddress,customerAddressId:options==null?void 0:options.customerAddressId}),setCloneAddress(id,"billing_address")}});return _jsx(BillingAddressContext.Provider,Object.assign({value:contextValue},{children}))};BillingAddressContainer.propTypes=propTypes;export default BillingAddressContainer;
|
|
@@ -1,8 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
declare type BillingAddressFormProps = {
|
|
3
|
-
children: ReactNode;
|
|
4
|
-
reset?: boolean;
|
|
5
|
-
errorClassName?: string;
|
|
6
|
-
} & Omit<JSX.IntrinsicElements['form'], 'onSubmit'>;
|
|
7
|
-
declare const BillingAddressForm: FunctionComponent<BillingAddressFormProps>;
|
|
8
|
-
export default BillingAddressForm;
|
|
1
|
+
import{FunctionComponent,ReactNode}from'react';declare type BillingAddressFormProps={children:ReactNode;reset?:boolean;errorClassName?:string;}&Omit<JSX.IntrinsicElements['form'],'onSubmit'>;declare const BillingAddressForm:FunctionComponent<BillingAddressFormProps>;export default BillingAddressForm;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{__rest}from"tslib";import{jsx as _jsx}from"react/jsx-runtime";import AddressesContext from"../context/AddressContext";import useRapidForm from"rapid-form";import{useContext,useEffect,useRef}from"react";import BillingAddressFormContext from"../context/BillingAddressFormContext";import{isEmpty}from"lodash";import components from"../config/components";import OrderContext from"../context/OrderContext";import{getSaveBillingAddressToAddressBook}from"../utils/localStorage";import{businessMandatoryField}from"../utils/validateFormFields";const propTypes=components.BillingAddressForm.propTypes,BillingAddressForm=props=>{const{children,errorClassName,autoComplete="on",reset=!1}=props,p=__rest(props,["children","errorClassName","autoComplete","reset"]),{validation,values,errors,reset:resetForm}=useRapidForm(),{setAddressErrors,setAddress,isBusiness}=useContext(AddressesContext),{saveAddressToCustomerAddressBook,order,include,addResourceToInclude,includeLoaded}=useContext(OrderContext),ref=useRef(null);useEffect(()=>{var _a,_b,_c;if((include==null?void 0:include.includes("billing_address"))?(includeLoaded==null?void 0:includeLoaded.billing_address)||addResourceToInclude({newResourceLoaded:{billing_address:!0}}):addResourceToInclude({newResource:"billing_address"}),isEmpty(errors)){if(!isEmpty(values)){setAddressErrors([],"billing_address");for(const name in values){const field=values[name];businessMandatoryField(name,isBusiness)||delete values[name],(field==null?void 0:field.value)&&(values[name.replace("billing_address_","")]=field.value,delete values[name]),(field==null?void 0:field.type)==="checkbox"&&(delete values[name],saveAddressToCustomerAddressBook({type:"billing_address",value:field.checked}))}setAddress({values:Object.assign(Object.assign({},values),isBusiness&&{business:isBusiness}),resource:"billing_address"})}}else{const formErrors=[];for(const fieldName in errors){const{code,message}=errors[fieldName];["billing_address_state_code"].includes(fieldName)?isEmpty(values.state_code)?delete errors[fieldName]:formErrors.push({code,message,resource:"billing_address",field:fieldName}):formErrors.push({code,message,resource:"billing_address",field:fieldName})}setAddressErrors(formErrors,"billing_address")}const checkboxChecked=((_b=(_a=ref.current)===null||_a===void 0?void 0:_a.querySelector('[name="billing_address_save_to_customer_book"]'))===null||_b===void 0?void 0:_b.checked)||getSaveBillingAddressToAddressBook();reset&&(!isEmpty(values)||!isEmpty(errors)||checkboxChecked)&&(saveAddressToCustomerAddressBook&&saveAddressToCustomerAddressBook({type:"billing_address",value:!1}),ref&&((_c=ref.current)===null||_c===void 0||_c.reset(),resetForm({target:ref.current}),setAddressErrors([],"billing_address"),setAddress({values:{},resource:"billing_address"})))},[errors,values,reset,include,includeLoaded,isBusiness]);const providerValues={isBusiness,values,validation,setValue:(name,value)=>{const field={[name.replace("billing_address_","")]:value};setAddress({values:Object.assign(Object.assign(Object.assign({},values),field),isBusiness&&{business:isBusiness}),resource:"billing_address"})},errorClassName,requiresBillingInfo:(order==null?void 0:order.requires_billing_info)||!1,errors,resetField:name=>resetForm({currentTarget:ref.current},name)};return _jsx(BillingAddressFormContext.Provider,Object.assign({value:providerValues},{children:_jsx("form",Object.assign({ref,autoComplete},p,{children})
|
|
1
|
+
import{__rest}from"tslib";import{jsx as _jsx}from"react/jsx-runtime";import AddressesContext from"../context/AddressContext";import useRapidForm from"rapid-form";import{useContext,useEffect,useRef}from"react";import BillingAddressFormContext from"../context/BillingAddressFormContext";import{isEmpty}from"lodash";import components from"../config/components";import OrderContext from"../context/OrderContext";import{getSaveBillingAddressToAddressBook}from"../utils/localStorage";import{businessMandatoryField}from"../utils/validateFormFields";const propTypes=components.BillingAddressForm.propTypes,BillingAddressForm=props=>{const{children,errorClassName,autoComplete="on",reset=!1}=props,p=__rest(props,["children","errorClassName","autoComplete","reset"]),{validation,values,errors,reset:resetForm}=useRapidForm(),{setAddressErrors,setAddress,isBusiness}=useContext(AddressesContext),{saveAddressToCustomerAddressBook,order,include,addResourceToInclude,includeLoaded}=useContext(OrderContext),ref=useRef(null);useEffect(()=>{var _a,_b,_c;if((include==null?void 0:include.includes("billing_address"))?(includeLoaded==null?void 0:includeLoaded.billing_address)||addResourceToInclude({newResourceLoaded:{billing_address:!0}}):addResourceToInclude({newResource:"billing_address"}),isEmpty(errors)){if(!isEmpty(values)){setAddressErrors([],"billing_address");for(const name in values){const field=values[name];businessMandatoryField(name,isBusiness)||delete values[name],(field==null?void 0:field.value)&&(values[name.replace("billing_address_","")]=field.value,delete values[name]),(field==null?void 0:field.type)==="checkbox"&&(delete values[name],saveAddressToCustomerAddressBook({type:"billing_address",value:field.checked}))}setAddress({values:Object.assign(Object.assign({},values),isBusiness&&{business:isBusiness}),resource:"billing_address"})}}else{const formErrors=[];for(const fieldName in errors){const{code,message}=errors[fieldName];["billing_address_state_code"].includes(fieldName)?isEmpty(values.state_code)?delete errors[fieldName]:formErrors.push({code,message,resource:"billing_address",field:fieldName}):formErrors.push({code,message,resource:"billing_address",field:fieldName})}setAddressErrors(formErrors,"billing_address")}const checkboxChecked=((_b=(_a=ref.current)===null||_a===void 0?void 0:_a.querySelector('[name="billing_address_save_to_customer_book"]'))===null||_b===void 0?void 0:_b.checked)||getSaveBillingAddressToAddressBook();reset&&(!isEmpty(values)||!isEmpty(errors)||checkboxChecked)&&(saveAddressToCustomerAddressBook&&saveAddressToCustomerAddressBook({type:"billing_address",value:!1}),ref&&((_c=ref.current)===null||_c===void 0||_c.reset(),resetForm({target:ref.current}),setAddressErrors([],"billing_address"),setAddress({values:{},resource:"billing_address"})))},[errors,values,reset,include,includeLoaded,isBusiness]);const providerValues={isBusiness,values,validation,setValue:(name,value)=>{const field={[name.replace("billing_address_","")]:value};setAddress({values:Object.assign(Object.assign(Object.assign({},values),field),isBusiness&&{business:isBusiness}),resource:"billing_address"})},errorClassName,requiresBillingInfo:(order==null?void 0:order.requires_billing_info)||!1,errors,resetField:name=>resetForm({currentTarget:ref.current},name)};return _jsx(BillingAddressFormContext.Provider,Object.assign({value:providerValues},{children:_jsx("form",Object.assign({ref,autoComplete},p,{children}))}))};BillingAddressForm.propTypes=propTypes;export default BillingAddressForm;
|
|
@@ -1,30 +1 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { HostedFieldFieldOptions } from 'braintree-web/modules/hosted-fields';
|
|
3
|
-
import { PaymentSourceProps } from './PaymentSource';
|
|
4
|
-
declare type BraintreeHostedFields<Type> = {
|
|
5
|
-
[Property in keyof Type]: {
|
|
6
|
-
label?: string;
|
|
7
|
-
} & Type[Property];
|
|
8
|
-
};
|
|
9
|
-
export declare type BraintreeConfig = {
|
|
10
|
-
containerClassName?: string;
|
|
11
|
-
cardContainerClassName?: string;
|
|
12
|
-
expDateContainerClassName?: string;
|
|
13
|
-
fieldsContainerClassName?: string;
|
|
14
|
-
cvvContainerClassName?: string;
|
|
15
|
-
cardDetailsContainerClassName?: string;
|
|
16
|
-
fieldLabelClassName?: string;
|
|
17
|
-
inputWrapperClassName?: string;
|
|
18
|
-
fields?: BraintreeHostedFields<HostedFieldFieldOptions>;
|
|
19
|
-
styles?: {
|
|
20
|
-
[key: string]: Record<string, string>;
|
|
21
|
-
};
|
|
22
|
-
};
|
|
23
|
-
declare type BraintreePaymentProps = {
|
|
24
|
-
authorization: string;
|
|
25
|
-
config?: BraintreeConfig;
|
|
26
|
-
templateCustomerSaveToWallet?: PaymentSourceProps['templateCustomerSaveToWallet'];
|
|
27
|
-
locale?: string;
|
|
28
|
-
};
|
|
29
|
-
declare const BraintreePayment: FunctionComponent<BraintreePaymentProps>;
|
|
30
|
-
export default BraintreePayment;
|
|
1
|
+
import{FunctionComponent}from'react';import{HostedFieldFieldOptions}from'braintree-web/modules/hosted-fields';import{PaymentSourceProps}from'./PaymentSource';declare type BraintreeHostedFields<Type>={[Property in keyof Type]:{label?:string;}&Type[Property];};export declare type BraintreeConfig={containerClassName?:string;cardContainerClassName?:string;expDateContainerClassName?:string;fieldsContainerClassName?:string;cvvContainerClassName?:string;cardDetailsContainerClassName?:string;fieldLabelClassName?:string;inputWrapperClassName?:string;fields?:BraintreeHostedFields<HostedFieldFieldOptions>;styles?:{[key:string]:Record<string,string>;};};declare type BraintreePaymentProps={authorization:string;config?:BraintreeConfig;templateCustomerSaveToWallet?:PaymentSourceProps['templateCustomerSaveToWallet'];locale?:string;};declare const BraintreePayment:FunctionComponent<BraintreePaymentProps>;export default BraintreePayment;
|
|
@@ -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,threeDSecureInstance)=>{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=()=>handleSubmitForm(ref.current,hostedFieldsInstance,threeDSecureInstance),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})
|
|
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,threeDSecureInstance)=>{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=()=>handleSubmitForm(ref.current,hostedFieldsInstance,threeDSecureInstance),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,23 +1 @@
|
|
|
1
|
-
import
|
|
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
|
-
success_url?: string;
|
|
10
|
-
failure_url?: string;
|
|
11
|
-
options?: {
|
|
12
|
-
style: FramesStyle;
|
|
13
|
-
};
|
|
14
|
-
[key: string]: unknown;
|
|
15
|
-
};
|
|
16
|
-
declare type CheckoutComPaymentProps = PaymentMethodConfig['checkoutComPayment'] & JSX.IntrinsicElements['div'] & {
|
|
17
|
-
show?: boolean;
|
|
18
|
-
publicKey: string;
|
|
19
|
-
locale?: string;
|
|
20
|
-
templateCustomerSaveToWallet?: PaymentSourceProps['templateCustomerSaveToWallet'];
|
|
21
|
-
};
|
|
22
|
-
declare const CheckoutComPayment: FunctionComponent<CheckoutComPaymentProps>;
|
|
23
|
-
export default CheckoutComPayment;
|
|
1
|
+
import{FunctionComponent}from'react';import{PaymentMethodConfig}from'../reducers/PaymentMethodReducer';import{PaymentSourceProps}from'./PaymentSource';import{FramesStyle}from'frames-react';export declare type CheckoutComConfig={containerClassName?:string;hintLabel?:string;name?:string;success_url?:string;failure_url?:string;options?:{style:FramesStyle;};[key:string]:unknown;};declare type CheckoutComPaymentProps=PaymentMethodConfig['checkoutComPayment']&JSX.IntrinsicElements['div']&{show?:boolean;publicKey:string;locale?:string;templateCustomerSaveToWallet?:PaymentSourceProps['templateCustomerSaveToWallet'];};declare const CheckoutComPayment:FunctionComponent<CheckoutComPaymentProps>;export default CheckoutComPayment;
|
|
@@ -1 +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,success_url=window.location.href,failure_url=window.location.href,show}=p,divProps=__rest(p,["containerClassName","templateCustomerSaveToWallet","success_url","failure_url","show"]),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,failure_url,_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&&show?_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,{}
|
|
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,success_url=window.location.href,failure_url=window.location.href,show}=p,divProps=__rest(p,["containerClassName","templateCustomerSaveToWallet","success_url","failure_url","show"]),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,failure_url,_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&&show?_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,{}),_jsx(ExpiryDate,{}),_jsx(Cvv,{})]}))})),templateCustomerSaveToWallet&&_jsx(Parent,Object.assign({},{name:"save_payment_source_to_customer_wallet"},{children:templateCustomerSaveToWallet}))]})):null};export default CheckoutComPayment;
|
|
@@ -1,13 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { FunctionChildren } from '../typings/index';
|
|
3
|
-
declare type CheckoutLinkChildrenProps = FunctionChildren<Omit<CheckoutLinkProps, 'children'> & {
|
|
4
|
-
checkoutUrl: string;
|
|
5
|
-
href: string;
|
|
6
|
-
}>;
|
|
7
|
-
declare type CheckoutLinkProps = {
|
|
8
|
-
children?: CheckoutLinkChildrenProps;
|
|
9
|
-
label?: string;
|
|
10
|
-
hostedCheckout?: boolean;
|
|
11
|
-
} & JSX.IntrinsicElements['a'];
|
|
12
|
-
declare const CheckoutLink: FunctionComponent<CheckoutLinkProps>;
|
|
13
|
-
export default CheckoutLink;
|
|
1
|
+
import{FunctionComponent}from'react';import{FunctionChildren}from'../typings/index';declare type CheckoutLinkChildrenProps=FunctionChildren<Omit<CheckoutLinkProps,'children'>&{checkoutUrl:string;href:string;}>;declare type CheckoutLinkProps={children?:CheckoutLinkChildrenProps;label?:string;hostedCheckout?:boolean;}&JSX.IntrinsicElements['a'];declare const CheckoutLink:FunctionComponent<CheckoutLinkProps>;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";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})
|
|
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})):_jsx("a",Object.assign({href},p,{children:label}))};CheckoutLink.propTypes=propTypes,CheckoutLink.defaultProps=defaultProps,CheckoutLink.displayName=displayName;export default CheckoutLink;
|
|
@@ -1,8 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
declare type CommerceLayerProps = {
|
|
3
|
-
children: ReactNode;
|
|
4
|
-
accessToken: string;
|
|
5
|
-
endpoint: string;
|
|
6
|
-
};
|
|
7
|
-
declare const CommerceLayer: FunctionComponent<CommerceLayerProps>;
|
|
8
|
-
export default CommerceLayer;
|
|
1
|
+
import{FunctionComponent,ReactNode}from'react';declare type CommerceLayerProps={children:ReactNode;accessToken:string;endpoint:string;};declare const CommerceLayer:FunctionComponent<CommerceLayerProps>;export default CommerceLayer;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{__rest}from"tslib";import{jsx as _jsx}from"react/jsx-runtime";import CommerceLayerContext from"../context/CommerceLayerContext";import components from"../config/components";const propTypes=components.CommerceLayer.propTypes,CommerceLayer=props=>{const{children}=props,p=__rest(props,["children"]);return _jsx(CommerceLayerContext.Provider,Object.assign({value:Object.assign({},p)},{children})
|
|
1
|
+
import{__rest}from"tslib";import{jsx as _jsx}from"react/jsx-runtime";import CommerceLayerContext from"../context/CommerceLayerContext";import components from"../config/components";const propTypes=components.CommerceLayer.propTypes,CommerceLayer=props=>{const{children}=props,p=__rest(props,["children"]);return _jsx(CommerceLayerContext.Provider,Object.assign({value:Object.assign({},p)},{children}))};CommerceLayer.propTypes=propTypes;export default CommerceLayer;
|
|
@@ -1,7 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
export declare type CustomerContainer = {
|
|
3
|
-
children: ReactNode;
|
|
4
|
-
isGuest?: boolean;
|
|
5
|
-
};
|
|
6
|
-
declare const CustomerContainer: FunctionComponent<CustomerContainer>;
|
|
7
|
-
export default CustomerContainer;
|
|
1
|
+
import{FunctionComponent,ReactNode}from'react';export declare type CustomerContainer={children:ReactNode;isGuest?:boolean;};declare const CustomerContainer:FunctionComponent<CustomerContainer>;export default CustomerContainer;
|