vibecash 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.
Files changed (3) hide show
  1. package/README.md +642 -0
  2. package/dist/index.js +1012 -0
  3. package/package.json +45 -0
package/README.md ADDED
@@ -0,0 +1,642 @@
1
+ # vibecash
2
+
3
+ Payment infrastructure CLI for AI agents and developers.
4
+
5
+ [![npm version](https://img.shields.io/npm/v/vibecash.svg)](https://www.npmjs.com/package/vibecash)
6
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
7
+
8
+ ## Install
9
+
10
+ ```bash
11
+ npm install -g vibecash
12
+ ```
13
+
14
+ ## Quick Start
15
+
16
+ ```bash
17
+ # 1. Create wallet (saves credentials to ~/.vibecash/config.json)
18
+ vibecash wallet create
19
+
20
+ # 2. Create a reusable payment link
21
+ vibecash link create 9.99 --name "My Product" --success-url "https://myapp.com/thanks#session_id={CHECKOUT_SESSION_ID}"
22
+
23
+ # 3. Share the URL - each visitor gets their own checkout session
24
+ # Output: { "url": "https://pay.vibecash.dev/p/plink_xxx", ... }
25
+
26
+ # 4. Verify payment (after user returns to your success URL)
27
+ vibecash checkout get cs_xxx
28
+ # Check: status === "complete"
29
+ ```
30
+
31
+ ## Environment Variables
32
+
33
+ ```bash
34
+ VIBECASH_SECRET=sk_live_xxx # API secret (or use ~/.vibecash/config.json)
35
+ VIBECASH_API_URL=https://api.vibecash.dev # API endpoint (default)
36
+ ```
37
+
38
+ ## All Commands
39
+
40
+ ```
41
+ vibecash wallet create # Create wallet, get API credentials
42
+ vibecash wallet info # Show balance and status
43
+ vibecash wallet claim # Generate dashboard claim link
44
+
45
+ vibecash link create <amount> # Create reusable payment link (recommended)
46
+ vibecash link list # List payment links
47
+ vibecash link get <id> # Get link details
48
+ vibecash link activate <id> # Activate link
49
+ vibecash link deactivate <id> # Deactivate link
50
+
51
+ vibecash checkout create # Create one-time checkout session
52
+ vibecash checkout get <id> # Get session status
53
+
54
+ vibecash product create <name> # Create product
55
+ vibecash product list # List products
56
+ vibecash product get <id> # Get product
57
+
58
+ vibecash price create <prod_id> <amount> # Create price
59
+ vibecash price list # List prices
60
+
61
+ vibecash subscription list # List subscriptions
62
+ vibecash subscription get <id> # Get subscription
63
+ vibecash subscription cancel <id> # Cancel subscription
64
+ vibecash subscription resume <id> # Resume subscription
65
+
66
+ vibecash customer create <email> # Create customer
67
+ vibecash customer list # List customers
68
+ vibecash customer get <id> # Get customer
69
+ vibecash customer portal <id> # Generate customer portal URL
70
+
71
+ vibecash create <amount> # Quick: create checkout in one command
72
+ ```
73
+
74
+ ## Output Format
75
+
76
+ ```bash
77
+ vibecash --json <command> # JSON output (default, best for scripts/AI)
78
+ vibecash --human <command> # Human-readable tables
79
+ ```
80
+
81
+ ---
82
+
83
+ ## Payment Links (Recommended)
84
+
85
+ Payment Links are **reusable URLs** - each visitor automatically gets their own checkout session. Perfect for:
86
+ - Static websites
87
+ - AI agents
88
+ - Sharing on social media
89
+ - QR codes
90
+
91
+ ```bash
92
+ # Create payment link with success redirect
93
+ vibecash link create 9.99 \
94
+ --name "Pro Plan" \
95
+ --description "Unlock all features" \
96
+ --currency USD \
97
+ --success-url "https://myapp.com/thanks#session_id={CHECKOUT_SESSION_ID}"
98
+ ```
99
+
100
+ Output:
101
+ ```json
102
+ {
103
+ "id": "plink_xxx",
104
+ "url": "https://pay.vibecash.dev/p/plink_xxx",
105
+ "amount": 999,
106
+ "currency": "USD",
107
+ "active": true
108
+ }
109
+ ```
110
+
111
+ ### Verify Payment in Your App
112
+
113
+ After payment, user is redirected to your success URL with session ID in the hash:
114
+ ```
115
+ https://myapp.com/thanks#session_id=cs_xxx
116
+ ```
117
+
118
+ Verify the payment:
119
+ ```javascript
120
+ // Browser JavaScript
121
+ const sessionId = new URLSearchParams(location.hash.slice(1)).get('session_id');
122
+ const res = await fetch(`https://api.vibecash.dev/v1/checkout/sessions/${sessionId}`);
123
+ const { session } = await res.json();
124
+ if (session.status === 'complete') {
125
+ // Payment successful - unlock content
126
+ localStorage.setItem('unlocked', 'true');
127
+ }
128
+ ```
129
+
130
+ Or via CLI:
131
+ ```bash
132
+ vibecash checkout get cs_xxx
133
+ # Look for: "status": "complete"
134
+ ```
135
+
136
+ ---
137
+
138
+ ## Configuration
139
+
140
+ The CLI reads configuration from two sources (environment variables take precedence):
141
+
142
+ | Environment Variable | Description | Default |
143
+ |---|---|---|
144
+ | `AIPAY_SECRET` | Wallet API secret (`sk_live_...`) | Read from `~/.vibecash/config.json` |
145
+ | `AIPAY_API_URL` | API server URL | `https://api.vibecash.dev` |
146
+ | `AIPAY_OUTPUT` | Output format (`json` or `human`) | `json` |
147
+
148
+ Config file location: `~/.vibecash/config.json`
149
+
150
+ ```json
151
+ {
152
+ "secret": "sk_live_xxx...",
153
+ "apiUrl": "https://api.vibecash.dev"
154
+ }
155
+ ```
156
+
157
+ ### Global flags
158
+
159
+ | Flag | Description |
160
+ |---|---|
161
+ | `--human` | Human-readable output (tables and formatted text) |
162
+ | `--json` | JSON output (default) |
163
+ | `--version` | Show version |
164
+ | `--help` | Show help for any command |
165
+
166
+ ---
167
+
168
+ ## Common Workflows
169
+
170
+ ### Collect a one-time payment
171
+
172
+ ```bash
173
+ vibecash create 5.00 -d "Service fee"
174
+ ```
175
+
176
+ ### Create a monthly subscription
177
+
178
+ ```bash
179
+ vibecash create 19.99 --monthly -d "Pro Plan"
180
+ ```
181
+
182
+ > **Note:** Subscriptions only support card payments. WeChat Pay, Alipay, and PayNow are one-time payment methods only.
183
+
184
+ ### Create a yearly subscription with trial
185
+
186
+ ```bash
187
+ vibecash create 99.99 --yearly -d "Annual Plan" --trial-days 14
188
+ ```
189
+
190
+ ### Full product + price + checkout workflow
191
+
192
+ ```bash
193
+ # Step 1: Create a product
194
+ vibecash product create "Premium Plan" -d "Full-featured plan"
195
+
196
+ # Step 2: Create a recurring price for that product
197
+ vibecash price create prod_xxx --amount 29.99 --type recurring --interval month
198
+
199
+ # Step 3: Create a checkout session with the price
200
+ vibecash checkout create --price price_xxx --success-url https://example.com/thanks
201
+ ```
202
+
203
+ ---
204
+
205
+ ## Command Reference
206
+
207
+ ### `vibecash create` -- Quick Checkout
208
+
209
+ The fastest way to generate a payment link. For one-time payments, it creates a checkout session directly. For subscriptions, it automatically creates the product, price, and checkout session in one step.
210
+
211
+ ```bash
212
+ vibecash create <amount> [options]
213
+ ```
214
+
215
+ **Arguments:**
216
+
217
+ | Argument | Description |
218
+ |---|---|
219
+ | `amount` | Amount to charge in dollars (e.g. `9.99`, `1.00`, `250`) |
220
+
221
+ **Options:**
222
+
223
+ | Option | Description |
224
+ |---|---|
225
+ | `-d, --description <desc>` | Payment description (shown to customer) |
226
+ | `--monthly` | Create a monthly subscription instead of one-time payment |
227
+ | `--yearly` | Create a yearly subscription |
228
+ | `--weekly` | Create a weekly subscription |
229
+ | `--trial-days <days>` | Trial period in days (subscriptions only) |
230
+ | `--success-url <url>` | URL to redirect after successful payment |
231
+ | `--cancel-url <url>` | URL to redirect if customer cancels |
232
+ | `--email <email>` | Pre-fill customer email |
233
+
234
+ **Examples:**
235
+
236
+ ```bash
237
+ # One-time $1 payment
238
+ vibecash create 1.00
239
+
240
+ # $25 with description
241
+ vibecash create 25.00 -d "Consulting hour"
242
+
243
+ # Monthly subscription
244
+ vibecash create 9.99 --monthly -d "Basic Plan"
245
+
246
+ # Yearly with 7-day trial and customer email
247
+ vibecash create 99.99 --yearly -d "Pro Plan" --trial-days 7 --email user@example.com
248
+
249
+ # One-time with redirect URLs
250
+ vibecash create 50.00 -d "Workshop" --success-url https://mysite.com/thanks --cancel-url https://mysite.com/cancel
251
+ ```
252
+
253
+ ---
254
+
255
+ ### `vibecash wallet` -- Wallet Management
256
+
257
+ #### `vibecash wallet create`
258
+
259
+ Create a new wallet. The API secret is automatically saved to `~/.vibecash/config.json`.
260
+
261
+ ```bash
262
+ vibecash wallet create
263
+ ```
264
+
265
+ No options. Returns the wallet ID and secret.
266
+
267
+ #### `vibecash wallet status`
268
+
269
+ Show the current wallet's balance and status.
270
+
271
+ ```bash
272
+ vibecash wallet status
273
+ ```
274
+
275
+ Returns: wallet ID, status, balance, pending balance, currency, creation date.
276
+
277
+ #### `vibecash wallet claim`
278
+
279
+ Generate a claim link to transfer wallet ownership. The link expires in 7 days.
280
+
281
+ ```bash
282
+ vibecash wallet claim
283
+ ```
284
+
285
+ ---
286
+
287
+ ### `vibecash product` -- Product Management
288
+
289
+ Products represent what you are selling. Each product can have multiple prices.
290
+
291
+ #### `vibecash product create`
292
+
293
+ ```bash
294
+ vibecash product create <name> [options]
295
+ ```
296
+
297
+ | Argument | Description |
298
+ |---|---|
299
+ | `name` | Product name (required) |
300
+
301
+ | Option | Description |
302
+ |---|---|
303
+ | `-d, --description <desc>` | Product description |
304
+
305
+ ```bash
306
+ vibecash product create "Starter Plan" -d "Basic features for individuals"
307
+ ```
308
+
309
+ #### `vibecash product list`
310
+
311
+ List all products in your wallet.
312
+
313
+ ```bash
314
+ vibecash product list
315
+ ```
316
+
317
+ #### `vibecash product get`
318
+
319
+ Get details of a specific product.
320
+
321
+ ```bash
322
+ vibecash product get <id>
323
+ ```
324
+
325
+ | Argument | Description |
326
+ |---|---|
327
+ | `id` | Product ID (`prod_xxx`) |
328
+
329
+ ```bash
330
+ vibecash product get prod_ZkRdRurL0CSS2OXPEhmHBw
331
+ ```
332
+
333
+ ---
334
+
335
+ ### `vibecash price` -- Price Management
336
+
337
+ Prices define how much to charge for a product. A product can have multiple prices (e.g. monthly and yearly).
338
+
339
+ #### `vibecash price create`
340
+
341
+ ```bash
342
+ vibecash price create <product_id> [options]
343
+ ```
344
+
345
+ | Argument | Description |
346
+ |---|---|
347
+ | `product_id` | Product ID to attach the price to (`prod_xxx`) |
348
+
349
+ | Option | Required | Description |
350
+ |---|---|---|
351
+ | `-a, --amount <amount>` | Yes | Price in dollars (e.g. `9.99`) |
352
+ | `-t, --type <type>` | Yes | `one_time` or `recurring` |
353
+ | `-c, --currency <code>` | No | Currency code (default: `USD`). Supports: USD, EUR, GBP, CAD, AUD, SGD, CNY, JPY, HKD |
354
+ | `-i, --interval <interval>` | When recurring | Billing interval: `day`, `week`, `month`, or `year` |
355
+ | `--interval-count <n>` | No | Number of intervals between billings (default: `1`). E.g. `--interval month --interval-count 3` = quarterly |
356
+ | `--trial-days <days>` | No | Free trial period in days |
357
+
358
+ ```bash
359
+ # One-time price
360
+ vibecash price create prod_xxx --amount 29.99 --type one_time
361
+
362
+ # Monthly recurring
363
+ vibecash price create prod_xxx --amount 9.99 --type recurring --interval month
364
+
365
+ # Yearly recurring in SGD
366
+ vibecash price create prod_xxx --amount 108.00 --type recurring --interval year --currency SGD
367
+
368
+ # Quarterly (every 3 months) with 14-day trial
369
+ vibecash price create prod_xxx --amount 49.99 --type recurring --interval month --interval-count 3 --trial-days 14
370
+ ```
371
+
372
+ #### `vibecash price list`
373
+
374
+ List all prices, optionally filtered by product.
375
+
376
+ ```bash
377
+ vibecash price list [options]
378
+ ```
379
+
380
+ | Option | Description |
381
+ |---|---|
382
+ | `-p, --product <id>` | Filter prices by product ID |
383
+
384
+ ```bash
385
+ # All prices
386
+ vibecash price list
387
+
388
+ # Prices for a specific product
389
+ vibecash price list --product prod_xxx
390
+ ```
391
+
392
+ ---
393
+
394
+ ### `vibecash checkout` -- Checkout Sessions
395
+
396
+ Checkout sessions represent a single payment or subscription attempt. Each session has a unique URL where customers complete their payment. Sessions expire after 24 hours.
397
+
398
+ #### `vibecash checkout create`
399
+
400
+ ```bash
401
+ vibecash checkout create [options]
402
+ ```
403
+
404
+ You must provide either `--price` or `--amount`:
405
+
406
+ | Option | Description |
407
+ |---|---|
408
+ | `-p, --price <id>` | Use an existing price ID (`price_xxx`) |
409
+ | `-a, --amount <amount>` | Create an inline one-time charge (in dollars) |
410
+ | `-d, --description <desc>` | Description for inline charge (use with `--amount`) |
411
+ | `-m, --mode <mode>` | `payment` (default) or `subscription` |
412
+ | `--success-url <url>` | Redirect URL after successful payment |
413
+ | `--cancel-url <url>` | Redirect URL if customer cancels |
414
+ | `--email <email>` | Pre-fill customer email |
415
+ | `--trial-days <days>` | Trial period (subscriptions only) |
416
+
417
+ ```bash
418
+ # Inline one-time charge
419
+ vibecash checkout create --amount 15.00 -d "T-shirt"
420
+
421
+ # Using an existing price
422
+ vibecash checkout create --price price_xxx --success-url https://mysite.com/thanks
423
+
424
+ # Subscription checkout
425
+ vibecash checkout create --price price_xxx --mode subscription --email user@example.com
426
+ ```
427
+
428
+ #### `vibecash checkout status`
429
+
430
+ Check the status of a checkout session. Can optionally poll until the session completes.
431
+
432
+ ```bash
433
+ vibecash checkout status <id> [options]
434
+ ```
435
+
436
+ | Argument | Description |
437
+ |---|---|
438
+ | `id` | Checkout session ID (`cs_xxx`) |
439
+
440
+ | Option | Description |
441
+ |---|---|
442
+ | `-w, --wait` | Poll every 2 seconds until session completes or expires |
443
+ | `--timeout <ms>` | Max wait time in milliseconds (default: `300000` = 5 minutes) |
444
+
445
+ ```bash
446
+ # Check once
447
+ vibecash checkout status cs_xxx
448
+
449
+ # Wait for completion (useful in scripts)
450
+ vibecash checkout status cs_xxx --wait --timeout 60000
451
+ ```
452
+
453
+ ---
454
+
455
+ ### `vibecash customer` -- Customer Management
456
+
457
+ #### `vibecash customer create`
458
+
459
+ ```bash
460
+ vibecash customer create [options]
461
+ ```
462
+
463
+ | Option | Required | Description |
464
+ |---|---|---|
465
+ | `-e, --email <email>` | Yes | Customer email address |
466
+ | `-n, --name <name>` | No | Customer display name |
467
+
468
+ ```bash
469
+ vibecash customer create --email alice@example.com --name "Alice"
470
+ ```
471
+
472
+ #### `vibecash customer list`
473
+
474
+ List all customers.
475
+
476
+ ```bash
477
+ vibecash customer list
478
+ ```
479
+
480
+ #### `vibecash customer get`
481
+
482
+ Get details of a specific customer.
483
+
484
+ ```bash
485
+ vibecash customer get <id>
486
+ ```
487
+
488
+ | Argument | Description |
489
+ |---|---|
490
+ | `id` | Customer ID (`cus_xxx`) |
491
+
492
+ #### `vibecash customer portal`
493
+
494
+ Create a self-service portal session for a customer to manage their subscriptions and billing.
495
+
496
+ ```bash
497
+ vibecash customer portal <id> [options]
498
+ ```
499
+
500
+ | Argument | Description |
501
+ |---|---|
502
+ | `id` | Customer ID (`cus_xxx`) |
503
+
504
+ | Option | Description |
505
+ |---|---|
506
+ | `-r, --return-url <url>` | URL to return to after the customer finishes |
507
+
508
+ ```bash
509
+ vibecash customer portal cus_xxx --return-url https://mysite.com/account
510
+ ```
511
+
512
+ ---
513
+
514
+ ### `vibecash subscription` -- Subscription Management
515
+
516
+ #### `vibecash subscription list`
517
+
518
+ ```bash
519
+ vibecash subscription list [options]
520
+ ```
521
+
522
+ | Option | Description |
523
+ |---|---|
524
+ | `-c, --customer <id>` | Filter by customer ID |
525
+ | `-s, --status <status>` | Filter by status (`active`, `canceled`, `past_due`, `trialing`) |
526
+
527
+ ```bash
528
+ # All subscriptions
529
+ vibecash subscription list
530
+
531
+ # Active only
532
+ vibecash subscription list --status active
533
+
534
+ # For a specific customer
535
+ vibecash subscription list --customer cus_xxx
536
+ ```
537
+
538
+ #### `vibecash subscription get`
539
+
540
+ ```bash
541
+ vibecash subscription get <id>
542
+ ```
543
+
544
+ | Argument | Description |
545
+ |---|---|
546
+ | `id` | Subscription ID (`sub_xxx`) |
547
+
548
+ #### `vibecash subscription cancel`
549
+
550
+ Cancel a subscription. By default, cancels at the end of the current billing period.
551
+
552
+ ```bash
553
+ vibecash subscription cancel <id> [options]
554
+ ```
555
+
556
+ | Argument | Description |
557
+ |---|---|
558
+ | `id` | Subscription ID (`sub_xxx`) |
559
+
560
+ | Option | Description |
561
+ |---|---|
562
+ | `--immediately` | Cancel right now instead of at period end |
563
+
564
+ ```bash
565
+ # Cancel at period end (customer keeps access until then)
566
+ vibecash subscription cancel sub_xxx
567
+
568
+ # Cancel immediately
569
+ vibecash subscription cancel sub_xxx --immediately
570
+ ```
571
+
572
+ #### `vibecash subscription resume`
573
+
574
+ Resume a previously canceled subscription (only if it hasn't expired yet).
575
+
576
+ ```bash
577
+ vibecash subscription resume <id>
578
+ ```
579
+
580
+ | Argument | Description |
581
+ |---|---|
582
+ | `id` | Subscription ID (`sub_xxx`) |
583
+
584
+ ---
585
+
586
+ ## Output Formats
587
+
588
+ By default, all commands output JSON. Use `--human` for formatted text.
589
+
590
+ ```bash
591
+ # JSON output (default, good for scripts and piping)
592
+ vibecash wallet status
593
+
594
+ # Human-readable output
595
+ vibecash wallet status --human
596
+ ```
597
+
598
+ Set the default format via environment variable:
599
+
600
+ ```bash
601
+ export AIPAY_OUTPUT=human
602
+ ```
603
+
604
+ ---
605
+
606
+ ## Supported Payment Methods
607
+
608
+ | Method | One-time Payment | Subscription |
609
+ |--------|-----------------|--------------|
610
+ | Credit/Debit Card | ✅ | ✅ |
611
+ | WeChat Pay | ✅ | ❌ |
612
+ | Alipay | ✅ | ❌ |
613
+ | PayNow (Singapore) | ✅ | ❌ |
614
+
615
+ > Subscriptions require card payment because only cards support automatic recurring charges. QR code payment methods (WeChat, Alipay, PayNow) are for one-time payments only.
616
+
617
+ ---
618
+
619
+ ## Supported Currencies
620
+
621
+ USD, EUR, GBP, CAD, AUD, SGD, CNY, JPY, HKD
622
+
623
+ > PayNow is only available for SGD transactions.
624
+
625
+ ---
626
+
627
+ ## Amount Format
628
+
629
+ All amounts are entered in **dollars** (or the main unit of the currency). The CLI converts them to cents internally.
630
+
631
+ | You type | Stored as | Meaning |
632
+ |---|---|---|
633
+ | `1` | 100 | $1.00 |
634
+ | `9.99` | 999 | $9.99 |
635
+ | `0.50` | 50 | $0.50 |
636
+ | `250` | 25000 | $250.00 |
637
+
638
+ ---
639
+
640
+ ## License
641
+
642
+ MIT