Skip to content

Commit

Permalink
feat: provide additional config for amazonpay
Browse files Browse the repository at this point in the history
  • Loading branch information
amihajlovski committed Nov 7, 2023
1 parent 09f34f1 commit 4f6884b
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 7 deletions.
1 change: 0 additions & 1 deletion adyen/components/AdyenCheckout.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ const AdyenCheckoutComponent = (props) => {
const urlParams = new URLSearchParams(location.search)
const redirectResult = urlParams.get('redirectResult')
const amazonCheckoutSessionId = urlParams.get('amazonCheckoutSessionId')
console.log(amazonCheckoutSessionId)

const createCheckout = async () => {
const paymentMethodsConfiguration = await getPaymentMethodsConfiguration(props)
Expand Down
10 changes: 10 additions & 0 deletions adyen/components/amazonpay/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import {baseConfig} from '../helpers/baseConfig'

export const amazonPayConfig = (props) => {
return {
...baseConfig(props),
showPayButton: true,
productType: 'PayAndShip',
checkoutMode: 'ProcessOrder'
}
}
4 changes: 3 additions & 1 deletion adyen/components/paymentMethodsConfiguration.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {klarnaConfig} from './klarna/config'
import {cardConfig} from './card/config'
import {paypalConfig} from './paypal/config'
import {applePayConfig} from './applepay/config'
import {amazonPayConfig} from './amazonpay/config'

export const paymentMethodsConfiguration = ({paymentMethods = [], ...props}) => {
const defaultConfig = baseConfig(props)
Expand All @@ -12,7 +13,8 @@ export const paymentMethodsConfiguration = ({paymentMethods = [], ...props}) =>
klarna_account: klarnaConfig(props),
klarna_paynow: klarnaConfig(props),
paypal: paypalConfig(props),
applepay: applePayConfig(props)
applepay: applePayConfig(props),
amazonpay: amazonPayConfig(props)
}

return Object.fromEntries(
Expand Down
10 changes: 5 additions & 5 deletions adyen/context/adyen-checkout-context.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ export const AdyenCheckoutProvider = ({children}) => {
const locale = resolveLocaleFromUrl(`${location.pathname}${location.search}`)
const navigate = useNavigation()

const [fetching, setFetching] = useState(false)
const [fetchingPaymentMethods, setFetchingPaymentMethods] = useState(false)
const [adyenPaymentMethods, setAdyenPaymentMethods] = useState()
const [adyenStateData, setAdyenStateData] = useState()

useEffect(() => {
const fetchPaymentMethods = async () => {
setFetching(true)
setFetchingPaymentMethods(true)
const token = await getTokenWhenReady()
const adyenPaymentMethodsService = new AdyenPaymentMethodsService(token)
try {
Expand All @@ -34,14 +34,14 @@ export const AdyenCheckoutProvider = ({children}) => {
locale
)
setAdyenPaymentMethods(data ? data : {error: true})
setFetching(false)
setFetchingPaymentMethods(false)
} catch (error) {
setAdyenPaymentMethods({error})
setFetching(false)
setFetchingPaymentMethods(false)
}
}

if (!adyenPaymentMethods && !fetching) {
if (!adyenPaymentMethods && !fetchingPaymentMethods) {
fetchPaymentMethods()
}
}, [basket?.basketId])
Expand Down

0 comments on commit 4f6884b

Please sign in to comment.