@commercelayer/react-components 3.4.0 → 3.4.3
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 +1 @@
|
|
|
1
|
-
import{__rest}from"tslib";import{jsx as _jsx}from"react/jsx-runtime";import{useContext,useEffect,useState}from"react";import Parent from"./utils/Parent";import components from"../config/components";import PlaceOrderContext from"../context/PlaceOrderContext";import isFunction from"lodash/isFunction";import PaymentMethodContext from"../context/PaymentMethodContext";import OrderContext from"../context/OrderContext";import getCardDetails from"../utils/getCardDetails";const propTypes=components.PlaceOrderButton.propTypes,defaultProps=components.PlaceOrderButton.defaultProps,displayName=components.PlaceOrderButton.displayName,PlaceOrderButton=props=>{var _a;const{children,label="Place order",disabled,onClick}=props,p=__rest(props,["children","label","disabled","onClick"]),{isPermitted,setPlaceOrder,options,paymentType}=useContext(PlaceOrderContext),[notPermitted,setNotPermitted]=useState(!0),[forceDisable,setForceDisable]=useState(disabled),{currentPaymentMethodRef,paymentSource,loading,currentPaymentMethodType}=useContext(PaymentMethodContext),{order}=useContext(OrderContext);useEffect(()=>{var _a2;if(loading)setNotPermitted(loading);else if(paymentType===currentPaymentMethodType&&paymentType){const card=getCardDetails({customerPayment:{payment_source:paymentSource},paymentType});(
|
|
1
|
+
import{__rest}from"tslib";import{jsx as _jsx}from"react/jsx-runtime";import{useContext,useEffect,useState}from"react";import Parent from"./utils/Parent";import components from"../config/components";import PlaceOrderContext from"../context/PlaceOrderContext";import isFunction from"lodash/isFunction";import PaymentMethodContext from"../context/PaymentMethodContext";import OrderContext from"../context/OrderContext";import getCardDetails from"../utils/getCardDetails";const propTypes=components.PlaceOrderButton.propTypes,defaultProps=components.PlaceOrderButton.defaultProps,displayName=components.PlaceOrderButton.displayName,PlaceOrderButton=props=>{var _a;const{children,label="Place order",disabled,onClick}=props,p=__rest(props,["children","label","disabled","onClick"]),{isPermitted,setPlaceOrder,options,paymentType}=useContext(PlaceOrderContext),[notPermitted,setNotPermitted]=useState(!0),[forceDisable,setForceDisable]=useState(disabled),{currentPaymentMethodRef,paymentSource,loading,currentPaymentMethodType}=useContext(PaymentMethodContext),{order}=useContext(OrderContext),isFree=(order==null?void 0:order.total_amount_with_taxes_cents)===0;useEffect(()=>{var _a2;if(loading)setNotPermitted(loading);else if(paymentType===currentPaymentMethodType&&paymentType){const card=getCardDetails({customerPayment:{payment_source:paymentSource},paymentType});(isFree||((_a2=currentPaymentMethodRef==null?void 0:currentPaymentMethodRef.current)===null||_a2===void 0?void 0:_a2.onsubmit)||card.brand)&&isPermitted&&setNotPermitted(!1)}else setNotPermitted(!isFree);return()=>{setNotPermitted(!0)}},[isPermitted,paymentType,(_a=currentPaymentMethodRef==null?void 0:currentPaymentMethodRef.current)===null||_a===void 0?void 0:_a.onsubmit,paymentSource,loading,currentPaymentMethodType,order]),useEffect(()=>{paymentType==="paypal_payments"&&(options==null?void 0:options.paypalPayerId)&&(order==null?void 0:order.status)&&["draft","pending"].includes(order==null?void 0:order.status)&&handleClick()},[options==null?void 0:options.paypalPayerId]),useEffect(()=>{var _a2,_b;paymentType==="adyen_payments"&&((_a2=options==null?void 0:options.adyen)===null||_a2===void 0?void 0:_a2.MD)&&((_b=options==null?void 0:options.adyen)===null||_b===void 0?void 0:_b.PaRes)&&(order==null?void 0:order.status)&&["draft","pending"].includes(order==null?void 0:order.status)&&handleClick()},[options==null?void 0:options.adyen]),useEffect(()=>{var _a2;paymentType==="checkout_com_payments"&&((_a2=options==null?void 0:options.checkoutCom)===null||_a2===void 0?void 0:_a2.session_id)&&(order==null?void 0:order.status)&&["draft","pending"].includes(order==null?void 0:order.status)&&handleClick()},[options==null?void 0:options.checkoutCom]);const handleClick=async()=>{var _a2,_b,_c,_d;let isValid=!0;setForceDisable(!0);const card=paymentType&&getCardDetails({paymentType,customerPayment:{payment_source:paymentSource}});((_a2=currentPaymentMethodRef==null?void 0:currentPaymentMethodRef.current)===null||_a2===void 0?void 0:_a2.onsubmit)&&[!(options==null?void 0:options.paypalPayerId),!((_b=options==null?void 0:options.adyen)===null||_b===void 0?void 0:_b.MD),!((_c=options==null?void 0:options.checkoutCom)===null||_c===void 0?void 0:_c.session_id)].every(Boolean)?isValid=await((_d=currentPaymentMethodRef.current)===null||_d===void 0?void 0:_d.onsubmit()):(card==null?void 0:card.brand)&&(isValid=!0);const placed=isValid&&setPlaceOrder&&(paymentSource||isFree)&&await setPlaceOrder({paymentSource});setForceDisable(!1),onClick&&placed&&onClick(placed)},disabledButton=disabled!==void 0?disabled:notPermitted,parentProps=Object.assign(Object.assign({},p),{label,disabled:disabledButton,handleClick});return children?_jsx(Parent,Object.assign({},parentProps,{children}),void 0):_jsx("button",Object.assign({type:"button",disabled:disabledButton||forceDisable,onClick:handleClick},p,{children:isFunction(label)?label():label}),void 0)};PlaceOrderButton.propTypes=propTypes,PlaceOrderButton.defaultProps=defaultProps,PlaceOrderButton.displayName=displayName;export default PlaceOrderButton;
|
|
@@ -4,7 +4,7 @@ import { PaymentSourceType } from '../reducers/PaymentMethodReducer';
|
|
|
4
4
|
declare type DefaultContext = {
|
|
5
5
|
setPlaceOrderErrors?: SetPlaceOrderErrors;
|
|
6
6
|
setPlaceOrder?: ({ paymentSource, }: {
|
|
7
|
-
paymentSource
|
|
7
|
+
paymentSource?: PaymentSourceType;
|
|
8
8
|
options?: PlaceOrderOptions;
|
|
9
9
|
}) => Promise<{
|
|
10
10
|
placed: boolean;
|
|
@@ -18,8 +18,11 @@ declare type Card = {
|
|
|
18
18
|
};
|
|
19
19
|
export declare type PaymentSourceObject = {
|
|
20
20
|
adyen_payments: AdyenPayment & {
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
payment_request_data?: {
|
|
22
|
+
payment_method?: Card;
|
|
23
|
+
};
|
|
24
|
+
payment_response?: {
|
|
25
|
+
resultCode?: 'Authorised';
|
|
23
26
|
};
|
|
24
27
|
};
|
|
25
28
|
braintree_payments: BraintreePayment & {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export default function getCardDetails({paymentType,customerPayment}){var _a,_b,_c,_d;switch(paymentType){case"checkout_com_payments":{const ps=customerPayment.payment_source,source=(_a=ps==null?void 0: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":case"braintree_payments":{const ps=customerPayment.payment_source,source=(_b=ps==null?void 0:ps.options)===null||_b===void 0?void 0:_b.card;if(source)return Object.assign({},source);break}case"adyen_payments":{const ps=customerPayment.payment_source,source=(_c=ps==null?void 0:ps.
|
|
1
|
+
export default function getCardDetails({paymentType,customerPayment}){var _a,_b,_c,_d,_e;switch(paymentType){case"checkout_com_payments":{const ps=customerPayment.payment_source,source=(_a=ps==null?void 0: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":case"braintree_payments":{const ps=customerPayment.payment_source,source=(_b=ps==null?void 0:ps.options)===null||_b===void 0?void 0:_b.card;if(source)return Object.assign({},source);break}case"adyen_payments":{const ps=customerPayment.payment_source,source=(_c=ps==null?void 0:ps.payment_request_data)===null||_c===void 0?void 0:_c.payment_method,authorized=((_d=ps==null?void 0:ps.payment_response)===null||_d===void 0?void 0:_d.resultCode)==="Authorised";if(source&&authorized)return Object.assign(Object.assign({},source),{brand:(source==null?void 0:source.brand)?source.brand:"credit-card"});break}default:{const ps=customerPayment.payment_source,source=(_e=ps==null?void 0:ps.metadata)===null||_e===void 0?void 0:_e.card;if(source)return Object.assign({},source);break}}return{brand:"",exp_month:"**",exp_year:"**",last4:"****"}}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@commercelayer/react-components",
|
|
3
|
-
"version": "3.4.
|
|
3
|
+
"version": "3.4.3",
|
|
4
4
|
"description": "The Official Commerce Layer React Components",
|
|
5
5
|
"module": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -83,12 +83,12 @@
|
|
|
83
83
|
"dependencies": {
|
|
84
84
|
"@ac-dev/countries-service": "^1.1.3",
|
|
85
85
|
"@ac-dev/states-service": "^1.0.3",
|
|
86
|
-
"@adyen/adyen-web": "^5.
|
|
86
|
+
"@adyen/adyen-web": "^5.8.0",
|
|
87
87
|
"@commercelayer/js-auth": "^3.0.0",
|
|
88
88
|
"@commercelayer/sdk": "^3.5.0",
|
|
89
89
|
"@stripe/react-stripe-js": "^1.7.0",
|
|
90
|
-
"@stripe/stripe-js": "^1.
|
|
91
|
-
"axios": "^0.
|
|
90
|
+
"@stripe/stripe-js": "^1.23.0",
|
|
91
|
+
"axios": "^0.26.0",
|
|
92
92
|
"braintree-web": "^3.85.2",
|
|
93
93
|
"frames-react": "^1.0.3",
|
|
94
94
|
"jwt-decode": "^3.1.2",
|
|
@@ -101,7 +101,7 @@
|
|
|
101
101
|
"@babel/preset-env": "^7.16.11",
|
|
102
102
|
"@babel/preset-react": "^7.16.7",
|
|
103
103
|
"@babel/preset-typescript": "^7.16.7",
|
|
104
|
-
"@playwright/test": "^1.
|
|
104
|
+
"@playwright/test": "^1.19.1",
|
|
105
105
|
"@semantic-release/changelog": "^6.0.1",
|
|
106
106
|
"@semantic-release/commit-analyzer": "^9.0.2",
|
|
107
107
|
"@semantic-release/git": "^10.0.1",
|
|
@@ -111,16 +111,16 @@
|
|
|
111
111
|
"@tailwindcss/aspect-ratio": "^0.4.0",
|
|
112
112
|
"@tailwindcss/forms": "^0.4.0",
|
|
113
113
|
"@tailwindcss/line-clamp": "^0.3.1",
|
|
114
|
-
"@tailwindcss/typography": "^0.5.
|
|
114
|
+
"@tailwindcss/typography": "^0.5.2",
|
|
115
115
|
"@types/braintree-web": "^3.75.17",
|
|
116
|
-
"@types/jest": "^27.4.
|
|
116
|
+
"@types/jest": "^27.4.1",
|
|
117
117
|
"@types/lodash": "^4.14.178",
|
|
118
|
-
"@types/node": "^17.0.
|
|
118
|
+
"@types/node": "^17.0.21",
|
|
119
119
|
"@types/prop-types": "^15.7.4",
|
|
120
120
|
"@types/react": "^17.0.39",
|
|
121
121
|
"@types/react-test-renderer": "^17.0.1",
|
|
122
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
123
|
-
"@typescript-eslint/parser": "^5.
|
|
122
|
+
"@typescript-eslint/eslint-plugin": "^5.12.1",
|
|
123
|
+
"@typescript-eslint/parser": "^5.12.1",
|
|
124
124
|
"@zeit/next-css": "^1.0.1",
|
|
125
125
|
"@zerollup/ts-transform-paths": "^1.7.18",
|
|
126
126
|
"autoprefixer": "^10.4.2",
|
|
@@ -128,16 +128,16 @@
|
|
|
128
128
|
"babel-loader": "^8.2.3",
|
|
129
129
|
"babel-plugin-istanbul": "^6.1.1",
|
|
130
130
|
"dotenv": "^16.0.0",
|
|
131
|
-
"eslint": "^8.
|
|
132
|
-
"eslint-config-prettier": "^8.
|
|
131
|
+
"eslint": "^8.9.0",
|
|
132
|
+
"eslint-config-prettier": "^8.4.0",
|
|
133
133
|
"eslint-config-react-app": "^7.0.0",
|
|
134
134
|
"eslint-plugin-react": "^7.28.0",
|
|
135
135
|
"eslint-plugin-react-hooks": "^4.3.0",
|
|
136
136
|
"jest": "^27.5.1",
|
|
137
137
|
"minimize-js": "^1.2.0",
|
|
138
|
-
"next": "^12.0
|
|
138
|
+
"next": "^12.1.0",
|
|
139
139
|
"nyc": "^15.1.0",
|
|
140
|
-
"playwright": "^1.
|
|
140
|
+
"playwright": "^1.19.1",
|
|
141
141
|
"postcss": "^8.4.6",
|
|
142
142
|
"postcss-loader": "^6.2.1",
|
|
143
143
|
"prettier": "^2.5.1",
|
|
@@ -147,10 +147,10 @@
|
|
|
147
147
|
"react-test-renderer": "^17.0.2",
|
|
148
148
|
"rollup-plugin-babel": "^4.4.0",
|
|
149
149
|
"rollup-plugin-node-resolve": "^5.2.0",
|
|
150
|
-
"tailwindcss": "^3.0.
|
|
150
|
+
"tailwindcss": "^3.0.23",
|
|
151
151
|
"ts-jest": "^27.1.3",
|
|
152
152
|
"ts-loader": "^9.2.6",
|
|
153
|
-
"tsc-alias": "^1.6.
|
|
153
|
+
"tsc-alias": "^1.6.2",
|
|
154
154
|
"tsconfig-paths-jest": "^0.0.1",
|
|
155
155
|
"ttypescript": "^1.5.13",
|
|
156
156
|
"typescript": "^4.5.5",
|