@caspay/sdk 1.0.2 → 1.0.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.
- package/README.md +4 -3
- package/dist/caspay.min.js +1 -1
- package/dist/core/client.d.ts +1 -1
- package/dist/index.esm.js +2 -3
- package/dist/index.js +2 -3
- package/dist/types/index.d.ts +0 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -18,7 +18,7 @@ yarn add @caspay/sdk
|
|
|
18
18
|
### CDN (WordPress, HTML)
|
|
19
19
|
|
|
20
20
|
```html
|
|
21
|
-
<script src="https://cdn.jsdelivr.net/npm/@caspay/sdk@1.0.
|
|
21
|
+
<script src="https://cdn.jsdelivr.net/npm/@caspay/sdk@1.0.2/dist/caspay.min.js"></script>
|
|
22
22
|
```
|
|
23
23
|
|
|
24
24
|
## 📖 Quick Start
|
|
@@ -47,7 +47,7 @@ console.log('Payment successful:', payment);
|
|
|
47
47
|
### WordPress / HTML
|
|
48
48
|
|
|
49
49
|
```html
|
|
50
|
-
<script src="https://cdn.jsdelivr.net/npm/@caspay/sdk@1.0.
|
|
50
|
+
<script src="https://cdn.jsdelivr.net/npm/@caspay/sdk@1.0.2/dist/caspay.min.js"></script>
|
|
51
51
|
|
|
52
52
|
<button id="payBtn">Pay Now</button>
|
|
53
53
|
|
|
@@ -77,10 +77,11 @@ console.log('Payment successful:', payment);
|
|
|
77
77
|
const caspay = new CasPay({
|
|
78
78
|
apiKey: string; // Required: Your CasPay API key
|
|
79
79
|
merchantId: string; // Required: Your merchant ID
|
|
80
|
-
baseUrl?: string; // Optional: API base URL (default: https://api.caspay.link)
|
|
81
80
|
});
|
|
82
81
|
```
|
|
83
82
|
|
|
83
|
+
**Note:** API endpoint is fixed to `https://caspay.link/api` for all requests.
|
|
84
|
+
|
|
84
85
|
### Get API Keys
|
|
85
86
|
|
|
86
87
|
1. Sign up at [caspay.link](https://caspay.link)
|
package/dist/caspay.min.js
CHANGED
|
@@ -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.
|
|
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.baseUrl="https://caspay.link/api",this.SDK_VERSION="1.0.3",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/core/client.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import type { CasPayConfig } from '../types';
|
|
|
4
4
|
* Handles all API requests with authentication and error handling
|
|
5
5
|
*/
|
|
6
6
|
export declare class HttpClient {
|
|
7
|
-
private baseUrl;
|
|
7
|
+
private readonly baseUrl;
|
|
8
8
|
private apiKey;
|
|
9
9
|
private merchantId;
|
|
10
10
|
private readonly SDK_VERSION;
|
package/dist/index.esm.js
CHANGED
|
@@ -4,9 +4,8 @@
|
|
|
4
4
|
*/
|
|
5
5
|
class HttpClient {
|
|
6
6
|
constructor(config) {
|
|
7
|
-
this.
|
|
8
|
-
|
|
9
|
-
this.baseUrl = config.baseUrl || 'https://api.caspay.link';
|
|
7
|
+
this.baseUrl = 'https://caspay.link/api';
|
|
8
|
+
this.SDK_VERSION = '1.0.3';
|
|
10
9
|
this.apiKey = config.apiKey;
|
|
11
10
|
this.merchantId = config.merchantId;
|
|
12
11
|
// Validate required config
|
package/dist/index.js
CHANGED
|
@@ -8,9 +8,8 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
8
8
|
*/
|
|
9
9
|
class HttpClient {
|
|
10
10
|
constructor(config) {
|
|
11
|
-
this.
|
|
12
|
-
|
|
13
|
-
this.baseUrl = config.baseUrl || 'https://api.caspay.link';
|
|
11
|
+
this.baseUrl = 'https://caspay.link/api';
|
|
12
|
+
this.SDK_VERSION = '1.0.3';
|
|
14
13
|
this.apiKey = config.apiKey;
|
|
15
14
|
this.merchantId = config.merchantId;
|
|
16
15
|
// Validate required config
|
package/dist/types/index.d.ts
CHANGED
package/package.json
CHANGED