|
| 1 | +# How to use the API |
| 2 | + |
| 3 | +This guide mirrors the routes currently implemented in the backend of this repository. |
| 4 | + |
| 5 | +## Base URL |
| 6 | + |
| 7 | +During local development, the frontend defaults to: |
| 8 | + |
| 9 | +```text |
| 10 | +http://localhost:4000 |
| 11 | +``` |
| 12 | + |
| 13 | +## 1. Register a merchant |
| 14 | + |
| 15 | +Create a merchant and receive both an API key and a webhook secret. |
| 16 | + |
| 17 | +**Endpoint** |
| 18 | + |
| 19 | +```http |
| 20 | +POST /api/register-merchant |
| 21 | +``` |
| 22 | + |
| 23 | +**Example** |
| 24 | + |
| 25 | +```bash |
| 26 | +curl -X POST http://localhost:4000/api/register-merchant \ |
| 27 | + -H "Content-Type: application/json" \ |
| 28 | + -d '{ |
| 29 | + "email": "merchant@example.com", |
| 30 | + "business_name": "Example Store", |
| 31 | + "notification_email": "ops@example.com" |
| 32 | + }' |
| 33 | +``` |
| 34 | + |
| 35 | +**Response fields to save** |
| 36 | + |
| 37 | +- `merchant.api_key` |
| 38 | +- `merchant.webhook_secret` |
| 39 | +- `merchant.id` |
| 40 | + |
| 41 | +## 2. Create a payment link |
| 42 | + |
| 43 | +All merchant-protected endpoints use the `x-api-key` header. |
| 44 | + |
| 45 | +**Endpoint** |
| 46 | + |
| 47 | +```http |
| 48 | +POST /api/create-payment |
| 49 | +``` |
| 50 | + |
| 51 | +**Headers** |
| 52 | + |
| 53 | +```text |
| 54 | +x-api-key: sk_... |
| 55 | +Content-Type: application/json |
| 56 | +Idempotency-Key: 3f0d65e1-27b8-4b28-8f2f-8a6f9fd9d7d9 |
| 57 | +``` |
| 58 | + |
| 59 | +`Idempotency-Key` is optional, but recommended. The backend caches successful duplicate requests for 24 hours. |
| 60 | + |
| 61 | +**Example** |
| 62 | + |
| 63 | +```bash |
| 64 | +curl -X POST http://localhost:4000/api/create-payment \ |
| 65 | + -H "Content-Type: application/json" \ |
| 66 | + -H "x-api-key: sk_your_api_key" \ |
| 67 | + -H "Idempotency-Key: 3f0d65e1-27b8-4b28-8f2f-8a6f9fd9d7d9" \ |
| 68 | + -d '{ |
| 69 | + "amount": 25, |
| 70 | + "asset": "XLM", |
| 71 | + "recipient": "GAAZI4TCR3TY5OJHCTJC2A4QSY6CJWJH5IAJTGKIN2ER7LBNVKOCCWN", |
| 72 | + "description": "Order #2048", |
| 73 | + "webhook_url": "https://merchant.example/webhooks/stellar" |
| 74 | + }' |
| 75 | +``` |
| 76 | + |
| 77 | +**Typical success response** |
| 78 | + |
| 79 | +```json |
| 80 | +{ |
| 81 | + "payment_id": "6aa64d44-faf1-41f0-a7e7-c8f9cce62f2f", |
| 82 | + "payment_link": "http://localhost:3000/pay/6aa64d44-faf1-41f0-a7e7-c8f9cce62f2f", |
| 83 | + "status": "pending", |
| 84 | + "branding_config": { |
| 85 | + "primary_color": "#5ef2c0", |
| 86 | + "secondary_color": "#b8ffe2", |
| 87 | + "background_color": "#050608" |
| 88 | + } |
| 89 | +} |
| 90 | +``` |
| 91 | + |
| 92 | +## 3. Check payment status |
| 93 | + |
| 94 | +Use the public status endpoint to read the latest payment state. |
| 95 | + |
| 96 | +**Endpoint** |
| 97 | + |
| 98 | +```http |
| 99 | +GET /api/payment-status/:id |
| 100 | +``` |
| 101 | + |
| 102 | +**Example** |
| 103 | + |
| 104 | +```bash |
| 105 | +curl http://localhost:4000/api/payment-status/6aa64d44-faf1-41f0-a7e7-c8f9cce62f2f |
| 106 | +``` |
| 107 | + |
| 108 | +## 4. Verify the payment on Stellar |
| 109 | + |
| 110 | +After the customer submits payment, verify it against the Stellar network. |
| 111 | + |
| 112 | +**Endpoint** |
| 113 | + |
| 114 | +```http |
| 115 | +POST /api/verify-payment/:id |
| 116 | +``` |
| 117 | + |
| 118 | +If the payment is found, the API marks it as `confirmed`, stores the `tx_id`, emits the merchant socket event, and sends the webhook. |
| 119 | + |
| 120 | +**Example** |
| 121 | + |
| 122 | +```bash |
| 123 | +curl -X POST http://localhost:4000/api/verify-payment/6aa64d44-faf1-41f0-a7e7-c8f9cce62f2f |
| 124 | +``` |
| 125 | + |
| 126 | +## 5. List merchant payments |
| 127 | + |
| 128 | +Read recent payments for the authenticated merchant. |
| 129 | + |
| 130 | +**Endpoint** |
| 131 | + |
| 132 | +```http |
| 133 | +GET /api/payments?page=1&limit=10 |
| 134 | +``` |
| 135 | + |
| 136 | +**Headers** |
| 137 | + |
| 138 | +```text |
| 139 | +x-api-key: sk_... |
| 140 | +``` |
| 141 | + |
| 142 | +## 6. Test webhook delivery |
| 143 | + |
| 144 | +If you already stored a webhook URL for the merchant, you can send a signed test event using: |
| 145 | + |
| 146 | +```http |
| 147 | +POST /api/webhooks/test |
| 148 | +``` |
| 149 | + |
| 150 | +If you want to ping an arbitrary URL directly, the repo also exposes: |
| 151 | + |
| 152 | +```http |
| 153 | +POST /api/test-webhook |
| 154 | +``` |
| 155 | + |
| 156 | +with: |
| 157 | + |
| 158 | +```json |
| 159 | +{ |
| 160 | + "webhook_url": "https://merchant.example/webhooks/stellar" |
| 161 | +} |
| 162 | +``` |
| 163 | + |
| 164 | +## Notes |
| 165 | + |
| 166 | +- Merchant auth in this codebase uses `x-api-key`, not `Authorization: Bearer ...`. |
| 167 | +- The create-payment flow supports optional `webhook_url`, `memo`, `memo_type`, and `branding_overrides`. |
| 168 | +- Webhook events are signed with the merchant webhook secret using `HMAC-SHA256`. |
| 169 | + |
| 170 | +Continue with the HMAC guide in `/docs/hmac-signatures` to verify those webhook requests correctly. |
0 commit comments