@commercelayer/react-components
Version:
The Official Commerce Layer React Components
2 lines • 2.88 kB
JavaScript
"use client";
;Object.defineProperty(exports,"__esModule",{value:!0}),exports.CheckoutComGateway=CheckoutComGateway;const tslib_1=require("tslib"),jsx_runtime_1=require("react/jsx-runtime"),isEmpty_1=tslib_1.__importDefault(require("lodash/isEmpty")),react_1=tslib_1.__importDefault(require("react")),CheckoutComPayment_1=tslib_1.__importDefault(require("../payment_source/CheckoutComPayment")),PaymentCardsTemplate_1=tslib_1.__importDefault(require("../utils/PaymentCardsTemplate")),CustomerContext_1=tslib_1.__importDefault(require("../../context/CustomerContext")),OrderContext_1=tslib_1.__importDefault(require("../../context/OrderContext")),PaymentMethodChildrenContext_1=tslib_1.__importDefault(require("../../context/PaymentMethodChildrenContext")),PaymentMethodContext_1=tslib_1.__importDefault(require("../../context/PaymentMethodContext")),PaymentSourceContext_1=tslib_1.__importDefault(require("../../context/PaymentSourceContext")),PaymentMethodReducer_1=require("../../reducers/PaymentMethodReducer"),getCardDetails_1=tslib_1.__importDefault(require("../../utils/getCardDetails"));function CheckoutComGateway(props){const{readonly,showCard,handleEditClick,children,templateCustomerCards,show,templateCustomerSaveToWallet,...p}=props,{order}=react_1.default.useContext(OrderContext_1.default),{payment}=react_1.default.useContext(PaymentMethodChildrenContext_1.default),{payments,isGuest}=react_1.default.useContext(CustomerContext_1.default),{currentPaymentMethodId,config,paymentSource}=react_1.default.useContext(PaymentMethodContext_1.default),paymentResource="checkout_com_payments",locale=order?.language_code;if(!readonly&&payment?.id!==currentPaymentMethodId)return null;const publicKey=paymentSource?.public_key,paymentConfig=config?(0,PaymentMethodReducer_1.getPaymentConfig)(paymentResource,config):{},customerPayments=!(0,isEmpty_1.default)(payments)&&payments?payments.filter(customerPayment=>customerPayment.payment_source?.type===paymentResource):[];if(readonly||showCard){const card=(0,getCardDetails_1.default)({customerPayment:{payment_source:paymentSource},paymentType:paymentResource}),value={...card,showCard,handleEditClick,readonly};return card.brand?(0,jsx_runtime_1.jsx)(PaymentSourceContext_1.default.Provider,{value,children}):null}return!isGuest&&templateCustomerCards?(0,jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment,{children:[(0,isEmpty_1.default)(customerPayments)?null:(0,jsx_runtime_1.jsx)("div",{className:p.className,children:(0,jsx_runtime_1.jsx)(PaymentCardsTemplate_1.default,{paymentResource,customerPayments,children:templateCustomerCards})}),(0,jsx_runtime_1.jsx)(CheckoutComPayment_1.default,{show,templateCustomerSaveToWallet,publicKey,locale,...paymentConfig.checkoutComPayment})]}):(0,jsx_runtime_1.jsx)(CheckoutComPayment_1.default,{show,publicKey,locale,...paymentConfig})}exports.default=CheckoutComGateway;