UNPKG

@commercelayer/react-components

Version:
2 lines 2.31 kB
"use client"; "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.getPaymentAttributes=getPaymentAttributes,exports.getPaypalAttributes=getPaypalAttributes,exports.getExternalPaymentAttributes=getExternalPaymentAttributes,exports.getStripeAttributes=getStripeAttributes,exports.getCkoAttributes=getCkoAttributes;const PaymentMethodReducer_1=require("../reducers/PaymentMethodReducer"),pick_1=require("./pick"),replace_1=require("./replace"),snakeToCamelCase_1=require("./snakeToCamelCase");function getPaymentAttributes(params){const{resource,config,keys}=params,attributes=(0,PaymentMethodReducer_1.getPaymentConfig)(resource,config),keysCamelCase=keys.map(key=>{const k=(0,replace_1.replace)((0,replace_1.replace)(key,"payments","payment"),"transfers","transfer");return(0,snakeToCamelCase_1.snakeToCamelCase)(k)}),currentResource=(0,snakeToCamelCase_1.snakeToCamelCase)((0,replace_1.replace)((0,replace_1.replace)(resource,"payments","payment"),"transfers","transfer"));return attributes!=null&&currentResource in attributes?(0,pick_1.pick)(attributes,keysCamelCase):void 0}function getPaypalAttributes(paymentResource,config){const attributes=getPaymentAttributes({resource:paymentResource,config,keys:["paypal_payments"]});return attributes?.paypalPayment!=null&&"paypalPayment"in attributes?(0,pick_1.pick)(attributes?.paypalPayment,["return_url","cancel_url"]):void 0}function getExternalPaymentAttributes(paymentResource,config){const attributes=getPaymentAttributes({resource:paymentResource,config,keys:["external_payments"]});return attributes?.externalPayment!=null&&"externalPayment"in attributes?(0,pick_1.pick)(attributes?.externalPayment,["payment_source_token"]):void 0}function getStripeAttributes(paymentResource,config){const attributes=getPaymentAttributes({resource:paymentResource,config,keys:["stripe_payments"]});return attributes?.stripePayment!=null&&"stripePayment"in attributes?(0,pick_1.pick)(attributes?.stripePayment,["return_url"]):void 0}function getCkoAttributes(paymentResource,config){const attributes=getPaymentAttributes({resource:paymentResource,config,keys:["checkout_com_payments"]});return attributes?.checkoutComPayment!=null&&"checkoutComPayment"in attributes?(0,pick_1.pick)(attributes?.checkoutComPayment,["success_url","failure_url"]):void 0}