UNPKG

@commercelayer/react-components

Version:
2 lines 3.17 kB
"use client"; "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.CheckoutComGateway=CheckoutComGateway;const tslib_1=require("tslib"),jsx_runtime_1=require("react/jsx-runtime"),CheckoutComPayment_1=tslib_1.__importDefault(require("../payment_source/CheckoutComPayment")),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"),isEmpty_1=tslib_1.__importDefault(require("lodash/isEmpty")),react_1=tslib_1.__importDefault(require("react")),PaymentCardsTemplate_1=tslib_1.__importDefault(require("../utils/PaymentCardsTemplate")),getCardDetails_1=tslib_1.__importDefault(require("../../utils/getCardDetails"));function CheckoutComGateway(props){const{readonly,showCard,handleEditClick,children,templateCustomerCards,show,loading,loaderComponent,templateCustomerSaveToWallet}=props,p=tslib_1.__rest(props,["readonly","showCard","handleEditClick","children","templateCustomerCards","show","loading","loaderComponent","templateCustomerSaveToWallet"]),{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=>{var _a;return((_a=customerPayment.payment_source)===null||_a===void 0?void 0:_a.type)===paymentResource}):[];if(readonly||showCard){const card=(0,getCardDetails_1.default)({customerPayment:{payment_source:paymentSource},paymentType:paymentResource}),value=Object.assign(Object.assign({},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,Object.assign({show,templateCustomerSaveToWallet,publicKey,locale},paymentConfig.checkoutComPayment))]}):(0,jsx_runtime_1.jsx)(CheckoutComPayment_1.default,Object.assign({show,publicKey,locale},paymentConfig))}exports.default=CheckoutComGateway;