@sphoq/payments 0.1.1 → 0.3.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/dist/client.js +2 -0
- package/dist/index.d.ts +1 -1
- package/dist/types.d.ts +101 -4
- package/package.json +1 -1
package/dist/client.js
CHANGED
|
@@ -228,6 +228,8 @@ class ChargesClient {
|
|
|
228
228
|
body.customer = options.customer;
|
|
229
229
|
if (options.expirationSeconds)
|
|
230
230
|
body.expirationSeconds = options.expirationSeconds;
|
|
231
|
+
if (options.items)
|
|
232
|
+
body.items = options.items;
|
|
231
233
|
if (options.metadata)
|
|
232
234
|
body.metadata = options.metadata;
|
|
233
235
|
return this.request("/v1/charges", body);
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export { SphoqPayments } from "./client.js";
|
|
2
2
|
export { SphoqApiError } from "./types.js";
|
|
3
|
-
export type { SphoqPaymentsOptions, CreateChargeOptions, Charge, GetChargeOptions, CancelChargeOptions, CancelChargeResult, WebhookPayload, VerifyWebhookOptions, } from "./types.js";
|
|
3
|
+
export type { SphoqPaymentsOptions, ChargeItem, CreateChargeOptions, Charge, GetChargeOptions, CancelChargeOptions, CancelChargeResult, WebhookPayload, VerifyWebhookOptions, } from "./types.js";
|
package/dist/types.d.ts
CHANGED
|
@@ -1,20 +1,34 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Configuration options for the {@link SphoqPayments} client.
|
|
3
3
|
*
|
|
4
|
+
* The API key prefix determines the environment:
|
|
5
|
+
* - `spq_live_*` — Production (real PIX charges)
|
|
6
|
+
* - `spq_test_*` — Development/Sandbox (EfiBank sandbox, no real money)
|
|
7
|
+
*
|
|
4
8
|
* @example
|
|
5
9
|
* ```ts
|
|
6
10
|
* import { SphoqPayments } from "@sphoq/payments";
|
|
7
11
|
*
|
|
12
|
+
* // Production
|
|
8
13
|
* const sphoq = new SphoqPayments({
|
|
9
|
-
* apiKey: "
|
|
14
|
+
* apiKey: "spq_live_abc123...",
|
|
15
|
+
* baseUrl: "https://your-deployment.convex.site",
|
|
16
|
+
* });
|
|
17
|
+
*
|
|
18
|
+
* // Sandbox / Testing
|
|
19
|
+
* const sphoqTest = new SphoqPayments({
|
|
20
|
+
* apiKey: "spq_test_abc123...",
|
|
10
21
|
* baseUrl: "https://your-deployment.convex.site",
|
|
11
22
|
* });
|
|
12
23
|
* ```
|
|
13
24
|
*/
|
|
14
25
|
export interface SphoqPaymentsOptions {
|
|
15
26
|
/**
|
|
16
|
-
* Your Sphoq API key.
|
|
17
|
-
*
|
|
27
|
+
* Your Sphoq API key.
|
|
28
|
+
* - `spq_live_*` keys target the **production** EfiBank environment (real charges).
|
|
29
|
+
* - `spq_test_*` keys target the **sandbox** EfiBank environment (test charges).
|
|
30
|
+
*
|
|
31
|
+
* Generate keys from the Plugin page in your Sphoq store dashboard.
|
|
18
32
|
*/
|
|
19
33
|
apiKey: string;
|
|
20
34
|
/**
|
|
@@ -26,10 +40,49 @@ export interface SphoqPaymentsOptions {
|
|
|
26
40
|
baseUrl?: string;
|
|
27
41
|
}
|
|
28
42
|
/**
|
|
29
|
-
*
|
|
43
|
+
* A line item included in a charge.
|
|
44
|
+
*
|
|
45
|
+
* When `items` are provided, the sum of `quantity * unitPrice` for all items
|
|
46
|
+
* **must** equal the charge `amount`. The API will reject the request otherwise.
|
|
30
47
|
*
|
|
31
48
|
* @example
|
|
32
49
|
* ```ts
|
|
50
|
+
* const items: ChargeItem[] = [
|
|
51
|
+
* { name: "Premium Sword", quantity: 2, unitPrice: 29.90 },
|
|
52
|
+
* { name: "Health Potion", quantity: 1, unitPrice: 10.00, externalId: "sku_hp_01" },
|
|
53
|
+
* ];
|
|
54
|
+
* // Total: (2 * 29.90) + (1 * 10.00) = 69.80
|
|
55
|
+
* const charge = await sphoq.charges.create({
|
|
56
|
+
* amount: 69.80,
|
|
57
|
+
* description: "3 items from GameStore",
|
|
58
|
+
* items,
|
|
59
|
+
* });
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
62
|
+
export interface ChargeItem {
|
|
63
|
+
/** Product or item name. */
|
|
64
|
+
name: string;
|
|
65
|
+
/** Quantity purchased. Must be a positive integer. */
|
|
66
|
+
quantity: number;
|
|
67
|
+
/** Price per unit in BRL. Must be greater than 0. */
|
|
68
|
+
unitPrice: number;
|
|
69
|
+
/** Optional item description or variant info. */
|
|
70
|
+
description?: string;
|
|
71
|
+
/**
|
|
72
|
+
* Your own identifier for this product (SKU, product ID, etc.).
|
|
73
|
+
* Useful for reconciling items with your catalog.
|
|
74
|
+
*
|
|
75
|
+
* @example "sku_sword_01"
|
|
76
|
+
*/
|
|
77
|
+
externalId?: string;
|
|
78
|
+
/** URL to an image of the product. */
|
|
79
|
+
imageUrl?: string;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Options for creating a new PIX charge.
|
|
83
|
+
*
|
|
84
|
+
* @example Simple charge
|
|
85
|
+
* ```ts
|
|
33
86
|
* const charge = await sphoq.charges.create({
|
|
34
87
|
* amount: 49.90,
|
|
35
88
|
* description: "Premium Plan - Monthly",
|
|
@@ -43,6 +96,18 @@ export interface SphoqPaymentsOptions {
|
|
|
43
96
|
* metadata: { planId: "premium", userId: "usr_abc" },
|
|
44
97
|
* });
|
|
45
98
|
* ```
|
|
99
|
+
*
|
|
100
|
+
* @example Charge with itemized products
|
|
101
|
+
* ```ts
|
|
102
|
+
* const charge = await sphoq.charges.create({
|
|
103
|
+
* amount: 69.80, // Must equal sum of items: (2 * 29.90) + (1 * 10.00)
|
|
104
|
+
* description: "3 items from GameStore",
|
|
105
|
+
* items: [
|
|
106
|
+
* { name: "Premium Sword", quantity: 2, unitPrice: 29.90, externalId: "sku_sword" },
|
|
107
|
+
* { name: "Health Potion", quantity: 1, unitPrice: 10.00, externalId: "sku_hp" },
|
|
108
|
+
* ],
|
|
109
|
+
* });
|
|
110
|
+
* ```
|
|
46
111
|
*/
|
|
47
112
|
export interface CreateChargeOptions {
|
|
48
113
|
/**
|
|
@@ -76,6 +141,27 @@ export interface CreateChargeOptions {
|
|
|
76
141
|
* @default 3600 (1 hour)
|
|
77
142
|
*/
|
|
78
143
|
expirationSeconds?: number;
|
|
144
|
+
/**
|
|
145
|
+
* Line items included in this charge.
|
|
146
|
+
*
|
|
147
|
+
* When provided, the sum of `quantity * unitPrice` across all items **must**
|
|
148
|
+
* exactly equal the `amount` field (within R$ 0.01 tolerance). The API rejects
|
|
149
|
+
* the request if the totals don't match.
|
|
150
|
+
*
|
|
151
|
+
* Items are stored with the charge and included in webhook payloads,
|
|
152
|
+
* making them available for order fulfillment and reconciliation.
|
|
153
|
+
*
|
|
154
|
+
* Maximum 100 items per charge.
|
|
155
|
+
*
|
|
156
|
+
* @example
|
|
157
|
+
* ```ts
|
|
158
|
+
* items: [
|
|
159
|
+
* { name: "Gamepass: VIP", quantity: 1, unitPrice: 19.90, externalId: "gp_vip" },
|
|
160
|
+
* { name: "Robux 1000", quantity: 2, unitPrice: 15.00 },
|
|
161
|
+
* ]
|
|
162
|
+
* ```
|
|
163
|
+
*/
|
|
164
|
+
items?: ChargeItem[];
|
|
79
165
|
/**
|
|
80
166
|
* Arbitrary key-value data attached to the charge.
|
|
81
167
|
* Returned in webhook payloads and charge queries.
|
|
@@ -156,11 +242,22 @@ export interface Charge {
|
|
|
156
242
|
* Can be used for reconciliation with bank statements.
|
|
157
243
|
*/
|
|
158
244
|
endToEndId?: string;
|
|
245
|
+
/**
|
|
246
|
+
* Line items included in the charge, if provided at creation.
|
|
247
|
+
* Returned as-is from the API. Useful for order fulfillment.
|
|
248
|
+
*/
|
|
249
|
+
items?: ChargeItem[];
|
|
159
250
|
/**
|
|
160
251
|
* Arbitrary metadata attached when the charge was created.
|
|
161
252
|
* Returned as-is from the API.
|
|
162
253
|
*/
|
|
163
254
|
metadata?: Record<string, unknown>;
|
|
255
|
+
/**
|
|
256
|
+
* The environment this charge was created in.
|
|
257
|
+
* - `"production"` — Real PIX charge.
|
|
258
|
+
* - `"development"` — EfiBank sandbox charge (no real money).
|
|
259
|
+
*/
|
|
260
|
+
environment?: "production" | "development";
|
|
164
261
|
/** Unix timestamp (milliseconds) when the charge was created. */
|
|
165
262
|
createdAt: number;
|
|
166
263
|
/** Unix timestamp (milliseconds) when the PIX QR code expires. */
|