@caspay/sdk 1.0.0 → 1.0.1

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,223 @@
1
+ # CasPay SDK
2
+
3
+ Official JavaScript/TypeScript SDK for CasPay - Accept crypto payments with Casper blockchain.
4
+
5
+ [![npm version](https://img.shields.io/npm/v/@caspay/sdk)](https://www.npmjs.com/package/@caspay/sdk)
6
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
7
+
8
+ ## 🚀 Installation
9
+
10
+ ### NPM / Yarn (React, Next.js, Node.js)
11
+
12
+ ```bash
13
+ npm install @caspay/sdk
14
+ # or
15
+ yarn add @caspay/sdk
16
+ ```
17
+
18
+ ### CDN (WordPress, HTML)
19
+
20
+ ```html
21
+ <script src="https://cdn.jsdelivr.net/npm/@caspay/sdk@1.0.1/dist/caspay.min.js"></script>
22
+ ```
23
+
24
+ ## 📖 Quick Start
25
+
26
+ ### React / Next.js
27
+
28
+ ```typescript
29
+ import CasPay from '@caspay/sdk';
30
+
31
+ const caspay = new CasPay({
32
+ apiKey: 'cp_live_...',
33
+ merchantId: 'MERCH_...'
34
+ });
35
+
36
+ // Create a payment
37
+ const payment = await caspay.payments.create({
38
+ senderAddress: '0x123...',
39
+ productId: 'prod_abc123',
40
+ amount: 100,
41
+ currency: 'USD'
42
+ });
43
+
44
+ console.log('Payment successful:', payment);
45
+ ```
46
+
47
+ ### WordPress / HTML
48
+
49
+ ```html
50
+ <script src="https://cdn.jsdelivr.net/npm/@caspay/sdk@1.0.1/dist/caspay.min.js"></script>
51
+
52
+ <button id="payBtn">Pay Now</button>
53
+
54
+ <script>
55
+ const caspay = new CasPay({
56
+ apiKey: 'cp_live_...',
57
+ merchantId: 'MERCH_...'
58
+ });
59
+
60
+ document.getElementById('payBtn').onclick = async () => {
61
+ const payment = await caspay.payments.create({
62
+ senderAddress: '0x123...',
63
+ productId: 'prod_abc',
64
+ amount: 50
65
+ });
66
+
67
+ alert('Payment successful!');
68
+ };
69
+ </script>
70
+ ```
71
+
72
+ ## 🔧 Configuration
73
+
74
+ ### Constructor Options
75
+
76
+ ```typescript
77
+ const caspay = new CasPay({
78
+ apiKey: string; // Required: Your CasPay API key
79
+ merchantId: string; // Required: Your merchant ID
80
+ baseUrl?: string; // Optional: API base URL (default: https://api.caspay.link)
81
+ });
82
+ ```
83
+
84
+ ### Get API Keys
85
+
86
+ 1. Sign up at [caspay.link](https://caspay.link)
87
+ 2. Navigate to Settings → API Keys
88
+ 3. Generate a new API key
89
+
90
+ ## 📚 API Reference
91
+
92
+ ### Payments
93
+
94
+ #### `caspay.payments.create(params)`
95
+
96
+ Create a new payment record.
97
+
98
+ **Parameters:**
99
+
100
+ ```typescript
101
+ {
102
+ senderAddress: string; // Sender's Casper wallet address
103
+ productId?: string; // Product ID (for one-time payments)
104
+ subscriptionPlanId?: string; // Subscription plan ID (for recurring)
105
+ amount: number; // Payment amount
106
+ currency?: string; // Currency code (default: USD)
107
+ transactionHash?: string; // Optional: Casper transaction hash
108
+ }
109
+ ```
110
+
111
+ **Returns:**
112
+
113
+ ```typescript
114
+ {
115
+ success: boolean;
116
+ payment: {
117
+ id: string;
118
+ transaction_hash: string;
119
+ amount: number;
120
+ token: string;
121
+ status: string;
122
+ invoice_number: string;
123
+ created_at: string;
124
+ };
125
+ verification?: {
126
+ verified: boolean;
127
+ transaction_hash: string;
128
+ amount: number;
129
+ };
130
+ }
131
+ ```
132
+
133
+ **Example:**
134
+
135
+ ```typescript
136
+ // One-time payment
137
+ const payment = await caspay.payments.create({
138
+ senderAddress: '0x123...',
139
+ productId: 'prod_abc123',
140
+ amount: 100
141
+ });
142
+
143
+ // Subscription payment
144
+ const subscription = await caspay.payments.create({
145
+ senderAddress: '0x123...',
146
+ subscriptionPlanId: 'plan_xyz789',
147
+ amount: 29.99
148
+ });
149
+ ```
150
+
151
+ ## 🛠️ Error Handling
152
+
153
+ All SDK methods throw structured errors:
154
+
155
+ ```typescript
156
+ try {
157
+ const payment = await caspay.payments.create({...});
158
+ } catch (error) {
159
+ console.error('Error:', error.error); // Error message
160
+ console.error('Code:', error.code); // Error code
161
+ console.error('Status:', error.status); // HTTP status
162
+ }
163
+ ```
164
+
165
+ ### Common Error Codes
166
+
167
+ - `INVALID_PARAMS` - Missing or invalid parameters
168
+ - `INVALID_API_KEY` - Invalid API key
169
+ - `RATE_LIMIT_EXCEEDED` - Too many requests
170
+ - `VERIFICATION_FAILED` - Transaction verification failed
171
+ - `NETWORK_ERROR` - Network connection error
172
+
173
+ ## 🌐 Environment Support
174
+
175
+ | Environment | Installation | Import |
176
+ |-------------|--------------|--------|
177
+ | React/Next.js | `npm install @caspay/sdk` | `import CasPay from '@caspay/sdk'` |
178
+ | Node.js | `npm install @caspay/sdk` | `const CasPay = require('@caspay/sdk')` |
179
+ | WordPress | CDN script tag | `window.CasPay` |
180
+ | HTML | CDN script tag | `window.CasPay` |
181
+
182
+ ## 🔒 Security
183
+
184
+ - **Never expose your API key** in client-side code in production
185
+ - Use environment variables for sensitive data
186
+ - API keys should be stored server-side
187
+ - Use test keys (`cp_test_...`) for development
188
+
189
+ ## 📦 TypeScript Support
190
+
191
+ Full TypeScript support with type definitions included:
192
+
193
+ ```typescript
194
+ import CasPay, { PaymentCreateParams, PaymentResponse } from '@caspay/sdk';
195
+
196
+ const params: PaymentCreateParams = {
197
+ senderAddress: '0x123...',
198
+ productId: 'prod_abc',
199
+ amount: 100
200
+ };
201
+
202
+ const payment: PaymentResponse = await caspay.payments.create(params);
203
+ ```
204
+
205
+ ## 🔗 Links
206
+
207
+ - **Documentation:** [docs.caspay.link](https://docs.caspay.link)
208
+ - **Dashboard:** [caspay.link](https://caspay.link)
209
+ - **NPM:** [@caspay/sdk](https://www.npmjs.com/package/@caspay/sdk)
210
+ - **GitHub:** [dmrdvn/caspay-sdk](https://github.com/dmrdvn/caspay-sdk)
211
+
212
+ ## 📄 License
213
+
214
+ MIT License - see [LICENSE](LICENSE) file for details.
215
+
216
+ ## 🤝 Support
217
+
218
+ - Email: support@caspay.link
219
+ - Issues: [GitHub Issues](https://github.com/dmrdvn/caspay-sdk/issues)
220
+
221
+ ---
222
+
223
+ Made with ❤️ by CasPay Team
@@ -1 +1 @@
1
- !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).CasPay=e()}(this,function(){"use strict";class t{constructor(t){if(this.SDK_VERSION="1.0.0",this.baseUrl=t.baseUrl||"https://api.caspay.link",this.apiKey=t.apiKey,this.merchantId=t.merchantId,!this.apiKey)throw new Error("CasPay SDK: apiKey is required");if(!this.merchantId)throw new Error("CasPay SDK: merchantId is required")}async request(t,e,r){const s=`${this.baseUrl}${e}`;try{const e=await fetch(s,{method:t,headers:{"Content-Type":"application/json","X-CasPay-Key":this.apiKey,"X-CasPay-SDK-Version":this.SDK_VERSION,"User-Agent":`CasPay-SDK-JS/${this.SDK_VERSION}`},body:r?JSON.stringify(r):void 0}),i=await e.json();if(!e.ok){throw{error:i.error||"Request failed",code:i.code||"UNKNOWN_ERROR",status:e.status}}return i}catch(t){if(t.error&&t.code)throw t;throw{error:t.message||"Network error",code:"NETWORK_ERROR",status:0}}}getMerchantId(){return this.merchantId}}class e{constructor(t){this.client=t}async create(t){if(!t.senderAddress)throw{error:"senderAddress is required",code:"INVALID_PARAMS",status:400};if(!t.amount||t.amount<=0)throw{error:"amount must be greater than 0",code:"INVALID_PARAMS",status:400};if(!t.productId&&!t.subscriptionPlanId)throw{error:"Either productId or subscriptionPlanId is required",code:"INVALID_PARAMS",status:400};const e={merchant_id:this.client.getMerchantId(),sender_address:t.senderAddress,transaction_hash:t.transactionHash||`mock_tx_${Date.now()}`,product_id:t.productId,subscription_plan_id:t.subscriptionPlanId,amount:t.amount,currency:t.currency||"USD"};return this.client.request("POST","/api/v1/payments/record",e)}}class r{constructor(r){this.client=new t(r),this.payments=new e(this.client)}static get version(){return"1.0.0"}}return"undefined"!=typeof window&&(window.CasPay=r),r});
1
+ !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).CasPay=e()}(this,function(){"use strict";class t{constructor(t){if(this.SDK_VERSION="1.0.1",this.baseUrl=t.baseUrl||"https://api.caspay.link",this.apiKey=t.apiKey,this.merchantId=t.merchantId,!this.apiKey)throw new Error("CasPay SDK: apiKey is required");if(!this.merchantId)throw new Error("CasPay SDK: merchantId is required")}async request(t,e,r){const s=`${this.baseUrl}${e}`;try{const e=await fetch(s,{method:t,headers:{"Content-Type":"application/json","X-CasPay-Key":this.apiKey,"X-CasPay-SDK-Version":this.SDK_VERSION,"User-Agent":`CasPay-SDK-JS/${this.SDK_VERSION}`},body:r?JSON.stringify(r):void 0}),i=await e.json();if(!e.ok){throw{error:i.error||"Request failed",code:i.code||"UNKNOWN_ERROR",status:e.status}}return i}catch(t){if(t.error&&t.code)throw t;throw{error:t.message||"Network error",code:"NETWORK_ERROR",status:0}}}getMerchantId(){return this.merchantId}}class e{constructor(t){this.client=t}async create(t){if(!t.senderAddress)throw{error:"senderAddress is required",code:"INVALID_PARAMS",status:400};if(!t.amount||t.amount<=0)throw{error:"amount must be greater than 0",code:"INVALID_PARAMS",status:400};if(!t.productId&&!t.subscriptionPlanId)throw{error:"Either productId or subscriptionPlanId is required",code:"INVALID_PARAMS",status:400};const e={merchant_id:this.client.getMerchantId(),sender_address:t.senderAddress,transaction_hash:t.transactionHash||`mock_tx_${Date.now()}`,product_id:t.productId,subscription_plan_id:t.subscriptionPlanId,amount:t.amount,currency:t.currency||"USD"};return this.client.request("POST","/api/v1/payments/record",e)}}class r{constructor(r){this.client=new t(r),this.payments=new e(this.client)}static get version(){return"1.0.0"}}return"undefined"!=typeof window&&(window.CasPay=r),r});
package/dist/index.esm.js CHANGED
@@ -4,7 +4,7 @@
4
4
  */
5
5
  class HttpClient {
6
6
  constructor(config) {
7
- this.SDK_VERSION = '1.0.0';
7
+ this.SDK_VERSION = '1.0.1';
8
8
  // Use production API by default
9
9
  this.baseUrl = config.baseUrl || 'https://api.caspay.link';
10
10
  this.apiKey = config.apiKey;
package/dist/index.js CHANGED
@@ -8,7 +8,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
8
8
  */
9
9
  class HttpClient {
10
10
  constructor(config) {
11
- this.SDK_VERSION = '1.0.0';
11
+ this.SDK_VERSION = '1.0.1';
12
12
  // Use production API by default
13
13
  this.baseUrl = config.baseUrl || 'https://api.caspay.link';
14
14
  this.apiKey = config.apiKey;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@caspay/sdk",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "Official CasPay JavaScript/TypeScript SDK - Accept crypto payments with Casper blockchain",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.esm.js",