@commercelayer/react-components
Version:
The Official Commerce Layer React Components
2 lines • 1.83 kB
JavaScript
"use client";
import{getPaymentConfig}from"../reducers/PaymentMethodReducer";import{pick}from"./pick";import{replace}from"./replace";import{snakeToCamelCase}from"./snakeToCamelCase";export function getPaymentAttributes(params){const{resource,config,keys}=params,attributes=getPaymentConfig(resource,config),keysCamelCase=keys.map(key=>{const k=replace(replace(key,"payments","payment"),"transfers","transfer");return snakeToCamelCase(k)}),currentResource=snakeToCamelCase(replace(replace(resource,"payments","payment"),"transfers","transfer"));return attributes!=null&¤tResource in attributes?pick(attributes,keysCamelCase):void 0}export function getPaypalAttributes(paymentResource,config){const attributes=getPaymentAttributes({resource:paymentResource,config,keys:["paypal_payments"]});return attributes?.paypalPayment!=null&&"paypalPayment"in attributes?pick(attributes?.paypalPayment,["return_url","cancel_url"]):void 0}export function getExternalPaymentAttributes(paymentResource,config){const attributes=getPaymentAttributes({resource:paymentResource,config,keys:["external_payments"]});return attributes?.externalPayment!=null&&"externalPayment"in attributes?pick(attributes?.externalPayment,["payment_source_token"]):void 0}export function getStripeAttributes(paymentResource,config){const attributes=getPaymentAttributes({resource:paymentResource,config,keys:["stripe_payments"]});return attributes?.stripePayment!=null&&"stripePayment"in attributes?pick(attributes?.stripePayment,["return_url"]):void 0}export function getCkoAttributes(paymentResource,config){const attributes=getPaymentAttributes({resource:paymentResource,config,keys:["checkout_com_payments"]});return attributes?.checkoutComPayment!=null&&"checkoutComPayment"in attributes?pick(attributes?.checkoutComPayment,["success_url","failure_url"]):void 0}