UNPKG

@commercelayer/react-components

Version:
2 lines 986 B
"use client"; import{jsx as _jsx}from"react/jsx-runtime";import Parent from"../utils/Parent";import{useContext}from"react";import PaymentMethodContext from"../../context/PaymentMethodContext";import PaymentSourceContext from"../../context/PaymentSourceContext";import getCardDetails from"../../utils/getCardDetails";export default function PaymentCardsTemplate({customerPayments,children,paymentResource}){const{setPaymentSource}=useContext(PaymentMethodContext),value={customerPayments:customerPayments.map(customerPayment=>{const attributes=customerPayment,card=getCardDetails({customerPayment,paymentType:paymentResource});return card.brand===""&&(card.brand=customerPayment.payment_source?.payment_instrument?.issuer_type??"credit-card"),{...attributes,card,handleClick:async e=>{e.stopPropagation(),await setPaymentSource({paymentResource,customerPaymentSourceId:customerPayment.id})}}}),PaymentSourceProvider:PaymentSourceContext.Provider};return _jsx(Parent,{...value,children})}