@beinfi/pulse-sdk 0.1.0

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 ADDED
@@ -0,0 +1,103 @@
1
+ # @beinfi/pulse-sdk
2
+
3
+ TypeScript SDK for the [Pulse Payment Platform](https://beinfi.com) API (`/api/v1`).
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm install @beinfi/pulse-sdk
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```typescript
14
+ import { Pulse } from '@beinfi/pulse-sdk'
15
+
16
+ const pulse = new Pulse('sk_live_...')
17
+ // or with options
18
+ const pulse = new Pulse({ apiKey: 'sk_live_...', baseUrl: 'https://api.beinfi.com' })
19
+ ```
20
+
21
+ ### Payment Links
22
+
23
+ ```typescript
24
+ // Create
25
+ const link = await pulse.paymentLinks.create({
26
+ title: 'Order #42',
27
+ amount: '100.00',
28
+ currency: 'USD', // optional, defaults to USD
29
+ description: 'Widget purchase', // optional
30
+ })
31
+
32
+ // List
33
+ const links = await pulse.paymentLinks.list({ limit: 10, offset: 0 })
34
+
35
+ // Get
36
+ const link = await pulse.paymentLinks.get('link-id')
37
+
38
+ // List payment intents for a link
39
+ const intents = await pulse.paymentLinks.listIntents('link-id')
40
+ ```
41
+
42
+ ### Webhooks
43
+
44
+ ```typescript
45
+ // Create
46
+ const wh = await pulse.webhooks.create({
47
+ url: 'https://example.com/webhook',
48
+ events: ['payment.confirmed'],
49
+ })
50
+ console.log(wh.secret) // save this
51
+
52
+ // List
53
+ const list = await pulse.webhooks.list()
54
+
55
+ // Delete
56
+ await pulse.webhooks.delete('webhook-id')
57
+ ```
58
+
59
+ ### Verify Webhook Signatures
60
+
61
+ ```typescript
62
+ import { Pulse } from '@beinfi/pulse-sdk'
63
+
64
+ const isValid = Pulse.webhooks.verifySignature(rawBody, signatureHeader, secret)
65
+ ```
66
+
67
+ The signature header format is `sha256={hmac_hex}`, sent as `X-Pulse-Signature`.
68
+
69
+ ## Error Handling
70
+
71
+ ```typescript
72
+ import { PulseApiError, PulseAuthenticationError, PulseRateLimitError } from '@beinfi/pulse-sdk'
73
+
74
+ try {
75
+ await pulse.paymentLinks.create({ title: 'Test', amount: '10.00' })
76
+ } catch (err) {
77
+ if (err instanceof PulseAuthenticationError) {
78
+ // 401 - invalid API key
79
+ } else if (err instanceof PulseRateLimitError) {
80
+ // 429 - retry after err.retryAfter seconds
81
+ } else if (err instanceof PulseApiError) {
82
+ // other API error - err.status, err.errorCode, err.message
83
+ }
84
+ }
85
+ ```
86
+
87
+ ## Example App
88
+
89
+ See [`examples/nextjs-checkout/`](./examples/nextjs-checkout/) for a full Next.js app that creates payment links and receives webhooks.
90
+
91
+ ```bash
92
+ cd examples/nextjs-checkout
93
+ cp .env.example .env.local
94
+ # edit .env.local with your API key and webhook secret
95
+ npm install
96
+ npm run dev
97
+ ```
98
+
99
+ ## Build
100
+
101
+ ```bash
102
+ npm run build # outputs ESM + CJS + .d.ts to dist/
103
+ ```