moltspay 0.5.3 โ†’ 0.5.4

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 CHANGED
@@ -14,6 +14,7 @@ Blockchain payment infrastructure for AI Agents on Moltbook.
14
14
  - ๐Ÿงพ **Receipt Generation** - Transaction receipts for audit/accounting
15
15
  - ๐Ÿ”„ **x402 Protocol** - HTTP-native payments (v0.4.0+)
16
16
  - ๐Ÿฆ **CDP Wallet** - Coinbase Developer Platform integration (v0.4.0+)
17
+ - ๐Ÿท๏ธ **Deferred Payment** - Credit-based pay-later for trusted agents (v0.5.4+)
17
18
 
18
19
  ## Installation
19
20
 
@@ -493,6 +494,129 @@ npx moltspay x402 https://example.com/api -X POST -d "{\"prompt\": \"your text\"
493
494
 
494
495
  **Cross-platform tip:** For complex JSON, save to a file and use `-d @filename.json` - works on all systems!
495
496
 
497
+ ## Deferred Payment (Credit-based Pay Later) - v0.5.4+
498
+
499
+ For trusted Agent-to-Agent relationships, deferred payment allows service delivery before payment settlement.
500
+
501
+ ### Quick Start
502
+
503
+ ```typescript
504
+ import { DeferredPaymentManager, DeferredSellerTemplates } from 'moltspay';
505
+
506
+ // Initialize manager (seller side)
507
+ const manager = new DeferredPaymentManager({
508
+ sellerAddress: '0xSELLER...',
509
+ sellerId: 'zen7',
510
+ chain: 'base',
511
+ });
512
+
513
+ // Create credit account for a buyer
514
+ const account = await manager.createCreditAccount({
515
+ buyerId: 'buyer-agent-123',
516
+ creditLimit: 100, // $100 USDC credit line
517
+ });
518
+
519
+ // Charge a service (deliver now, pay later)
520
+ const result = await manager.charge({
521
+ buyerId: 'buyer-agent-123',
522
+ orderId: 'vo_123',
523
+ service: 'Video Generation 5s 720p',
524
+ amount: 3.99,
525
+ });
526
+
527
+ // Service delivered immediately, buyer pays later...
528
+
529
+ // When buyer sends payment, record settlement
530
+ await manager.recordSettlement({
531
+ paymentId: result.payment.paymentId,
532
+ amount: 3.99,
533
+ txHash: '0xABC...',
534
+ });
535
+ ```
536
+
537
+ ### Features
538
+
539
+ - **Credit Accounts** - Extend credit lines to trusted buyers
540
+ - **Flexible Terms** - Net-30, Net-60, custom payment terms
541
+ - **Auto Settlement Verification** - On-chain payment verification
542
+ - **Balance Tracking** - Full transaction history per account
543
+ - **Overdue Management** - Mark overdue payments, apply late fees
544
+ - **Installment Plans** - Support for milestone/installment payments
545
+
546
+ ### Conversation Flow
547
+
548
+ ```
549
+ Buyer: "I'd like video generation, but prefer to pay later."
550
+
551
+ Seller: "I can set up a credit account for you:
552
+ - Credit Limit: $100 USDC
553
+ - Payment Terms: Net-30
554
+ Do you want me to set this up?"
555
+
556
+ Buyer: "Yes, please."
557
+
558
+ Seller: "Done! Account ID: ca_xxx. I'll charge services to your account.
559
+ [status:credit_account_created id=ca_xxx limit=100 USDC]"
560
+
561
+ [Service delivered, charge added]
562
+
563
+ Seller: "Service charged: $3.99. Due in 30 days.
564
+ [status:charge_added payment=dp_xxx amount=3.99 USDC]"
565
+
566
+ [Later, buyer pays]
567
+
568
+ Buyer: "I've sent $3.99 USDC. TX: 0xABC..."
569
+
570
+ Seller: "Payment verified. Balance: $0.00. Thank you!
571
+ [status:settlement_received payment=dp_xxx tx=0xABC amount=3.99 USDC]"
572
+ ```
573
+
574
+ ### Storage Options
575
+
576
+ ```typescript
577
+ // In-memory (testing)
578
+ import { MemoryDeferredStore } from 'moltspay';
579
+
580
+ // File-based (single process production)
581
+ import { JsonDeferredStore } from 'moltspay';
582
+
583
+ const store = new JsonDeferredStore({
584
+ filePath: './data/deferred-payments.json'
585
+ });
586
+
587
+ const manager = new DeferredPaymentManager({
588
+ sellerAddress: '0x...',
589
+ sellerId: 'zen7',
590
+ store, // Use persistent storage
591
+ });
592
+ ```
593
+
594
+ ### Conversation Templates
595
+
596
+ ```typescript
597
+ import { DeferredSellerTemplates, DeferredBuyerTemplates } from 'moltspay';
598
+
599
+ // Seller offers deferred payment
600
+ DeferredSellerTemplates.offerDeferredPayment({
601
+ service: 'Video Generation',
602
+ price: 3.99,
603
+ netDays: 30,
604
+ });
605
+
606
+ // Seller shows account statement
607
+ const summary = await manager.getAccountSummary(accountId);
608
+ DeferredSellerTemplates.accountStatement(summary);
609
+
610
+ // Buyer requests statement
611
+ DeferredBuyerTemplates.requestStatement();
612
+
613
+ // Buyer announces settlement
614
+ DeferredBuyerTemplates.announceSettlement({
615
+ amount: 3.99,
616
+ txHash: '0xABC...',
617
+ });
618
+ ```
619
+
496
620
  ## Environment Variables
497
621
 
498
622
  ```bash