@sphoq/payments 0.4.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/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,
@@ -201,7 +208,7 @@ export interface ChargeFee {
201
208
  amount: number;
202
209
  }
203
210
  /**
204
- * A PIX charge object returned by the Sphoq API.
211
+ * A charge object returned by the Sphoq API.
205
212
  *
206
213
  * @example
207
214
  * ```ts
@@ -210,16 +217,16 @@ export interface ChargeFee {
210
217
  * description: "Monthly subscription",
211
218
  * });
212
219
  *
213
- * // Display QR code to user
214
- * console.log(charge.qrCode); // Base64-encoded QR code image
215
- * 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
216
223
  * console.log(charge.status); // "pending"
217
224
  *
218
225
  * // After payment, query the charge
219
226
  * const paid = await sphoq.charges.get({ id: charge.id });
220
- * console.log(paid.status); // "paid"
221
- * console.log(paid.paidAt); // Unix timestamp in ms
222
- * 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
223
230
  * ```
224
231
  */
225
232
  export interface Charge {
@@ -227,50 +234,54 @@ export interface Charge {
227
234
  id: string;
228
235
  /** Your external ID, if provided when creating the charge. */
229
236
  externalId?: string;
230
- /** Charge amount in BRL. */
237
+ /** Charge amount. */
231
238
  amount: number;
232
- /**
233
- * Currency code. Always `"BRL"` (Brazilian Real).
234
- */
239
+ /** Currency code (e.g., `"BRL"`, `"USD"`). */
235
240
  currency: string;
236
241
  /** Human-readable description of the charge. */
237
242
  description: string;
238
243
  /**
239
244
  * Current status of the charge.
240
245
  *
241
- * - `"pending"` — Awaiting payment. QR code is active.
242
- * - `"paid"` — Payment confirmed by the bank.
243
- * - `"expired"` — QR code expired before payment.
246
+ * - `"pending"` — Awaiting payment.
247
+ * - `"paid"` — Payment confirmed by the provider.
248
+ * - `"expired"` — Charge expired before payment.
244
249
  * - `"cancelled"` — Charge was cancelled via the API.
245
250
  */
246
251
  status: "pending" | "paid" | "expired" | "cancelled";
247
- /** PIX transaction ID (txid). Unique identifier in the Brazilian PIX system. */
248
- 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;
249
258
  /**
250
- * PIX "copia e cola" (copy-paste) string.
251
- * 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).
252
261
  */
253
- pixCopiaECola?: string;
262
+ paymentCode?: string;
254
263
  /**
255
- * Base64-encoded PNG image of the PIX QR code.
256
- * Display this to the customer for scanning.
264
+ * Base64-encoded checkout image (e.g., QR code, barcode).
265
+ * Display this to the customer.
257
266
  */
258
- qrCode?: string;
267
+ checkoutImage?: string;
259
268
  /** Customer name, if provided. */
260
269
  customerName?: string;
261
270
  /** Customer email, if provided. */
262
271
  customerEmail?: string;
272
+ /** Your own customer identifier, if provided. */
273
+ customerExternalId?: string;
263
274
  /**
264
275
  * Unix timestamp (milliseconds) when the payment was confirmed.
265
276
  * Only present when `status` is `"paid"`.
266
277
  */
267
278
  paidAt?: number;
268
279
  /**
269
- * Central Bank end-to-end ID for the PIX transaction.
280
+ * Provider's payment confirmation ID.
270
281
  * Only present when `status` is `"paid"`.
271
- * Can be used for reconciliation with bank statements.
282
+ * Can be used for reconciliation with bank/provider statements.
272
283
  */
273
- endToEndId?: string;
284
+ providerPaymentId?: string;
274
285
  /**
275
286
  * Line items included in the charge, if provided at creation.
276
287
  * Returned as-is from the API. Useful for order fulfillment.
@@ -287,24 +298,24 @@ export interface Charge {
287
298
  */
288
299
  fees: ChargeFee[];
289
300
  /**
290
- * Sum of all fee amounts in BRL.
301
+ * Sum of all fee amounts.
291
302
  * Equal to `fees.reduce((sum, f) => sum + f.amount, 0)`.
292
303
  */
293
304
  totalFees: number;
294
305
  /**
295
- * Amount after fees in BRL.
306
+ * Amount after fees.
296
307
  * Equal to `amount - totalFees`.
297
308
  */
298
309
  netAmount: number;
299
310
  /**
300
311
  * The environment this charge was created in.
301
- * - `"production"` — Real PIX charge.
302
- * - `"development"` — EfiBank sandbox charge (no real money).
312
+ * - `"production"` — Real charge.
313
+ * - `"development"` — Sandbox charge (no real money).
303
314
  */
304
315
  environment?: "production" | "development";
305
316
  /** Unix timestamp (milliseconds) when the charge was created. */
306
317
  createdAt: number;
307
- /** Unix timestamp (milliseconds) when the PIX QR code expires. */
318
+ /** Unix timestamp (milliseconds) when the charge expires. */
308
319
  expiresAt: number;
309
320
  }
310
321
  /**
@@ -391,8 +402,8 @@ export interface WebhookPayload {
391
402
  /**
392
403
  * The event type.
393
404
  *
394
- * - `"charge.paid"` — Customer completed the PIX payment.
395
- * - `"charge.expired"` — QR code expired before payment.
405
+ * - `"charge.paid"` — Customer completed the payment.
406
+ * - `"charge.expired"` — Charge expired before payment.
396
407
  * - `"charge.cancelled"` — Charge was cancelled via the API.
397
408
  */
398
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.4.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",