# ngauge-stripe

Stripe API integration module for NGauge/Yii2.

## Features

- Thin Stripe API client using `yiisoft/yii2-httpclient`
- JSON controller endpoints for common payment operations
- Webhook endpoint with Stripe signature verification
- Backend config/test page for quick connectivity checks
- Centralized module config for API key, timeout, and API version
- Endpoint reference in `docs/API.MD`

## Requirements

- PHP 8.4+
- Yii2 `~2.0`
- `yiisoft/yii2-httpclient`

## Installation

```bash
composer require portalpeople/ngauge-stripe
```

## Configuration

Add the module to your application config:

```php
'modules' => [
    'stripe' => [
        'class' => \portalpeople\stripe\Module::class,
        'secretKey' => getenv('STRIPE_SECRET_KEY'),
        'webhookSigningSecret' => getenv('STRIPE_WEBHOOK_SECRET'),
        // Optional:
        'apiBaseUrl' => 'https://api.stripe.com/v1',
        'stripeVersion' => null,
        'timeout' => 30,
        'webhookTolerance' => 300,
        'debug' => false,
    ],
],
'bootstrap' => ['stripe'],
```

Set your environment variable:

```bash
STRIPE_SECRET_KEY=sk_test_xxx
STRIPE_WEBHOOK_SECRET=whsec_xxx
```

## Local Endpoints

| Method | URL | Purpose |
|---|---|---|
| GET | `/stripe/api/customers` | List customers |
| GET | `/stripe/api/customer?id=cus_xxx` | Retrieve one customer |
| POST | `/stripe/api/payment-intent-create` | Create payment intent |
| GET | `/stripe/api/payment-intent?id=pi_xxx` | Retrieve payment intent |
| GET | `/stripe/api/refunds` | List refunds |
| POST | `/stripe/api/refund-create` | Create refund |
| GET | `/stripe/api/balance` | Retrieve account balance |
| POST | `/stripe/webhook/receive` | Receive Stripe webhook events (verified) |
| GET | `/stripe/config/index` | View module config and run basic connectivity checks |

## API Documentation

See `docs/API.MD` for Stripe endpoint mapping, request/response notes, and operational guidance.
