# PHP SDK Reference

## Install

```bash
composer require ponponpay/php-sdk
```

## Environment

```dotenv
PONPONPAY_API_KEY=sk_live_xxx
PONPONPAY_API_URL=https://api.ponponpay.com
```

## Initialize

```php
use PonponPay\PonponPay;

$ponponpay = new PonponPay(getenv('PONPONPAY_API_KEY'), [
    'api_url' => getenv('PONPONPAY_API_URL') ?: 'https://api.ponponpay.com',
]);
```

## Create Order

```php
$order = $ponponpay->createOrder([
    'mch_order_id' => 'ORDER_' . time(),
    'currency' => 'USDT',
    'network' => 'tron',
    'amount' => 10.00,
    'notify_url' => 'https://your-site.com/webhook/ponponpay',
    'redirect_url' => 'https://your-site.com/payment/success',
]);

header('Location: ' . $order->paymentUrl);
exit;
```

## Query Order

```php
$order = $ponponpay->getOrderByTradeId('T20240101120000123456');
$order = $ponponpay->getOrderByMchOrderId('ORDER_001');
```

## Framework Notes

- Laravel: bind the SDK in a service class, load secrets from `config/services.php`, add webhook route under `routes/api.php`.
- WordPress: load credentials with `get_option`, create orders in a shortcode or controller, and expose webhook with `admin-post.php` or REST API.
- Custom PHP: keep SDK initialization in one bootstrap file and reuse it in checkout and webhook scripts.

## Validation

- Run `composer validate` when `composer.json` changed.
- Run existing PHP tests if available.
- Manually create a low-value test order and verify redirect plus webhook.
