# larablog/payment

Stub payment foundation: orders, transactions, entitlements, and admin order tools.

## Enable

1. Sync plugins from disk (`php artisan plugins:sync` or Admin → Plugins → Sync).
2. Enable **larablog/payment**.
3. Run migrations so plugin tables exist:

```bash
php artisan migrate
```

Tables: `orders`, `order_items`, `entitlements`, `payment_transactions`.

## Stub checkout flow

Must be logged in.

```text
GET /plugins/payment/checkout
  ?product_type=article
  &product_id=1
  &title=Demo%20article
  &amount=9.90
  &currency=CNY
  &return_url=/
```

Flow:

1. Creates a `pending` order (+ one order item), or shows an error if an active entitlement already exists.
2. Redirects to `/plugins/payment/orders/{id}` confirm page.
3. Click **模拟支付成功** / stub pay → `POST .../pay` → marks paid, writes `payment_transactions`, upserts entitlement, dispatches `order.paid`.
4. Redirects to `return_url` (same-origin only) or `/`.

## Admin

With the plugin enabled:

- **Orders** — list / view orders (`admin.nav.orders`).
- **Mark paid** — on a pending order view page (`admin.actions.mark_paid`).
- **Payment settings** — shows this README (`admin.nav.payment_settings`).

## Admin lang keys

| Key | Purpose |
|---|---|
| `admin.nav.orders` | Orders nav |
| `admin.nav.payment_settings` | Settings/docs nav |
| `admin.models.order` / `admin.models.orders` | Resource labels |
| `admin.fields.status/amount/currency/gateway/paid_at` | Table/infolist |
| `admin.actions.mark_paid` | View action |
| `admin.messages.mark_paid_success` / `mark_paid_failed` | Notifications |
| `payment.*` | Stub checkout UI + domain errors (`lang/{locale}/payment.php`) |

## Notes

- Gateway value for this phase is `stub` only.
- `product_type` reserved values: `article`, `theme`, `membership`.
- Real WeChat / Alipay / Stripe gateways are out of scope.
