# Paystack Setup

## Environment

Use test credentials first:

`PAYSTACK_SECRET_KEY=sk_test_...`
`PAYSTACK_PUBLIC_KEY=pk_test_...`

Never commit these values.

## Transaction flow

1. Approved client selects a fixed-price service.
2. Browser submits only the service ID.
3. PHP loads the authoritative price from MySQL.
4. PHP creates a unique order reference.
5. PHP initializes Paystack using the secret key.
6. Client is redirected to Paystack checkout.
7. Paystack returns to `payment-callback.php`.
8. Server verifies the transaction.
9. Server checks status, amount and currency.
10. Webhook independently confirms successful charges.
11. Database update is idempotent, preventing double fulfilment.

## Callback

Configure the callback in Paystack or per transaction as:

`https://letstalkipdaphne.com/payment-callback.php`

## Webhook

Configure:

`https://letstalkipdaphne.com/api/paystack/webhook.php`

The webhook must remain publicly reachable.

## Signature

The implementation calculates HMAC SHA512 over the raw request body using the Paystack secret and compares it to `x-paystack-signature`.

## Critical rule

Never trust a client-submitted amount. The server reads `services.price_minor`.

Paystack amounts are sent in the currency subunit. For NGN, store naira amounts as kobo in `price_minor`.

Example:

₦15,000 = `1500000`

## Live switch

Only after successful test-mode validation:

- replace test keys with live keys
- verify callback and webhook URLs
- verify HTTPS
- test a low-risk live transaction
- inspect logs and database state
