|
| 1 | +# Manual Payment Processing SPA Example |
| 2 | + |
| 3 | +This example showcases how to implement **manual payment gateway processing** with **Elastic Path Commerce Cloud** in a Single-Page Application (SPA) written in React. It builds on the `spa-guest-checkout` example, although omits a number of its features. |
| 4 | + |
| 5 | +> **Heads-up:** This project focuses **exclusively** on manual payment processing workflows. It creates minimal test orders solely to demonstrate payment handling—cart management, product catalogs, customer accounts, etc. are kept deliberately simple and are not the focus. |
| 6 | +
|
| 7 | +Key capabilities demonstrated: |
| 8 | + |
| 9 | +1. **Test Order Creation** – automatically creates incomplete orders with test products for payment processing demonstration. |
| 10 | +2. **Manual Payment Gateway** – processes payments using Elastic Path's manual payment gateway for scenarios like: |
| 11 | + • Bank transfers |
| 12 | + • Cash payments |
| 13 | + • Check payments |
| 14 | + • Custom payment workflows |
| 15 | +3. **Order State Management** – converts incomplete orders to complete orders after manual payment recording. |
| 16 | +4. **Payment Status Tracking** – displays real-time order and payment status updates with proper UI indicators. |
| 17 | + |
| 18 | +> The example purposefully uses simplified order creation and minimal product selection to keep the focus on manual payment mechanics. |
| 19 | +
|
| 20 | +--- |
| 21 | + |
| 22 | +## Project Structure |
| 23 | + |
| 24 | +``` |
| 25 | +spa-manual-payments/ |
| 26 | +├── index.html # Vite entry point |
| 27 | +├── src/ |
| 28 | +│ ├── App.tsx # Main app orchestration & state management |
| 29 | +│ ├── components/ |
| 30 | +│ │ ├── AppHeader.tsx # Authentication status & cart ID display |
| 31 | +│ │ ├── StepIndicator.tsx # Multi-step progress indicator |
| 32 | +│ │ ├── OrderCreator.tsx # Creates test orders for payment demo |
| 33 | +│ │ ├── ManualPayment.tsx # Manual payment processing form |
| 34 | +│ │ ├── OrderStatus.tsx # Order & payment status display |
| 35 | +│ │ └── OrderCompleteView.tsx # Success screen with reset functionality |
| 36 | +│ ├── hooks/ |
| 37 | +│ │ ├── useAppInitialization.ts # App startup & authentication logic |
| 38 | +│ │ └── useOrderCreation.ts # Order creation workflow & state |
| 39 | +│ └── auth/ |
| 40 | +│ ├── CartProvider.tsx # Basic cart initialization |
| 41 | +│ └── StorefrontProvider.tsx # Elastic Path client setup |
| 42 | +└── README.md # ← you are here |
| 43 | +``` |
| 44 | + |
| 45 | +## How It Works |
| 46 | + |
| 47 | +### 1. Test Order Creation |
| 48 | + |
| 49 | +`OrderCreator` automatically creates a test scenario: |
| 50 | + |
| 51 | +```tsx |
| 52 | +// Creates cart → adds test product → checkout → incomplete order |
| 53 | +const createIncompleteOrder = async () => { |
| 54 | + const products = await getByContextAllProducts() |
| 55 | + const selectedProduct = products.data.find(/* stock logic */) |
| 56 | + // ... cart creation, checkout, order creation |
| 57 | +} |
| 58 | +``` |
| 59 | + |
| 60 | +This generates an incomplete order ready for manual payment processing. |
| 61 | + |
| 62 | +### 2. Manual Payment Processing |
| 63 | + |
| 64 | +`ManualPayment` captures payment details and processes them: |
| 65 | + |
| 66 | +```tsx |
| 67 | +const paymentData = { |
| 68 | + gateway: "manual", |
| 69 | + method: "purchase", |
| 70 | + // if the user supplies a reference |
| 71 | + paymentmethod_meta: { |
| 72 | + custom_reference: paymentReference, |
| 73 | + name: "Manual Payment", |
| 74 | + }, |
| 75 | +} |
| 76 | + |
| 77 | +await paymentSetup({ |
| 78 | + path: { orderID: order.id }, |
| 79 | + body: { data: paymentData }, |
| 80 | +}) |
| 81 | +``` |
| 82 | + |
| 83 | +### 3. Status Display |
| 84 | + |
| 85 | +`OrderStatus` shows order and payment status. |
| 86 | + |
| 87 | +--- |
| 88 | + |
| 89 | +## Running the Example Locally |
| 90 | + |
| 91 | +1. **Install deps** (from the repo root): |
| 92 | + |
| 93 | +```bash |
| 94 | +pnpm i # or npm install / yarn |
| 95 | +``` |
| 96 | + |
| 97 | +2. **Set environment variables** – create a `.env` file in `examples/spa-manual-payments` (or export in your shell): |
| 98 | + |
| 99 | +``` |
| 100 | +VITE_APP_EPCC_ENDPOINT_URL=https://YOUR_EP_DOMAIN.elasticpath.com |
| 101 | +VITE_APP_EPCC_CLIENT_ID=YOUR_CLIENT_ID |
| 102 | +``` |
| 103 | + |
| 104 | +3. **Start Vite dev server**: |
| 105 | + |
| 106 | +```bash |
| 107 | +pnpm --filter spa-manual-payments dev |
| 108 | +``` |
| 109 | + |
| 110 | +## Learn More |
| 111 | + |
| 112 | +- [Manual Payment Gateway Documentation](https://elasticpath.dev/docs/api/carts/cart-management) |
| 113 | +- [Order Management with Elastic Path](https://elasticpath.dev/docs/api/carts/cart-management) |
| 114 | +- [Payment Processing APIs](https://elasticpath.dev/docs/api/carts/cart-management) |
0 commit comments