@commercelayer/react-components 4.20.5 → 4.20.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
- import type { GatewayBaseType } from '../payment_gateways/PaymentGateway';
2
- import { type JSX } from 'react';
1
+ import type { GatewayBaseType } from "../payment_gateways/PaymentGateway";
2
+ import { type JSX } from "react";
3
3
  type Props = GatewayBaseType;
4
4
  export declare function ExternalGateway(props: Props): JSX.Element | null;
5
5
  export default ExternalGateway;
@@ -1,2 +1,2 @@
1
1
  "use client";
2
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.ExternalGateway=ExternalGateway;const tslib_1=require("tslib"),jsx_runtime_1=require("react/jsx-runtime"),ExternalPayment_1=tslib_1.__importDefault(require("../payment_source/ExternalPayment")),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"),getCardDetails_1=tslib_1.__importDefault(require("../../utils/getCardDetails")),isEmpty_1=tslib_1.__importDefault(require("lodash/isEmpty")),react_1=tslib_1.__importDefault(require("react")),PaymentCardsTemplate_1=tslib_1.__importDefault(require("../utils/PaymentCardsTemplate"));function ExternalGateway(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="external_payments",locale=order?.language_code;if(!readonly&&payment?.id!==currentPaymentMethodId)return null;const paymentSourceToken=paymentSource?.payment_source_token,getConfig=config?(0,PaymentMethodReducer_1.getPaymentConfig)(paymentResource,config):{},paymentConfig=getConfig?.externalPayment,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(0,isEmpty_1.default)(card)?null:(0,jsx_runtime_1.jsx)(PaymentSourceContext_1.default.Provider,{value,children})}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)(ExternalPayment_1.default,Object.assign({show,templateCustomerSaveToWallet,paymentSourceToken,locale},paymentConfig))]}):(0,jsx_runtime_1.jsx)(ExternalPayment_1.default,Object.assign({show,paymentSourceToken,locale},paymentConfig))}exports.default=ExternalGateway;
2
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.ExternalGateway=ExternalGateway;const tslib_1=require("tslib"),jsx_runtime_1=require("react/jsx-runtime"),ExternalPayment_1=tslib_1.__importDefault(require("../payment_source/ExternalPayment")),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"),getCardDetails_1=tslib_1.__importDefault(require("../../utils/getCardDetails")),isEmpty_1=tslib_1.__importDefault(require("lodash/isEmpty")),react_1=tslib_1.__importDefault(require("react")),PaymentCardsTemplate_1=tslib_1.__importDefault(require("../utils/PaymentCardsTemplate"));function ExternalGateway(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="external_payments",locale=order?.language_code;if(!readonly&&payment?.id!==currentPaymentMethodId)return null;const paymentSourceToken=paymentSource?.payment_source_token,getConfig=config?(0,PaymentMethodReducer_1.getPaymentConfig)(paymentResource,config):{},paymentConfig=getConfig?.externalPayment,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){const card=(0,getCardDetails_1.default)({customerPayment:{payment_source:paymentSource},paymentType:paymentResource}),value=Object.assign(Object.assign({},card),{showCard,handleEditClick,readonly});return(0,isEmpty_1.default)(card)?null:(0,jsx_runtime_1.jsx)(PaymentSourceContext_1.default.Provider,{value,children})}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)(ExternalPayment_1.default,Object.assign({show,templateCustomerSaveToWallet,paymentSourceToken,locale},paymentConfig))]}):(0,jsx_runtime_1.jsx)(ExternalPayment_1.default,Object.assign({show,paymentSourceToken,locale},paymentConfig))}exports.default=ExternalGateway;
@@ -1,7 +1,7 @@
1
- import type { ChildrenFunction } from '../../typings/index';
2
- import type { StripeElementLocale } from '@stripe/stripe-js';
3
- import { type JSX } from 'react';
4
- import type { PaymentSourceProps } from './PaymentSource';
1
+ import type { ChildrenFunction } from "../../typings/index";
2
+ import type { StripeElementLocale } from "@stripe/stripe-js";
3
+ import { type JSX } from "react";
4
+ import type { PaymentSourceProps } from "./PaymentSource";
5
5
  export interface ExternalPaymentConfig {
6
6
  /**
7
7
  * Show the component. Default is false
@@ -10,13 +10,13 @@ export interface ExternalPaymentConfig {
10
10
  /**
11
11
  * Use to display information about the external payment or whatever else.
12
12
  */
13
- customComponent?: ChildrenFunction<Omit<Props, 'customComponent'>>;
13
+ customComponent?: ChildrenFunction<Omit<Props, "customComponent">>;
14
14
  /**
15
15
  * The payment source token, as generated by the external gateway SDK. Credit Card numbers are rejected.
16
16
  */
17
17
  payment_source_token: string;
18
18
  }
