A minimal payment integration demo for agricultural applications using the Chapa payment gateway. This project demonstrates how to handle payments in an Ethiopian context, with support for mobile money and other payment methods.
# PayFlow
A minimal payment integration demo using the Chapa payment gateway. This project demonstrates how to handle payments in an Ethiopian context, with support for mobile money and other payment methods.
## Features
- **Payment Creation**: Initialize payments with customer details and amount
- **Payment Verification**: Verify transaction status after payment
- **Webhook Handling**: Receive and process payment status updates from Chapa
- **Order Management**: Store and retrieve payment records in MongoDB
- **Test Mode Support**: Mock payments for development and testing
- **Simple Frontend**: HTML form for creating payments
## Tech Stack
- **Backend**: Node.js with Express.js
- **Database**: MongoDB with Mongoose ODM
- **Payment Gateway**: Chapa API
- **Frontend**: Vanilla HTML/JavaScript
- **Other**: Axios for HTTP requests, CORS for cross-origin support
## Installation
1. Clone the repository:
```bash
git clone
cd payflow
```
2. Install dependencies:
```bash
npm install
```
3. Create a `.env` file in the root directory with the following variables:
```
CHAPA_SECRET_KEY=your_chapa_secret_key_here
CHAPA_WEBHOOK_SECRET=your_webhook_secret_here
MONGO_URI=mongodb://localhost:27017/payflow
PORT=3000
```
4. Start the server:
```bash
npm start
```
For development with auto-restart:
```bash
npm run dev
```
The server will run at `
localhost`.
## Usage
1. Open `
localhost` in your browser
2. Fill out the payment form with:
- Amount in ETB
- Mobile number (Ethiopian format)
- Customer details (first name, last name, email)
- Payment type (currently supports 'test' mode)
3. Click "Create Payment" to initiate the transaction
4. You'll be redirected to Chapa's checkout page (or a mock page in test mode)
5. After payment, the verification endpoint will update the order status
## API Endpoints
### Create Payment
- **POST** `/create-payment`
- **Body**:
```json
{
"amount": 100,
"mobile": "+251911000000",
"first_name": "Test",
"last_name": …