# Nexera Africa Pi Payment Integration

This workspace contains a Pi payment checkout page and a backend gateway to connect your app to the Pi Network API.

## Files

- `checkout.html` - frontend payment UI built for Pi Browser.
- `pi_payment_gateway.php` - backend PHP gateway for server-side approval and completion.

## Required Database Table

Run this SQL in `nexora_db` before using the gateway:

```sql
CREATE TABLE IF NOT EXISTS `pi_payments` (
  `id` INT AUTO_INCREMENT PRIMARY KEY,
  `payment_id` VARCHAR(255) NOT NULL UNIQUE,
  `user_uid` VARCHAR(255) NOT NULL,
  `amount` DECIMAL(18, 8) NOT NULL,
  `txid` VARCHAR(255) NULL,
  `status` ENUM('initialized', 'approved', 'completed', 'cancelled', 'failed') DEFAULT 'initialized',
  `metadata` TEXT NULL,
  `created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
  `updated_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
```

## Setup

1. Open `pi_payment_gateway.php` and update:
   - `DB_USER`
   - `DB_PASS`
   - `DB_NAME`
   - `PI_API_KEY`

2. Deploy both files to your HTTPS-enabled server.
3. Open `checkout.html` inside Pi Browser.
4. Change `sandbox: true` to `sandbox: false` in `checkout.html` after production configuration is complete.

## Notes

- The frontend uses `Pi.authenticate(...)` and `Pi.createPayment(...)`.
- The backend verifies the payment with Pi API and then calls `/approve` and `/complete`.
- Keep the API key secret and never expose it in frontend code.
