-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(payment): implement Adyen and PayPal payment methods
- Loading branch information
1 parent
91b32aa
commit b6570fa
Showing
33 changed files
with
628 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
@use '../../styles/variables'; | ||
@use '../../styles/theme'; | ||
|
||
.adyen { | ||
margin-bottom: 24px; | ||
|
||
:global { | ||
.adyen-checkout__label__text { | ||
color: variables.$white; | ||
font-family: theme.$body-font-family; | ||
font-size: 16px; | ||
line-height: 18px; | ||
} | ||
|
||
.adyen-checkout__error-text { | ||
font-family: theme.$body-font-family; | ||
font-size: 14px; | ||
} | ||
} | ||
} | ||
|
||
.container { | ||
margin-bottom: 24px; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import React, { useEffect, useRef, useState } from 'react'; | ||
import { useTranslation } from 'react-i18next'; | ||
|
||
import { addScript, addStyleSheet } from '../../utils/dom'; | ||
import useOpaqueId from '../../hooks/useOpaqueId'; | ||
import Button from '../Button/Button'; | ||
import FormFeedback from '../FormFeedback/FormFeedback'; | ||
|
||
import styles from './Adyen.module.scss'; | ||
|
||
type Props = { | ||
onChange?: (data: AdyenEventData) => void; | ||
onSubmit: (data: AdyenEventData) => void; | ||
error?: string; | ||
}; | ||
|
||
const Adyen: React.FC<Props> = ({ onChange, onSubmit, error }) => { | ||
const { t } = useTranslation('account'); | ||
const id = useOpaqueId('adyen', 'checkout'); | ||
const adyenRef = useRef<AdyenCheckout>(null) as React.MutableRefObject<AdyenCheckout>; | ||
const [scriptsLoaded, setScriptsLoaded] = useState(!!window.AdyenCheckout); | ||
|
||
useEffect(() => { | ||
const loadExternalScripts = async () => { | ||
await Promise.all([ | ||
addScript('https://checkoutshopper-test.adyen.com/checkoutshopper/sdk/3.10.1/adyen.js'), | ||
addStyleSheet('https://checkoutshopper-test.adyen.com/checkoutshopper/sdk/3.11.4/adyen.css'), | ||
]); | ||
|
||
setScriptsLoaded(true); | ||
}; | ||
|
||
loadExternalScripts(); | ||
}, []); | ||
|
||
useEffect(() => { | ||
if (scriptsLoaded) { | ||
const configuration = { | ||
showPayButton: false, | ||
environment: 'test', | ||
clientKey: 'test_I4OFGUUCEVB5TI222AS3N2Y2LY6PJM3K', | ||
onSubmit, | ||
onChange, | ||
}; | ||
|
||
// @ts-ignore | ||
adyenRef.current = new window.AdyenCheckout(configuration).create('card').mount(`#${id}`); | ||
|
||
return () => { | ||
if (adyenRef.current) { | ||
adyenRef.current.unmount(); | ||
} | ||
}; | ||
} | ||
}, [id, onChange, onSubmit, scriptsLoaded]); | ||
|
||
return ( | ||
<div className={styles.adyen}> | ||
{error ? <FormFeedback variant="error">{error}</FormFeedback> : null} | ||
<div className={styles.container}> | ||
<div id={id} /> | ||
</div> | ||
<Button label={t('checkout.continue')} variant="contained" color="primary" size="large" onClick={() => adyenRef.current?.submit()} fullWidth /> | ||
</div> | ||
); | ||
}; | ||
|
||
export default Adyen; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`<Adyen> renders and matches snapshot 1`] = ` | ||
<div> | ||
<div | ||
class="adyen" | ||
> | ||
<div | ||
class="container" | ||
> | ||
<div | ||
id="adyen_1235_checkout" | ||
/> | ||
</div> | ||
<button | ||
class="button primary fullWidth large" | ||
> | ||
<span> | ||
checkout.continue | ||
</span> | ||
</button> | ||
</div> | ||
</div> | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
src/components/NoPaymentRequired/NoPaymentRequired.module.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
@use '../../styles/variables'; | ||
@use '../../styles/theme'; | ||
|
||
.noPaymentRequired { | ||
p { | ||
font-family: theme.$body-font-family; | ||
font-weight: 700; | ||
font-size: 20px; | ||
text-align: center; | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
src/components/NoPaymentRequired/NoPaymentRequired.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import React from 'react'; | ||
import { render } from '@testing-library/react'; | ||
|
||
import NoPaymentRequired from './NoPaymentRequired'; | ||
|
||
describe('<NoPaymentRequired>', () => { | ||
test('renders and matches snapshot', () => { | ||
const { container } = render(<NoPaymentRequired />); | ||
|
||
expect(container).toMatchSnapshot(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import React from 'react'; | ||
import { useTranslation } from 'react-i18next'; | ||
|
||
import Button from '../Button/Button'; | ||
import FormFeedback from '../FormFeedback/FormFeedback'; | ||
|
||
import styles from './NoPaymentRequired.module.scss'; | ||
|
||
type Props = { | ||
onSubmit?: () => void; | ||
error?: string; | ||
}; | ||
|
||
const NoPaymentRequired: React.FC<Props> = ({ onSubmit, error }) => { | ||
const { t } = useTranslation('account'); | ||
|
||
return ( | ||
<div className={styles.noPaymentRequired}> | ||
{error ? <FormFeedback variant="error">{error}</FormFeedback> : null} | ||
<p>{t('checkout.no_payment_needed')}</p> | ||
<Button label={t('checkout.continue')} variant="contained" color="primary" size="large" onClick={onSubmit} fullWidth /> | ||
</div> | ||
); | ||
}; | ||
|
||
export default NoPaymentRequired; |
20 changes: 20 additions & 0 deletions
20
src/components/NoPaymentRequired/__snapshots__/NoPaymentRequired.test.tsx.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`<NoPaymentRequired> renders and matches snapshot 1`] = ` | ||
<div> | ||
<div | ||
class="noPaymentRequired" | ||
> | ||
<p> | ||
checkout.no_payment_needed | ||
</p> | ||
<button | ||
class="button primary fullWidth large" | ||
> | ||
<span> | ||
checkout.continue | ||
</span> | ||
</button> | ||
</div> | ||
</div> | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
@use '../../styles/variables'; | ||
@use '../../styles/theme'; | ||
|
||
.payPal { | ||
p { | ||
font-family: theme.$body-font-family; | ||
font-weight: 700; | ||
font-size: 20px; | ||
text-align: center; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import React from 'react'; | ||
import { render } from '@testing-library/react'; | ||
|
||
import PayPal from './PayPal'; | ||
|
||
describe('<PayPal>', () => { | ||
test('renders and matches snapshot', () => { | ||
const { container } = render(<PayPal />); | ||
|
||
expect(container).toMatchSnapshot(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import React from 'react'; | ||
import { useTranslation } from 'react-i18next'; | ||
|
||
import Button from '../Button/Button'; | ||
import FormFeedback from '../FormFeedback/FormFeedback'; | ||
|
||
import styles from './PayPal.module.scss'; | ||
|
||
type Props = { | ||
onSubmit?: () => void; | ||
error?: string; | ||
}; | ||
|
||
const PayPal: React.FC<Props> = ({ onSubmit, error }) => { | ||
const { t } = useTranslation('account'); | ||
|
||
return ( | ||
<div className={styles.payPal}> | ||
{error ? <FormFeedback variant="error">{error}</FormFeedback> : null} | ||
<p>{t('checkout.paypal_instructions')}</p> | ||
<Button label={t('checkout.continue')} variant="contained" color="primary" size="large" onClick={onSubmit} fullWidth /> | ||
</div> | ||
); | ||
}; | ||
|
||
export default PayPal; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`<PayPal> renders and matches snapshot 1`] = ` | ||
<div> | ||
<div | ||
class="payPal" | ||
> | ||
<p> | ||
checkout.paypal_instructions | ||
</p> | ||
<button | ||
class="button primary fullWidth large" | ||
> | ||
<span> | ||
checkout.continue | ||
</span> | ||
</button> | ||
</div> | ||
</div> | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
@use '../../styles/variables'; | ||
@use '../../styles/theme'; | ||
|
||
.title { | ||
font-family: theme.$body-font-family; | ||
font-weight: 700; | ||
font-size: 24px; | ||
} | ||
|
||
.message { | ||
font-family: theme.$body-font-family; | ||
font-size: 16px; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import React from 'react'; | ||
import { render } from '@testing-library/react'; | ||
|
||
import PaymentFailed from './PaymentFailed'; | ||
|
||
describe('<PaymentFailed>', () => { | ||
test('renders and matches snapshot', () => { | ||
const { container } = render(<PaymentFailed type="error" onCloseButtonClick={jest.fn()} message="Error message" />); | ||
|
||
expect(container).toMatchSnapshot(); | ||
}); | ||
}); |
Oops, something went wrong.