# PayPilot BD — PHP/MySQL payment checkout starter

An original Bangladesh-focused mobile-wallet checkout UI inspired by common local payment workflows. It is **not affiliated with ZiniPay, bKash, Nagad, Rocket, Upay or any bank** and does not copy their branding.

## What is included

- Responsive HTML/CSS/JavaScript checkout UI.
- PHP 8.1+ backend using PDO prepared statements.
- MySQL schema for payment sessions, transaction references and admin audit history.
- bKash, Nagad, Rocket and Upay method selection (merchant wallet numbers are placeholders).
- Unique checkout tokens, expiry, CSRF protection, basic field validation and duplicate TrxID constraint.
- Admin login and manual approve/reject workflow.

## Important payment limitation

This starter does **not** automatically verify wallet transfers and does not move money. A customer-entered TrxID is untrusted input and stays `pending_review` until a merchant verifies it against an authorized provider API, official statement, or permitted device integration. Do not approve from a screenshot alone. Do not request/store wallet PINs, passwords, OTPs, card numbers or CVVs. To enable real automatic verification, obtain written authorization and official API/device access from the relevant provider and implement its documented server-to-server adapter.

For card/bank checkout, integrate a licensed gateway such as SSLCommerz using your own merchant account. Official SSLCommerz docs describe hosted checkout, server-side validation and IPN: https://developer.sslcommerz.com/doc/v4/ and https://sandbox-gw.sslcommerz.com/docs. Do not set an order to paid from the browser redirect alone.

## Requirements

- PHP 8.1 or later with `pdo_mysql` enabled.
- MySQL 8.0+ or MariaDB 10.5+.
- HTTPS in production.

## Install

1. Create a MySQL database and import `sql/schema.sql`.
2. Configure environment variables on your host:

   ```text
   DB_HOST=127.0.0.1
   DB_NAME=paypilot_bd
   DB_USER=paypilot_user
   DB_PASS=replace_with_a_long_password
   ADMIN_USERNAME=admin
   ADMIN_PASSWORD_HASH=<password_hash output>
   ```

3. Generate the admin password hash:

   ```bash
   php -r 'echo password_hash("CHANGE_THIS_PASSWORD", PASSWORD_DEFAULT), PHP_EOL;'
   ```

   Put the result in `ADMIN_PASSWORD_HASH`. Do not use the sample password in production.
4. Edit `config.php` and replace the demo wallet numbers in `WALLET_METHODS` with the merchant's authorized receiving numbers. Keep the labels and visual treatment generic; do not use provider logos without permission.
5. Point your web server document root to this directory. For production, preferably move `config.php` and SQL files outside the public web root, disable directory listing, enable HTTPS, and restrict `/admin` by an additional access policy.
6. Visit `/index.php`; admin is at `/admin/login.php`.

## Production hardening checklist

- Add per-IP and per-session rate limiting at the reverse proxy and application layers.
- Add email/SMS notifications without exposing sensitive data.
- Use secure, HttpOnly, SameSite cookies and `session.cookie_secure=1` on HTTPS.
- Add strict Content Security Policy and other security headers.
- Protect admin with MFA and role-based accounts; rotate credentials.
- Add audit review, reconciliation and retention policies.
- Implement provider-specific transaction verification with authenticated server-side credentials, idempotency and amount/currency/session matching.
- Never accept a payment-success flag from JavaScript, URL parameters, screenshots or user-submitted references.
- Have the integration and regulatory requirements reviewed before accepting real payments.

## Project structure

```text
index.php
pay.php
status.php
config.php
api/create-session.php
api/submit-transaction.php
admin/login.php
admin/index.php
admin/logout.php
assets/style.css
assets/app.js
sql/schema.sql
```
