Checkout Page
Documentation: Checkout Page
Overview
The Checkout Page in our payment dashboard allows users to finalize their payment transactions. It integrates with the backend to fetch payment details and billing information, providing a smooth and efficient checkout experience.
State Structure
The state is organized into three main sections:
- payment:
- data: Stores the fetched payment details.
- isLoading: Indicates if the payment data is being fetched.
- error: Captures any errors during the payment data fetch process.
- billingDetails:
- data: Array of billing details fetched for the user.
- isLoading: Loading state for billing details fetch.
- error: Error state for billing details fetch.
- selectedBillingDetails:
- Stores the billing detail selected by the user for the current transaction.
Key Components
-
State Management with Reducer:
checkoutReducerandinitialStatemanage the state of the Checkout Page.- States:
payment,billingDetails,selectedBillingDetails. - Actions:
FETCH_PAYMENT_START,FETCH_PAYMENT_SUCCESS,FETCH_PAYMENT_ERROR,FETCH_BILLING_DETAILS_START,FETCH_BILLING_DETAILS_SUCCESS,FETCH_BILLING_DETAILS_ERROR,SET_SELECTED_BILLING_DETAILS.
-
Action Creators (
checkoutActions.js):fetchPayment: Fetches a specific payment detail.fetchBillingDetails: Retrieves all billing details for a user.setSelectedBillingDetails: Sets the selected billing address for the transaction.
-
Component Structure:
- The page is structured using MDB React components.
- It includes a form for billing details (
BillingDetailsForm) and a section to display payment information (CheckoutDetails). - A modal (
CreditCardModal) is used for credit card input. - Loading states are handled by
LargeLoadingSpinnerandSmallLoadingSpinner.
-
Data Fetching and Error Handling:
- On component mount, it fetches the payment and billing details.
- Loading and error states are managed using the reducer.
-
User Interaction:
- Users can select a billing address from listed options or add a new one.
Proceed to Paymentbutton is enabled only when a billing address is selected.
Detailed Workflow
-
Initialization:
- When the page loads,
useEffecttriggers thefetchPaymentandfetchBillingDetailsactions. - These actions dispatch types to start fetching data and handle success or error scenarios.
- When the page loads,
-
Rendering:
- The page first checks for any errors. If found,
ErrorComponentdisplays the error message. - If no errors and data is loading,
LargeLoadingSpinneris displayed. - Once data is fetched, the page renders billing details and payment information.
- The page first checks for any errors. If found,
-
Selecting Billing Details:
- Users can click on a billing address to select it for the payment.
setSelectedBillingDetailsis invoked on selection, updating the state with the selected details.
-
Proceeding to Payment:
- The
Proceed to Paymentbutton is active only when a billing address is selected. - On click, it opens the
CreditCardModalfor entering credit card details.
- The
APIs and Helpers
getAllBillingDetails: Fetches billing details for a user.getOnePayment: Retrieves specific payment details.
Future Enhancements
- UI Improvements: Further refine the UI for a more intuitive and seamless user experience.
Error Handling and Debugging
- Check for common API call failures and ensure the reducer properly handles these scenarios.
- Monitor network requests and responses for troubleshooting.
Conclusion
The Checkout Page is a crucial component of our payment dashboard, enabling users to review and complete their transactions effectively. Continuous enhancements and optimizations will ensure a better user experience and reliability.