@paychainly/cli 1.0.2 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +98 -0
- package/package.json +1 -1
package/README.md
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
# @paychainly/cli
|
|
2
|
+
|
|
3
|
+
Relay Paychainly webhooks to your local development server. No public URL or tunneling service required.
|
|
4
|
+
|
|
5
|
+
## The Problem
|
|
6
|
+
|
|
7
|
+
When you add a webhook URL like `http://localhost:3000/webhook` in the Paychainly dashboard, the Paychainly server cannot reach your machine — it's behind NAT/firewall. This CLI solves that by opening an outbound WebSocket connection from your machine to Paychainly and forwarding incoming webhooks locally.
|
|
8
|
+
|
|
9
|
+
## Installation
|
|
10
|
+
|
|
11
|
+
No install needed — use `npx`:
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
npx @paychainly/cli listen --api-key <your-api-key> --port 3000
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
Or install globally:
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
npm install -g @paychainly/cli
|
|
21
|
+
paychainly listen --api-key <your-api-key> --port 3000
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Usage
|
|
25
|
+
|
|
26
|
+
```
|
|
27
|
+
paychainly listen [options]
|
|
28
|
+
|
|
29
|
+
Options:
|
|
30
|
+
--api-key Your Paychainly API key (pk_live_... or pk_test_...) [required]
|
|
31
|
+
--port Local port to forward webhooks to (default: 3000)
|
|
32
|
+
--forward-to Full local URL to forward webhooks to (overrides --port)
|
|
33
|
+
--host Paychainly server URL (default: https://api.paychainly.com)
|
|
34
|
+
--secret Webhook signing secret to verify HMAC-SHA256 signatures
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
### Basic — forward to port 3000
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
npx @paychainly/cli listen \
|
|
41
|
+
--api-key pk_live_xxxxxxxxxxxxxxxxxxxx \
|
|
42
|
+
--port 3000
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### Custom path
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
npx @paychainly/cli listen \
|
|
49
|
+
--api-key pk_live_xxxxxxxxxxxxxxxxxxxx \
|
|
50
|
+
--forward-to http://localhost:4000/api/webhook
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
### With signature verification
|
|
54
|
+
|
|
55
|
+
If you set a webhook secret in the Paychainly dashboard, pass it here to verify every incoming signature:
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
npx @paychainly/cli listen \
|
|
59
|
+
--api-key pk_live_xxxxxxxxxxxxxxxxxxxx \
|
|
60
|
+
--port 3000 \
|
|
61
|
+
--secret whsec_xxxxxxxxxxxxxxxxxxxx
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## How It Works
|
|
65
|
+
|
|
66
|
+
1. The CLI connects to Paychainly via WebSocket using your API key.
|
|
67
|
+
2. Paychainly detects that your webhook URL points to `localhost` and routes events through the relay instead of making a direct HTTP call.
|
|
68
|
+
3. The CLI receives each event, POSTs it to your local server, and returns the response back to Paychainly.
|
|
69
|
+
|
|
70
|
+
Your local server handles webhooks exactly as it would in production — same headers, same payload, same HMAC signature.
|
|
71
|
+
|
|
72
|
+
## Webhook Payload
|
|
73
|
+
|
|
74
|
+
Paychainly sends a signed `POST` with `Content-Type: application/json`. The `X-Paychainly-Signature` header contains an HMAC-SHA256 signature you can verify:
|
|
75
|
+
|
|
76
|
+
```js
|
|
77
|
+
const crypto = require('crypto')
|
|
78
|
+
|
|
79
|
+
function verifySignature(rawBody, signature, secret) {
|
|
80
|
+
const expected = crypto
|
|
81
|
+
.createHmac('sha256', secret)
|
|
82
|
+
.update(rawBody)
|
|
83
|
+
.digest('hex')
|
|
84
|
+
return crypto.timingSafeEqual(
|
|
85
|
+
Buffer.from(signature),
|
|
86
|
+
Buffer.from(expected)
|
|
87
|
+
)
|
|
88
|
+
}
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
## Requirements
|
|
92
|
+
|
|
93
|
+
- Node.js 18 or later
|
|
94
|
+
- A Paychainly account with an API key
|
|
95
|
+
|
|
96
|
+
## License
|
|
97
|
+
|
|
98
|
+
MIT
|