arcpaykit 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.
- package/README.md +188 -0
- package/dist/client.d.ts +6 -0
- package/dist/client.js +25 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +14 -0
- package/dist/payments.d.ts +106 -0
- package/dist/payments.js +60 -0
- package/package.json +22 -0
package/README.md
ADDED
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
# arcpaykit
|
|
2
|
+
|
|
3
|
+
Official ArcPay JavaScript SDK for accepting stablecoin payments.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install arcpaykit
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Quick Start
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
import { ArcPay } from "arcpaykit";
|
|
15
|
+
|
|
16
|
+
const arcpay = new ArcPay("your-api-key");
|
|
17
|
+
|
|
18
|
+
// Create a payment
|
|
19
|
+
const payment = await arcpay.payments.create({
|
|
20
|
+
amount: "100.00",
|
|
21
|
+
currency: "USDC",
|
|
22
|
+
merchantWallet: "0x...",
|
|
23
|
+
description: "Payment for order #123"
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
console.log(payment.checkout_url); // Send this URL to your customer
|
|
27
|
+
|
|
28
|
+
// Retrieve a payment
|
|
29
|
+
const retrieved = await arcpay.payments.retrieve(payment.id);
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## API Reference
|
|
33
|
+
|
|
34
|
+
### ArcPay
|
|
35
|
+
|
|
36
|
+
Main SDK class.
|
|
37
|
+
|
|
38
|
+
#### Constructor
|
|
39
|
+
|
|
40
|
+
```typescript
|
|
41
|
+
new ArcPay(apiKey: string, baseUrl?: string)
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
- `apiKey`: Your ArcPay API key
|
|
45
|
+
- `baseUrl`: Optional base URL (defaults to `https://pay.arcpaykit.com`)
|
|
46
|
+
|
|
47
|
+
### Payments
|
|
48
|
+
|
|
49
|
+
#### `create(data: CreatePaymentRequest): Promise<CreatePaymentResponse>`
|
|
50
|
+
|
|
51
|
+
Create a new payment.
|
|
52
|
+
|
|
53
|
+
**Request:**
|
|
54
|
+
```typescript
|
|
55
|
+
{
|
|
56
|
+
amount: string; // Required: Payment amount
|
|
57
|
+
currency?: string; // Optional: Payment currency (default: "USDC")
|
|
58
|
+
settlementCurrency?: "USDC" | "EURC"; // Optional: Settlement currency (default: "USDC")
|
|
59
|
+
paymentAsset?: string; // Optional: Specific asset identifier
|
|
60
|
+
paymentChainId?: number; // Optional: Chain ID for payment
|
|
61
|
+
conversionPath?: string; // Optional: Conversion path JSON
|
|
62
|
+
estimatedFees?: string; // Optional: Estimated fees
|
|
63
|
+
description?: string; // Optional: Payment description
|
|
64
|
+
customerEmail?: string; // Optional: Customer email
|
|
65
|
+
merchantWallet: string; // Required: Merchant wallet address
|
|
66
|
+
expiresInMinutes?: number; // Optional: Expiration time in minutes
|
|
67
|
+
isTest?: boolean; // Optional: Test mode flag
|
|
68
|
+
gasSponsored?: boolean; // Optional: Gas sponsorship preference
|
|
69
|
+
}
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
**Response:**
|
|
73
|
+
```typescript
|
|
74
|
+
{
|
|
75
|
+
id: string;
|
|
76
|
+
status: string;
|
|
77
|
+
checkout_url: string;
|
|
78
|
+
amount: number;
|
|
79
|
+
currency: string;
|
|
80
|
+
merchantWallet: string;
|
|
81
|
+
expiresAt: string;
|
|
82
|
+
createdAt: string;
|
|
83
|
+
}
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
#### `retrieve(id: string): Promise<Payment>`
|
|
87
|
+
|
|
88
|
+
Retrieve a payment by ID.
|
|
89
|
+
|
|
90
|
+
#### `submitTx(data: ConfirmPaymentRequest): Promise<ConfirmPaymentResponse>`
|
|
91
|
+
|
|
92
|
+
Submit a transaction hash for a payment.
|
|
93
|
+
|
|
94
|
+
**Request:**
|
|
95
|
+
```typescript
|
|
96
|
+
{
|
|
97
|
+
paymentId: string; // Required
|
|
98
|
+
txHash: string; // Required: Transaction hash
|
|
99
|
+
payerWallet: string; // Required: Payer wallet address
|
|
100
|
+
customerEmail?: string; // Optional
|
|
101
|
+
customerName?: string; // Optional
|
|
102
|
+
gasSponsored?: boolean; // Optional
|
|
103
|
+
}
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
#### `confirm(data: ConfirmPaymentRequest): Promise<ConfirmPaymentResponse>`
|
|
107
|
+
|
|
108
|
+
Confirm a payment (legacy endpoint).
|
|
109
|
+
|
|
110
|
+
#### `fail(data: FailPaymentRequest): Promise<FailPaymentResponse>`
|
|
111
|
+
|
|
112
|
+
Mark a payment as failed.
|
|
113
|
+
|
|
114
|
+
**Request:**
|
|
115
|
+
```typescript
|
|
116
|
+
{
|
|
117
|
+
paymentId: string; // Required
|
|
118
|
+
reason?: string; // Optional failure reason
|
|
119
|
+
}
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
#### `expire(data: ExpirePaymentRequest): Promise<ExpirePaymentResponse>`
|
|
123
|
+
|
|
124
|
+
Expire a payment.
|
|
125
|
+
|
|
126
|
+
**Request:**
|
|
127
|
+
```typescript
|
|
128
|
+
{
|
|
129
|
+
paymentId: string; // Required
|
|
130
|
+
}
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
## Examples
|
|
134
|
+
|
|
135
|
+
### Create and Track a Payment
|
|
136
|
+
|
|
137
|
+
```typescript
|
|
138
|
+
import { ArcPay } from "arcpaykit";
|
|
139
|
+
|
|
140
|
+
const arcpay = new ArcPay(process.env.ARCPAY_API_KEY!);
|
|
141
|
+
|
|
142
|
+
// Create payment
|
|
143
|
+
const payment = await arcpay.payments.create({
|
|
144
|
+
amount: "50.00",
|
|
145
|
+
currency: "USDC",
|
|
146
|
+
merchantWallet: "0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb",
|
|
147
|
+
description: "Monthly subscription",
|
|
148
|
+
customerEmail: "customer@example.com",
|
|
149
|
+
expiresInMinutes: 30
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
console.log(`Payment created: ${payment.id}`);
|
|
153
|
+
console.log(`Checkout URL: ${payment.checkout_url}`);
|
|
154
|
+
|
|
155
|
+
// Later, check payment status
|
|
156
|
+
const status = await arcpay.payments.retrieve(payment.id);
|
|
157
|
+
console.log(`Payment status: ${status.status}`);
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
### Using Custom Base URL
|
|
161
|
+
|
|
162
|
+
```typescript
|
|
163
|
+
const arcpay = new ArcPay(
|
|
164
|
+
"your-api-key",
|
|
165
|
+
"https://staging.arcpaykit.com"
|
|
166
|
+
);
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
## Error Handling
|
|
170
|
+
|
|
171
|
+
The SDK throws errors for failed requests:
|
|
172
|
+
|
|
173
|
+
```typescript
|
|
174
|
+
try {
|
|
175
|
+
const payment = await arcpay.payments.create({...});
|
|
176
|
+
} catch (error) {
|
|
177
|
+
console.error("Payment creation failed:", error.message);
|
|
178
|
+
}
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
## REST API
|
|
182
|
+
|
|
183
|
+
The SDK is a thin wrapper around the ArcPay REST API. You can also use the REST API directly if needed. See the [ArcPay API documentation](https://docs.arcpaykit.com) for more details.
|
|
184
|
+
|
|
185
|
+
## License
|
|
186
|
+
|
|
187
|
+
MIT
|
|
188
|
+
|
package/dist/client.d.ts
ADDED
package/dist/client.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ArcPayClient = void 0;
|
|
4
|
+
class ArcPayClient {
|
|
5
|
+
constructor(apiKey, baseUrl = "https://pay.arcpaykit.com") {
|
|
6
|
+
this.apiKey = apiKey;
|
|
7
|
+
this.baseUrl = baseUrl;
|
|
8
|
+
}
|
|
9
|
+
async request(path, options = {}) {
|
|
10
|
+
const res = await fetch(`${this.baseUrl}${path}`, {
|
|
11
|
+
...options,
|
|
12
|
+
headers: {
|
|
13
|
+
"Content-Type": "application/json",
|
|
14
|
+
"Authorization": `Bearer ${this.apiKey}`,
|
|
15
|
+
...(options.headers || {})
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
if (!res.ok) {
|
|
19
|
+
const errorText = await res.text();
|
|
20
|
+
throw new Error(errorText || `HTTP ${res.status}: ${res.statusText}`);
|
|
21
|
+
}
|
|
22
|
+
return res.json();
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
exports.ArcPayClient = ArcPayClient;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Payments } from "./payments";
|
|
2
|
+
export declare class ArcPay {
|
|
3
|
+
payments: Payments;
|
|
4
|
+
constructor(apiKey: string, baseUrl?: string);
|
|
5
|
+
}
|
|
6
|
+
export type { CreatePaymentRequest, CreatePaymentResponse, Payment, ConfirmPaymentRequest, ConfirmPaymentResponse, FailPaymentRequest, FailPaymentResponse, ExpirePaymentRequest, ExpirePaymentResponse, } from "./payments";
|
|
7
|
+
export default ArcPay;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ArcPay = void 0;
|
|
4
|
+
const client_1 = require("./client");
|
|
5
|
+
const payments_1 = require("./payments");
|
|
6
|
+
class ArcPay {
|
|
7
|
+
constructor(apiKey, baseUrl) {
|
|
8
|
+
const client = new client_1.ArcPayClient(apiKey, baseUrl);
|
|
9
|
+
this.payments = new payments_1.Payments(client);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
exports.ArcPay = ArcPay;
|
|
13
|
+
// Default export
|
|
14
|
+
exports.default = ArcPay;
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { ArcPayClient } from "./client";
|
|
2
|
+
export interface CreatePaymentRequest {
|
|
3
|
+
amount: string;
|
|
4
|
+
currency?: string;
|
|
5
|
+
settlementCurrency?: "USDC" | "EURC";
|
|
6
|
+
paymentAsset?: string;
|
|
7
|
+
paymentChainId?: number;
|
|
8
|
+
conversionPath?: string;
|
|
9
|
+
estimatedFees?: string;
|
|
10
|
+
description?: string;
|
|
11
|
+
customerEmail?: string;
|
|
12
|
+
merchantWallet: string;
|
|
13
|
+
expiresInMinutes?: number;
|
|
14
|
+
isTest?: boolean;
|
|
15
|
+
gasSponsored?: boolean;
|
|
16
|
+
}
|
|
17
|
+
export interface CreatePaymentResponse {
|
|
18
|
+
id: string;
|
|
19
|
+
status: string;
|
|
20
|
+
checkout_url: string;
|
|
21
|
+
amount: number;
|
|
22
|
+
currency: string;
|
|
23
|
+
merchantWallet: string;
|
|
24
|
+
expiresAt: string;
|
|
25
|
+
createdAt: string;
|
|
26
|
+
}
|
|
27
|
+
export interface Payment {
|
|
28
|
+
id: string;
|
|
29
|
+
merchantId: string;
|
|
30
|
+
amount: string;
|
|
31
|
+
currency: string;
|
|
32
|
+
settlementCurrency: string;
|
|
33
|
+
paymentAsset?: string;
|
|
34
|
+
paymentChainId?: number;
|
|
35
|
+
conversionPath?: string;
|
|
36
|
+
estimatedFees?: string;
|
|
37
|
+
status: "created" | "pending" | "confirmed" | "failed" | "refunded" | "expired";
|
|
38
|
+
description?: string;
|
|
39
|
+
customerEmail?: string;
|
|
40
|
+
payerWallet?: string;
|
|
41
|
+
merchantWallet: string;
|
|
42
|
+
txHash?: string;
|
|
43
|
+
settlementTime?: number;
|
|
44
|
+
metadata?: string;
|
|
45
|
+
isDemo: boolean;
|
|
46
|
+
isTest: boolean;
|
|
47
|
+
expiresAt?: string;
|
|
48
|
+
createdAt: string;
|
|
49
|
+
updatedAt: string;
|
|
50
|
+
explorerLink?: string;
|
|
51
|
+
}
|
|
52
|
+
export interface ConfirmPaymentRequest {
|
|
53
|
+
paymentId: string;
|
|
54
|
+
txHash: string;
|
|
55
|
+
payerWallet: string;
|
|
56
|
+
customerEmail?: string;
|
|
57
|
+
customerName?: string;
|
|
58
|
+
gasSponsored?: boolean;
|
|
59
|
+
}
|
|
60
|
+
export interface ConfirmPaymentResponse {
|
|
61
|
+
success: boolean;
|
|
62
|
+
payment: Payment | null;
|
|
63
|
+
}
|
|
64
|
+
export interface FailPaymentRequest {
|
|
65
|
+
paymentId: string;
|
|
66
|
+
reason?: string;
|
|
67
|
+
}
|
|
68
|
+
export interface FailPaymentResponse {
|
|
69
|
+
success: boolean;
|
|
70
|
+
payment: Payment;
|
|
71
|
+
}
|
|
72
|
+
export interface ExpirePaymentRequest {
|
|
73
|
+
paymentId: string;
|
|
74
|
+
}
|
|
75
|
+
export interface ExpirePaymentResponse {
|
|
76
|
+
success: boolean;
|
|
77
|
+
payment: Payment;
|
|
78
|
+
}
|
|
79
|
+
export declare class Payments {
|
|
80
|
+
private client;
|
|
81
|
+
constructor(client: ArcPayClient);
|
|
82
|
+
/**
|
|
83
|
+
* Create a new payment
|
|
84
|
+
*/
|
|
85
|
+
create(data: CreatePaymentRequest): Promise<CreatePaymentResponse>;
|
|
86
|
+
/**
|
|
87
|
+
* Retrieve a payment by ID
|
|
88
|
+
*/
|
|
89
|
+
retrieve(id: string): Promise<Payment>;
|
|
90
|
+
/**
|
|
91
|
+
* Submit a transaction hash for a payment
|
|
92
|
+
*/
|
|
93
|
+
submitTx(data: ConfirmPaymentRequest): Promise<ConfirmPaymentResponse>;
|
|
94
|
+
/**
|
|
95
|
+
* Confirm a payment (legacy endpoint)
|
|
96
|
+
*/
|
|
97
|
+
confirm(data: ConfirmPaymentRequest): Promise<ConfirmPaymentResponse>;
|
|
98
|
+
/**
|
|
99
|
+
* Mark a payment as failed
|
|
100
|
+
*/
|
|
101
|
+
fail(data: FailPaymentRequest): Promise<FailPaymentResponse>;
|
|
102
|
+
/**
|
|
103
|
+
* Expire a payment
|
|
104
|
+
*/
|
|
105
|
+
expire(data: ExpirePaymentRequest): Promise<ExpirePaymentResponse>;
|
|
106
|
+
}
|
package/dist/payments.js
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Payments = void 0;
|
|
4
|
+
class Payments {
|
|
5
|
+
constructor(client) {
|
|
6
|
+
this.client = client;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Create a new payment
|
|
10
|
+
*/
|
|
11
|
+
create(data) {
|
|
12
|
+
return this.client.request("/api/payments/create", {
|
|
13
|
+
method: "POST",
|
|
14
|
+
body: JSON.stringify(data)
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Retrieve a payment by ID
|
|
19
|
+
*/
|
|
20
|
+
retrieve(id) {
|
|
21
|
+
return this.client.request(`/api/payments/${id}`);
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Submit a transaction hash for a payment
|
|
25
|
+
*/
|
|
26
|
+
submitTx(data) {
|
|
27
|
+
return this.client.request("/api/payments/submit-tx", {
|
|
28
|
+
method: "POST",
|
|
29
|
+
body: JSON.stringify(data)
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Confirm a payment (legacy endpoint)
|
|
34
|
+
*/
|
|
35
|
+
confirm(data) {
|
|
36
|
+
return this.client.request("/api/payments/confirm", {
|
|
37
|
+
method: "POST",
|
|
38
|
+
body: JSON.stringify(data)
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Mark a payment as failed
|
|
43
|
+
*/
|
|
44
|
+
fail(data) {
|
|
45
|
+
return this.client.request("/api/payments/fail", {
|
|
46
|
+
method: "POST",
|
|
47
|
+
body: JSON.stringify(data)
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Expire a payment
|
|
52
|
+
*/
|
|
53
|
+
expire(data) {
|
|
54
|
+
return this.client.request("/api/payments/expire", {
|
|
55
|
+
method: "POST",
|
|
56
|
+
body: JSON.stringify(data)
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
exports.Payments = Payments;
|
package/package.json
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "arcpaykit",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Official ArcPay JavaScript SDK",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"files": ["dist"],
|
|
8
|
+
"license": "MIT",
|
|
9
|
+
"keywords": ["payments", "web3", "stablecoin", "arcpay"],
|
|
10
|
+
"scripts": {
|
|
11
|
+
"build": "tsc",
|
|
12
|
+
"prepublishOnly": "npm run build"
|
|
13
|
+
},
|
|
14
|
+
"devDependencies": {
|
|
15
|
+
"typescript": "^5.0.0"
|
|
16
|
+
},
|
|
17
|
+
"repository": {
|
|
18
|
+
"type": "git",
|
|
19
|
+
"url": "https://github.com/arcpay/gateway.git"
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|