@sphoq/payments 0.1.1 → 0.2.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 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
@@ -26,10 +26,49 @@ export interface SphoqPaymentsOptions {
26
26
  baseUrl?: string;
27
27
  }
28
28
  /**
29
- * Options for creating a new PIX charge.
29
+ * A line item included in a charge.
30
+ *
31
+ * When `items` are provided, the sum of `quantity * unitPrice` for all items
32
+ * **must** equal the charge `amount`. The API will reject the request otherwise.
30
33
  *
31
34
  * @example
32
35
  * ```ts
36
+ * const items: ChargeItem[] = [
37
+ * { name: "Premium Sword", quantity: 2, unitPrice: 29.90 },
38
+ * { name: "Health Potion", quantity: 1, unitPrice: 10.00, externalId: "sku_hp_01" },
39
+ * ];
40
+ * // Total: (2 * 29.90) + (1 * 10.00) = 69.80
41
+ * const charge = await sphoq.charges.create({
42
+ * amount: 69.80,
43
+ * description: "3 items from GameStore",
44
+ * items,
45
+ * });
46
+ * ```
47
+ */
48
+ export interface ChargeItem {
49
+ /** Product or item name. */
50
+ name: string;
51
+ /** Quantity purchased. Must be a positive integer. */
52
+ quantity: number;
53
+ /** Price per unit in BRL. Must be greater than 0. */
54
+ unitPrice: number;
55
+ /** Optional item description or variant info. */
56
+ description?: string;
57
+ /**
58
+ * Your own identifier for this product (SKU, product ID, etc.).
59
+ * Useful for reconciling items with your catalog.
60
+ *
61
+ * @example "sku_sword_01"
62
+ */
63
+ externalId?: string;
64
+ /** URL to an image of the product. */
65
+ imageUrl?: string;
66
+ }
67
+ /**
68
+ * Options for creating a new PIX charge.
69
+ *
70
+ * @example Simple charge
71
+ * ```ts
33
72
  * const charge = await sphoq.charges.create({
34
73
  * amount: 49.90,
35
74
  * description: "Premium Plan - Monthly",
@@ -43,6 +82,18 @@ export interface SphoqPaymentsOptions {
43
82
  * metadata: { planId: "premium", userId: "usr_abc" },
44
83
  * });
45
84
  * ```
85
+ *
86
+ * @example Charge with itemized products
87
+ * ```ts
88
+ * const charge = await sphoq.charges.create({
89
+ * amount: 69.80, // Must equal sum of items: (2 * 29.90) + (1 * 10.00)
90
+ * description: "3 items from GameStore",
91
+ * items: [
92
+ * { name: "Premium Sword", quantity: 2, unitPrice: 29.90, externalId: "sku_sword" },
93
+ * { name: "Health Potion", quantity: 1, unitPrice: 10.00, externalId: "sku_hp" },
94
+ * ],
95
+ * });
96
+ * ```
46
97
  */
47
98
  export interface CreateChargeOptions {
48
99
  /**
@@ -76,6 +127,27 @@ export interface CreateChargeOptions {
76
127
  * @default 3600 (1 hour)
77
128
  */
78
129
  expirationSeconds?: number;
130
+ /**
131
+ * Line items included in this charge.
132
+ *
133
+ * When provided, the sum of `quantity * unitPrice` across all items **must**
134
+ * exactly equal the `amount` field (within R$ 0.01 tolerance). The API rejects
135
+ * the request if the totals don't match.
136
+ *
137
+ * Items are stored with the charge and included in webhook payloads,
138
+ * making them available for order fulfillment and reconciliation.
139
+ *
140
+ * Maximum 100 items per charge.
141
+ *
142
+ * @example
143
+ * ```ts
144
+ * items: [
145
+ * { name: "Gamepass: VIP", quantity: 1, unitPrice: 19.90, externalId: "gp_vip" },
146
+ * { name: "Robux 1000", quantity: 2, unitPrice: 15.00 },
147
+ * ]
148
+ * ```
149
+ */
150
+ items?: ChargeItem[];
79
151
  /**
80
152
  * Arbitrary key-value data attached to the charge.
81
153
  * Returned in webhook payloads and charge queries.
@@ -156,6 +228,11 @@ export interface Charge {
156
228
  * Can be used for reconciliation with bank statements.
157
229
  */
158
230
  endToEndId?: string;
231
+ /**
232
+ * Line items included in the charge, if provided at creation.
233
+ * Returned as-is from the API. Useful for order fulfillment.
234
+ */
235
+ items?: ChargeItem[];
159
236
  /**
160
237
  * Arbitrary metadata attached when the charge was created.
161
238
  * Returned as-is from the API.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sphoq/payments",
3
- "version": "0.1.1",
3
+ "version": "0.2.0",
4
4
  "description": "Sphoq Payments SDK — integrate PIX payment processing into your app",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",