# BrewmyApp — Mobile App Builder for WooCommerce

Turn your WooCommerce store into a native mobile app. OTP login, in-app payments, push notifications — no coding required.

## Features

- **OTP Authentication** — Passwordless login via email or WhatsApp OTP with rate limiting and JWT response
- **In-App Payments** — Secure, auto-login payment URLs for seamless in-app checkout
- **Push Notifications** — Expo push token registration, broadcast/targeted notifications, and automatic order status alerts
- **API Logging** — Full audit trail with JSON export
- **Health Check** — Monitor API availability from your app
- **JWT Authentication** — HS256-based token auth with configurable secret and expiry

## Requirements

- WordPress 5.8+
- WooCommerce 5.0+
- PHP 7.4+

## Installation

1. Upload the `brewmyapp` folder to `/wp-content/plugins/`
2. Activate through **Plugins › Installed Plugins**
3. Go to **BrewmyApp** in the admin menu to configure settings

## Configuration

| Setting | Description |
|---------|-------------|
| JWT Secret | Secret key for token signing (auto-generated on activation) |
| JWT Expiry | Token lifetime in seconds (default: 86400) |
| WhatsApp Token | WhatsApp Business API access token (optional) |
| WhatsApp Phone ID | WhatsApp Business phone number ID (optional) |
| OTP Valid For | OTP expiry in seconds (default: 600) |

## REST API

All endpoints are registered under `/wp-json/app/v1/`.

### Authentication

| Method | Endpoint | Auth | Description |
|--------|----------|------|-------------|
| POST | `/otp/request` | None | Send email OTP |
| POST | `/otp/verify` | None | Verify email OTP, receive JWT |
| POST | `/whatsapp/otp/request` | None | Send WhatsApp OTP |
| POST | `/whatsapp/otp/verify` | None | Verify WhatsApp OTP, receive JWT |

### Payments

| Method | Endpoint | Auth | Description |
|--------|----------|------|-------------|
| POST | `/payment/order-pay-url` | JWT | Generate auto-login payment URL |

### Push Notifications

| Method | Endpoint | Auth | Description |
|--------|----------|------|-------------|
| POST | `/push/register` | JWT | Register Expo push token |
| POST | `/push/send` | Admin | Send push notification |

### Utility

| Method | Endpoint | Auth | Description |
|--------|----------|------|-------------|
| GET | `/health` | None | API health check |

## External Services

This plugin connects to the following third-party services:

### Expo Push Notification Service

- **When:** Sending push notifications to mobile devices
- **Data sent:** Expo push tokens, notification title, body, and data payload
- **Endpoint:** `https://exp.host/--/api/v2/push/send`
- [Terms of Service](https://expo.dev/terms) · [Privacy Policy](https://expo.dev/privacy)

### WhatsApp Cloud API (Meta)

- **When:** Sending OTP codes via WhatsApp (optional feature)
- **Data sent:** Recipient phone number, OTP code (via message template)
- **Endpoint:** `https://graph.facebook.com/v17.0/`
- [Terms of Service](https://www.whatsapp.com/legal/terms-of-service) · [Privacy Policy](https://www.whatsapp.com/legal/privacy-policy)

## Development

```bash
# Install PHP dependencies (Firebase JWT)
composer install

# The plugin is a single-file architecture — all logic lives in brewmyapp.php
```

## License

GPL-2.0-or-later — see [LICENSE](https://www.gnu.org/licenses/gpl-2.0.html)
