@sphoq/payments 0.3.0 → 0.5.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.d.ts CHANGED
@@ -2,7 +2,7 @@ import type { SphoqPaymentsOptions, CreateChargeOptions, Charge, GetChargeOption
2
2
  /**
3
3
  * Sphoq Payments SDK client.
4
4
  *
5
- * Provides methods for creating and managing PIX charges, and verifying webhook signatures.
5
+ * Provides methods for creating and managing charges, and verifying webhook signatures.
6
6
  * Zero dependencies — uses native `fetch` and Web Crypto API.
7
7
  *
8
8
  * @example Basic setup
@@ -15,20 +15,20 @@ import type { SphoqPaymentsOptions, CreateChargeOptions, Charge, GetChargeOption
15
15
  * });
16
16
  * ```
17
17
  *
18
- * @example Create a PIX charge and display QR code
18
+ * @example Create a charge and display checkout image
19
19
  * ```ts
20
20
  * const charge = await sphoq.charges.create({
21
21
  * amount: 49.90,
22
22
  * description: "Premium Plan",
23
23
  * externalId: "order_123",
24
- * customer: { name: "João Silva", cpf: "12345678900" },
24
+ * customer: { name: "João Silva", taxId: "12345678900" },
25
25
  * });
26
26
  *
27
- * // Show QR code to user (base64 PNG)
28
- * document.getElementById("qr").src = `data:image/png;base64,${charge.qrCode}`;
27
+ * // Show checkout image to user (base64 PNG)
28
+ * document.getElementById("qr").src = `data:image/png;base64,${charge.checkoutImage}`;
29
29
  *
30
- * // Or show the copy-paste PIX string
31
- * console.log(charge.pixCopiaECola);
30
+ * // Or show the copy-paste payment code
31
+ * console.log(charge.paymentCode);
32
32
  * ```
33
33
  *
34
34
  * @example Convex integration — reactive payment status
@@ -72,7 +72,7 @@ export declare class SphoqPayments {
72
72
  private readonly apiKey;
73
73
  private readonly baseUrl;
74
74
  /**
75
- * Client for creating, querying, and cancelling PIX charges.
75
+ * Client for creating, querying, and cancelling charges.
76
76
  *
77
77
  * @example
78
78
  * ```ts
@@ -155,14 +155,14 @@ declare class ChargesClient {
155
155
  private readonly baseUrl;
156
156
  constructor(apiKey: string, baseUrl: string);
157
157
  /**
158
- * Create a new PIX charge.
158
+ * Create a new charge.
159
159
  *
160
- * Generates a PIX QR code and copy-paste string that the customer can use to pay.
160
+ * Generates a payment code and checkout image that the customer can use to pay.
161
161
  * The charge starts with `status: "pending"` and transitions to `"paid"` when
162
162
  * the customer completes the payment.
163
163
  *
164
164
  * @param options - Charge details (amount, description, customer info, etc.).
165
- * @returns The created charge with QR code data.
165
+ * @returns The created charge with payment data.
166
166
  * @throws {@link SphoqApiError} if the API returns an error (invalid params, rate limit, etc.).
167
167
  *
168
168
  * @example Simple charge
@@ -171,7 +171,7 @@ declare class ChargesClient {
171
171
  * amount: 29.90,
172
172
  * description: "Monthly subscription",
173
173
  * });
174
- * console.log(charge.pixCopiaECola); // PIX copy-paste string
174
+ * console.log(charge.paymentCode); // Copy-paste payment string
175
175
  * ```
176
176
  *
177
177
  * @example Full options
@@ -183,7 +183,7 @@ declare class ChargesClient {
183
183
  * customer: {
184
184
  * name: "Maria Santos",
185
185
  * email: "maria@example.com",
186
- * cpf: "12345678900",
186
+ * taxId: "12345678900",
187
187
  * },
188
188
  * expirationSeconds: 1800, // 30 minutes
189
189
  * metadata: { planId: "annual", coupon: "SAVE20" },
@@ -213,10 +213,10 @@ declare class ChargesClient {
213
213
  */
214
214
  get(options: GetChargeOptions): Promise<Charge>;
215
215
  /**
216
- * Cancel a pending PIX charge.
216
+ * Cancel a pending charge.
217
217
  *
218
218
  * Only charges with `status: "pending"` can be cancelled.
219
- * After cancellation, the QR code is invalidated and the charge
219
+ * After cancellation, the payment code is invalidated and the charge
220
220
  * cannot be paid.
221
221
  *
222
222
  * @param options - The charge ID to cancel.
package/dist/client.js CHANGED
@@ -3,7 +3,7 @@ const DEFAULT_BASE_URL = "https://your-convex-deployment.convex.site";
3
3
  /**
4
4
  * Sphoq Payments SDK client.
5
5
  *
6
- * Provides methods for creating and managing PIX charges, and verifying webhook signatures.
6
+ * Provides methods for creating and managing charges, and verifying webhook signatures.
7
7
  * Zero dependencies — uses native `fetch` and Web Crypto API.
8
8
  *
9
9
  * @example Basic setup
@@ -16,20 +16,20 @@ const DEFAULT_BASE_URL = "https://your-convex-deployment.convex.site";
16
16
  * });
17
17
  * ```
18
18
  *
19
- * @example Create a PIX charge and display QR code
19
+ * @example Create a charge and display checkout image
20
20
  * ```ts
21
21
  * const charge = await sphoq.charges.create({
22
22
  * amount: 49.90,
23
23
  * description: "Premium Plan",
24
24
  * externalId: "order_123",
25
- * customer: { name: "João Silva", cpf: "12345678900" },
25
+ * customer: { name: "João Silva", taxId: "12345678900" },
26
26
  * });
27
27
  *
28
- * // Show QR code to user (base64 PNG)
29
- * document.getElementById("qr").src = `data:image/png;base64,${charge.qrCode}`;
28
+ * // Show checkout image to user (base64 PNG)
29
+ * document.getElementById("qr").src = `data:image/png;base64,${charge.checkoutImage}`;
30
30
  *
31
- * // Or show the copy-paste PIX string
32
- * console.log(charge.pixCopiaECola);
31
+ * // Or show the copy-paste payment code
32
+ * console.log(charge.paymentCode);
33
33
  * ```
34
34
  *
35
35
  * @example Convex integration — reactive payment status
@@ -73,7 +73,7 @@ export class SphoqPayments {
73
73
  apiKey;
74
74
  baseUrl;
75
75
  /**
76
- * Client for creating, querying, and cancelling PIX charges.
76
+ * Client for creating, querying, and cancelling charges.
77
77
  *
78
78
  * @example
79
79
  * ```ts
@@ -182,14 +182,14 @@ class ChargesClient {
182
182
  this.baseUrl = baseUrl;
183
183
  }
184
184
  /**
185
- * Create a new PIX charge.
185
+ * Create a new charge.
186
186
  *
187
- * Generates a PIX QR code and copy-paste string that the customer can use to pay.
187
+ * Generates a payment code and checkout image that the customer can use to pay.
188
188
  * The charge starts with `status: "pending"` and transitions to `"paid"` when
189
189
  * the customer completes the payment.
190
190
  *
191
191
  * @param options - Charge details (amount, description, customer info, etc.).
192
- * @returns The created charge with QR code data.
192
+ * @returns The created charge with payment data.
193
193
  * @throws {@link SphoqApiError} if the API returns an error (invalid params, rate limit, etc.).
194
194
  *
195
195
  * @example Simple charge
@@ -198,7 +198,7 @@ class ChargesClient {
198
198
  * amount: 29.90,
199
199
  * description: "Monthly subscription",
200
200
  * });
201
- * console.log(charge.pixCopiaECola); // PIX copy-paste string
201
+ * console.log(charge.paymentCode); // Copy-paste payment string
202
202
  * ```
203
203
  *
204
204
  * @example Full options
@@ -210,7 +210,7 @@ class ChargesClient {
210
210
  * customer: {
211
211
  * name: "Maria Santos",
212
212
  * email: "maria@example.com",
213
- * cpf: "12345678900",
213
+ * taxId: "12345678900",
214
214
  * },
215
215
  * expirationSeconds: 1800, // 30 minutes
216
216
  * metadata: { planId: "annual", coupon: "SAVE20" },
@@ -266,10 +266,10 @@ class ChargesClient {
266
266
  return this.request("/v1/charges/get", body);
267
267
  }
268
268
  /**
269
- * Cancel a pending PIX charge.
269
+ * Cancel a pending charge.
270
270
  *
271
271
  * Only charges with `status: "pending"` can be cancelled.
272
- * After cancellation, the QR code is invalidated and the charge
272
+ * After cancellation, the payment code is invalidated and the charge
273
273
  * cannot be paid.
274
274
  *
275
275
  * @param options - The charge ID to cancel.
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, ChargeItem, CreateChargeOptions, Charge, GetChargeOptions, CancelChargeOptions, CancelChargeResult, WebhookPayload, VerifyWebhookOptions, } from "./types.js";
3
+ export type { SphoqPaymentsOptions, ChargeItem, ChargeFee, CreateChargeOptions, Charge, GetChargeOptions, CancelChargeOptions, CancelChargeResult, WebhookPayload, VerifyWebhookOptions, } from "./types.js";
package/dist/types.d.ts CHANGED
@@ -79,7 +79,7 @@ export interface ChargeItem {
79
79
  imageUrl?: string;
80
80
  }
81
81
  /**
82
- * Options for creating a new PIX charge.
82
+ * Options for creating a new charge.
83
83
  *
84
84
  * @example Simple charge
85
85
  * ```ts
@@ -90,7 +90,7 @@ export interface ChargeItem {
90
90
  * customer: {
91
91
  * name: "João Silva",
92
92
  * email: "joao@example.com",
93
- * cpf: "12345678900",
93
+ * taxId: "12345678900",
94
94
  * },
95
95
  * expirationSeconds: 3600, // 1 hour
96
96
  * metadata: { planId: "premium", userId: "usr_abc" },
@@ -111,8 +111,8 @@ export interface ChargeItem {
111
111
  */
112
112
  export interface CreateChargeOptions {
113
113
  /**
114
- * Charge amount in BRL (Brazilian Real).
115
- * Must be greater than 0. Use decimal notation (e.g., `29.90` for R$ 29,90).
114
+ * Charge amount. Must be greater than 0.
115
+ * Use decimal notation (e.g., `29.90`).
116
116
  */
117
117
  amount: number;
118
118
  /** Human-readable description shown to the customer. */
@@ -131,12 +131,19 @@ export interface CreateChargeOptions {
131
131
  name?: string;
132
132
  /** Customer's email address. */
133
133
  email?: string;
134
- /** Customer's CPF (Brazilian tax ID, 11 digits, no formatting). */
135
- cpf?: string;
134
+ /** Customer's tax ID (e.g., CPF in Brazil, 11 digits, no formatting). */
135
+ taxId?: string;
136
+ /**
137
+ * Your own identifier for this customer.
138
+ * Useful for mapping charges to users in your system.
139
+ *
140
+ * @example "usr_abc123"
141
+ */
142
+ externalId?: string;
136
143
  };
137
144
  /**
138
- * Time in seconds until the PIX charge expires.
139
- * After expiration, the QR code can no longer be paid.
145
+ * Time in seconds until the charge expires.
146
+ * After expiration, the payment code can no longer be used.
140
147
  *
141
148
  * @default 3600 (1 hour)
142
149
  */
@@ -145,7 +152,7 @@ export interface CreateChargeOptions {
145
152
  * Line items included in this charge.
146
153
  *
147
154
  * 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
155
+ * exactly equal the `amount` field (within 0.01 tolerance). The API rejects
149
156
  * the request if the totals don't match.
150
157
  *
151
158
  * Items are stored with the charge and included in webhook payloads,
@@ -172,7 +179,36 @@ export interface CreateChargeOptions {
172
179
  metadata?: Record<string, unknown>;
173
180
  }
174
181
  /**
175
- * A PIX charge object returned by the Sphoq API.
182
+ * A fee applied to a charge.
183
+ *
184
+ * Fees are calculated at charge creation and included in every charge response
185
+ * and webhook payload.
186
+ *
187
+ * @example
188
+ * ```ts
189
+ * const charge = await sphoq.charges.create({ amount: 100, description: "Test" });
190
+ * for (const fee of charge.fees) {
191
+ * console.log(`${fee.type} (${fee.provider}): ${fee.rate}% = R$ ${fee.amount}`);
192
+ * }
193
+ * console.log(`Net amount: R$ ${charge.netAmount}`);
194
+ * ```
195
+ */
196
+ export interface ChargeFee {
197
+ /**
198
+ * The category of this fee.
199
+ * - `"platform"` — Sphoq platform fee
200
+ * - `"processor"` — Payment processor fee (e.g., EfiBank PIX)
201
+ */
202
+ type: "platform" | "processor";
203
+ /** Who charges this fee (e.g., `"sphoq"`, `"efibank"`). */
204
+ provider: string;
205
+ /** Fee percentage (e.g., `5` for 5%). */
206
+ rate: number;
207
+ /** Calculated fee amount in BRL. */
208
+ amount: number;
209
+ }
210
+ /**
211
+ * A charge object returned by the Sphoq API.
176
212
  *
177
213
  * @example
178
214
  * ```ts
@@ -181,16 +217,16 @@ export interface CreateChargeOptions {
181
217
  * description: "Monthly subscription",
182
218
  * });
183
219
  *
184
- * // Display QR code to user
185
- * console.log(charge.qrCode); // Base64-encoded QR code image
186
- * console.log(charge.pixCopiaECola); // PIX copy-paste string
220
+ * // Display checkout image to user
221
+ * console.log(charge.checkoutImage); // Base64-encoded checkout image (QR code, barcode, etc.)
222
+ * console.log(charge.paymentCode); // Copy-paste payment string
187
223
  * console.log(charge.status); // "pending"
188
224
  *
189
225
  * // After payment, query the charge
190
226
  * const paid = await sphoq.charges.get({ id: charge.id });
191
- * console.log(paid.status); // "paid"
192
- * console.log(paid.paidAt); // Unix timestamp in ms
193
- * console.log(paid.endToEndId); // Central Bank end-to-end ID
227
+ * console.log(paid.status); // "paid"
228
+ * console.log(paid.paidAt); // Unix timestamp in ms
229
+ * console.log(paid.providerPaymentId); // Provider's payment confirmation ID
194
230
  * ```
195
231
  */
196
232
  export interface Charge {
@@ -198,50 +234,54 @@ export interface Charge {
198
234
  id: string;
199
235
  /** Your external ID, if provided when creating the charge. */
200
236
  externalId?: string;
201
- /** Charge amount in BRL. */
237
+ /** Charge amount. */
202
238
  amount: number;
203
- /**
204
- * Currency code. Always `"BRL"` (Brazilian Real).
205
- */
239
+ /** Currency code (e.g., `"BRL"`, `"USD"`). */
206
240
  currency: string;
207
241
  /** Human-readable description of the charge. */
208
242
  description: string;
209
243
  /**
210
244
  * Current status of the charge.
211
245
  *
212
- * - `"pending"` — Awaiting payment. QR code is active.
213
- * - `"paid"` — Payment confirmed by the bank.
214
- * - `"expired"` — QR code expired before payment.
246
+ * - `"pending"` — Awaiting payment.
247
+ * - `"paid"` — Payment confirmed by the provider.
248
+ * - `"expired"` — Charge expired before payment.
215
249
  * - `"cancelled"` — Charge was cancelled via the API.
216
250
  */
217
251
  status: "pending" | "paid" | "expired" | "cancelled";
218
- /** PIX transaction ID (txid). Unique identifier in the Brazilian PIX system. */
219
- txid: string;
252
+ /** Provider's charge identifier (e.g., PIX txid, Stripe charge_id). */
253
+ providerChargeId: string;
254
+ /** Payment method used (e.g., `"pix"`). */
255
+ paymentMethod: string;
256
+ /** Payment provider (e.g., `"efibank"`). */
257
+ provider: string;
220
258
  /**
221
- * PIX "copia e cola" (copy-paste) string.
222
- * The customer can paste this into their banking app to pay.
259
+ * Copy-paste payment string for the customer
260
+ * (e.g., PIX copia-e-cola, Boleto barcode digits).
223
261
  */
224
- pixCopiaECola?: string;
262
+ paymentCode?: string;
225
263
  /**
226
- * Base64-encoded PNG image of the PIX QR code.
227
- * Display this to the customer for scanning.
264
+ * Base64-encoded checkout image (e.g., QR code, barcode).
265
+ * Display this to the customer.
228
266
  */
229
- qrCode?: string;
267
+ checkoutImage?: string;
230
268
  /** Customer name, if provided. */
231
269
  customerName?: string;
232
270
  /** Customer email, if provided. */
233
271
  customerEmail?: string;
272
+ /** Your own customer identifier, if provided. */
273
+ customerExternalId?: string;
234
274
  /**
235
275
  * Unix timestamp (milliseconds) when the payment was confirmed.
236
276
  * Only present when `status` is `"paid"`.
237
277
  */
238
278
  paidAt?: number;
239
279
  /**
240
- * Central Bank end-to-end ID for the PIX transaction.
280
+ * Provider's payment confirmation ID.
241
281
  * Only present when `status` is `"paid"`.
242
- * Can be used for reconciliation with bank statements.
282
+ * Can be used for reconciliation with bank/provider statements.
243
283
  */
244
- endToEndId?: string;
284
+ providerPaymentId?: string;
245
285
  /**
246
286
  * Line items included in the charge, if provided at creation.
247
287
  * Returned as-is from the API. Useful for order fulfillment.
@@ -252,15 +292,30 @@ export interface Charge {
252
292
  * Returned as-is from the API.
253
293
  */
254
294
  metadata?: Record<string, unknown>;
295
+ /**
296
+ * Fees applied to this charge.
297
+ * Calculated at creation time based on the store's tax settings.
298
+ */
299
+ fees: ChargeFee[];
300
+ /**
301
+ * Sum of all fee amounts.
302
+ * Equal to `fees.reduce((sum, f) => sum + f.amount, 0)`.
303
+ */
304
+ totalFees: number;
305
+ /**
306
+ * Amount after fees.
307
+ * Equal to `amount - totalFees`.
308
+ */
309
+ netAmount: number;
255
310
  /**
256
311
  * The environment this charge was created in.
257
- * - `"production"` — Real PIX charge.
258
- * - `"development"` — EfiBank sandbox charge (no real money).
312
+ * - `"production"` — Real charge.
313
+ * - `"development"` — Sandbox charge (no real money).
259
314
  */
260
315
  environment?: "production" | "development";
261
316
  /** Unix timestamp (milliseconds) when the charge was created. */
262
317
  createdAt: number;
263
- /** Unix timestamp (milliseconds) when the PIX QR code expires. */
318
+ /** Unix timestamp (milliseconds) when the charge expires. */
264
319
  expiresAt: number;
265
320
  }
266
321
  /**
@@ -347,8 +402,8 @@ export interface WebhookPayload {
347
402
  /**
348
403
  * The event type.
349
404
  *
350
- * - `"charge.paid"` — Customer completed the PIX payment.
351
- * - `"charge.expired"` — QR code expired before payment.
405
+ * - `"charge.paid"` — Customer completed the payment.
406
+ * - `"charge.expired"` — Charge expired before payment.
352
407
  * - `"charge.cancelled"` — Charge was cancelled via the API.
353
408
  */
354
409
  type: "charge.paid" | "charge.expired" | "charge.cancelled";
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@sphoq/payments",
3
- "version": "0.3.0",
4
- "description": "Sphoq Payments SDK — integrate PIX payment processing into your app",
3
+ "version": "0.5.0",
4
+ "description": "Sphoq Payments SDK — integrate payment processing into your app",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",