@blocklet/payment-js 1.16.1 → 1.16.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.
Files changed (2) hide show
  1. package/README.md +103 -2
  2. package/package.json +3 -3
package/README.md CHANGED
@@ -5,15 +5,116 @@ A Node.js SDK for the PaymentKit API, can be used to manage resources in Payment
5
5
  ## Installation
6
6
 
7
7
  ```bash
8
- npm install @payment-kit/client
8
+ npm install @blocklet/payment-js
9
9
  ```
10
10
 
11
11
  ## Usage
12
12
 
13
13
  ```js
14
- // TODO
14
+ import payment from '@blocklet/payment-js';
15
+
16
+ // Configure the SDK
17
+ payment.environments.setTestMode(true); // Use test environment
18
+ payment.environments.setApiKey('your-api-key'); // Set API key if needed
19
+
20
+ // List subscriptions
21
+ const subscriptions = await payment.subscriptions.list({
22
+ order: 'updated_at:ASC',
23
+ activeFirst: true,
24
+ });
25
+
26
+ // Create a checkout session
27
+ const session = await payment.checkout.sessions.create({
28
+ success_url: 'https://example.com/success',
29
+ cancel_url: 'https://example.com/cancel',
30
+ mode: 'payment',
31
+ line_items: [
32
+ { price_id: 'price_xxx', quantity: 1 }
33
+ ]
34
+ });
35
+
36
+ // Handle refunds
37
+ const refund = await payment.paymentIntents.refund('pi_xxx', {
38
+ amount: '0.001',
39
+ reason: 'requested_by_customer',
40
+ description: 'Refund description'
41
+ });
15
42
  ```
16
43
 
17
44
  ## Resources
18
45
 
46
+ The SDK provides access to the following resources:
47
+
48
+ ### Customers
49
+ - `payment.customers.create()`
50
+ - `payment.customers.retrieve(id)`
51
+ - `payment.customers.update(id, data)`
52
+ - `payment.customers.list(params)`
53
+ - `payment.customers.search(params)`
54
+ - `payment.customers.del(id)`
55
+
56
+ ### Subscriptions
57
+ - `payment.subscriptions.create()`
58
+ - `payment.subscriptions.retrieve(id)`
59
+ - `payment.subscriptions.update(id, data)`
60
+ - `payment.subscriptions.list(params)`
61
+ - `payment.subscriptions.cancel(id, options)`
62
+ - `payment.subscriptions.recover(id)`
63
+ - `payment.subscriptions.pause(id)`
64
+ - `payment.subscriptions.resume(id)`
65
+
66
+ ### Products & Prices
67
+ - `payment.products.*` - Manage products
68
+ - `payment.prices.*` - Manage prices and inventory
69
+
70
+ ### Payments
71
+ - `payment.paymentIntents.*` - Handle payment intents
72
+ - `payment.paymentMethods.*` - Manage payment methods
73
+ - `payment.refunds.*` - Handle refunds
74
+
75
+ ### Checkout
76
+ - `payment.checkout.sessions.*` - Create and manage checkout sessions
77
+ - `payment.paymentLinks.*` - Handle payment links
78
+
79
+ ### Usage & Metering
80
+ - `payment.subscriptionItems.createUsageRecord()`
81
+ - `payment.subscriptionItems.listUsageRecordSummaries()`
82
+
83
+ ### Webhooks
84
+ - `payment.webhookEndpoints.*` - Manage webhook endpoints
85
+
19
86
  ## Configuration
87
+
88
+ The SDK can be configured with the following options:
89
+
90
+ ```js
91
+ // Set environment
92
+ payment.environments.setTestMode(true); // Use test environment
93
+ payment.environments.setLiveMode(true); // Use live environment
94
+
95
+ // Set API configuration
96
+ payment.environments.setApiKey('your-api-key');
97
+ payment.environments.setEndpoint('https://api.example.com');
98
+ ```
99
+
100
+ ## Error Handling
101
+
102
+ ```js
103
+ try {
104
+ const subscription = await payment.subscriptions.retrieve('sub_xxx');
105
+ } catch (error) {
106
+ if (error.type === 'NotFoundError') {
107
+ console.error('Subscription not found');
108
+ } else {
109
+ console.error('An error occurred:', error.message);
110
+ }
111
+ }
112
+ ```
113
+
114
+ ## TypeScript Support
115
+
116
+ The SDK is written in TypeScript and provides full type definitions for all resources and methods.
117
+
118
+ ## License
119
+
120
+ MIT
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blocklet/payment-js",
3
- "version": "1.16.1",
3
+ "version": "1.16.3",
4
4
  "description": "Node.js client for Payment Kit",
5
5
  "keywords": [
6
6
  "types",
@@ -36,7 +36,7 @@
36
36
  "url": "https://github.com/blocklet/payment-kit/issues"
37
37
  },
38
38
  "dependencies": {
39
- "@blocklet/payment-types": "1.16.1",
39
+ "@blocklet/payment-types": "1.16.3",
40
40
  "@blocklet/sdk": "1.16.33-beta-20241031-073543-49b1ff9b"
41
41
  },
42
42
  "importSort": {
@@ -62,5 +62,5 @@
62
62
  "type-fest": "^4.23.0",
63
63
  "typescript": "^5.5.4"
64
64
  },
65
- "gitHead": "590597d056e31eafd2b8ebd2a9d0a0c236c33440"
65
+ "gitHead": "6accc56a51e4ea0906e65f69dc5f41eaa82685fb"
66
66
  }