@commercelayer/react-components 4.12.0-beta.1 → 4.13.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/cjs/components/MetadataInput.d.ts +0 -1
- package/lib/cjs/components/addresses/Address.d.ts +0 -1
- package/lib/cjs/components/addresses/AddressCountrySelector.d.ts +0 -1
- package/lib/cjs/components/addresses/AddressInput.d.ts +0 -1
- package/lib/cjs/components/addresses/AddressInputSelect.d.ts +0 -1
- package/lib/cjs/components/addresses/AddressStateSelector.d.ts +0 -1
- package/lib/cjs/components/addresses/AddressesEmpty.d.ts +0 -1
- package/lib/cjs/components/addresses/ShippingAddressContainer.d.ts +0 -1
- package/lib/cjs/components/auth/CommerceLayer.d.ts +0 -1
- package/lib/cjs/components/customers/CustomerContainer.d.ts +0 -1
- package/lib/cjs/components/customers/CustomerContainer.js +1 -1
- package/lib/cjs/components/customers/CustomerField.d.ts +0 -1
- package/lib/cjs/components/customers/CustomerInput.d.ts +0 -1
- package/lib/cjs/components/customers/CustomerPaymentSource.d.ts +0 -1
- package/lib/cjs/components/customers/CustomerPaymentSourceEmpty.d.ts +0 -1
- package/lib/cjs/components/customers/MyAccountLink.d.ts +0 -1
- package/lib/cjs/components/customers/MyAccountLink.js +1 -1
- package/lib/cjs/components/customers/MyIdentityLink.d.ts +0 -1
- package/lib/cjs/components/customers/MyIdentityLink.js +1 -1
- package/lib/cjs/components/errors/Errors.d.ts +0 -1
- package/lib/cjs/components/gift_cards/GiftCard.d.ts +0 -1
- package/lib/cjs/components/gift_cards/GiftCardCurrencySelector.d.ts +0 -1
- package/lib/cjs/components/gift_cards/GiftCardInput.d.ts +0 -1
- package/lib/cjs/components/gift_cards/GiftCardOrCouponCode.d.ts +0 -1
- package/lib/cjs/components/gift_cards/GiftCardOrCouponForm.d.ts +0 -1
- package/lib/cjs/components/gift_cards/GiftCardOrCouponForm.js +1 -1
- package/lib/cjs/components/gift_cards/GiftCardOrCouponInput.d.ts +0 -1
- package/lib/cjs/components/in_stock_subscriptions/InStockSubscriptionButton.d.ts +0 -1
- package/lib/cjs/components/in_stock_subscriptions/InStockSubscriptionsContainer.d.ts +0 -1
- package/lib/cjs/components/in_stock_subscriptions/InStockSubscriptionsContainer.js +1 -1
- package/lib/cjs/components/line_items/LineItem.d.ts +0 -1
- package/lib/cjs/components/line_items/LineItemAmount.d.ts +0 -1
- package/lib/cjs/components/line_items/LineItemCode.d.ts +0 -1
- package/lib/cjs/components/line_items/LineItemField.d.ts +0 -1
- package/lib/cjs/components/line_items/LineItemImage.d.ts +0 -1
- package/lib/cjs/components/line_items/LineItemName.d.ts +0 -1
- package/lib/cjs/components/line_items/LineItemsContainer.d.ts +0 -1
- package/lib/cjs/components/line_items/LineItemsContainer.js +1 -1
- package/lib/cjs/components/line_items/LineItemsCount.d.ts +0 -1
- package/lib/cjs/components/line_items/LineItemsEmpty.d.ts +0 -1
- package/lib/cjs/components/orders/AddToCartButton.js +1 -1
- package/lib/cjs/components/orders/AdjustmentAmount.d.ts +0 -1
- package/lib/cjs/components/orders/CartLink.js +1 -1
- package/lib/cjs/components/orders/CheckoutLink.d.ts +0 -1
- package/lib/cjs/components/orders/DiscountAmount.d.ts +0 -1
- package/lib/cjs/components/orders/GiftCardAmount.d.ts +0 -1
- package/lib/cjs/components/orders/HostedCart.js +1 -1
- package/lib/cjs/components/orders/OrderContainer.d.ts +0 -1
- package/lib/cjs/components/orders/OrderContainer.js +1 -1
- package/lib/cjs/components/orders/OrderList.d.ts +0 -1
- package/lib/cjs/components/orders/OrderListEmpty.d.ts +0 -1
- package/lib/cjs/components/orders/OrderListPaginationButtons.d.ts +0 -1
- package/lib/cjs/components/orders/OrderListPaginationInfo.d.ts +0 -1
- package/lib/cjs/components/orders/OrderListRow.d.ts +0 -1
- package/lib/cjs/components/orders/OrderNumber.d.ts +0 -1
- package/lib/cjs/components/orders/PaymentMethodAmount.d.ts +0 -1
- package/lib/cjs/components/orders/PlaceOrderButton.d.ts +4 -0
- package/lib/cjs/components/orders/PlaceOrderButton.js +1 -1
- package/lib/cjs/components/orders/PlaceOrderContainer.js +1 -1
- package/lib/cjs/components/orders/PrivacyAndTermsCheckbox.d.ts +0 -1
- package/lib/cjs/components/orders/ShippingAmount.d.ts +0 -1
- package/lib/cjs/components/orders/SubTotalAmount.d.ts +0 -1
- package/lib/cjs/components/orders/TaxesAmount.d.ts +0 -1
- package/lib/cjs/components/orders/TotalAmount.d.ts +0 -1
- package/lib/cjs/components/parcels/ParcelField.d.ts +0 -1
- package/lib/cjs/components/parcels/ParcelLineItem.d.ts +0 -1
- package/lib/cjs/components/parcels/ParcelLineItemField.d.ts +0 -1
- package/lib/cjs/components/parcels/ParcelLineItemsCount.d.ts +0 -1
- package/lib/cjs/components/parcels/Parcels.d.ts +0 -1
- package/lib/cjs/components/parcels/ParcelsCount.d.ts +0 -1
- package/lib/cjs/components/payment_gateways/AdyenGateway.d.ts +0 -1
- package/lib/cjs/components/payment_gateways/AdyenGateway.js +1 -1
- package/lib/cjs/components/payment_gateways/BraintreeGateway.d.ts +0 -1
- package/lib/cjs/components/payment_gateways/BraintreeGateway.js +1 -1
- package/lib/cjs/components/payment_gateways/CheckoutComGateway.d.ts +0 -1
- package/lib/cjs/components/payment_gateways/CheckoutComGateway.js +1 -1
- package/lib/cjs/components/payment_gateways/ExternalGateway.d.ts +0 -1
- package/lib/cjs/components/payment_gateways/ExternalGateway.js +1 -1
- package/lib/cjs/components/payment_gateways/KlarnaGateway.d.ts +0 -1
- package/lib/cjs/components/payment_gateways/KlarnaGateway.js +1 -1
- package/lib/cjs/components/payment_gateways/PaymentGateway.d.ts +0 -1
- package/lib/cjs/components/payment_gateways/PaymentGateway.js +1 -1
- package/lib/cjs/components/payment_gateways/PaypalGateway.d.ts +0 -1
- package/lib/cjs/components/payment_gateways/StripeGateway.d.ts +0 -1
- package/lib/cjs/components/payment_gateways/StripeGateway.js +1 -1
- package/lib/cjs/components/payment_gateways/WireTransferGateway.d.ts +0 -1
- package/lib/cjs/components/payment_methods/PaymentMethod.d.ts +0 -1
- package/lib/cjs/components/payment_methods/PaymentMethodName.d.ts +0 -1
- package/lib/cjs/components/payment_methods/PaymentMethodPrice.d.ts +0 -1
- package/lib/cjs/components/payment_source/BraintreePayment.d.ts +0 -1
- package/lib/cjs/components/payment_source/BraintreePayment.js +1 -1
- package/lib/cjs/components/payment_source/CheckoutComPayment.d.ts +0 -1
- package/lib/cjs/components/payment_source/ExternalPayment.d.ts +0 -1
- package/lib/cjs/components/payment_source/KlarnaPayment.d.ts +0 -1
- package/lib/cjs/components/payment_source/PaymentSource.d.ts +0 -1
- package/lib/cjs/components/payment_source/PaymentSourceBrandIcon.d.ts +0 -1
- package/lib/cjs/components/payment_source/PaymentSourceBrandName.d.ts +0 -1
- package/lib/cjs/components/payment_source/PaymentSourceDetail.d.ts +0 -1
- package/lib/cjs/components/payment_source/StripeExpressPayment.d.ts +0 -1
- package/lib/cjs/components/payment_source/StripePayment.d.ts +0 -1
- package/lib/cjs/components/payment_source/StripePayment.js +1 -1
- package/lib/cjs/components/payment_source/WireTransferPayment.d.ts +0 -1
- package/lib/cjs/components/prices/Price.d.ts +0 -1
- package/lib/cjs/components/prices/PricesContainer.d.ts +0 -1
- package/lib/cjs/components/shipments/ShipmentField.d.ts +0 -1
- package/lib/cjs/components/shipments/ShipmentsCount.d.ts +0 -1
- package/lib/cjs/components/shipping_methods/ShippingMethodName.d.ts +0 -1
- package/lib/cjs/components/shipping_methods/ShippingMethodPrice.d.ts +0 -1
- package/lib/cjs/components/shipping_methods/ShippingMethodRadioButton.d.ts +0 -1
- package/lib/cjs/components/skus/AvailabilityTemplate.d.ts +0 -1
- package/lib/cjs/components/skus/DeliveryLeadTime.d.ts +0 -1
- package/lib/cjs/components/skus/SkuField.d.ts +0 -1
- package/lib/cjs/components/stock_transfers/StockTransfer.d.ts +0 -1
- package/lib/cjs/components/stock_transfers/StockTransferField.d.ts +0 -1
- package/lib/cjs/components/utils/AddressCardsTemplate.d.ts +0 -1
- package/lib/cjs/components/utils/BaseOrderPrice.d.ts +0 -1
- package/lib/cjs/components/utils/PaymentCardsTemplate.d.ts +0 -1
- package/lib/cjs/components/utils/PriceTemplate.d.ts +0 -1
- package/lib/cjs/components/utils/getAllErrors.d.ts +0 -1
- package/lib/cjs/context/ExternalFunctionContext.js +1 -1
- package/lib/cjs/context/SkuContext.d.ts +1 -1
- package/lib/cjs/reducers/AddressReducer.js +1 -1
- package/lib/cjs/reducers/AvailabilityReducer.js +1 -1
- package/lib/cjs/reducers/CustomerReducer.js +1 -1
- package/lib/cjs/reducers/GiftCardReducer.js +1 -1
- package/lib/cjs/reducers/InStockSubscriptionReducer.js +1 -1
- package/lib/cjs/reducers/OrderReducer.js +1 -1
- package/lib/cjs/reducers/PaymentMethodReducer.js +1 -1
- package/lib/cjs/reducers/PlaceOrderReducer.js +1 -1
- package/lib/cjs/reducers/ShipmentReducer.js +1 -1
- package/lib/cjs/reducers/SkuListsReducer.js +1 -1
- package/lib/cjs/reducers/SkuReducer.js +1 -1
- package/lib/cjs/typings/globals.d.ts +0 -1
- package/lib/cjs/utils/addressesManager.js +1 -1
- package/lib/cjs/utils/expressPaymentHelper.js +1 -1
- package/lib/cjs/utils/filterChildren.d.ts +0 -1
- package/lib/cjs/utils/getLoaderComponent.d.ts +0 -1
- package/lib/cjs/utils/getPrices.d.ts +0 -1
- package/lib/cjs/utils/getSdk.js +1 -1
- package/lib/cjs/utils/organization.d.ts +13 -1
- package/lib/cjs/utils/organization.js +1 -1
- package/lib/cjs/utils/triggerAttributeHelper.js +1 -1
- package/lib/esm/components/MetadataInput.d.ts +0 -1
- package/lib/esm/components/addresses/Address.d.ts +0 -1
- package/lib/esm/components/addresses/AddressCountrySelector.d.ts +0 -1
- package/lib/esm/components/addresses/AddressInput.d.ts +0 -1
- package/lib/esm/components/addresses/AddressInputSelect.d.ts +0 -1
- package/lib/esm/components/addresses/AddressStateSelector.d.ts +0 -1
- package/lib/esm/components/addresses/AddressesEmpty.d.ts +0 -1
- package/lib/esm/components/addresses/ShippingAddressContainer.d.ts +0 -1
- package/lib/esm/components/auth/CommerceLayer.d.ts +0 -1
- package/lib/esm/components/customers/CustomerContainer.d.ts +0 -1
- package/lib/esm/components/customers/CustomerField.d.ts +0 -1
- package/lib/esm/components/customers/CustomerInput.d.ts +0 -1
- package/lib/esm/components/customers/CustomerPaymentSource.d.ts +0 -1
- package/lib/esm/components/customers/CustomerPaymentSourceEmpty.d.ts +0 -1
- package/lib/esm/components/customers/MyAccountLink.d.ts +0 -1
- package/lib/esm/components/customers/MyAccountLink.js +1 -1
- package/lib/esm/components/customers/MyIdentityLink.d.ts +0 -1
- package/lib/esm/components/customers/MyIdentityLink.js +1 -1
- package/lib/esm/components/errors/Errors.d.ts +0 -1
- package/lib/esm/components/gift_cards/GiftCard.d.ts +0 -1
- package/lib/esm/components/gift_cards/GiftCardCurrencySelector.d.ts +0 -1
- package/lib/esm/components/gift_cards/GiftCardInput.d.ts +0 -1
- package/lib/esm/components/gift_cards/GiftCardOrCouponCode.d.ts +0 -1
- package/lib/esm/components/gift_cards/GiftCardOrCouponForm.d.ts +0 -1
- package/lib/esm/components/gift_cards/GiftCardOrCouponForm.js +1 -1
- package/lib/esm/components/gift_cards/GiftCardOrCouponInput.d.ts +0 -1
- package/lib/esm/components/in_stock_subscriptions/InStockSubscriptionButton.d.ts +0 -1
- package/lib/esm/components/in_stock_subscriptions/InStockSubscriptionsContainer.d.ts +0 -1
- package/lib/esm/components/line_items/LineItem.d.ts +0 -1
- package/lib/esm/components/line_items/LineItemAmount.d.ts +0 -1
- package/lib/esm/components/line_items/LineItemCode.d.ts +0 -1
- package/lib/esm/components/line_items/LineItemField.d.ts +0 -1
- package/lib/esm/components/line_items/LineItemImage.d.ts +0 -1
- package/lib/esm/components/line_items/LineItemName.d.ts +0 -1
- package/lib/esm/components/line_items/LineItemsContainer.d.ts +0 -1
- package/lib/esm/components/line_items/LineItemsCount.d.ts +0 -1
- package/lib/esm/components/line_items/LineItemsEmpty.d.ts +0 -1
- package/lib/esm/components/orders/AddToCartButton.js +1 -1
- package/lib/esm/components/orders/AdjustmentAmount.d.ts +0 -1
- package/lib/esm/components/orders/CartLink.js +1 -1
- package/lib/esm/components/orders/CheckoutLink.d.ts +0 -1
- package/lib/esm/components/orders/DiscountAmount.d.ts +0 -1
- package/lib/esm/components/orders/GiftCardAmount.d.ts +0 -1
- package/lib/esm/components/orders/HostedCart.js +1 -1
- package/lib/esm/components/orders/OrderContainer.d.ts +0 -1
- package/lib/esm/components/orders/OrderList.d.ts +0 -1
- package/lib/esm/components/orders/OrderListEmpty.d.ts +0 -1
- package/lib/esm/components/orders/OrderListPaginationButtons.d.ts +0 -1
- package/lib/esm/components/orders/OrderListPaginationInfo.d.ts +0 -1
- package/lib/esm/components/orders/OrderListRow.d.ts +0 -1
- package/lib/esm/components/orders/OrderNumber.d.ts +0 -1
- package/lib/esm/components/orders/PaymentMethodAmount.d.ts +0 -1
- package/lib/esm/components/orders/PlaceOrderButton.d.ts +4 -0
- package/lib/esm/components/orders/PlaceOrderButton.js +1 -1
- package/lib/esm/components/orders/PrivacyAndTermsCheckbox.d.ts +0 -1
- package/lib/esm/components/orders/ShippingAmount.d.ts +0 -1
- package/lib/esm/components/orders/SubTotalAmount.d.ts +0 -1
- package/lib/esm/components/orders/TaxesAmount.d.ts +0 -1
- package/lib/esm/components/orders/TotalAmount.d.ts +0 -1
- package/lib/esm/components/parcels/ParcelField.d.ts +0 -1
- package/lib/esm/components/parcels/ParcelLineItem.d.ts +0 -1
- package/lib/esm/components/parcels/ParcelLineItemField.d.ts +0 -1
- package/lib/esm/components/parcels/ParcelLineItemsCount.d.ts +0 -1
- package/lib/esm/components/parcels/Parcels.d.ts +0 -1
- package/lib/esm/components/parcels/ParcelsCount.d.ts +0 -1
- package/lib/esm/components/payment_gateways/AdyenGateway.d.ts +0 -1
- package/lib/esm/components/payment_gateways/AdyenGateway.js +1 -1
- package/lib/esm/components/payment_gateways/BraintreeGateway.d.ts +0 -1
- package/lib/esm/components/payment_gateways/BraintreeGateway.js +1 -1
- package/lib/esm/components/payment_gateways/CheckoutComGateway.d.ts +0 -1
- package/lib/esm/components/payment_gateways/CheckoutComGateway.js +1 -1
- package/lib/esm/components/payment_gateways/ExternalGateway.d.ts +0 -1
- package/lib/esm/components/payment_gateways/ExternalGateway.js +1 -1
- package/lib/esm/components/payment_gateways/KlarnaGateway.d.ts +0 -1
- package/lib/esm/components/payment_gateways/KlarnaGateway.js +1 -1
- package/lib/esm/components/payment_gateways/PaymentGateway.d.ts +0 -1
- package/lib/esm/components/payment_gateways/PaymentGateway.js +1 -1
- package/lib/esm/components/payment_gateways/PaypalGateway.d.ts +0 -1
- package/lib/esm/components/payment_gateways/StripeGateway.d.ts +0 -1
- package/lib/esm/components/payment_gateways/StripeGateway.js +1 -1
- package/lib/esm/components/payment_gateways/WireTransferGateway.d.ts +0 -1
- package/lib/esm/components/payment_methods/PaymentMethod.d.ts +0 -1
- package/lib/esm/components/payment_methods/PaymentMethodName.d.ts +0 -1
- package/lib/esm/components/payment_methods/PaymentMethodPrice.d.ts +0 -1
- package/lib/esm/components/payment_source/BraintreePayment.d.ts +0 -1
- package/lib/esm/components/payment_source/CheckoutComPayment.d.ts +0 -1
- package/lib/esm/components/payment_source/ExternalPayment.d.ts +0 -1
- package/lib/esm/components/payment_source/KlarnaPayment.d.ts +0 -1
- package/lib/esm/components/payment_source/PaymentSource.d.ts +0 -1
- package/lib/esm/components/payment_source/PaymentSourceBrandIcon.d.ts +0 -1
- package/lib/esm/components/payment_source/PaymentSourceBrandName.d.ts +0 -1
- package/lib/esm/components/payment_source/PaymentSourceDetail.d.ts +0 -1
- package/lib/esm/components/payment_source/StripeExpressPayment.d.ts +0 -1
- package/lib/esm/components/payment_source/StripePayment.d.ts +0 -1
- package/lib/esm/components/payment_source/WireTransferPayment.d.ts +0 -1
- package/lib/esm/components/prices/Price.d.ts +0 -1
- package/lib/esm/components/prices/PricesContainer.d.ts +0 -1
- package/lib/esm/components/shipments/ShipmentField.d.ts +0 -1
- package/lib/esm/components/shipments/ShipmentsCount.d.ts +0 -1
- package/lib/esm/components/shipping_methods/ShippingMethodName.d.ts +0 -1
- package/lib/esm/components/shipping_methods/ShippingMethodPrice.d.ts +0 -1
- package/lib/esm/components/shipping_methods/ShippingMethodRadioButton.d.ts +0 -1
- package/lib/esm/components/skus/AvailabilityTemplate.d.ts +0 -1
- package/lib/esm/components/skus/DeliveryLeadTime.d.ts +0 -1
- package/lib/esm/components/skus/SkuField.d.ts +0 -1
- package/lib/esm/components/stock_transfers/StockTransfer.d.ts +0 -1
- package/lib/esm/components/stock_transfers/StockTransferField.d.ts +0 -1
- package/lib/esm/components/utils/AddressCardsTemplate.d.ts +0 -1
- package/lib/esm/components/utils/BaseOrderPrice.d.ts +0 -1
- package/lib/esm/components/utils/PaymentCardsTemplate.d.ts +0 -1
- package/lib/esm/components/utils/PriceTemplate.d.ts +0 -1
- package/lib/esm/components/utils/getAllErrors.d.ts +0 -1
- package/lib/esm/context/SkuContext.d.ts +1 -1
- package/lib/esm/reducers/CustomerReducer.js +1 -1
- package/lib/esm/reducers/OrderReducer.js +1 -1
- package/lib/esm/typings/globals.d.ts +0 -1
- package/lib/esm/utils/filterChildren.d.ts +0 -1
- package/lib/esm/utils/getLoaderComponent.d.ts +0 -1
- package/lib/esm/utils/getPrices.d.ts +0 -1
- package/lib/esm/utils/getSdk.js +1 -1
- package/lib/esm/utils/organization.d.ts +13 -1
- package/lib/esm/utils/organization.js +1 -1
- package/package.json +15 -14
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
1
|
import { type ConditionalElement } from '../../typings/index';
|
|
3
2
|
import { type TGenericChildrenProps, type TResources } from '../utils/GenericFieldComponent';
|
|
4
3
|
type LineItemFieldChildrenProps = TGenericChildrenProps<TResources['LineItem']>;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import{jsx as _jsx}from"react/jsx-runtime";import{useContext}from"react";import Parent from"../utils/Parent";import OrderContext from"../../context/OrderContext";import SkuListsContext from"../../context/SkuListsContext";import ExternalFunctionContext from"../../context/ExternalFunctionContext";import SkuChildrenContext from"../../context/SkuChildrenContext";import{getApplicationLink}from"../../utils/getApplicationLink";import CommerceLayerContext from"../../context/CommerceLayerContext";import useCustomContext from"../../utils/hooks/useCustomContext";import{getDomain}from"../../utils/getDomain";import{publish}from"../../utils/events";export function AddToCartButton(props){const{label="Add to cart",children,skuCode,bundleCode,skuListId,lineItem,buyNowMode=!1,checkoutUrl,redirectToHostedCart,hostedCartUrl,quantity,lineItemOption,protocol="https",...p}=props,{accessToken,endpoint}=useCustomContext({context:CommerceLayerContext,contextComponentName:"CommerceLayer",currentComponentName:"AddToCartButton",key:"accessToken"}),{addToCart,orderId,getOrder,setOrderErrors}=useCustomContext({context:OrderContext,contextComponentName:"OrderContainer",currentComponentName:"AddToCartButton",key:"addToCart"}),{url,callExternalFunction}=useContext(ExternalFunctionContext),{skuLists}=useContext(SkuListsContext),{sku}=useContext(SkuChildrenContext),sCode=sku?.code??skuCode,handleClick=async()=>{const qty=quantity!=null?parseInt(quantity):1;if(skuLists!=null&&skuListId&&url&&skuListId in skuLists){const lineItems=skuLists?.[skuListId]?.map(skuCode2=>({skuCode:skuCode2,quantity:qty,_update_quantity:1}));return await callExternalFunction({url,data:{resourceType:"orders",inputs:[{id:orderId,lineItems}]}}).then(async res=>(getOrder&&orderId&&await getOrder(orderId),publish("open-cart"),res)).catch(({response})=>(setOrderErrors&&setOrderErrors(response.data),response))}if(!url&&addToCart!=null){const res=await addToCart({bundleCode,skuCode:sCode,quantity:qty,lineItemOption,lineItem,buyNowMode,checkoutUrl});if(redirectToHostedCart&&accessToken!=null&&endpoint!=null){const{slug,domain}=getDomain(endpoint),orderId2=res?.orderId;hostedCartUrl&&orderId2?location.href=`${protocol}://${hostedCartUrl}/${orderId2}?accessToken=${accessToken}`:orderId2&&slug&&(location.href=getApplicationLink({orderId:orderId2,slug,accessToken,domain,applicationType:"cart"}))}return publish("open-cart"),res}else if(url)return await callExternalFunction({url,data:{bundleCode,skuCode:sCode,quantity:qty,lineItemOption,lineItem,buyNowMode,checkoutUrl}}).then(async res=>(getOrder&&orderId&&await getOrder(orderId),publish("open-cart"),res)).catch(({response})=>(setOrderErrors&&setOrderErrors(response.data),response))},parentProps={handleClick,label,...props};return children?_jsx(Parent,{...parentProps,children}):_jsx("button",{...p,onClick:()=>{handleClick()},children:label})}export default AddToCartButton;
|
|
2
|
+
import{jsx as _jsx}from"react/jsx-runtime";import{useContext}from"react";import Parent from"../utils/Parent";import OrderContext from"../../context/OrderContext";import SkuListsContext from"../../context/SkuListsContext";import ExternalFunctionContext from"../../context/ExternalFunctionContext";import SkuChildrenContext from"../../context/SkuChildrenContext";import{getApplicationLink}from"../../utils/getApplicationLink";import CommerceLayerContext from"../../context/CommerceLayerContext";import useCustomContext from"../../utils/hooks/useCustomContext";import{getDomain}from"../../utils/getDomain";import{publish}from"../../utils/events";export function AddToCartButton(props){const{label="Add to cart",children,skuCode,bundleCode,skuListId,lineItem,buyNowMode=!1,checkoutUrl,redirectToHostedCart,hostedCartUrl,quantity,lineItemOption,protocol="https",...p}=props,{accessToken,endpoint}=useCustomContext({context:CommerceLayerContext,contextComponentName:"CommerceLayer",currentComponentName:"AddToCartButton",key:"accessToken"}),{addToCart,orderId,getOrder,setOrderErrors}=useCustomContext({context:OrderContext,contextComponentName:"OrderContainer",currentComponentName:"AddToCartButton",key:"addToCart"}),{url,callExternalFunction}=useContext(ExternalFunctionContext),{skuLists}=useContext(SkuListsContext),{sku}=useContext(SkuChildrenContext),sCode=sku?.code??skuCode,handleClick=async()=>{const qty=quantity!=null?parseInt(quantity):1;if(skuLists!=null&&skuListId&&url&&skuListId in skuLists){const lineItems=skuLists?.[skuListId]?.map(skuCode2=>({skuCode:skuCode2,quantity:qty,_update_quantity:1}));return await callExternalFunction({url,data:{resourceType:"orders",inputs:[{id:orderId,lineItems}]}}).then(async res=>(getOrder&&orderId&&await getOrder(orderId),buyNowMode||publish("open-cart"),res)).catch(({response})=>(setOrderErrors&&setOrderErrors(response.data),response))}if(!url&&addToCart!=null){const res=await addToCart({bundleCode,skuCode:sCode,quantity:qty,lineItemOption,lineItem,buyNowMode,checkoutUrl});if(redirectToHostedCart&&accessToken!=null&&endpoint!=null){const{slug,domain}=getDomain(endpoint),orderId2=res?.orderId;hostedCartUrl&&orderId2?location.href=`${protocol}://${hostedCartUrl}/${orderId2}?accessToken=${accessToken}`:orderId2&&slug&&(location.href=getApplicationLink({orderId:orderId2,slug,accessToken,domain,applicationType:"cart"}))}return buyNowMode||publish("open-cart"),res}else if(url)return await callExternalFunction({url,data:{bundleCode,skuCode:sCode,quantity:qty,lineItemOption,lineItem,buyNowMode,checkoutUrl}}).then(async res=>(getOrder&&orderId&&await getOrder(orderId),buyNowMode||publish("open-cart"),res)).catch(({response})=>(setOrderErrors&&setOrderErrors(response.data),response))},parentProps={handleClick,label,...props};return children?_jsx(Parent,{...parentProps,children}):_jsx("button",{...p,onClick:()=>{handleClick()},children:label})}export default AddToCartButton;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import{jsx as _jsx}from"react/jsx-runtime";import{useContext}from"react";import OrderContext from"../../context/OrderContext";import Parent from"../utils/Parent";import CommerceLayerContext from"../../context/CommerceLayerContext";import{getApplicationLink}from"../../utils/getApplicationLink";import{getDomain}from"../../utils/getDomain";import{publish}from"../../utils/events";export function CartLink(props){const{label,children,type,customDomain,...p}=props,{order,createOrder}=useContext(OrderContext),{accessToken,endpoint}=useContext(CommerceLayerContext);if(accessToken==null)throw new Error("Cannot use `CartLink` outside of `CommerceLayer`");if(endpoint==null)throw new Error("Cannot use `CartLink` outside of `CommerceLayer`");const{domain,slug}=getDomain(endpoint),href=slug&&order?.id?getApplicationLink({slug,orderId:order?.id,accessToken,domain,applicationType:"cart",customDomain}):void 0,handleClick=async event=>{if(event.preventDefault(),type!=="mini")if(order?.id)location.href=href??""
|
|
2
|
+
import{jsx as _jsx}from"react/jsx-runtime";import{useContext}from"react";import OrderContext from"../../context/OrderContext";import Parent from"../utils/Parent";import CommerceLayerContext from"../../context/CommerceLayerContext";import{getApplicationLink}from"../../utils/getApplicationLink";import{getDomain}from"../../utils/getDomain";import{publish}from"../../utils/events";import{getOrganizationConfig}from"../../utils/organization";export function CartLink(props){const{label,children,type,customDomain,...p}=props,{order,createOrder}=useContext(OrderContext),{accessToken,endpoint}=useContext(CommerceLayerContext);if(accessToken==null)throw new Error("Cannot use `CartLink` outside of `CommerceLayer`");if(endpoint==null)throw new Error("Cannot use `CartLink` outside of `CommerceLayer`");const{domain,slug}=getDomain(endpoint),href=slug&&order?.id?getApplicationLink({slug,orderId:order?.id,accessToken,domain,applicationType:"cart",customDomain}):void 0,handleClick=async event=>{if(event.preventDefault(),type!=="mini")if(order?.id){const config=await getOrganizationConfig({accessToken,endpoint,params:{orderId:order?.id,accessToken}});location.href=config?.links?.cart??href??""}else{const orderId=await createOrder({}),config=await getOrganizationConfig({accessToken,endpoint,params:{orderId:order?.id,accessToken}});slug&&(location.href=config?.links?.cart??getApplicationLink({slug,orderId,accessToken,domain,applicationType:"cart",customDomain}))}else publish("open-cart")},parentProps={handleClick,label,href,orderId:order?.id,accessToken,...p};return accessToken?children?_jsx(Parent,{...parentProps,children}):_jsx("a",{href,onClick:e=>{handleClick(e)},...p,children:label}):null}export default CartLink;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import{jsx as _jsx,jsxs as _jsxs,Fragment as _Fragment}from"react/jsx-runtime";import CommerceLayerContext from"../../context/CommerceLayerContext";import OrderContext from"../../context/OrderContext";import OrderStorageContext from"../../context/OrderStorageContext";import{getApplicationLink}from"../../utils/getApplicationLink";import{getDomain}from"../../utils/getDomain";import useCustomContext from"../../utils/hooks/useCustomContext";import{useContext,useEffect,useState,useRef}from"react";import{iframeResizer}from"iframe-resizer";import{subscribe,unsubscribe}from"../../utils/events";const defaultIframeStyle={width:"1px",minWidth:"100%",minHeight:"100%",border:"none"},defaultContainerStyle={position:"fixed",top:"0",right:"-25rem",height:"100%",width:"23rem",transition:"right 0.5s ease-in-out",pointerEvents:"none",overflow:"auto"},defaultBackgroundStyle={opacity:"0",position:"fixed",top:"0",left:"0",height:"100%",width:"100vw",transition:"opacity 0.5s ease-in-out",pointerEvents:"none",backgroundColor:"black"},defaultIconStyle={width:"1.25rem",height:"1.25rem"},defaultIconContainer={textAlign:"left",paddingLeft:"20px",paddingTop:"20px",background:"#ffffff",color:"#686E6E"},defaultStyle={cart:defaultIframeStyle,container:defaultContainerStyle,background:defaultBackgroundStyle,icon:defaultIconStyle,iconContainer:defaultIconContainer};export function HostedCart({type,openAdd=!1,style,open=!1,handleOpen,customDomain,...props}){const[isOpen,setOpen]=useState(!1),ref=useRef(null),{accessToken,endpoint}=useCustomContext({context:CommerceLayerContext,contextComponentName:"CommerceLayer",currentComponentName:"HostedCart",key:"accessToken"}),[src,setSrc]=useState();if(accessToken==null||endpoint==null)return null;const{order,createOrder,getOrder}=useContext(OrderContext),{persistKey}=useContext(OrderStorageContext),{domain,slug}=getDomain(endpoint);async function setOrder(openCart){const orderId=localStorage.getItem(persistKey)??await createOrder({});orderId!=null&&accessToken&&(setSrc(getApplicationLink({slug,orderId,accessToken,domain,applicationType:"cart",customDomain})),openCart&&setTimeout(()=>{handleOpen!=null?handleOpen():setOpen(!0)},300)
|
|
2
|
+
import{jsx as _jsx,jsxs as _jsxs,Fragment as _Fragment}from"react/jsx-runtime";import CommerceLayerContext from"../../context/CommerceLayerContext";import OrderContext from"../../context/OrderContext";import OrderStorageContext from"../../context/OrderStorageContext";import{getApplicationLink}from"../../utils/getApplicationLink";import{getDomain}from"../../utils/getDomain";import useCustomContext from"../../utils/hooks/useCustomContext";import{useContext,useEffect,useState,useRef}from"react";import{iframeResizer}from"iframe-resizer";import{subscribe,unsubscribe}from"../../utils/events";import{getOrganizationConfig}from"../../utils/organization";const defaultIframeStyle={width:"1px",minWidth:"100%",minHeight:"100%",border:"none"},defaultContainerStyle={position:"fixed",top:"0",right:"-25rem",height:"100%",width:"23rem",transition:"right 0.5s ease-in-out",pointerEvents:"none",overflow:"auto"},defaultBackgroundStyle={opacity:"0",position:"fixed",top:"0",left:"0",height:"100%",width:"100vw",transition:"opacity 0.5s ease-in-out",pointerEvents:"none",backgroundColor:"black"},defaultIconStyle={width:"1.25rem",height:"1.25rem"},defaultIconContainer={textAlign:"left",paddingLeft:"20px",paddingTop:"20px",background:"#ffffff",color:"#686E6E"},defaultStyle={cart:defaultIframeStyle,container:defaultContainerStyle,background:defaultBackgroundStyle,icon:defaultIconStyle,iconContainer:defaultIconContainer};export function HostedCart({type,openAdd=!1,style,open=!1,handleOpen,customDomain,...props}){const[isOpen,setOpen]=useState(!1),ref=useRef(null),{accessToken,endpoint}=useCustomContext({context:CommerceLayerContext,contextComponentName:"CommerceLayer",currentComponentName:"HostedCart",key:"accessToken"}),[src,setSrc]=useState();if(accessToken==null||endpoint==null)return null;const{order,createOrder,getOrder}=useContext(OrderContext),{persistKey}=useContext(OrderStorageContext),{domain,slug}=getDomain(endpoint);async function setOrder(openCart){const orderId=localStorage.getItem(persistKey)??await createOrder({});if(orderId!=null&&accessToken&&endpoint){const config=await getOrganizationConfig({accessToken,endpoint,params:{orderId:order?.id,accessToken}});setSrc(config?.links?.cart??getApplicationLink({slug,orderId,accessToken,domain,applicationType:"cart",customDomain})),openCart&&setTimeout(()=>{handleOpen!=null?handleOpen():setOpen(!0)},300)}}function onMessage(data){switch(data.message.type){case"update":data.message.payload!=null&&getOrder(data.message.payload.id);break;case"close":type==="mini"&&(handleOpen!=null?handleOpen():setOpen(!1));break;case"blur":type==="mini"&&isOpen&&ref.current?.focus();break}}useEffect(()=>{const orderId=localStorage.getItem(persistKey);let ignore=!1;return open!=null&&open!==isOpen&&setOpen(open),openAdd&&type==="mini"&&subscribe("open-cart",()=>{window.document.body.style.overflow="hidden",src==null&&order?.id==null&&orderId==null?setOrder(!0):(src!=null&&ref.current!=null&&(ref.current.src=src),setTimeout(()=>{handleOpen!=null?handleOpen():setOpen(!0)},300))}),src==null&&order?.id==null&&orderId==null&&accessToken!=null&&!ignore&&isOpen?setOrder():src==null&&(order?.id!=null||orderId!=null)&&accessToken&&getOrganizationConfig({accessToken,endpoint,params:{orderId:order?.id,accessToken}}).then(config=>{setSrc(config?.links?.cart??getApplicationLink({slug,orderId:order?.id??orderId??"",accessToken,domain,applicationType:"cart"}))}),src!=null&&ref.current!=null&&(ref.current.src=src),()=>{ignore=!0,openAdd&&type==="mini"&&unsubscribe("open-cart",()=>{})}},[src,open,order?.id,accessToken]),useEffect(()=>{ref.current!=null&&iframeResizer({checkOrigin:!1,bodyPadding:"20px",onMessage},ref.current)},[ref.current!=null]);function onCloseCart(){window.document.body.style.removeProperty("overflow"),handleOpen!=null?handleOpen():setOpen(!1)}return src==null?null:type==="mini"?_jsxs(_Fragment,{children:[_jsx("div",{"aria-hidden":"true",style:{...defaultStyle.background,...style?.background,opacity:isOpen?"0.5":defaultStyle.background?.opacity,pointerEvents:isOpen?"initial":defaultStyle.background?.pointerEvents},onClick:onCloseCart}),_jsxs("div",{style:{...defaultStyle.container,...style?.container,right:isOpen?"0":defaultStyle.container?.right,pointerEvents:isOpen?"initial":defaultStyle.container?.pointerEvents},...props,children:[_jsx("div",{style:{...defaultStyle.iconContainer,...style?.iconContainer},children:_jsx("svg",{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",strokeWidth:1.5,stroke:"currentColor",style:{...defaultStyle.icon,...style?.icon},onClick:onCloseCart,children:_jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M6 18L18 6M6 6l12 12"})})}),_jsx("iframe",{title:"Cart",ref,style:{...defaultStyle.cart,...style?.cart},src,width:"100%",height:"100%"})]})]}):_jsx("iframe",{title:"Cart",ref,style:{...defaultStyle.cart,...style?.cart},src,width:"100%",height:"100%"})}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
1
|
import { type TOrderList, type InitialOrderListContext, type OrderListContent } from '../../context/OrderListChildrenContext';
|
|
3
2
|
import { type ColumnDef, type SortingState } from '@tanstack/react-table';
|
|
4
3
|
import type { DefaultChildrenType, TRange } from '../../typings/globals';
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
1
|
import { type OrderListPaginationContext as TOrderListPaginationContext } from '../../context/OrderListPaginationContext';
|
|
3
2
|
import { type ChildrenFunction } from '../../typings/index';
|
|
4
3
|
interface PaginationButton extends Omit<JSX.IntrinsicElements['button'], 'children' | 'disabled'> {
|
|
@@ -14,6 +14,10 @@ interface Props extends Omit<JSX.IntrinsicElements['button'], 'children' | 'onCl
|
|
|
14
14
|
* The label of the button
|
|
15
15
|
*/
|
|
16
16
|
label?: string | ReactNode;
|
|
17
|
+
/**
|
|
18
|
+
* The label of the button when it's loading
|
|
19
|
+
*/
|
|
20
|
+
loadingLabel?: string | ReactNode;
|
|
17
21
|
/**
|
|
18
22
|
* If false, the button doesn't place the order automatically. Default: true
|
|
19
23
|
*/
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import{jsx as _jsx}from"react/jsx-runtime";import{useContext,useEffect,useRef,useState}from"react";import Parent from"../utils/Parent";import PlaceOrderContext from"../../context/PlaceOrderContext";import isFunction from"lodash/isFunction";import PaymentMethodContext from"../../context/PaymentMethodContext";import OrderContext from"../../context/OrderContext";import getCardDetails from"../../utils/getCardDetails";export function PlaceOrderButton(props){const ref=useRef(null),{children,label="Place order",autoPlaceOrder=!0,disabled,onClick,...p}=props,{isPermitted,setPlaceOrder,options,paymentType,setButtonRef}=useContext(PlaceOrderContext),[notPermitted,setNotPermitted]=useState(!0),[forceDisable,setForceDisable]=useState(disabled),{currentPaymentMethodRef,loading,currentPaymentMethodType,paymentSource,setPaymentSource,setPaymentMethodErrors,currentCustomerPaymentSourceId}=useContext(PaymentMethodContext),{order}=useContext(OrderContext),isFree=order?.total_amount_with_taxes_cents===0;useEffect(()=>{if(loading)setNotPermitted(loading);else if(paymentType===currentPaymentMethodType&&paymentType){const card=getCardDetails({customerPayment:{payment_source:paymentSource},paymentType});currentCustomerPaymentSourceId!=null&&paymentSource?.id===currentCustomerPaymentSourceId&&card.brand===""&&(card.brand="credit-card"),(isFree&&isPermitted||currentPaymentMethodRef?.current?.onsubmit||card.brand)&&isPermitted&&setNotPermitted(!1)}else setNotPermitted(!(isFree&&isPermitted));return()=>{setNotPermitted(!0)}},[isPermitted,paymentType,currentPaymentMethodRef?.current?.onsubmit,loading,currentPaymentMethodType,order,paymentSource]),useEffect(()=>{paymentType==="paypal_payments"&&options?.paypalPayerId&&order?.status&&["draft","pending"].includes(order?.status)&&autoPlaceOrder&&handleClick()},[options?.paypalPayerId,paymentType]),useEffect(()=>{paymentType==="stripe_payments"&&["succeeded","pending"].includes(options?.stripe?.redirectStatus??"")&&order?.status&&["draft","pending"].includes(order?.status)&&autoPlaceOrder&&handleClick()},[options?.stripe?.redirectStatus,paymentType]),useEffect(()=>{if(order?.status!=null&&["draft","pending"].includes(order?.status))if(paymentType==="adyen_payments"&&options?.adyen?.redirectResult&&paymentSource!=null){const attributes={payment_request_details:{details:{redirectResult:options?.adyen?.redirectResult}},_details:1};setPaymentSource({paymentSourceId:paymentSource?.id,paymentResource:"adyen_payments",attributes}).then(res=>{const resultCode=res?.payment_response?.resultCode,errorCode=res?.payment_response?.errorCode,message=res?.payment_response?.message;["Authorised","Pending","Received"].includes(resultCode)&&autoPlaceOrder?handleClick():errorCode!=null&&setPaymentMethodErrors([{code:"PAYMENT_INTENT_AUTHENTICATION_FAILURE",resource:"payment_methods",field:currentPaymentMethodType,message}])})}else(paymentType==="adyen_payments"&&options?.adyen?.MD&&options?.adyen?.PaRes&&autoPlaceOrder||paymentType==="adyen_payments"&&order?.payment_source?.payment_response?.resultCode==="Authorised"&&ref?.current?.disabled===!1&¤tCustomerPaymentSourceId==null&&autoPlaceOrder)&&handleClick()},[options?.adyen,paymentType,order?.payment_source?.payment_response?.resultCode]),useEffect(()=>{paymentType==="checkout_com_payments"&&options?.checkoutCom?.session_id&&order?.status&&["draft","pending"].includes(order?.status)&&autoPlaceOrder&&handleClick()},[options?.checkoutCom,paymentType]),useEffect(()=>{ref?.current!=null&&setButtonRef!=null&&setButtonRef(ref)},[ref]);const handleClick=async e=>{e?.preventDefault(),e?.stopPropagation();let isValid=!0;setForceDisable(!0);const checkPaymentSource=await setPaymentSource({paymentResource:paymentType,paymentSourceId:paymentSource?.id}),card=paymentType&&getCardDetails({paymentType,customerPayment:{payment_source:checkPaymentSource}});currentPaymentMethodRef?.current?.onsubmit&&[!options?.paypalPayerId,!options?.adyen?.MD,!options?.checkoutCom?.session_id].every(Boolean)?(isValid=await currentPaymentMethodRef.current?.onsubmit({paymentSource:checkPaymentSource,setPlaceOrder,onclickCallback:onClick}),!isValid&&checkPaymentSource.payment_response?.resultCode==="Authorised"&&(isValid=!0)):card?.brand&&(isValid=!0);const placed=isValid&&setPlaceOrder&&(checkPaymentSource||isFree)&&await setPlaceOrder({paymentSource:checkPaymentSource,currentCustomerPaymentSourceId});setForceDisable(!1),onClick&&placed&&onClick(placed)},disabledButton=disabled!==void 0?disabled:notPermitted,parentProps={...p,label,disabled:disabledButton,handleClick,ref};return children?_jsx(Parent,{...parentProps,children}):_jsx("button",{ref,type:"button",disabled:disabledButton||forceDisable,onClick:e=>{handleClick(e)},...p,children:
|
|
2
|
+
import{jsx as _jsx}from"react/jsx-runtime";import{useContext,useEffect,useRef,useState}from"react";import Parent from"../utils/Parent";import PlaceOrderContext from"../../context/PlaceOrderContext";import isFunction from"lodash/isFunction";import PaymentMethodContext from"../../context/PaymentMethodContext";import OrderContext from"../../context/OrderContext";import getCardDetails from"../../utils/getCardDetails";export function PlaceOrderButton(props){const ref=useRef(null),{children,label="Place order",loadingLabel="Placing...",autoPlaceOrder=!0,disabled,onClick,...p}=props,{isPermitted,setPlaceOrder,options,paymentType,setButtonRef}=useContext(PlaceOrderContext),[notPermitted,setNotPermitted]=useState(!0),[forceDisable,setForceDisable]=useState(disabled),[isLoading,setIsLoading]=useState(!1),{currentPaymentMethodRef,loading,currentPaymentMethodType,paymentSource,setPaymentSource,setPaymentMethodErrors,currentCustomerPaymentSourceId}=useContext(PaymentMethodContext),{order}=useContext(OrderContext),isFree=order?.total_amount_with_taxes_cents===0;useEffect(()=>{if(loading)setNotPermitted(loading);else if(paymentType===currentPaymentMethodType&&paymentType){const card=getCardDetails({customerPayment:{payment_source:paymentSource},paymentType});currentCustomerPaymentSourceId!=null&&paymentSource?.id===currentCustomerPaymentSourceId&&card.brand===""&&(card.brand="credit-card"),(isFree&&isPermitted||currentPaymentMethodRef?.current?.onsubmit||card.brand)&&isPermitted&&setNotPermitted(!1)}else setNotPermitted(!(isFree&&isPermitted));return()=>{setNotPermitted(!0)}},[isPermitted,paymentType,currentPaymentMethodRef?.current?.onsubmit,loading,currentPaymentMethodType,order,paymentSource]),useEffect(()=>{paymentType==="paypal_payments"&&options?.paypalPayerId&&order?.status&&["draft","pending"].includes(order?.status)&&autoPlaceOrder&&handleClick()},[options?.paypalPayerId,paymentType]),useEffect(()=>{paymentType==="stripe_payments"&&["succeeded","pending"].includes(options?.stripe?.redirectStatus??"")&&order?.status&&["draft","pending"].includes(order?.status)&&autoPlaceOrder&&handleClick()},[options?.stripe?.redirectStatus,paymentType]),useEffect(()=>{if(order?.status!=null&&["draft","pending"].includes(order?.status))if(paymentType==="adyen_payments"&&options?.adyen?.redirectResult&&paymentSource!=null){const attributes={payment_request_details:{details:{redirectResult:options?.adyen?.redirectResult}},_details:1};setPaymentSource({paymentSourceId:paymentSource?.id,paymentResource:"adyen_payments",attributes}).then(res=>{const resultCode=res?.payment_response?.resultCode,errorCode=res?.payment_response?.errorCode,message=res?.payment_response?.message;["Authorised","Pending","Received"].includes(resultCode)&&autoPlaceOrder?handleClick():errorCode!=null&&setPaymentMethodErrors([{code:"PAYMENT_INTENT_AUTHENTICATION_FAILURE",resource:"payment_methods",field:currentPaymentMethodType,message}])})}else(paymentType==="adyen_payments"&&options?.adyen?.MD&&options?.adyen?.PaRes&&autoPlaceOrder||paymentType==="adyen_payments"&&order?.payment_source?.payment_response?.resultCode==="Authorised"&&ref?.current?.disabled===!1&¤tCustomerPaymentSourceId==null&&autoPlaceOrder)&&handleClick()},[options?.adyen,paymentType,order?.payment_source?.payment_response?.resultCode]),useEffect(()=>{paymentType==="checkout_com_payments"&&options?.checkoutCom?.session_id&&order?.status&&["draft","pending"].includes(order?.status)&&autoPlaceOrder&&handleClick()},[options?.checkoutCom,paymentType]),useEffect(()=>{ref?.current!=null&&setButtonRef!=null&&setButtonRef(ref)},[ref]);const handleClick=async e=>{e?.preventDefault(),e?.stopPropagation(),setIsLoading(!0);let isValid=!0;setForceDisable(!0);const checkPaymentSource=await setPaymentSource({paymentResource:paymentType,paymentSourceId:paymentSource?.id}),card=paymentType&&getCardDetails({paymentType,customerPayment:{payment_source:checkPaymentSource}});currentPaymentMethodRef?.current?.onsubmit&&[!options?.paypalPayerId,!options?.adyen?.MD,!options?.checkoutCom?.session_id].every(Boolean)?(isValid=await currentPaymentMethodRef.current?.onsubmit({paymentSource:checkPaymentSource,setPlaceOrder,onclickCallback:onClick}),!isValid&&checkPaymentSource.payment_response?.resultCode==="Authorised"&&(isValid=!0)):card?.brand&&(isValid=!0);const placed=isValid&&setPlaceOrder&&(checkPaymentSource||isFree)&&await setPlaceOrder({paymentSource:checkPaymentSource,currentCustomerPaymentSourceId});setForceDisable(!1),onClick&&placed&&onClick(placed),setIsLoading(!1)},disabledButton=disabled!==void 0?disabled:notPermitted,labelButton=isLoading?loadingLabel:isFunction(label)?label():label,parentProps={...p,label,disabled:disabledButton,handleClick,parentRef:ref,isLoading};return children?_jsx(Parent,{...parentProps,children}):_jsx("button",{ref,type:"button",disabled:disabledButton||forceDisable,onClick:e=>{handleClick(e)},...p,children:labelButton})}export default PlaceOrderButton;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
1
|
import { type ConditionalElement } from '../../typings/index';
|
|
3
2
|
import { type TGenericChildrenProps, type TResources } from '../utils/GenericFieldComponent';
|
|
4
3
|
type ParcelLineItemFieldChildrenProps = TGenericChildrenProps<TResources['ParcelLineItem']>;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import{jsx as _jsx,Fragment as _Fragment,jsxs as _jsxs}from"react/jsx-runtime";import CommerceLayerContext from"../../context/CommerceLayerContext";import CustomerContext from"../../context/CustomerContext";import OrderContext from"../../context/OrderContext";import PaymentMethodChildrenContext from"../../context/PaymentMethodChildrenContext";import PaymentMethodContext from"../../context/PaymentMethodContext";import PaymentSourceContext from"../../context/PaymentSourceContext";import isEmpty from"lodash/isEmpty";import{useContext}from"react";import AdyenPayment from"../payment_source/AdyenPayment";import PaymentCardsTemplate from"../utils/PaymentCardsTemplate";import{jwt}from"../../utils/jwt";import getCardDetails from"../../utils/getCardDetails";import{getPaymentAttributes}from"../../utils/getPaymentAttributes";export function AdyenGateway(props){const{readonly,showCard,handleEditClick,children,templateCustomerCards,loading,loaderComponent,templateCustomerSaveToWallet,...p}=props,{order}=useContext(OrderContext),{accessToken}=useContext(CommerceLayerContext),{payment}=useContext(PaymentMethodChildrenContext),{payments,isGuest}=useContext(CustomerContext),{currentPaymentMethodId,config,paymentSource}=useContext(PaymentMethodContext),paymentResource="adyen_payments",locale=order?.language_code
|
|
2
|
+
import{jsx as _jsx,Fragment as _Fragment,jsxs as _jsxs}from"react/jsx-runtime";import CommerceLayerContext from"../../context/CommerceLayerContext";import CustomerContext from"../../context/CustomerContext";import OrderContext from"../../context/OrderContext";import PaymentMethodChildrenContext from"../../context/PaymentMethodChildrenContext";import PaymentMethodContext from"../../context/PaymentMethodContext";import PaymentSourceContext from"../../context/PaymentSourceContext";import isEmpty from"lodash/isEmpty";import{useContext}from"react";import AdyenPayment from"../payment_source/AdyenPayment";import PaymentCardsTemplate from"../utils/PaymentCardsTemplate";import{jwt}from"../../utils/jwt";import getCardDetails from"../../utils/getCardDetails";import{getPaymentAttributes}from"../../utils/getPaymentAttributes";export function AdyenGateway(props){const{readonly,showCard,handleEditClick,children,templateCustomerCards,loading,loaderComponent,templateCustomerSaveToWallet,...p}=props,{order}=useContext(OrderContext),{accessToken}=useContext(CommerceLayerContext),{payment}=useContext(PaymentMethodChildrenContext),{payments,isGuest}=useContext(CustomerContext),{currentPaymentMethodId,config,paymentSource}=useContext(PaymentMethodContext),paymentResource="adyen_payments",locale=order?.language_code;if(!readonly&&payment?.id!==currentPaymentMethodId)return null;const clientKey=paymentSource?.public_key,environment=accessToken&&jwt(accessToken).test?"test":"live",paymentConfig=getPaymentAttributes({resource:paymentResource,config:config??{},keys:["adyen_payments"]})?.adyenPayment,customerPayments=!isEmpty(payments)&&payments?payments.filter(customerPayment=>customerPayment.payment_source?.type==="adyen_payments"||customerPayment.payment_method!=null):[];if(readonly||showCard){const card=getCardDetails({customerPayment:{payment_source:paymentSource},paymentType:paymentResource}),value={...card,showCard,handleEditClick,readonly};return isEmpty(card)?null:_jsx(PaymentSourceContext.Provider,{value,children})}return!isGuest&&templateCustomerCards?_jsxs(_Fragment,{children:[isEmpty(customerPayments)?null:_jsx("div",{className:p.className,children:_jsx(PaymentCardsTemplate,{paymentResource,customerPayments,children:templateCustomerCards})}),_jsx(AdyenPayment,{templateCustomerSaveToWallet,clientKey,locale,environment,config:paymentConfig})]}):_jsx(AdyenPayment,{clientKey,locale,config:paymentConfig,environment})}export default AdyenGateway;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import{jsx as _jsx,Fragment as _Fragment,jsxs as _jsxs}from"react/jsx-runtime";import BraintreePayment from"../payment_source/BraintreePayment";import CustomerContext from"../../context/CustomerContext";import OrderContext from"../../context/OrderContext";import PaymentMethodChildrenContext from"../../context/PaymentMethodChildrenContext";import PaymentMethodContext from"../../context/PaymentMethodContext";import PaymentSourceContext from"../../context/PaymentSourceContext";import getCardDetails from"../../utils/getCardDetails";import isEmpty from"lodash/isEmpty";import{useContext}from"react";import PaymentCardsTemplate from"../utils/PaymentCardsTemplate";import{getPaymentAttributes}from"../../utils/getPaymentAttributes";export function BraintreeGateway(props){const{readonly,showCard,handleEditClick,children,templateCustomerCards,loading,loaderComponent,templateCustomerSaveToWallet,...p}=props,{order}=useContext(OrderContext),{payment}=useContext(PaymentMethodChildrenContext),{payments,isGuest}=useContext(CustomerContext),{currentPaymentMethodId,config,paymentSource}=useContext(PaymentMethodContext),paymentResource="braintree_payments",locale=order?.language_code;if(!readonly&&payment?.id!==currentPaymentMethodId)return null;const authorization=paymentSource?.client_token,paymentConfig=getPaymentAttributes({resource:paymentResource,config:config??{},keys:["braintree_payments"]})?.braintreePayment,customerPayments=!isEmpty(payments)&&payments?payments.filter(customerPayment=>customerPayment.payment_source?.type==="braintree_payments"):[];if(readonly||showCard){const card=getCardDetails({customerPayment:{payment_source:paymentSource},paymentType:paymentResource}),value={...card,showCard,handleEditClick,readonly};return isEmpty(card)?null:_jsx(PaymentSourceContext.Provider,{value,children})}return!isGuest&&templateCustomerCards?
|
|
2
|
+
import{jsx as _jsx,Fragment as _Fragment,jsxs as _jsxs}from"react/jsx-runtime";import BraintreePayment from"../payment_source/BraintreePayment";import CustomerContext from"../../context/CustomerContext";import OrderContext from"../../context/OrderContext";import PaymentMethodChildrenContext from"../../context/PaymentMethodChildrenContext";import PaymentMethodContext from"../../context/PaymentMethodContext";import PaymentSourceContext from"../../context/PaymentSourceContext";import getCardDetails from"../../utils/getCardDetails";import isEmpty from"lodash/isEmpty";import{useContext}from"react";import PaymentCardsTemplate from"../utils/PaymentCardsTemplate";import{getPaymentAttributes}from"../../utils/getPaymentAttributes";export function BraintreeGateway(props){const{readonly,showCard,handleEditClick,children,templateCustomerCards,loading,loaderComponent,templateCustomerSaveToWallet,...p}=props,{order}=useContext(OrderContext),{payment}=useContext(PaymentMethodChildrenContext),{payments,isGuest}=useContext(CustomerContext),{currentPaymentMethodId,config,paymentSource}=useContext(PaymentMethodContext),paymentResource="braintree_payments",locale=order?.language_code;if(!readonly&&payment?.id!==currentPaymentMethodId)return null;const authorization=paymentSource?.client_token,paymentConfig=getPaymentAttributes({resource:paymentResource,config:config??{},keys:["braintree_payments"]})?.braintreePayment,customerPayments=!isEmpty(payments)&&payments?payments.filter(customerPayment=>customerPayment.payment_source?.type==="braintree_payments"):[];if(readonly||showCard){const card=getCardDetails({customerPayment:{payment_source:paymentSource},paymentType:paymentResource}),value={...card,showCard,handleEditClick,readonly};return isEmpty(card)?null:_jsx(PaymentSourceContext.Provider,{value,children})}return!isGuest&&templateCustomerCards?_jsxs(_Fragment,{children:[isEmpty(customerPayments)?null:_jsx("div",{className:p.className,children:_jsx(PaymentCardsTemplate,{paymentResource,customerPayments,children:templateCustomerCards})}),_jsx(BraintreePayment,{templateCustomerSaveToWallet,authorization,locale,config:paymentConfig})]}):_jsx(BraintreePayment,{locale,authorization,config:paymentConfig})}export default BraintreeGateway;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import{jsx as _jsx,Fragment as _Fragment,jsxs as _jsxs}from"react/jsx-runtime";import CheckoutComPayment from"../payment_source/CheckoutComPayment";import CustomerContext from"../../context/CustomerContext";import OrderContext from"../../context/OrderContext";import PaymentMethodChildrenContext from"../../context/PaymentMethodChildrenContext";import PaymentMethodContext from"../../context/PaymentMethodContext";import PaymentSourceContext from"../../context/PaymentSourceContext";import{getPaymentConfig}from"../../reducers/PaymentMethodReducer";import isEmpty from"lodash/isEmpty";import React from"react";import PaymentCardsTemplate from"../utils/PaymentCardsTemplate";import getCardDetails from"../../utils/getCardDetails";export function CheckoutComGateway(props){const{readonly,showCard,handleEditClick,children,templateCustomerCards,show,loading,loaderComponent,templateCustomerSaveToWallet,...p}=props,{order}=React.useContext(OrderContext),{payment}=React.useContext(PaymentMethodChildrenContext),{payments,isGuest}=React.useContext(CustomerContext),{currentPaymentMethodId,config,paymentSource}=React.useContext(PaymentMethodContext),paymentResource="checkout_com_payments",locale=order?.language_code;if(!readonly&&payment?.id!==currentPaymentMethodId)return null;const publicKey=paymentSource?.public_key,paymentConfig=config?getPaymentConfig(paymentResource,config):{},customerPayments=!isEmpty(payments)&&payments?payments.filter(customerPayment=>customerPayment.payment_source?.type===paymentResource):[];if(readonly||showCard){const card=getCardDetails({customerPayment:{payment_source:paymentSource},paymentType:paymentResource}),value={...card,showCard,handleEditClick,readonly};return card.brand?_jsx(PaymentSourceContext.Provider,{value,children}):null}return!isGuest&&templateCustomerCards?
|
|
2
|
+
import{jsx as _jsx,Fragment as _Fragment,jsxs as _jsxs}from"react/jsx-runtime";import CheckoutComPayment from"../payment_source/CheckoutComPayment";import CustomerContext from"../../context/CustomerContext";import OrderContext from"../../context/OrderContext";import PaymentMethodChildrenContext from"../../context/PaymentMethodChildrenContext";import PaymentMethodContext from"../../context/PaymentMethodContext";import PaymentSourceContext from"../../context/PaymentSourceContext";import{getPaymentConfig}from"../../reducers/PaymentMethodReducer";import isEmpty from"lodash/isEmpty";import React from"react";import PaymentCardsTemplate from"../utils/PaymentCardsTemplate";import getCardDetails from"../../utils/getCardDetails";export function CheckoutComGateway(props){const{readonly,showCard,handleEditClick,children,templateCustomerCards,show,loading,loaderComponent,templateCustomerSaveToWallet,...p}=props,{order}=React.useContext(OrderContext),{payment}=React.useContext(PaymentMethodChildrenContext),{payments,isGuest}=React.useContext(CustomerContext),{currentPaymentMethodId,config,paymentSource}=React.useContext(PaymentMethodContext),paymentResource="checkout_com_payments",locale=order?.language_code;if(!readonly&&payment?.id!==currentPaymentMethodId)return null;const publicKey=paymentSource?.public_key,paymentConfig=config?getPaymentConfig(paymentResource,config):{},customerPayments=!isEmpty(payments)&&payments?payments.filter(customerPayment=>customerPayment.payment_source?.type===paymentResource):[];if(readonly||showCard){const card=getCardDetails({customerPayment:{payment_source:paymentSource},paymentType:paymentResource}),value={...card,showCard,handleEditClick,readonly};return card.brand?_jsx(PaymentSourceContext.Provider,{value,children}):null}return!isGuest&&templateCustomerCards?_jsxs(_Fragment,{children:[isEmpty(customerPayments)?null:_jsx("div",{className:p.className,children:_jsx(PaymentCardsTemplate,{paymentResource,customerPayments,children:templateCustomerCards})}),_jsx(CheckoutComPayment,{show,templateCustomerSaveToWallet,publicKey,locale,...paymentConfig})]}):_jsx(CheckoutComPayment,{show,publicKey,locale,...paymentConfig})}export default CheckoutComGateway;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import{jsx as _jsx,Fragment as _Fragment,jsxs as _jsxs}from"react/jsx-runtime";import ExternalPayment from"../payment_source/ExternalPayment";import CustomerContext from"../../context/CustomerContext";import OrderContext from"../../context/OrderContext";import PaymentMethodChildrenContext from"../../context/PaymentMethodChildrenContext";import PaymentMethodContext from"../../context/PaymentMethodContext";import PaymentSourceContext from"../../context/PaymentSourceContext";import{getPaymentConfig}from"../../reducers/PaymentMethodReducer";import getCardDetails from"../../utils/getCardDetails";import isEmpty from"lodash/isEmpty";import React from"react";import PaymentCardsTemplate from"../utils/PaymentCardsTemplate";export function ExternalGateway(props){const{readonly,showCard,handleEditClick,children,templateCustomerCards,show,loading,loaderComponent,templateCustomerSaveToWallet,...p}=props,{order}=React.useContext(OrderContext),{payment}=React.useContext(PaymentMethodChildrenContext),{payments,isGuest}=React.useContext(CustomerContext),{currentPaymentMethodId,config,paymentSource}=React.useContext(PaymentMethodContext),paymentResource="external_payments",locale=order?.language_code;if(!readonly&&payment?.id!==currentPaymentMethodId)return null;const paymentSourceToken=paymentSource?.payment_source_token,
|
|
2
|
+
import{jsx as _jsx,Fragment as _Fragment,jsxs as _jsxs}from"react/jsx-runtime";import ExternalPayment from"../payment_source/ExternalPayment";import CustomerContext from"../../context/CustomerContext";import OrderContext from"../../context/OrderContext";import PaymentMethodChildrenContext from"../../context/PaymentMethodChildrenContext";import PaymentMethodContext from"../../context/PaymentMethodContext";import PaymentSourceContext from"../../context/PaymentSourceContext";import{getPaymentConfig}from"../../reducers/PaymentMethodReducer";import getCardDetails from"../../utils/getCardDetails";import isEmpty from"lodash/isEmpty";import React from"react";import PaymentCardsTemplate from"../utils/PaymentCardsTemplate";export function ExternalGateway(props){const{readonly,showCard,handleEditClick,children,templateCustomerCards,show,loading,loaderComponent,templateCustomerSaveToWallet,...p}=props,{order}=React.useContext(OrderContext),{payment}=React.useContext(PaymentMethodChildrenContext),{payments,isGuest}=React.useContext(CustomerContext),{currentPaymentMethodId,config,paymentSource}=React.useContext(PaymentMethodContext),paymentResource="external_payments",locale=order?.language_code;if(!readonly&&payment?.id!==currentPaymentMethodId)return null;const paymentSourceToken=paymentSource?.payment_source_token,paymentConfig=(config?getPaymentConfig(paymentResource,config):{})?.externalPayment,customerPayments=!isEmpty(payments)&&payments?payments.filter(customerPayment=>customerPayment.payment_source?.type===paymentResource):[];if(readonly||showCard){const card=getCardDetails({customerPayment:{payment_source:paymentSource},paymentType:paymentResource}),value={...card,showCard,handleEditClick,readonly};return isEmpty(card)?null:_jsx(PaymentSourceContext.Provider,{value,children})}return!isGuest&&templateCustomerCards?_jsxs(_Fragment,{children:[isEmpty(customerPayments)?null:_jsx("div",{className:p.className,children:_jsx(PaymentCardsTemplate,{paymentResource,customerPayments,children:templateCustomerCards})}),_jsx(ExternalPayment,{show,templateCustomerSaveToWallet,paymentSourceToken,locale,...paymentConfig})]}):_jsx(ExternalPayment,{show,paymentSourceToken,locale,...paymentConfig})}export default ExternalGateway;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import{jsx as _jsx,Fragment as _Fragment,jsxs as _jsxs}from"react/jsx-runtime";import React from"react";import KlarnaPayment from"../payment_source/KlarnaPayment";import CustomerContext from"../../context/CustomerContext";import OrderContext from"../../context/OrderContext";import PaymentMethodChildrenContext from"../../context/PaymentMethodChildrenContext";import PaymentMethodContext from"../../context/PaymentMethodContext";import PaymentSourceContext from"../../context/PaymentSourceContext";import{getPaymentConfig}from"../../reducers/PaymentMethodReducer";import isEmpty from"lodash/isEmpty";import PaymentCardsTemplate from"../utils/PaymentCardsTemplate";import getCardDetails from"../../utils/getCardDetails";export function KlarnaGateway(props){const{readonly,showCard,handleEditClick,children,templateCustomerCards,loading,loaderComponent,...p}=props,{order}=React.useContext(OrderContext),{payment}=React.useContext(PaymentMethodChildrenContext),{payments,isGuest}=React.useContext(CustomerContext),{currentPaymentMethodId,config,paymentSource}=React.useContext(PaymentMethodContext),paymentResource="klarna_payments",locale=order?.language_code;if(!readonly&&payment?.id!==currentPaymentMethodId)return null;const clientToken=paymentSource?.client_token,klarnaConfig=config?getPaymentConfig(paymentResource,config):{},customerPayments=!isEmpty(payments)&&payments?payments.filter(customerPayment=>customerPayment.payment_source?.type===paymentResource):[];if(readonly||showCard){const card=getCardDetails({customerPayment:{payment_source:paymentSource},paymentType:paymentResource}),value={...card,showCard,handleEditClick,readonly};return isEmpty(card)?null:_jsx(PaymentSourceContext.Provider,{value,children})}return!isGuest&&templateCustomerCards?_jsxs(_Fragment,{children:[isEmpty(customerPayments)?null:_jsx("div",{className:p.className,children:_jsx(PaymentCardsTemplate,{paymentResource,customerPayments,children:templateCustomerCards})}),_jsx(KlarnaPayment,{clientToken,locale,...klarnaConfig})]}):
|
|
2
|
+
import{jsx as _jsx,Fragment as _Fragment,jsxs as _jsxs}from"react/jsx-runtime";import React from"react";import KlarnaPayment from"../payment_source/KlarnaPayment";import CustomerContext from"../../context/CustomerContext";import OrderContext from"../../context/OrderContext";import PaymentMethodChildrenContext from"../../context/PaymentMethodChildrenContext";import PaymentMethodContext from"../../context/PaymentMethodContext";import PaymentSourceContext from"../../context/PaymentSourceContext";import{getPaymentConfig}from"../../reducers/PaymentMethodReducer";import isEmpty from"lodash/isEmpty";import PaymentCardsTemplate from"../utils/PaymentCardsTemplate";import getCardDetails from"../../utils/getCardDetails";export function KlarnaGateway(props){const{readonly,showCard,handleEditClick,children,templateCustomerCards,loading,loaderComponent,...p}=props,{order}=React.useContext(OrderContext),{payment}=React.useContext(PaymentMethodChildrenContext),{payments,isGuest}=React.useContext(CustomerContext),{currentPaymentMethodId,config,paymentSource}=React.useContext(PaymentMethodContext),paymentResource="klarna_payments",locale=order?.language_code;if(!readonly&&payment?.id!==currentPaymentMethodId)return null;const clientToken=paymentSource?.client_token,klarnaConfig=config?getPaymentConfig(paymentResource,config):{},customerPayments=!isEmpty(payments)&&payments?payments.filter(customerPayment=>customerPayment.payment_source?.type===paymentResource):[];if(readonly||showCard){const card=getCardDetails({customerPayment:{payment_source:paymentSource},paymentType:paymentResource}),value={...card,showCard,handleEditClick,readonly};return isEmpty(card)?null:_jsx(PaymentSourceContext.Provider,{value,children})}return!isGuest&&templateCustomerCards?_jsxs(_Fragment,{children:[isEmpty(customerPayments)?null:_jsx("div",{className:p.className,children:_jsx(PaymentCardsTemplate,{paymentResource,customerPayments,children:templateCustomerCards})}),_jsx(KlarnaPayment,{clientToken,locale,...klarnaConfig})]}):_jsx(KlarnaPayment,{clientToken,locale,...klarnaConfig})}export default KlarnaGateway;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import{jsx as _jsx}from"react/jsx-runtime";import OrderContext from"../../context/OrderContext";import PaymentMethodChildrenContext from"../../context/PaymentMethodChildrenContext";import PaymentMethodContext from"../../context/PaymentMethodContext";import{useContext,useEffect,useState}from"react";import getLoaderComponent from"../../utils/getLoaderComponent";import AdyenGateway from"./AdyenGateway";import StripeGateway from"./StripeGateway";import BraintreeGateway from"./BraintreeGateway";import PaypalGateway from"./PaypalGateway";import WireTransferGateway from"./WireTransferGateway";import CustomerContext from"../../context/CustomerContext";import CheckoutComGateway from"./CheckoutComGateway";import KlarnaGateway from"./KlarnaGateway";import{getExternalPaymentAttributes,getPaypalAttributes,getStripeAttributes}from"../../utils/getPaymentAttributes";import ExternalGateway from"./ExternalGateway";export function PaymentGateway({readonly,showCard,handleEditClick,children,templateCustomerCards,templateCustomerSaveToWallet,onClickCustomerCards,show,loader="Loading...",...p}){const loaderComponent=getLoaderComponent(loader),[loading,setLoading]=useState(!0),{payment,expressPayments}=useContext(PaymentMethodChildrenContext),{order}=useContext(OrderContext),{getCustomerPaymentSources}=useContext(CustomerContext),{currentPaymentMethodId,config,currentPaymentMethodType,setPaymentSource,paymentSource}=useContext(PaymentMethodContext),paymentResource=readonly?currentPaymentMethodType:payment?.payment_source_type;useEffect(()=>{if(payment?.id===currentPaymentMethodId&&paymentResource&&order?.payment_method?.payment_source_type===paymentResource&&!expressPayments){let attributes={};config!=null&&paymentResource==="paypal_payments"&&(attributes=getPaypalAttributes(paymentResource,config)),config!=null&&paymentResource==="external_payments"&&(attributes=getExternalPaymentAttributes(paymentResource,config)),config!=null&&paymentResource==="stripe_payments"&&(attributes=getStripeAttributes(paymentResource,config),attributes!=null&&attributes.return_url==null&&(attributes.return_url=window.location.href));const setPaymentSources=async()=>{order!=null&&await setPaymentSource({paymentResource,order,attributes}),getCustomerPaymentSources&&getCustomerPaymentSources()};(!paymentSource&&order?.payment_method.id&&show&&!expressPayments||(!paymentSource&&!expressPayments||paymentSource?.type!==paymentResource)&&show)&&setPaymentSources(),paymentSource?.mismatched_amounts&&show&&setPaymentSources(),setLoading(!1)}return expressPayments&&show&&setLoading(!1),()=>{setLoading(!0)}},[order?.payment_method?.id,show,paymentSource]);const gatewayConfig={readonly,showCard,handleEditClick,children,templateCustomerCards,show,loading,onClickCustomerCards,loaderComponent,templateCustomerSaveToWallet,...p};switch(paymentResource){case"adyen_payments":return _jsx(AdyenGateway,{...gatewayConfig,children});case"braintree_payments":return _jsx(BraintreeGateway,{...gatewayConfig,children});case"checkout_com_payments":return _jsx(CheckoutComGateway,{...gatewayConfig,children});case"external_payments":return _jsx(ExternalGateway,{...gatewayConfig,children});case"klarna_payments":return _jsx(KlarnaGateway,{...gatewayConfig,children});case"stripe_payments":return _jsx(StripeGateway,{...gatewayConfig,children});case"wire_transfers":return _jsx(WireTransferGateway,{...gatewayConfig,children});case"paypal_payments":return _jsx(PaypalGateway,{...gatewayConfig,children});default:return null}}export default PaymentGateway;
|
|
2
|
+
import{jsx as _jsx}from"react/jsx-runtime";import OrderContext from"../../context/OrderContext";import PaymentMethodChildrenContext from"../../context/PaymentMethodChildrenContext";import PaymentMethodContext from"../../context/PaymentMethodContext";import{useContext,useEffect,useState}from"react";import getLoaderComponent from"../../utils/getLoaderComponent";import AdyenGateway from"./AdyenGateway";import StripeGateway from"./StripeGateway";import BraintreeGateway from"./BraintreeGateway";import PaypalGateway from"./PaypalGateway";import WireTransferGateway from"./WireTransferGateway";import CustomerContext from"../../context/CustomerContext";import CheckoutComGateway from"./CheckoutComGateway";import KlarnaGateway from"./KlarnaGateway";import{getExternalPaymentAttributes,getPaypalAttributes,getStripeAttributes}from"../../utils/getPaymentAttributes";import ExternalGateway from"./ExternalGateway";export function PaymentGateway({readonly,showCard,handleEditClick,children,templateCustomerCards,templateCustomerSaveToWallet,onClickCustomerCards,show,loader="Loading...",...p}){const loaderComponent=getLoaderComponent(loader),[loading,setLoading]=useState(!0),{payment,expressPayments}=useContext(PaymentMethodChildrenContext),{order}=useContext(OrderContext),{getCustomerPaymentSources}=useContext(CustomerContext),{currentPaymentMethodId,config,currentPaymentMethodType,setPaymentSource,paymentSource}=useContext(PaymentMethodContext),paymentResource=readonly?currentPaymentMethodType:payment?.payment_source_type;useEffect(()=>{if(payment?.id===currentPaymentMethodId&&paymentResource&&order?.payment_method?.payment_source_type===paymentResource&&!expressPayments){let attributes={};config!=null&&paymentResource==="paypal_payments"&&(attributes=getPaypalAttributes(paymentResource,config)),config!=null&&paymentResource==="external_payments"&&(attributes=getExternalPaymentAttributes(paymentResource,config)),config!=null&&paymentResource==="stripe_payments"&&(attributes=getStripeAttributes(paymentResource,config),attributes!=null&&attributes.return_url==null&&(attributes.return_url=window.location.href));const setPaymentSources=async()=>{order!=null&&await setPaymentSource({paymentResource,order,attributes}),getCustomerPaymentSources&&getCustomerPaymentSources()};(!paymentSource&&order?.payment_method.id&&show&&!expressPayments||(!paymentSource&&!expressPayments||paymentSource?.type!==paymentResource)&&show)&&setPaymentSources(),paymentSource?.mismatched_amounts&&show&&setPaymentSources(),order?.payment_source?.id!=null&&setLoading(!1)}return expressPayments&&show&&setLoading(!1),order?.status!=null&&!["draft","pending"].includes(order?.status)&&show&&order?.payment_source?.id!=null&&setLoading(!1),()=>{setLoading(!0)}},[order?.payment_method?.id,show,paymentSource]);const gatewayConfig={readonly,showCard,handleEditClick,children,templateCustomerCards,show,loading,onClickCustomerCards,loaderComponent,templateCustomerSaveToWallet,...p};if(loading)return loaderComponent;switch(paymentResource){case"adyen_payments":return _jsx(AdyenGateway,{...gatewayConfig,children});case"braintree_payments":return _jsx(BraintreeGateway,{...gatewayConfig,children});case"checkout_com_payments":return _jsx(CheckoutComGateway,{...gatewayConfig,children});case"external_payments":return _jsx(ExternalGateway,{...gatewayConfig,children});case"klarna_payments":return _jsx(KlarnaGateway,{...gatewayConfig,children});case"stripe_payments":return _jsx(StripeGateway,{...gatewayConfig,children});case"wire_transfers":return _jsx(WireTransferGateway,{...gatewayConfig,children});case"paypal_payments":return _jsx(PaypalGateway,{...gatewayConfig,children});default:return null}}export default PaymentGateway;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import{jsx as _jsx,Fragment as _Fragment,jsxs as _jsxs}from"react/jsx-runtime";import StripePayment from"../payment_source/StripePayment";import CustomerContext from"../../context/CustomerContext";import OrderContext from"../../context/OrderContext";import PaymentMethodChildrenContext from"../../context/PaymentMethodChildrenContext";import PaymentMethodContext from"../../context/PaymentMethodContext";import PaymentSourceContext from"../../context/PaymentSourceContext";import{getPaymentConfig}from"../../reducers/PaymentMethodReducer";import getCardDetails from"../../utils/getCardDetails";import isEmpty from"lodash/isEmpty";import
|
|
2
|
+
import{jsx as _jsx,Fragment as _Fragment,jsxs as _jsxs}from"react/jsx-runtime";import StripePayment from"../payment_source/StripePayment";import CustomerContext from"../../context/CustomerContext";import OrderContext from"../../context/OrderContext";import PaymentMethodChildrenContext from"../../context/PaymentMethodChildrenContext";import PaymentMethodContext from"../../context/PaymentMethodContext";import PaymentSourceContext from"../../context/PaymentSourceContext";import{getPaymentConfig}from"../../reducers/PaymentMethodReducer";import getCardDetails from"../../utils/getCardDetails";import isEmpty from"lodash/isEmpty";import{useContext}from"react";import PaymentCardsTemplate from"../utils/PaymentCardsTemplate";export function StripeGateway(props){const{readonly,showCard,handleEditClick,children,templateCustomerCards,show,loading,loaderComponent,templateCustomerSaveToWallet,...p}=props,{order}=useContext(OrderContext),{payment,expressPayments}=useContext(PaymentMethodChildrenContext),{payments,isGuest}=useContext(CustomerContext),{currentPaymentMethodId,config,paymentSource}=useContext(PaymentMethodContext),paymentResource="stripe_payments",locale=order?.language_code;if(!readonly&&payment?.id!==currentPaymentMethodId)return null;const publishableKey=paymentSource?.publishable_key,clientSecret=paymentSource?.client_secret,stripeConfig=config?getPaymentConfig(paymentResource,config).stripePayment:{},customerPayments=!isEmpty(payments)&&payments?payments.filter(customerPayment=>customerPayment.payment_source?.type===paymentResource):[];if(readonly||showCard){const card=getCardDetails({customerPayment:{payment_source:paymentSource},paymentType:paymentResource}),value={...card,showCard,handleEditClick,readonly};return isEmpty(card)?null:_jsx(PaymentSourceContext.Provider,{value,children})}return!isGuest&&templateCustomerCards?_jsxs(_Fragment,{children:[isEmpty(customerPayments)?null:_jsx("div",{className:p.className,children:_jsx(PaymentCardsTemplate,{paymentResource,customerPayments,children:templateCustomerCards})}),_jsx(StripePayment,{show,templateCustomerSaveToWallet,publishableKey,clientSecret,expressPayments,locale,...stripeConfig})]}):_jsx(StripePayment,{show,publishableKey,clientSecret,locale,expressPayments,...stripeConfig})}export default StripeGateway;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
1
|
import { type PaymentMethodConfig } from '../../reducers/PaymentMethodReducer';
|
|
3
2
|
import { type PaymentSourceProps } from './PaymentSource';
|
|
4
3
|
type KlarnaPaymentProps = PaymentMethodConfig['klarnaPayment'] & JSX.IntrinsicElements['div'] & Partial<PaymentSourceProps['templateCustomerSaveToWallet']> & {
|