@commercelayer/react-components
Version:
The Official Commerce Layer React Components
2 lines • 1.39 kB
JavaScript
"use client";
export function manageGiftCard({order}){if(!order||!order?.payment_source)return null;const getPaymentSource=order.payment_source?.type==="adyen_payments"?order.payment_source:null;if(!getPaymentSource||getPaymentSource?.payment_response?.errorCode||getPaymentSource?.payment_response?.refusalReasonCode!=="12"||!(getPaymentSource?.payment_request_data?.payment_method?.type==="giftcard"))return null;const additionalData=getPaymentSource?.payment_response?.additionalData,amount=getPaymentSource?.payment_response?.amount?.value,giftCardData={cardSummary:additionalData?.cardSummary,currentBalanceValue:amount??Number.parseInt(additionalData?.currentBalanceValue),currentBalanceCurrency:additionalData?.currentBalanceCurrency,cardBrand:additionalData?.originalSelectedBrand??additionalData?.paymentMethod,formattedBalanceValue:additionalData?.currentBalanceValue},formattedOrderTotal=((order?.total_amount_with_taxes_cents!=null?order?.total_amount_with_taxes_cents-giftCardData.currentBalanceValue:0)/100).toLocaleString(order.language_code??"en",{style:"currency",currency:order?.currency_code??"USD"}),formattedCurrentBalance=(giftCardData.currentBalanceValue/100).toLocaleString(order.language_code??"en",{style:"currency",currency:order?.currency_code??"USD"});return giftCardData.formattedBalanceValue=formattedCurrentBalance,{...giftCardData,formattedOrderTotal}}