19
- interface Props extends Omit<ExternalPaymentConfig, 'payment_source_token'>, Pick<PaymentSourceProps, 'templateCustomerSaveToWallet'> {
19
+ interface Props extends Omit<ExternalPaymentConfig, "payment_source_token">, Pick<PaymentSourceProps, "templateCustomerSaveToWallet"> {
20
20
  paymentSourceToken: string;
21
21
  locale?: StripeElementLocale;
22
22
  }
@@ -1,13 +1,13 @@
1
- import { type JSX } from 'react';
2
- import type { LoaderType } from '../../typings/index';
3
- import type { CustomerCardsTemplateChildren } from '../utils/PaymentCardsTemplate';
1
+ import { type JSX } from "react";
2
+ import type { LoaderType } from "../../typings/index";
3
+ import type { CustomerCardsTemplateChildren } from "../utils/PaymentCardsTemplate";
4
4
  export interface CustomerCardsProps {
5
5
  handleClick: () => void;
6
6
  }
7
7
  export interface CustomerSaveToWalletProps {
8
- name: 'save_payment_source_to_customer_wallet';
8
+ name: "save_payment_source_to_customer_wallet";
9
9
  }
10
- export interface PaymentSourceProps extends Omit<JSX.IntrinsicElements['div'], 'children'> {
10
+ export interface PaymentSourceProps extends Omit<JSX.IntrinsicElements["div"], "children"> {
11
11
  children?: JSX.Element | JSX.Element[];
12
12
  readonly?: boolean;
13
13
  templateCustomerCards?: CustomerCardsTemplateChildren;
@@ -1,2 +1,2 @@
1
1
  "use client";
2
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.PaymentSource=PaymentSource;const tslib_1=require("tslib"),jsx_runtime_1=require("react/jsx-runtime"),react_1=require("react"),PaymentMethodChildrenContext_1=tslib_1.__importDefault(require("../../context/PaymentMethodChildrenContext")),PaymentMethodContext_1=tslib_1.__importDefault(require("../../context/PaymentMethodContext")),CustomerContext_1=tslib_1.__importDefault(require("../../context/CustomerContext")),PaymentGateway_1=tslib_1.__importDefault(require("../payment_gateways/PaymentGateway")),getCardDetails_1=tslib_1.__importDefault(require("../../utils/getCardDetails")),OrderContext_1=tslib_1.__importDefault(require("../../context/OrderContext"));function PaymentSource(props){const{readonly}=props,{payment,expressPayments}=(0,react_1.useContext)(PaymentMethodChildrenContext_1.default),{order}=(0,react_1.useContext)(OrderContext_1.default),{payments}=(0,react_1.useContext)(CustomerContext_1.default),{currentPaymentMethodId,paymentSource,destroyPaymentSource,currentPaymentMethodType,currentCustomerPaymentSourceId}=(0,react_1.useContext)(PaymentMethodContext_1.default),[show,setShow]=(0,react_1.useState)(!1),[showCard,setShowCard]=(0,react_1.useState)(!1);(0,react_1.useEffect)(()=>{const isCustomerPaymentSource=currentCustomerPaymentSourceId!=null&&currentCustomerPaymentSourceId===paymentSource?.id;if(readonly)setShow(!0),setShowCard(!0);else if((payment?.id===currentPaymentMethodId||isCustomerPaymentSource)&&!expressPayments){setShow(!0);const card=(0,getCardDetails_1.default)({paymentType:payment?.payment_source_type,customerPayment:{payment_source:paymentSource}});isCustomerPaymentSource&&card.brand===""&&(card.brand=card.issuer_type!=null&&card.issuer_type!==""?card.issuer_type:"credit-card"),card.brand&&setShowCard(!0)}else setShow(!!(expressPayments&&currentPaymentMethodType==="stripe_payments"));return()=>{setShow(!1),setShowCard(!1)}},[currentPaymentMethodId,paymentSource?.id,payments!=null,payment!=null,readonly,order?.status,expressPayments]);const handleEditClick=e=>tslib_1.__awaiter(this,void 0,void 0,function*(){if(e.stopPropagation(),paymentSource){const paymentSourceId=paymentSource?.id;yield destroyPaymentSource({paymentSourceId,paymentResource:payment?.payment_source_type})}setShowCard(!showCard),setShow(!0)}),gatewayProps=Object.assign(Object.assign({},props),{show,showCard,handleEditClick,readonly});return(0,jsx_runtime_1.jsx)(PaymentGateway_1.default,Object.assign({},gatewayProps))}exports.default=PaymentSource;
2
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.PaymentSource=PaymentSource;const tslib_1=require("tslib"),jsx_runtime_1=require("react/jsx-runtime"),react_1=require("react"),PaymentMethodChildrenContext_1=tslib_1.__importDefault(require("../../context/PaymentMethodChildrenContext")),PaymentMethodContext_1=tslib_1.__importDefault(require("../../context/PaymentMethodContext")),CustomerContext_1=tslib_1.__importDefault(require("../../context/CustomerContext")),PaymentGateway_1=tslib_1.__importDefault(require("../payment_gateways/PaymentGateway")),getCardDetails_1=tslib_1.__importDefault(require("../../utils/getCardDetails")),OrderContext_1=tslib_1.__importDefault(require("../../context/OrderContext"));function PaymentSource(props){const{readonly}=props,{payment,expressPayments}=(0,react_1.useContext)(PaymentMethodChildrenContext_1.default),{order}=(0,react_1.useContext)(OrderContext_1.default),{payments}=(0,react_1.useContext)(CustomerContext_1.default),{currentPaymentMethodId,paymentSource,destroyPaymentSource,currentPaymentMethodType,currentCustomerPaymentSourceId}=(0,react_1.useContext)(PaymentMethodContext_1.default),[show,setShow]=(0,react_1.useState)(!1),[showCard,setShowCard]=(0,react_1.useState)(!1);(0,react_1.useEffect)(()=>{const isCustomerPaymentSource=currentCustomerPaymentSourceId!=null&&currentCustomerPaymentSourceId===paymentSource?.id;if(readonly)setShow(!0),setShowCard(!0);else if((payment?.id===currentPaymentMethodId||isCustomerPaymentSource)&&!expressPayments){const card=(0,getCardDetails_1.default)({paymentType:payment?.payment_source_type,customerPayment:{payment_source:paymentSource}});isCustomerPaymentSource&&card.brand===""&&(card.brand=card.issuer_type!=null&&card.issuer_type!==""?card.issuer_type:"credit-card"),card.brand&&setShowCard(!0),setShow(!0)}else expressPayments&&currentPaymentMethodType==="stripe_payments"&&setShow(!0);return()=>{setShow(!1),setShowCard(!1)}},[currentPaymentMethodId,paymentSource?.id,payments!=null,payment!=null,readonly,order?.status,expressPayments]);const handleEditClick=e=>tslib_1.__awaiter(this,void 0,void 0,function*(){if(e.stopPropagation(),paymentSource){const paymentSourceId=paymentSource?.id;yield destroyPaymentSource({paymentSourceId,paymentResource:payment?.payment_source_type})}setShowCard(!showCard),setShow(!0)}),gatewayProps=Object.assign(Object.assign({},props),{show,showCard,handleEditClick,readonly});return(0,jsx_runtime_1.jsx)(PaymentGateway_1.default,Object.assign({},gatewayProps))}exports.default=PaymentSource;
@@ -1,6 +1,6 @@
1
- import type { IconBrand } from '../context/PaymentSourceContext';
2
- import type { PaymentResource } from '../reducers/PaymentMethodReducer';
3
- import type { CustomerPaymentSource } from '@commercelayer/sdk';
1
+ import type { IconBrand } from "../context/PaymentSourceContext";
2
+ import type { PaymentResource } from "../reducers/PaymentMethodReducer";
3
+ import type { CustomerPaymentSource } from "@commercelayer/sdk";
4
4
  interface CardDetails {
5
5
  brand: IconBrand | string;
6
6
  last4: string;
@@ -12,5 +12,5 @@ interface Args {
12
12
  paymentType: PaymentResource;
13
13
  customerPayment: Partial<CustomerPaymentSource>;
14
14
  }
15
- export default function getCardDetails({ paymentType, customerPayment }: Args): CardDetails;
15
+ export default function getCardDetails({ paymentType, customerPayment, }: Args): CardDetails;
16
16
  export {};
@@ -1,2 +1,2 @@
1
1
  "use client";
2
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=getCardDetails;function getCardDetails({paymentType,customerPayment}){var _a,_b,_c,_d,_e,_f,_g,_h,_j,_k,_l,_m,_o,_p,_q,_r,_s,_t,_u,_v,_w,_x,_y,_z,_0,_1,_2,_3,_4,_5;switch(paymentType){case"checkout_com_payments":{const ps=customerPayment.payment_source,source=(_a=ps?.payment_response)===null||_a===void 0?void 0:_a.source;if(source)return{brand:source.scheme.toLowerCase(),exp_month:source.expiry_month,exp_year:source.expiry_year,last4:source.last4};break}case"stripe_payments":{const ps=customerPayment.payment_source,source=((_e=(_c=(_b=ps?.options)===null||_b===void 0?void 0:_b.card)!==null&&_c!==void 0?_c:(_d=ps?.payment_method)===null||_d===void 0?void 0:_d.card)!==null&&_e!==void 0?_e:ps?.payment_instrument)?{brand:(_f=ps?.payment_instrument)===null||_f===void 0?void 0:_f.card_type,exp_month:(_g=ps?.payment_instrument)===null||_g===void 0?void 0:_g.card_expiry_month,exp_year:(_h=ps?.payment_instrument)===null||_h===void 0?void 0:_h.card_expiry_year,last4:(_j=ps?.payment_instrument)===null||_j===void 0?void 0:_j.card_last_digits,issuer_type:(_k=ps?.payment_instrument)===null||_k===void 0?void 0:_k.issuer_type}:void 0;if(source?.brand!=null)return Object.assign({},source);break}case"klarna_payments":{const ps=customerPayment.payment_source,source=ps?.auth_token!=null&&ps?.payment_instrument!=null?{brand:"klarna",exp_month:"",exp_year:"",last4:"",issuer_type:(_l=ps?.payment_instrument)===null||_l===void 0?void 0:_l.issuer_type}:void 0;if(source)return Object.assign({},source);break}case"braintree_payments":{const ps=customerPayment.payment_source,source=(_m=ps?.options)===null||_m===void 0?void 0:_m.card;if(source)return Object.assign({},source);break}case"adyen_payments":{const ps=customerPayment.payment_source,source=(_o=ps?.payment_request_data)===null||_o===void 0?void 0:_o.payment_method,authorized=((_p=ps?.payment_response)===null||_p===void 0?void 0:_p.resultCode)==="Authorised",last4=(_u=(_s=(_r=(_q=ps?.payment_response)===null||_q===void 0?void 0:_q.additionalData)===null||_r===void 0?void 0:_r.cardSummary)!==null&&_s!==void 0?_s:(_t=ps?.payment_instrument)===null||_t===void 0?void 0:_t.card_last_digits)!==null&&_u!==void 0?_u:"****";if(source&&authorized){const brand=source.type==="scheme"?(_v=source.brand)!==null&&_v!==void 0?_v:"credit-card":source.type.replace("_account","");return Object.assign(Object.assign({},source),{last4,brand})}break}default:{const ps=customerPayment.payment_source,source=(_x=(_w=ps?.metadata)===null||_w===void 0?void 0:_w.card)!==null&&_x!==void 0?_x:{brand:(_z=(_y=ps?.payment_instrument)===null||_y===void 0?void 0:_y.issuer_type.replace("_","-"))!==null&&_z!==void 0?_z:"",last4:(_1=(_0=ps?.metadata)===null||_0===void 0?void 0:_0.last4)!==null&&_1!==void 0?_1:"",exp_month:(_3=(_2=ps?.metadata)===null||_2===void 0?void 0:_2.exp_month)!==null&&_3!==void 0?_3:"",exp_year:(_5=(_4=ps?.metadata)===null||_4===void 0?void 0:_4.exp_year)!==null&&_5!==void 0?_5:""};if(source)return Object.assign({},source);break}}return{brand:"",exp_month:"**",exp_year:"**",last4:"****",issuer_type:""}}
2
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=getCardDetails;function getCardDetails({paymentType,customerPayment}){var _a,_b,_c,_d,_e,_f,_g,_h,_j,_k,_l,_m,_o,_p,_q,_r,_s,_t,_u,_v,_w,_x,_y,_z,_0,_1,_2,_3,_4,_5;switch(paymentType){case"checkout_com_payments":{const ps=customerPayment.payment_source,source=(_a=ps?.payment_response)===null||_a===void 0?void 0:_a.source;if(source)return{brand:source.scheme.toLowerCase(),exp_month:source.expiry_month,exp_year:source.expiry_year,last4:source.last4};break}case"stripe_payments":{const ps=customerPayment.payment_source,source=((_e=(_c=(_b=ps?.options)===null||_b===void 0?void 0:_b.card)!==null&&_c!==void 0?_c:(_d=ps?.payment_method)===null||_d===void 0?void 0:_d.card)!==null&&_e!==void 0?_e:ps?.payment_instrument)?{brand:(_f=ps?.payment_instrument)===null||_f===void 0?void 0:_f.card_type,exp_month:(_g=ps?.payment_instrument)===null||_g===void 0?void 0:_g.card_expiry_month,exp_year:(_h=ps?.payment_instrument)===null||_h===void 0?void 0:_h.card_expiry_year,last4:(_j=ps?.payment_instrument)===null||_j===void 0?void 0:_j.card_last_digits,issuer_type:(_k=ps?.payment_instrument)===null||_k===void 0?void 0:_k.issuer_type}:void 0;if(source?.brand!=null)return Object.assign({},source);break}case"klarna_payments":{const ps=customerPayment.payment_source,source=ps?.auth_token!=null&&ps?.payment_instrument!=null?{brand:"klarna",exp_month:"",exp_year:"",last4:"",issuer_type:(_l=ps?.payment_instrument)===null||_l===void 0?void 0:_l.issuer_type}:void 0;if(source)return Object.assign({},source);break}case"braintree_payments":{const ps=customerPayment.payment_source,source=(_m=ps?.options)===null||_m===void 0?void 0:_m.card;if(source)return Object.assign({},source);break}case"adyen_payments":{const ps=customerPayment.payment_source,source=(_o=ps?.payment_request_data)===null||_o===void 0?void 0:_o.payment_method,authorized=((_p=ps?.payment_response)===null||_p===void 0?void 0:_p.resultCode)==="Authorised",last4=(_u=(_s=(_r=(_q=ps?.payment_response)===null||_q===void 0?void 0:_q.additionalData)===null||_r===void 0?void 0:_r.cardSummary)!==null&&_s!==void 0?_s:(_t=ps?.payment_instrument)===null||_t===void 0?void 0:_t.card_last_digits)!==null&&_u!==void 0?_u:"****";if(source&&authorized){const brand=source.type==="scheme"?(_v=source.brand)!==null&&_v!==void 0?_v:"credit-card":source.type.replace("_account","");return Object.assign(Object.assign({},source),{last4,brand})}break}default:{const ps=customerPayment.payment_source;if(ps?.type!==paymentType)break;const source=(_x=(_w=ps?.metadata)===null||_w===void 0?void 0:_w.card)!==null&&_x!==void 0?_x:{brand:(_z=(_y=ps?.payment_instrument)===null||_y===void 0?void 0:_y.issuer_type.replace("_","-"))!==null&&_z!==void 0?_z:"",last4:(_1=(_0=ps?.metadata)===null||_0===void 0?void 0:_0.last4)!==null&&_1!==void 0?_1:"",exp_month:(_3=(_2=ps?.metadata)===null||_2===void 0?void 0:_2.exp_month)!==null&&_3!==void 0?_3:"",exp_year:(_5=(_4=ps?.metadata)===null||_4===void 0?void 0:_4.exp_year)!==null&&_5!==void 0?_5:""};if(source)return Object.assign({},source);break}}return{brand:"",exp_month:"**",exp_year:"**",last4:"****",issuer_type:""}}
@@ -1,5 +1,5 @@
1
- import type { GatewayBaseType } from '../payment_gateways/PaymentGateway';
2
- import { type JSX } from 'react';
1
+ import type { GatewayBaseType } from "../payment_gateways/PaymentGateway";
2
+ import { type JSX } from "react";
3
3
  type Props = GatewayBaseType;
4
4
  export declare function ExternalGateway(props: Props): JSX.Element | null;
5
5
  export default ExternalGateway;
@@ -1,2 +1,2 @@
1
1
  "use client";
2
- import{jsx as _jsx,Fragment as _Fragment,jsxs as _jsxs}from"react/jsx-runtime";import ExternalPayment from"../payment_source/ExternalPayment";import CustomerContext from"../../context/CustomerContext";import OrderContext from"../../context/OrderContext";import PaymentMethodChildrenContext from"../../context/PaymentMethodChildrenContext";import PaymentMethodContext from"../../context/PaymentMethodContext";import PaymentSourceContext from"../../context/PaymentSourceContext";import{getPaymentConfig}from"../../reducers/PaymentMethodReducer";import getCardDetails from"../../utils/getCardDetails";import isEmpty from"lodash/isEmpty";import React from"react";import PaymentCardsTemplate from"../utils/PaymentCardsTemplate";export function ExternalGateway(props){const{readonly,showCard,handleEditClick,children,templateCustomerCards,show,loading,loaderComponent,templateCustomerSaveToWallet,...p}=props,{order}=React.useContext(OrderContext),{payment}=React.useContext(PaymentMethodChildrenContext),{payments,isGuest}=React.useContext(CustomerContext),{currentPaymentMethodId,config,paymentSource}=React.useContext(PaymentMethodContext),paymentResource="external_payments",locale=order?.language_code;if(!readonly&&payment?.id!==currentPaymentMethodId)return null;const paymentSourceToken=paymentSource?.payment_source_token,paymentConfig=(config?getPaymentConfig(paymentResource,config):{})?.externalPayment,customerPayments=!isEmpty(payments)&&payments?payments.filter(customerPayment=>customerPayment.payment_source?.type===paymentResource):[];if(readonly||showCard){const card=getCardDetails({customerPayment:{payment_source:paymentSource},paymentType:paymentResource}),value={...card,showCard,handleEditClick,readonly};return isEmpty(card)?null:_jsx(PaymentSourceContext.Provider,{value,children})}return!isGuest&&templateCustomerCards?_jsxs(_Fragment,{children:[isEmpty(customerPayments)?null:_jsx("div",{className:p.className,children:_jsx(PaymentCardsTemplate,{paymentResource,customerPayments,children:templateCustomerCards})}),_jsx(ExternalPayment,{show,templateCustomerSaveToWallet,paymentSourceToken,locale,...paymentConfig})]}):_jsx(ExternalPayment,{show,paymentSourceToken,locale,...paymentConfig})}export default ExternalGateway;
2
+ import{jsx as _jsx,Fragment as _Fragment,jsxs as _jsxs}from"react/jsx-runtime";import ExternalPayment from"../payment_source/ExternalPayment";import CustomerContext from"../../context/CustomerContext";import OrderContext from"../../context/OrderContext";import PaymentMethodChildrenContext from"../../context/PaymentMethodChildrenContext";import PaymentMethodContext from"../../context/PaymentMethodContext";import PaymentSourceContext from"../../context/PaymentSourceContext";import{getPaymentConfig}from"../../reducers/PaymentMethodReducer";import getCardDetails from"../../utils/getCardDetails";import isEmpty from"lodash/isEmpty";import React from"react";import PaymentCardsTemplate from"../utils/PaymentCardsTemplate";export function ExternalGateway(props){const{readonly,showCard,handleEditClick,children,templateCustomerCards,show,loading,loaderComponent,templateCustomerSaveToWallet,...p}=props,{order}=React.useContext(OrderContext),{payment}=React.useContext(PaymentMethodChildrenContext),{payments,isGuest}=React.useContext(CustomerContext),{currentPaymentMethodId,config,paymentSource}=React.useContext(PaymentMethodContext),paymentResource="external_payments",locale=order?.language_code;if(!readonly&&payment?.id!==currentPaymentMethodId)return null;const paymentSourceToken=paymentSource?.payment_source_token,paymentConfig=(config?getPaymentConfig(paymentResource,config):{})?.externalPayment,customerPayments=!isEmpty(payments)&&payments?payments.filter(customerPayment=>customerPayment.payment_source?.type===paymentResource):[];if(readonly){const card=getCardDetails({customerPayment:{payment_source:paymentSource},paymentType:paymentResource}),value={...card,showCard,handleEditClick,readonly};return isEmpty(card)?null:_jsx(PaymentSourceContext.Provider,{value,children})}return!isGuest&&templateCustomerCards?_jsxs(_Fragment,{children:[isEmpty(customerPayments)?null:_jsx("div",{className:p.className,children:_jsx(PaymentCardsTemplate,{paymentResource,customerPayments,children:templateCustomerCards})}),_jsx(ExternalPayment,{show,templateCustomerSaveToWallet,paymentSourceToken,locale,...paymentConfig})]}):_jsx(ExternalPayment,{show,paymentSourceToken,locale,...paymentConfig})}export default ExternalGateway;
@@ -1,7 +1,7 @@
1
- import type { ChildrenFunction } from '../../typings/index';
2
- import type { StripeElementLocale } from '@stripe/stripe-js';
3
- import { type JSX } from 'react';
4
- import type { PaymentSourceProps } from './PaymentSource';
1
+ import type { ChildrenFunction } from "../../typings/index";
2
+ import type { StripeElementLocale } from "@stripe/stripe-js";
3
+ import { type JSX } from "react";
4
+ import type { PaymentSourceProps } from "./PaymentSource";
5
5
  export interface ExternalPaymentConfig {
6
6
  /**
7
7
  * Show the component. Default is false
@@ -10,13 +10,13 @@ export interface ExternalPaymentConfig {
10
10
  /**
11
11
  * Use to display information about the external payment or whatever else.
12
12
  */
13
- customComponent?: ChildrenFunction<Omit<Props, 'customComponent'>>;
13
+ customComponent?: ChildrenFunction<Omit<Props, "customComponent">>;
14
14
  /**
15
15
  * The payment source token, as generated by the external gateway SDK. Credit Card numbers are rejected.
16
16
  */
17
17
  payment_source_token: string;
18
18
  }
19
- interface Props extends Omit<ExternalPaymentConfig, 'payment_source_token'>, Pick<PaymentSourceProps, 'templateCustomerSaveToWallet'> {
19
+ interface Props extends Omit<ExternalPaymentConfig, "payment_source_token">, Pick<PaymentSourceProps, "templateCustomerSaveToWallet"> {
20
20
  paymentSourceToken: string;
21
21
  locale?: StripeElementLocale;
22
22
  }
@@ -1,13 +1,13 @@
1
- import { type JSX } from 'react';
2
- import type { LoaderType } from '../../typings/index';
3
- import type { CustomerCardsTemplateChildren } from '../utils/PaymentCardsTemplate';
1
+ import { type JSX } from "react";
2
+ import type { LoaderType } from "../../typings/index";
3
+ import type { CustomerCardsTemplateChildren } from "../utils/PaymentCardsTemplate";
4
4
  export interface CustomerCardsProps {
5
5
  handleClick: () => void;
6
6
  }
7
7
  export interface CustomerSaveToWalletProps {
8
- name: 'save_payment_source_to_customer_wallet';
8
+ name: "save_payment_source_to_customer_wallet";
9
9
  }
10
- export interface PaymentSourceProps extends Omit<JSX.IntrinsicElements['div'], 'children'> {
10
+ export interface PaymentSourceProps extends Omit<JSX.IntrinsicElements["div"], "children"> {
11
11
  children?: JSX.Element | JSX.Element[];
12
12
  readonly?: boolean;
13
13
  templateCustomerCards?: CustomerCardsTemplateChildren;
@@ -1,2 +1,2 @@
1
1
  "use client";
2
- import{jsx as _jsx}from"react/jsx-runtime";import{useContext,useState,useEffect}from"react";import PaymentMethodChildrenContext from"../../context/PaymentMethodChildrenContext";import PaymentMethodContext from"../../context/PaymentMethodContext";import CustomerContext from"../../context/CustomerContext";import PaymentGateway from"../payment_gateways/PaymentGateway";import getCardDetails from"../../utils/getCardDetails";import OrderContext from"../../context/OrderContext";export function PaymentSource(props){const{readonly}=props,{payment,expressPayments}=useContext(PaymentMethodChildrenContext),{order}=useContext(OrderContext),{payments}=useContext(CustomerContext),{currentPaymentMethodId,paymentSource,destroyPaymentSource,currentPaymentMethodType,currentCustomerPaymentSourceId}=useContext(PaymentMethodContext),[show,setShow]=useState(!1),[showCard,setShowCard]=useState(!1);useEffect(()=>{const isCustomerPaymentSource=currentCustomerPaymentSourceId!=null&&currentCustomerPaymentSourceId===paymentSource?.id;if(readonly)setShow(!0),setShowCard(!0);else if((payment?.id===currentPaymentMethodId||isCustomerPaymentSource)&&!expressPayments){setShow(!0);const card=getCardDetails({paymentType:payment?.payment_source_type,customerPayment:{payment_source:paymentSource}});isCustomerPaymentSource&&card.brand===""&&(card.brand=card.issuer_type!=null&&card.issuer_type!==""?card.issuer_type:"credit-card"),card.brand&&setShowCard(!0)}else setShow(!!(expressPayments&&currentPaymentMethodType==="stripe_payments"));return()=>{setShow(!1),setShowCard(!1)}},[currentPaymentMethodId,paymentSource?.id,payments!=null,payment!=null,readonly,order?.status,expressPayments]);const gatewayProps={...props,show,showCard,handleEditClick:async e=>{if(e.stopPropagation(),paymentSource){const paymentSourceId=paymentSource?.id;await destroyPaymentSource({paymentSourceId,paymentResource:payment?.payment_source_type})}setShowCard(!showCard),setShow(!0)},readonly};return _jsx(PaymentGateway,{...gatewayProps})}export default PaymentSource;
2
+ import{jsx as _jsx}from"react/jsx-runtime";import{useContext,useState,useEffect}from"react";import PaymentMethodChildrenContext from"../../context/PaymentMethodChildrenContext";import PaymentMethodContext from"../../context/PaymentMethodContext";import CustomerContext from"../../context/CustomerContext";import PaymentGateway from"../payment_gateways/PaymentGateway";import getCardDetails from"../../utils/getCardDetails";import OrderContext from"../../context/OrderContext";export function PaymentSource(props){const{readonly}=props,{payment,expressPayments}=useContext(PaymentMethodChildrenContext),{order}=useContext(OrderContext),{payments}=useContext(CustomerContext),{currentPaymentMethodId,paymentSource,destroyPaymentSource,currentPaymentMethodType,currentCustomerPaymentSourceId}=useContext(PaymentMethodContext),[show,setShow]=useState(!1),[showCard,setShowCard]=useState(!1);useEffect(()=>{const isCustomerPaymentSource=currentCustomerPaymentSourceId!=null&&currentCustomerPaymentSourceId===paymentSource?.id;if(readonly)setShow(!0),setShowCard(!0);else if((payment?.id===currentPaymentMethodId||isCustomerPaymentSource)&&!expressPayments){const card=getCardDetails({paymentType:payment?.payment_source_type,customerPayment:{payment_source:paymentSource}});isCustomerPaymentSource&&card.brand===""&&(card.brand=card.issuer_type!=null&&card.issuer_type!==""?card.issuer_type:"credit-card"),card.brand&&setShowCard(!0),setShow(!0)}else expressPayments&&currentPaymentMethodType==="stripe_payments"&&setShow(!0);return()=>{setShow(!1),setShowCard(!1)}},[currentPaymentMethodId,paymentSource?.id,payments!=null,payment!=null,readonly,order?.status,expressPayments]);const gatewayProps={...props,show,showCard,handleEditClick:async e=>{if(e.stopPropagation(),paymentSource){const paymentSourceId=paymentSource?.id;await destroyPaymentSource({paymentSourceId,paymentResource:payment?.payment_source_type})}setShowCard(!showCard),setShow(!0)},readonly};return _jsx(PaymentGateway,{...gatewayProps})}export default PaymentSource;
@@ -1,6 +1,6 @@
1
- import type { IconBrand } from '../context/PaymentSourceContext';
2
- import type { PaymentResource } from '../reducers/PaymentMethodReducer';
3
- import type { CustomerPaymentSource } from '@commercelayer/sdk';
1
+ import type { IconBrand } from "../context/PaymentSourceContext";
2
+ import type { PaymentResource } from "../reducers/PaymentMethodReducer";
3
+ import type { CustomerPaymentSource } from "@commercelayer/sdk";
4
4
  interface CardDetails {
5
5
  brand: IconBrand | string;
6
6
  last4: string;
@@ -12,5 +12,5 @@ interface Args {
12
12
  paymentType: PaymentResource;
13
13
  customerPayment: Partial<CustomerPaymentSource>;
14
14
  }
15
- export default function getCardDetails({ paymentType, customerPayment }: Args): CardDetails;
15
+ export default function getCardDetails({ paymentType, customerPayment, }: Args): CardDetails;
16
16
  export {};
@@ -1,2 +1,2 @@
1
1
  "use client";
2
- export default function getCardDetails({paymentType,customerPayment}){switch(paymentType){case"checkout_com_payments":{const source=customerPayment.payment_source?.payment_response?.source;if(source)return{brand:source.scheme.toLowerCase(),exp_month:source.expiry_month,exp_year:source.expiry_year,last4:source.last4};break}case"stripe_payments":{const ps=customerPayment.payment_source,source=ps?.options?.card??ps?.payment_method?.card??ps?.payment_instrument?{brand:ps?.payment_instrument?.card_type,exp_month:ps?.payment_instrument?.card_expiry_month,exp_year:ps?.payment_instrument?.card_expiry_year,last4:ps?.payment_instrument?.card_last_digits,issuer_type:ps?.payment_instrument?.issuer_type}:void 0;if(source?.brand!=null)return{...source};break}case"klarna_payments":{const ps=customerPayment.payment_source,source=ps?.auth_token!=null&&ps?.payment_instrument!=null?{brand:"klarna",exp_month:"",exp_year:"",last4:"",issuer_type:ps?.payment_instrument?.issuer_type}:void 0;if(source)return{...source};break}case"braintree_payments":{const source=customerPayment.payment_source?.options?.card;if(source)return{...source};break}case"adyen_payments":{const ps=customerPayment.payment_source,source=ps?.payment_request_data?.payment_method,authorized=ps?.payment_response?.resultCode==="Authorised",last4=ps?.payment_response?.additionalData?.cardSummary??ps?.payment_instrument?.card_last_digits??"****";if(source&&authorized){const brand=source.type==="scheme"?source.brand??"credit-card":source.type.replace("_account","");return{...source,last4,brand}}break}default:{const ps=customerPayment.payment_source,source=ps?.metadata?.card??{brand:ps?.payment_instrument?.issuer_type.replace("_","-")??"",last4:ps?.metadata?.last4??"",exp_month:ps?.metadata?.exp_month??"",exp_year:ps?.metadata?.exp_year??""};if(source)return{...source};break}}return{brand:"",exp_month:"**",exp_year:"**",last4:"****",issuer_type:""}}
2
+ export default function getCardDetails({paymentType,customerPayment}){switch(paymentType){case"checkout_com_payments":{const source=customerPayment.payment_source?.payment_response?.source;if(source)return{brand:source.scheme.toLowerCase(),exp_month:source.expiry_month,exp_year:source.expiry_year,last4:source.last4};break}case"stripe_payments":{const ps=customerPayment.payment_source,source=ps?.options?.card??ps?.payment_method?.card??ps?.payment_instrument?{brand:ps?.payment_instrument?.card_type,exp_month:ps?.payment_instrument?.card_expiry_month,exp_year:ps?.payment_instrument?.card_expiry_year,last4:ps?.payment_instrument?.card_last_digits,issuer_type:ps?.payment_instrument?.issuer_type}:void 0;if(source?.brand!=null)return{...source};break}case"klarna_payments":{const ps=customerPayment.payment_source,source=ps?.auth_token!=null&&ps?.payment_instrument!=null?{brand:"klarna",exp_month:"",exp_year:"",last4:"",issuer_type:ps?.payment_instrument?.issuer_type}:void 0;if(source)return{...source};break}case"braintree_payments":{const source=customerPayment.payment_source?.options?.card;if(source)return{...source};break}case"adyen_payments":{const ps=customerPayment.payment_source,source=ps?.payment_request_data?.payment_method,authorized=ps?.payment_response?.resultCode==="Authorised",last4=ps?.payment_response?.additionalData?.cardSummary??ps?.payment_instrument?.card_last_digits??"****";if(source&&authorized){const brand=source.type==="scheme"?source.brand??"credit-card":source.type.replace("_account","");return{...source,last4,brand}}break}default:{const ps=customerPayment.payment_source;if(ps?.type!==paymentType)break;const source=ps?.metadata?.card??{brand:ps?.payment_instrument?.issuer_type.replace("_","-")??"",last4:ps?.metadata?.last4??"",exp_month:ps?.metadata?.exp_month??"",exp_year:ps?.metadata?.exp_year??""};if(source)return{...source};break}}return{brand:"",exp_month:"**",exp_year:"**",last4:"****",issuer_type:""}}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@commercelayer/react-components",
3
- "version": "4.20.5",
3
+ "version": "4.20.6",
4
4
  "description": "The Official Commerce Layer React Components",
5
5
  "main": "lib/cjs/index.js",
6
6
  "module": "lib/esm/index.js",