Add amount to payment validation button
This commit is contained in:
@@ -9,10 +9,11 @@ import {Button, Container, LinearProgress, Paper} from '@mui/material'
|
|||||||
|
|
||||||
const SITE_URL = process.env.NEXT_PUBLIC_SITE_URL || 'http://localhost:3001'
|
const SITE_URL = process.env.NEXT_PUBLIC_SITE_URL || 'http://localhost:3001'
|
||||||
|
|
||||||
export default function CheckoutForm({setPaymentIsReady, setError, isLoading, setIsLoading}) {
|
export default function CheckoutForm({prices, validMontant, setPaymentIsReady, setError, isLoading, setIsLoading}) {
|
||||||
const stripe = useStripe()
|
const stripe = useStripe()
|
||||||
const elements = useElements()
|
const elements = useElements()
|
||||||
const [isPaymentLoading, setIsPaymentLoading] = useState(false)
|
const [isPaymentLoading, setIsPaymentLoading] = useState(false)
|
||||||
|
const amount = prices.find(({id}) => id === validMontant).unit_amount
|
||||||
|
|
||||||
const handleSubmit = async event => {
|
const handleSubmit = async event => {
|
||||||
event.preventDefault()
|
event.preventDefault()
|
||||||
@@ -50,7 +51,7 @@ export default function CheckoutForm({setPaymentIsReady, setError, isLoading, se
|
|||||||
<PaymentElement id='payment-element' onReady={handleReady} />
|
<PaymentElement id='payment-element' onReady={handleReady} />
|
||||||
{!isLoading && (
|
{!isLoading && (
|
||||||
<Button fullWidth sx={{marginTop: 2}} variant='outlined' disabled={isPaymentLoading || !stripe || !elements} id='submit' onClick={handleSubmit}>
|
<Button fullWidth sx={{marginTop: 2}} variant='outlined' disabled={isPaymentLoading || !stripe || !elements} id='submit' onClick={handleSubmit}>
|
||||||
Valider le paiement
|
Valider le paiement de <strong>{amount / 100} euros</strong>
|
||||||
</Button>
|
</Button>
|
||||||
)}
|
)}
|
||||||
{isPaymentLoading && (
|
{isPaymentLoading && (
|
||||||
@@ -62,6 +63,8 @@ export default function CheckoutForm({setPaymentIsReady, setError, isLoading, se
|
|||||||
}
|
}
|
||||||
|
|
||||||
CheckoutForm.propTypes = {
|
CheckoutForm.propTypes = {
|
||||||
|
validMontant: PropTypes.string.isRequired,
|
||||||
|
prices: PropTypes.array.isRequired,
|
||||||
setPaymentIsReady: PropTypes.func.isRequired,
|
setPaymentIsReady: PropTypes.func.isRequired,
|
||||||
setError: PropTypes.func.isRequired,
|
setError: PropTypes.func.isRequired,
|
||||||
isLoading: PropTypes.bool.isRequired,
|
isLoading: PropTypes.bool.isRequired,
|
||||||
|
|||||||
@@ -93,6 +93,8 @@ export default function PaymentMethod({isLoading, paymentMethod, setPaymentMetho
|
|||||||
{clientSecret && validMontant && paymentMethod === 0 && (
|
{clientSecret && validMontant && paymentMethod === 0 && (
|
||||||
<Elements options={options} stripe={stripePromise}>
|
<Elements options={options} stripe={stripePromise}>
|
||||||
<CheckoutForm
|
<CheckoutForm
|
||||||
|
prices={prices}
|
||||||
|
validMontant={validMontant}
|
||||||
setPaymentIsReady={setPaymentIsReady}
|
setPaymentIsReady={setPaymentIsReady}
|
||||||
setError={setError}
|
setError={setError}
|
||||||
isLoading={isLoading}
|
isLoading={isLoading}
|
||||||
|
|||||||
Reference in New Issue
Block a user