Skip to content

Commit

Permalink
Merge pull request #464 from commercelayer/fix/payment-flow
Browse files Browse the repository at this point in the history
fix: Adyen payments input flow.
  • Loading branch information
acasazza authored Jan 4, 2024
2 parents e584dba + bd7d9a3 commit 53430b9
Show file tree
Hide file tree
Showing 7 changed files with 169 additions and 156 deletions.
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"$schema": "node_modules/lerna/schemas/lerna-schema.json",
"useNx": false,
"npmClient": "pnpm",
"version": "4.8.4",
"version": "4.8.5-beta.0",
"command": {
"version": {
"preid": "beta"
Expand Down
4 changes: 2 additions & 2 deletions packages/react-components/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@commercelayer/react-components",
"version": "4.8.4",
"version": "4.8.5-beta.0",
"description": "The Official Commerce Layer React Components",
"main": "lib/cjs/index.js",
"module": "lib/esm/index.js",
Expand Down Expand Up @@ -178,7 +178,7 @@
},
"homepage": "https://github.com/commercelayer/commercelayer-react-components#readme",
"dependencies": {
"@adyen/adyen-web": "^5.51.0",
"@adyen/adyen-web": "^5.55.1",
"@commercelayer/sdk": "^5.14.0",
"@stripe/react-stripe-js": "^2.3.0",
"@stripe/stripe-js": "^2.1.6",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,6 @@ export function PlaceOrderButton(props: Props): JSX.Element {
setButtonRef(ref)
}
}, [ref])

const handleClick = async (
e?: MouseEvent<HTMLButtonElement>
): Promise<void> => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,13 @@ export function PlaceOrderContainer(props: Props): JSX.Element {
const contextValue = {
...state,
setPlaceOrder: async ({
paymentSource
paymentSource,
currentCustomerPaymentSourceId
}: {
paymentSource?: Parameters<typeof setPlaceOrder>['0']['paymentSource']
currentCustomerPaymentSourceId?: Parameters<
typeof setPlaceOrder
>['0']['currentCustomerPaymentSourceId']
}) =>
await setPlaceOrder({
config,
Expand All @@ -107,7 +111,8 @@ export function PlaceOrderContainer(props: Props): JSX.Element {
setOrderErrors,
paymentSource,
include,
setOrder
setOrder,
currentCustomerPaymentSourceId
}),
placeOrderPermitted: () => {
placeOrderPermitted({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,6 @@ import OrderContext from '#context/OrderContext'
import omit from '#utils/omit'
import type UIElement from '@adyen/adyen-web/dist/types/components/UIElement'

const threeDSConfiguration = {
challengeWindowSize: '05'
// Set to any of the following:
// '02': ['390px', '400px'] - The default window size
// '01': ['250px', '400px']
// '03': ['500px', '600px']
// '04': ['600px', '400px']
// '05': ['100%', '100%']
}

type Styles = Partial<{
base: CSSProperties
error: CSSProperties
Expand Down Expand Up @@ -303,7 +293,7 @@ export function AdyenPayment({
}
return true
}
if (['Cancelled'].includes(resultCode)) {
if (['Cancelled', 'Refused'].includes(resultCode)) {
// @ts-expect-error no type
const message = res?.payment_response?.refusalReason
setPaymentMethodErrors([
Expand All @@ -314,6 +304,9 @@ export function AdyenPayment({
message
}
])
if (component) {
component.mount('#adyen-dropin')
}
}
// @ts-expect-error no type
const errorType = res?.payment_response?.errorType
Expand Down Expand Up @@ -348,6 +341,7 @@ export function AdyenPayment({
return false
}
}

useEffect(() => {
// @ts-expect-error no type
const paymentMethodsResponse = paymentSource?.payment_methods
Expand Down Expand Up @@ -378,7 +372,6 @@ export function AdyenPayment({
},
showPayButton: false,
paymentMethodsConfiguration: {
threeDS2: threeDSConfiguration,
paypal: {
showPayButton: true,
style: styles?.paypal
Expand Down Expand Up @@ -433,7 +426,7 @@ export function AdyenPayment({
setPaymentRef({ ref: { current: null } })
setLoadAdyen(false)
}
}, [clientKey, ref])
}, [clientKey, ref != null])
return !clientKey && !loadAdyen && !checkout ? null : (
<form
ref={ref}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,6 @@ export async function setPlaceOrder({
}) ||
order?.subscription_created_at != null ||
false

if (
hasSubscriptions &&
config?.accessToken != null &&
Expand Down
Loading

0 comments on commit 53430b9

Please sign in to comment.