@garuhq/node 0.5.0 → 0.6.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/index.cjs +81 -1
- package/dist/index.d.cts +105 -15
- package/dist/index.d.ts +105 -15
- package/dist/index.js +81 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -637,10 +637,23 @@ var ScheduledCharges = class {
|
|
|
637
637
|
}
|
|
638
638
|
/**
|
|
639
639
|
* Manually mark a scheduled charge as paid, e.g. when the customer paid
|
|
640
|
-
* outside Garu (bank transfer, cash).
|
|
640
|
+
* outside Garu (bank transfer, cash).
|
|
641
|
+
*
|
|
642
|
+
* - **One-time:** omit `cycleNumber`. Allowed from `due_today` / `overdue`.
|
|
643
|
+
* - **Recurring:** pass `cycleNumber`. Allowed from cycle status
|
|
644
|
+
* `due_today` / `overdue` / `failed`. Future cycles continue.
|
|
645
|
+
*
|
|
646
|
+
* @example
|
|
647
|
+
* // One-time
|
|
648
|
+
* await garu.scheduledCharges.markPaid('sch_abc123', {
|
|
649
|
+
* paymentDate: '2026-06-20',
|
|
650
|
+
* externalReference: 'TED 4472881'
|
|
651
|
+
* });
|
|
641
652
|
*
|
|
642
653
|
* @example
|
|
654
|
+
* // Recurring — mark cycle 3 paid; future cycles keep billing
|
|
643
655
|
* await garu.scheduledCharges.markPaid('sch_abc123', {
|
|
656
|
+
* cycleNumber: 3,
|
|
644
657
|
* paymentDate: '2026-06-20',
|
|
645
658
|
* externalReference: 'TED 4472881'
|
|
646
659
|
* });
|
|
@@ -653,6 +666,73 @@ var ScheduledCharges = class {
|
|
|
653
666
|
}).then((r) => r)
|
|
654
667
|
);
|
|
655
668
|
}
|
|
669
|
+
/**
|
|
670
|
+
* Stop future cycles for a recurring series. The currently in-flight
|
|
671
|
+
* cycle (if any) remains active until paid, postponed, or marked-paid;
|
|
672
|
+
* only after that resolves does the series flip to `recurrence_canceled`.
|
|
673
|
+
* Recurring-only.
|
|
674
|
+
*
|
|
675
|
+
* @example
|
|
676
|
+
* await garu.scheduledCharges.cancelRecurrence('sch_abc123', {
|
|
677
|
+
* reason: 'cliente cancelou plano'
|
|
678
|
+
* });
|
|
679
|
+
*/
|
|
680
|
+
async cancelRecurrence(id, params = {}) {
|
|
681
|
+
return this.http.call(
|
|
682
|
+
(signal) => this.http.client.POST(`/api/scheduled-charges/${id}/cancel-recurrence`, {
|
|
683
|
+
body: params,
|
|
684
|
+
signal
|
|
685
|
+
}).then((r) => r)
|
|
686
|
+
);
|
|
687
|
+
}
|
|
688
|
+
/**
|
|
689
|
+
* Toggle Stripe-style soft cancel on a recurring series. With
|
|
690
|
+
* `enabled: true`, the cycle generator stops emitting new cycles after
|
|
691
|
+
* the next paid cycle; the in-flight cycle still bills + can be paid.
|
|
692
|
+
* Reversible by passing `enabled: false`. Recurring-only.
|
|
693
|
+
*
|
|
694
|
+
* @example
|
|
695
|
+
* await garu.scheduledCharges.setCancelAtPeriodEnd('sch_abc123', { enabled: true });
|
|
696
|
+
*/
|
|
697
|
+
async setCancelAtPeriodEnd(id, params) {
|
|
698
|
+
return this.http.call(
|
|
699
|
+
(signal) => this.http.client.POST(`/api/scheduled-charges/${id}/cancel-at-period-end`, {
|
|
700
|
+
body: params,
|
|
701
|
+
signal
|
|
702
|
+
}).then((r) => r)
|
|
703
|
+
);
|
|
704
|
+
}
|
|
705
|
+
/**
|
|
706
|
+
* Swap the saved card on a recurring series. The new PaymentMethod must
|
|
707
|
+
* belong to the same customerId. Future cycles silent-charge the new
|
|
708
|
+
* card; the in-flight cycle is not retroactively rebound.
|
|
709
|
+
*
|
|
710
|
+
* @example
|
|
711
|
+
* await garu.scheduledCharges.changePaymentMethod('sch_abc123', { paymentMethodId: 42 });
|
|
712
|
+
*/
|
|
713
|
+
async changePaymentMethod(id, params) {
|
|
714
|
+
return this.http.call(
|
|
715
|
+
(signal) => this.http.client.POST(`/api/scheduled-charges/${id}/payment-method`, {
|
|
716
|
+
body: params,
|
|
717
|
+
signal
|
|
718
|
+
}).then((r) => r)
|
|
719
|
+
);
|
|
720
|
+
}
|
|
721
|
+
/**
|
|
722
|
+
* Clear the saved card on a recurring series. Future cycles fall back
|
|
723
|
+
* to the email-with-link flow so the customer can re-enter card details
|
|
724
|
+
* or pay via PIX/Boleto.
|
|
725
|
+
*
|
|
726
|
+
* @example
|
|
727
|
+
* await garu.scheduledCharges.clearPaymentMethod('sch_abc123');
|
|
728
|
+
*/
|
|
729
|
+
async clearPaymentMethod(id) {
|
|
730
|
+
return this.http.call(
|
|
731
|
+
(signal) => this.http.client.DELETE(`/api/scheduled-charges/${id}/payment-method`, {
|
|
732
|
+
signal
|
|
733
|
+
}).then((r) => r)
|
|
734
|
+
);
|
|
735
|
+
}
|
|
656
736
|
};
|
|
657
737
|
var webhooks = {
|
|
658
738
|
verify(params) {
|
package/dist/index.d.cts
CHANGED
|
@@ -277,7 +277,17 @@ interface ListCustomersParams {
|
|
|
277
277
|
}
|
|
278
278
|
type ScheduledChargeStatus = 'scheduled' | 'due_today' | 'overdue' | 'paid' | 'paused' | 'canceled' | 'trial' | 'pending_tokenization' | 'recurrence_canceled';
|
|
279
279
|
type ScheduledChargeType = 'one_time' | 'recurring';
|
|
280
|
-
type ScheduledPaymentMethod = 'pix' | 'boleto';
|
|
280
|
+
type ScheduledPaymentMethod = 'pix' | 'boleto' | 'card';
|
|
281
|
+
type RecurrenceInterval = 'weekly' | 'biweekly' | 'monthly' | 'bimonthly' | 'quarterly' | 'biannual' | 'yearly';
|
|
282
|
+
interface RecurrenceConfig {
|
|
283
|
+
interval: RecurrenceInterval;
|
|
284
|
+
/** Multiplier for the interval (default 1). */
|
|
285
|
+
intervalCount?: number;
|
|
286
|
+
/** Stop after N successful cycles. Mutually exclusive with `endsOn`. */
|
|
287
|
+
endsAfter?: number;
|
|
288
|
+
/** Stop after this calendar date (YYYY-MM-DD). Mutually exclusive with `endsAfter`. */
|
|
289
|
+
endsOn?: string;
|
|
290
|
+
}
|
|
281
291
|
type ScheduledChargeEventType = 'created' | 'postponed' | 'paused' | 'resumed' | 'recurrence_canceled' | 'manually_marked_paid' | 'paid' | 'overdue_reminder_sent' | 'd_day_reminder_sent';
|
|
282
292
|
type ScheduledChargeActor = {
|
|
283
293
|
type: 'user';
|
|
@@ -346,19 +356,28 @@ interface ScheduledChargeDetail {
|
|
|
346
356
|
type ScheduledChargeList = PaginatedList<ScheduledChargeRecord>;
|
|
347
357
|
interface CreateScheduledChargeParams {
|
|
348
358
|
customerId: number;
|
|
359
|
+
/**
|
|
360
|
+
* Required when `methods` includes `card` — Celcoin transactions are
|
|
361
|
+
* scoped per product. Optional otherwise.
|
|
362
|
+
*/
|
|
349
363
|
productId?: number;
|
|
350
364
|
/** Decimal BRL (e.g. `297.50`). */
|
|
351
365
|
amount: number;
|
|
352
366
|
description?: string;
|
|
353
|
-
/**
|
|
354
|
-
|
|
355
|
-
* literal narrows to that until recurring schedules ship.
|
|
356
|
-
*/
|
|
357
|
-
type: 'one_time';
|
|
367
|
+
/** Schedule type. `recurring` requires a `recurrence` block. */
|
|
368
|
+
type: ScheduledChargeType;
|
|
358
369
|
/** YYYY-MM-DD in São Paulo time. Must be today or future. */
|
|
359
370
|
dueDate: string;
|
|
360
|
-
/**
|
|
371
|
+
/** `card` is recurring-only and requires `productId`. */
|
|
361
372
|
methods: ScheduledPaymentMethod[];
|
|
373
|
+
/** Cadence for `type='recurring'`. Must be omitted when `type='one_time'`. */
|
|
374
|
+
recurrence?: RecurrenceConfig;
|
|
375
|
+
/**
|
|
376
|
+
* Free-trial duration in days (1..365). Recurring-only. When set, cycle 1
|
|
377
|
+
* is rebased to `today + trialDays` and `customer.trial_started` fires
|
|
378
|
+
* immediately.
|
|
379
|
+
*/
|
|
380
|
+
trialDays?: number;
|
|
362
381
|
externalReference?: string;
|
|
363
382
|
metadata?: Record<string, unknown>;
|
|
364
383
|
/**
|
|
@@ -393,6 +412,22 @@ interface MarkPaidScheduledChargeParams {
|
|
|
393
412
|
paymentDate: string;
|
|
394
413
|
/** Bank reference, internal ID, or any stable string for reconciliation. */
|
|
395
414
|
externalReference?: string;
|
|
415
|
+
/**
|
|
416
|
+
* Cycle number to mark paid. REQUIRED for recurring schedules. Omitted
|
|
417
|
+
* for one-time charges.
|
|
418
|
+
*/
|
|
419
|
+
cycleNumber?: number;
|
|
420
|
+
}
|
|
421
|
+
interface CancelRecurrenceScheduledChargeParams {
|
|
422
|
+
reason?: string;
|
|
423
|
+
}
|
|
424
|
+
interface CancelAtPeriodEndScheduledChargeParams {
|
|
425
|
+
/** `true` enables Stripe-style soft cancel; `false` clears the flag. */
|
|
426
|
+
enabled: boolean;
|
|
427
|
+
}
|
|
428
|
+
interface ChangePaymentMethodScheduledChargeParams {
|
|
429
|
+
/** PaymentMethod id to bind. Must belong to the same customerId. */
|
|
430
|
+
paymentMethodId: number;
|
|
396
431
|
}
|
|
397
432
|
interface Product {
|
|
398
433
|
id: number;
|
|
@@ -651,13 +686,15 @@ declare class Products {
|
|
|
651
686
|
* Scheduled charges — bill a customer on a future date.
|
|
652
687
|
*
|
|
653
688
|
* The seller registers a customer (see `garu.customers.create`), then
|
|
654
|
-
* schedules one or more charges (PIX or
|
|
655
|
-
* pre-charge customer email on the due date, dunning to the seller
|
|
656
|
-
* after the due date, and a state machine for
|
|
657
|
-
* mark-paid actions.
|
|
689
|
+
* schedules one or more charges (PIX, Boleto, or Card). Garu drives the
|
|
690
|
+
* rest: pre-charge customer email on the due date, dunning to the seller
|
|
691
|
+
* team after the due date, and a state machine for
|
|
692
|
+
* postpone/pause/resume/mark-paid actions.
|
|
658
693
|
*
|
|
659
|
-
* Recurring schedules
|
|
660
|
-
*
|
|
694
|
+
* Recurring schedules (`type: 'recurring'`) silent-charge the saved card
|
|
695
|
+
* on every cycle past the first. Optional trial periods, cancel-recurrence,
|
|
696
|
+
* cancel-at-period-end, and payment-method swap actions cover the SaaS
|
|
697
|
+
* lifecycle.
|
|
661
698
|
*/
|
|
662
699
|
declare class ScheduledCharges {
|
|
663
700
|
private readonly http;
|
|
@@ -732,15 +769,68 @@ declare class ScheduledCharges {
|
|
|
732
769
|
resume(id: string): Promise<ScheduledChargeRecord>;
|
|
733
770
|
/**
|
|
734
771
|
* Manually mark a scheduled charge as paid, e.g. when the customer paid
|
|
735
|
-
* outside Garu (bank transfer, cash).
|
|
772
|
+
* outside Garu (bank transfer, cash).
|
|
773
|
+
*
|
|
774
|
+
* - **One-time:** omit `cycleNumber`. Allowed from `due_today` / `overdue`.
|
|
775
|
+
* - **Recurring:** pass `cycleNumber`. Allowed from cycle status
|
|
776
|
+
* `due_today` / `overdue` / `failed`. Future cycles continue.
|
|
777
|
+
*
|
|
778
|
+
* @example
|
|
779
|
+
* // One-time
|
|
780
|
+
* await garu.scheduledCharges.markPaid('sch_abc123', {
|
|
781
|
+
* paymentDate: '2026-06-20',
|
|
782
|
+
* externalReference: 'TED 4472881'
|
|
783
|
+
* });
|
|
736
784
|
*
|
|
737
785
|
* @example
|
|
786
|
+
* // Recurring — mark cycle 3 paid; future cycles keep billing
|
|
738
787
|
* await garu.scheduledCharges.markPaid('sch_abc123', {
|
|
788
|
+
* cycleNumber: 3,
|
|
739
789
|
* paymentDate: '2026-06-20',
|
|
740
790
|
* externalReference: 'TED 4472881'
|
|
741
791
|
* });
|
|
742
792
|
*/
|
|
743
793
|
markPaid(id: string, params: MarkPaidScheduledChargeParams): Promise<ScheduledChargeRecord>;
|
|
794
|
+
/**
|
|
795
|
+
* Stop future cycles for a recurring series. The currently in-flight
|
|
796
|
+
* cycle (if any) remains active until paid, postponed, or marked-paid;
|
|
797
|
+
* only after that resolves does the series flip to `recurrence_canceled`.
|
|
798
|
+
* Recurring-only.
|
|
799
|
+
*
|
|
800
|
+
* @example
|
|
801
|
+
* await garu.scheduledCharges.cancelRecurrence('sch_abc123', {
|
|
802
|
+
* reason: 'cliente cancelou plano'
|
|
803
|
+
* });
|
|
804
|
+
*/
|
|
805
|
+
cancelRecurrence(id: string, params?: CancelRecurrenceScheduledChargeParams): Promise<ScheduledChargeRecord>;
|
|
806
|
+
/**
|
|
807
|
+
* Toggle Stripe-style soft cancel on a recurring series. With
|
|
808
|
+
* `enabled: true`, the cycle generator stops emitting new cycles after
|
|
809
|
+
* the next paid cycle; the in-flight cycle still bills + can be paid.
|
|
810
|
+
* Reversible by passing `enabled: false`. Recurring-only.
|
|
811
|
+
*
|
|
812
|
+
* @example
|
|
813
|
+
* await garu.scheduledCharges.setCancelAtPeriodEnd('sch_abc123', { enabled: true });
|
|
814
|
+
*/
|
|
815
|
+
setCancelAtPeriodEnd(id: string, params: CancelAtPeriodEndScheduledChargeParams): Promise<ScheduledChargeRecord>;
|
|
816
|
+
/**
|
|
817
|
+
* Swap the saved card on a recurring series. The new PaymentMethod must
|
|
818
|
+
* belong to the same customerId. Future cycles silent-charge the new
|
|
819
|
+
* card; the in-flight cycle is not retroactively rebound.
|
|
820
|
+
*
|
|
821
|
+
* @example
|
|
822
|
+
* await garu.scheduledCharges.changePaymentMethod('sch_abc123', { paymentMethodId: 42 });
|
|
823
|
+
*/
|
|
824
|
+
changePaymentMethod(id: string, params: ChangePaymentMethodScheduledChargeParams): Promise<ScheduledChargeRecord>;
|
|
825
|
+
/**
|
|
826
|
+
* Clear the saved card on a recurring series. Future cycles fall back
|
|
827
|
+
* to the email-with-link flow so the customer can re-enter card details
|
|
828
|
+
* or pay via PIX/Boleto.
|
|
829
|
+
*
|
|
830
|
+
* @example
|
|
831
|
+
* await garu.scheduledCharges.clearPaymentMethod('sch_abc123');
|
|
832
|
+
*/
|
|
833
|
+
clearPaymentMethod(id: string): Promise<ScheduledChargeRecord>;
|
|
744
834
|
}
|
|
745
835
|
|
|
746
836
|
interface GaruOptions {
|
|
@@ -841,4 +931,4 @@ declare class GaruServerError extends GaruAPIError {
|
|
|
841
931
|
constructor(message: string, status: number, requestId: string | null, body: unknown);
|
|
842
932
|
}
|
|
843
933
|
|
|
844
|
-
export { type CardInfo, type Charge, type ChargeList, type ChargeStatus, type CreateChargeParams, type CreateCustomerParams, type CreateScheduledChargeParams, type Customer, type CustomerList, type CustomerRecord, Garu, GaruAPIError, GaruAuthenticationError, GaruConnectionError, GaruError, type GaruErrorCode, GaruNotFoundError, type GaruOptions, GaruPermissionError, GaruRateLimitError, GaruServerError, GaruSignatureVerificationError, GaruValidationError, type ListChargesParams, type ListCustomersParams, type ListProductsParams, type ListScheduledChargesParams, type MarkPaidScheduledChargeParams, type MetaFeatures, type MetaResponse, type PaginatedList, type PauseScheduledChargeParams, type PaymentMethod, type PostponeScheduledChargeParams, type Product, type ProductList, type RefundChargeParams, type ScheduledChargeActor, type ScheduledChargeDetail, type ScheduledChargeEvent, type ScheduledChargeEventType, type ScheduledChargeLinkedTransaction, type ScheduledChargeList, type ScheduledChargeRecord, type ScheduledChargeStatus, type ScheduledChargeType, type ScheduledPaymentMethod, type UpdateCustomerParams, type VerifiedWebhook, type VerifyWebhookParams, type WirePaymentMethodId, webhooks };
|
|
934
|
+
export { type CancelAtPeriodEndScheduledChargeParams, type CancelRecurrenceScheduledChargeParams, type CardInfo, type ChangePaymentMethodScheduledChargeParams, type Charge, type ChargeList, type ChargeStatus, type CreateChargeParams, type CreateCustomerParams, type CreateScheduledChargeParams, type Customer, type CustomerList, type CustomerRecord, Garu, GaruAPIError, GaruAuthenticationError, GaruConnectionError, GaruError, type GaruErrorCode, GaruNotFoundError, type GaruOptions, GaruPermissionError, GaruRateLimitError, GaruServerError, GaruSignatureVerificationError, GaruValidationError, type ListChargesParams, type ListCustomersParams, type ListProductsParams, type ListScheduledChargesParams, type MarkPaidScheduledChargeParams, type MetaFeatures, type MetaResponse, type PaginatedList, type PauseScheduledChargeParams, type PaymentMethod, type PostponeScheduledChargeParams, type Product, type ProductList, type RecurrenceConfig, type RecurrenceInterval, type RefundChargeParams, type ScheduledChargeActor, type ScheduledChargeDetail, type ScheduledChargeEvent, type ScheduledChargeEventType, type ScheduledChargeLinkedTransaction, type ScheduledChargeList, type ScheduledChargeRecord, type ScheduledChargeStatus, type ScheduledChargeType, type ScheduledPaymentMethod, type UpdateCustomerParams, type VerifiedWebhook, type VerifyWebhookParams, type WirePaymentMethodId, webhooks };
|
package/dist/index.d.ts
CHANGED
|
@@ -277,7 +277,17 @@ interface ListCustomersParams {
|
|
|
277
277
|
}
|
|
278
278
|
type ScheduledChargeStatus = 'scheduled' | 'due_today' | 'overdue' | 'paid' | 'paused' | 'canceled' | 'trial' | 'pending_tokenization' | 'recurrence_canceled';
|
|
279
279
|
type ScheduledChargeType = 'one_time' | 'recurring';
|
|
280
|
-
type ScheduledPaymentMethod = 'pix' | 'boleto';
|
|
280
|
+
type ScheduledPaymentMethod = 'pix' | 'boleto' | 'card';
|
|
281
|
+
type RecurrenceInterval = 'weekly' | 'biweekly' | 'monthly' | 'bimonthly' | 'quarterly' | 'biannual' | 'yearly';
|
|
282
|
+
interface RecurrenceConfig {
|
|
283
|
+
interval: RecurrenceInterval;
|
|
284
|
+
/** Multiplier for the interval (default 1). */
|
|
285
|
+
intervalCount?: number;
|
|
286
|
+
/** Stop after N successful cycles. Mutually exclusive with `endsOn`. */
|
|
287
|
+
endsAfter?: number;
|
|
288
|
+
/** Stop after this calendar date (YYYY-MM-DD). Mutually exclusive with `endsAfter`. */
|
|
289
|
+
endsOn?: string;
|
|
290
|
+
}
|
|
281
291
|
type ScheduledChargeEventType = 'created' | 'postponed' | 'paused' | 'resumed' | 'recurrence_canceled' | 'manually_marked_paid' | 'paid' | 'overdue_reminder_sent' | 'd_day_reminder_sent';
|
|
282
292
|
type ScheduledChargeActor = {
|
|
283
293
|
type: 'user';
|
|
@@ -346,19 +356,28 @@ interface ScheduledChargeDetail {
|
|
|
346
356
|
type ScheduledChargeList = PaginatedList<ScheduledChargeRecord>;
|
|
347
357
|
interface CreateScheduledChargeParams {
|
|
348
358
|
customerId: number;
|
|
359
|
+
/**
|
|
360
|
+
* Required when `methods` includes `card` — Celcoin transactions are
|
|
361
|
+
* scoped per product. Optional otherwise.
|
|
362
|
+
*/
|
|
349
363
|
productId?: number;
|
|
350
364
|
/** Decimal BRL (e.g. `297.50`). */
|
|
351
365
|
amount: number;
|
|
352
366
|
description?: string;
|
|
353
|
-
/**
|
|
354
|
-
|
|
355
|
-
* literal narrows to that until recurring schedules ship.
|
|
356
|
-
*/
|
|
357
|
-
type: 'one_time';
|
|
367
|
+
/** Schedule type. `recurring` requires a `recurrence` block. */
|
|
368
|
+
type: ScheduledChargeType;
|
|
358
369
|
/** YYYY-MM-DD in São Paulo time. Must be today or future. */
|
|
359
370
|
dueDate: string;
|
|
360
|
-
/**
|
|
371
|
+
/** `card` is recurring-only and requires `productId`. */
|
|
361
372
|
methods: ScheduledPaymentMethod[];
|
|
373
|
+
/** Cadence for `type='recurring'`. Must be omitted when `type='one_time'`. */
|
|
374
|
+
recurrence?: RecurrenceConfig;
|
|
375
|
+
/**
|
|
376
|
+
* Free-trial duration in days (1..365). Recurring-only. When set, cycle 1
|
|
377
|
+
* is rebased to `today + trialDays` and `customer.trial_started` fires
|
|
378
|
+
* immediately.
|
|
379
|
+
*/
|
|
380
|
+
trialDays?: number;
|
|
362
381
|
externalReference?: string;
|
|
363
382
|
metadata?: Record<string, unknown>;
|
|
364
383
|
/**
|
|
@@ -393,6 +412,22 @@ interface MarkPaidScheduledChargeParams {
|
|
|
393
412
|
paymentDate: string;
|
|
394
413
|
/** Bank reference, internal ID, or any stable string for reconciliation. */
|
|
395
414
|
externalReference?: string;
|
|
415
|
+
/**
|
|
416
|
+
* Cycle number to mark paid. REQUIRED for recurring schedules. Omitted
|
|
417
|
+
* for one-time charges.
|
|
418
|
+
*/
|
|
419
|
+
cycleNumber?: number;
|
|
420
|
+
}
|
|
421
|
+
interface CancelRecurrenceScheduledChargeParams {
|
|
422
|
+
reason?: string;
|
|
423
|
+
}
|
|
424
|
+
interface CancelAtPeriodEndScheduledChargeParams {
|
|
425
|
+
/** `true` enables Stripe-style soft cancel; `false` clears the flag. */
|
|
426
|
+
enabled: boolean;
|
|
427
|
+
}
|
|
428
|
+
interface ChangePaymentMethodScheduledChargeParams {
|
|
429
|
+
/** PaymentMethod id to bind. Must belong to the same customerId. */
|
|
430
|
+
paymentMethodId: number;
|
|
396
431
|
}
|
|
397
432
|
interface Product {
|
|
398
433
|
id: number;
|
|
@@ -651,13 +686,15 @@ declare class Products {
|
|
|
651
686
|
* Scheduled charges — bill a customer on a future date.
|
|
652
687
|
*
|
|
653
688
|
* The seller registers a customer (see `garu.customers.create`), then
|
|
654
|
-
* schedules one or more charges (PIX or
|
|
655
|
-
* pre-charge customer email on the due date, dunning to the seller
|
|
656
|
-
* after the due date, and a state machine for
|
|
657
|
-
* mark-paid actions.
|
|
689
|
+
* schedules one or more charges (PIX, Boleto, or Card). Garu drives the
|
|
690
|
+
* rest: pre-charge customer email on the due date, dunning to the seller
|
|
691
|
+
* team after the due date, and a state machine for
|
|
692
|
+
* postpone/pause/resume/mark-paid actions.
|
|
658
693
|
*
|
|
659
|
-
* Recurring schedules
|
|
660
|
-
*
|
|
694
|
+
* Recurring schedules (`type: 'recurring'`) silent-charge the saved card
|
|
695
|
+
* on every cycle past the first. Optional trial periods, cancel-recurrence,
|
|
696
|
+
* cancel-at-period-end, and payment-method swap actions cover the SaaS
|
|
697
|
+
* lifecycle.
|
|
661
698
|
*/
|
|
662
699
|
declare class ScheduledCharges {
|
|
663
700
|
private readonly http;
|
|
@@ -732,15 +769,68 @@ declare class ScheduledCharges {
|
|
|
732
769
|
resume(id: string): Promise<ScheduledChargeRecord>;
|
|
733
770
|
/**
|
|
734
771
|
* Manually mark a scheduled charge as paid, e.g. when the customer paid
|
|
735
|
-
* outside Garu (bank transfer, cash).
|
|
772
|
+
* outside Garu (bank transfer, cash).
|
|
773
|
+
*
|
|
774
|
+
* - **One-time:** omit `cycleNumber`. Allowed from `due_today` / `overdue`.
|
|
775
|
+
* - **Recurring:** pass `cycleNumber`. Allowed from cycle status
|
|
776
|
+
* `due_today` / `overdue` / `failed`. Future cycles continue.
|
|
777
|
+
*
|
|
778
|
+
* @example
|
|
779
|
+
* // One-time
|
|
780
|
+
* await garu.scheduledCharges.markPaid('sch_abc123', {
|
|
781
|
+
* paymentDate: '2026-06-20',
|
|
782
|
+
* externalReference: 'TED 4472881'
|
|
783
|
+
* });
|
|
736
784
|
*
|
|
737
785
|
* @example
|
|
786
|
+
* // Recurring — mark cycle 3 paid; future cycles keep billing
|
|
738
787
|
* await garu.scheduledCharges.markPaid('sch_abc123', {
|
|
788
|
+
* cycleNumber: 3,
|
|
739
789
|
* paymentDate: '2026-06-20',
|
|
740
790
|
* externalReference: 'TED 4472881'
|
|
741
791
|
* });
|
|
742
792
|
*/
|
|
743
793
|
markPaid(id: string, params: MarkPaidScheduledChargeParams): Promise<ScheduledChargeRecord>;
|
|
794
|
+
/**
|
|
795
|
+
* Stop future cycles for a recurring series. The currently in-flight
|
|
796
|
+
* cycle (if any) remains active until paid, postponed, or marked-paid;
|
|
797
|
+
* only after that resolves does the series flip to `recurrence_canceled`.
|
|
798
|
+
* Recurring-only.
|
|
799
|
+
*
|
|
800
|
+
* @example
|
|
801
|
+
* await garu.scheduledCharges.cancelRecurrence('sch_abc123', {
|
|
802
|
+
* reason: 'cliente cancelou plano'
|
|
803
|
+
* });
|
|
804
|
+
*/
|
|
805
|
+
cancelRecurrence(id: string, params?: CancelRecurrenceScheduledChargeParams): Promise<ScheduledChargeRecord>;
|
|
806
|
+
/**
|
|
807
|
+
* Toggle Stripe-style soft cancel on a recurring series. With
|
|
808
|
+
* `enabled: true`, the cycle generator stops emitting new cycles after
|
|
809
|
+
* the next paid cycle; the in-flight cycle still bills + can be paid.
|
|
810
|
+
* Reversible by passing `enabled: false`. Recurring-only.
|
|
811
|
+
*
|
|
812
|
+
* @example
|
|
813
|
+
* await garu.scheduledCharges.setCancelAtPeriodEnd('sch_abc123', { enabled: true });
|
|
814
|
+
*/
|
|
815
|
+
setCancelAtPeriodEnd(id: string, params: CancelAtPeriodEndScheduledChargeParams): Promise<ScheduledChargeRecord>;
|
|
816
|
+
/**
|
|
817
|
+
* Swap the saved card on a recurring series. The new PaymentMethod must
|
|
818
|
+
* belong to the same customerId. Future cycles silent-charge the new
|
|
819
|
+
* card; the in-flight cycle is not retroactively rebound.
|
|
820
|
+
*
|
|
821
|
+
* @example
|
|
822
|
+
* await garu.scheduledCharges.changePaymentMethod('sch_abc123', { paymentMethodId: 42 });
|
|
823
|
+
*/
|
|
824
|
+
changePaymentMethod(id: string, params: ChangePaymentMethodScheduledChargeParams): Promise<ScheduledChargeRecord>;
|
|
825
|
+
/**
|
|
826
|
+
* Clear the saved card on a recurring series. Future cycles fall back
|
|
827
|
+
* to the email-with-link flow so the customer can re-enter card details
|
|
828
|
+
* or pay via PIX/Boleto.
|
|
829
|
+
*
|
|
830
|
+
* @example
|
|
831
|
+
* await garu.scheduledCharges.clearPaymentMethod('sch_abc123');
|
|
832
|
+
*/
|
|
833
|
+
clearPaymentMethod(id: string): Promise<ScheduledChargeRecord>;
|
|
744
834
|
}
|
|
745
835
|
|
|
746
836
|
interface GaruOptions {
|
|
@@ -841,4 +931,4 @@ declare class GaruServerError extends GaruAPIError {
|
|
|
841
931
|
constructor(message: string, status: number, requestId: string | null, body: unknown);
|
|
842
932
|
}
|
|
843
933
|
|
|
844
|
-
export { type CardInfo, type Charge, type ChargeList, type ChargeStatus, type CreateChargeParams, type CreateCustomerParams, type CreateScheduledChargeParams, type Customer, type CustomerList, type CustomerRecord, Garu, GaruAPIError, GaruAuthenticationError, GaruConnectionError, GaruError, type GaruErrorCode, GaruNotFoundError, type GaruOptions, GaruPermissionError, GaruRateLimitError, GaruServerError, GaruSignatureVerificationError, GaruValidationError, type ListChargesParams, type ListCustomersParams, type ListProductsParams, type ListScheduledChargesParams, type MarkPaidScheduledChargeParams, type MetaFeatures, type MetaResponse, type PaginatedList, type PauseScheduledChargeParams, type PaymentMethod, type PostponeScheduledChargeParams, type Product, type ProductList, type RefundChargeParams, type ScheduledChargeActor, type ScheduledChargeDetail, type ScheduledChargeEvent, type ScheduledChargeEventType, type ScheduledChargeLinkedTransaction, type ScheduledChargeList, type ScheduledChargeRecord, type ScheduledChargeStatus, type ScheduledChargeType, type ScheduledPaymentMethod, type UpdateCustomerParams, type VerifiedWebhook, type VerifyWebhookParams, type WirePaymentMethodId, webhooks };
|
|
934
|
+
export { type CancelAtPeriodEndScheduledChargeParams, type CancelRecurrenceScheduledChargeParams, type CardInfo, type ChangePaymentMethodScheduledChargeParams, type Charge, type ChargeList, type ChargeStatus, type CreateChargeParams, type CreateCustomerParams, type CreateScheduledChargeParams, type Customer, type CustomerList, type CustomerRecord, Garu, GaruAPIError, GaruAuthenticationError, GaruConnectionError, GaruError, type GaruErrorCode, GaruNotFoundError, type GaruOptions, GaruPermissionError, GaruRateLimitError, GaruServerError, GaruSignatureVerificationError, GaruValidationError, type ListChargesParams, type ListCustomersParams, type ListProductsParams, type ListScheduledChargesParams, type MarkPaidScheduledChargeParams, type MetaFeatures, type MetaResponse, type PaginatedList, type PauseScheduledChargeParams, type PaymentMethod, type PostponeScheduledChargeParams, type Product, type ProductList, type RecurrenceConfig, type RecurrenceInterval, type RefundChargeParams, type ScheduledChargeActor, type ScheduledChargeDetail, type ScheduledChargeEvent, type ScheduledChargeEventType, type ScheduledChargeLinkedTransaction, type ScheduledChargeList, type ScheduledChargeRecord, type ScheduledChargeStatus, type ScheduledChargeType, type ScheduledPaymentMethod, type UpdateCustomerParams, type VerifiedWebhook, type VerifyWebhookParams, type WirePaymentMethodId, webhooks };
|
package/dist/index.js
CHANGED
|
@@ -631,10 +631,23 @@ var ScheduledCharges = class {
|
|
|
631
631
|
}
|
|
632
632
|
/**
|
|
633
633
|
* Manually mark a scheduled charge as paid, e.g. when the customer paid
|
|
634
|
-
* outside Garu (bank transfer, cash).
|
|
634
|
+
* outside Garu (bank transfer, cash).
|
|
635
|
+
*
|
|
636
|
+
* - **One-time:** omit `cycleNumber`. Allowed from `due_today` / `overdue`.
|
|
637
|
+
* - **Recurring:** pass `cycleNumber`. Allowed from cycle status
|
|
638
|
+
* `due_today` / `overdue` / `failed`. Future cycles continue.
|
|
639
|
+
*
|
|
640
|
+
* @example
|
|
641
|
+
* // One-time
|
|
642
|
+
* await garu.scheduledCharges.markPaid('sch_abc123', {
|
|
643
|
+
* paymentDate: '2026-06-20',
|
|
644
|
+
* externalReference: 'TED 4472881'
|
|
645
|
+
* });
|
|
635
646
|
*
|
|
636
647
|
* @example
|
|
648
|
+
* // Recurring — mark cycle 3 paid; future cycles keep billing
|
|
637
649
|
* await garu.scheduledCharges.markPaid('sch_abc123', {
|
|
650
|
+
* cycleNumber: 3,
|
|
638
651
|
* paymentDate: '2026-06-20',
|
|
639
652
|
* externalReference: 'TED 4472881'
|
|
640
653
|
* });
|
|
@@ -647,6 +660,73 @@ var ScheduledCharges = class {
|
|
|
647
660
|
}).then((r) => r)
|
|
648
661
|
);
|
|
649
662
|
}
|
|
663
|
+
/**
|
|
664
|
+
* Stop future cycles for a recurring series. The currently in-flight
|
|
665
|
+
* cycle (if any) remains active until paid, postponed, or marked-paid;
|
|
666
|
+
* only after that resolves does the series flip to `recurrence_canceled`.
|
|
667
|
+
* Recurring-only.
|
|
668
|
+
*
|
|
669
|
+
* @example
|
|
670
|
+
* await garu.scheduledCharges.cancelRecurrence('sch_abc123', {
|
|
671
|
+
* reason: 'cliente cancelou plano'
|
|
672
|
+
* });
|
|
673
|
+
*/
|
|
674
|
+
async cancelRecurrence(id, params = {}) {
|
|
675
|
+
return this.http.call(
|
|
676
|
+
(signal) => this.http.client.POST(`/api/scheduled-charges/${id}/cancel-recurrence`, {
|
|
677
|
+
body: params,
|
|
678
|
+
signal
|
|
679
|
+
}).then((r) => r)
|
|
680
|
+
);
|
|
681
|
+
}
|
|
682
|
+
/**
|
|
683
|
+
* Toggle Stripe-style soft cancel on a recurring series. With
|
|
684
|
+
* `enabled: true`, the cycle generator stops emitting new cycles after
|
|
685
|
+
* the next paid cycle; the in-flight cycle still bills + can be paid.
|
|
686
|
+
* Reversible by passing `enabled: false`. Recurring-only.
|
|
687
|
+
*
|
|
688
|
+
* @example
|
|
689
|
+
* await garu.scheduledCharges.setCancelAtPeriodEnd('sch_abc123', { enabled: true });
|
|
690
|
+
*/
|
|
691
|
+
async setCancelAtPeriodEnd(id, params) {
|
|
692
|
+
return this.http.call(
|
|
693
|
+
(signal) => this.http.client.POST(`/api/scheduled-charges/${id}/cancel-at-period-end`, {
|
|
694
|
+
body: params,
|
|
695
|
+
signal
|
|
696
|
+
}).then((r) => r)
|
|
697
|
+
);
|
|
698
|
+
}
|
|
699
|
+
/**
|
|
700
|
+
* Swap the saved card on a recurring series. The new PaymentMethod must
|
|
701
|
+
* belong to the same customerId. Future cycles silent-charge the new
|
|
702
|
+
* card; the in-flight cycle is not retroactively rebound.
|
|
703
|
+
*
|
|
704
|
+
* @example
|
|
705
|
+
* await garu.scheduledCharges.changePaymentMethod('sch_abc123', { paymentMethodId: 42 });
|
|
706
|
+
*/
|
|
707
|
+
async changePaymentMethod(id, params) {
|
|
708
|
+
return this.http.call(
|
|
709
|
+
(signal) => this.http.client.POST(`/api/scheduled-charges/${id}/payment-method`, {
|
|
710
|
+
body: params,
|
|
711
|
+
signal
|
|
712
|
+
}).then((r) => r)
|
|
713
|
+
);
|
|
714
|
+
}
|
|
715
|
+
/**
|
|
716
|
+
* Clear the saved card on a recurring series. Future cycles fall back
|
|
717
|
+
* to the email-with-link flow so the customer can re-enter card details
|
|
718
|
+
* or pay via PIX/Boleto.
|
|
719
|
+
*
|
|
720
|
+
* @example
|
|
721
|
+
* await garu.scheduledCharges.clearPaymentMethod('sch_abc123');
|
|
722
|
+
*/
|
|
723
|
+
async clearPaymentMethod(id) {
|
|
724
|
+
return this.http.call(
|
|
725
|
+
(signal) => this.http.client.DELETE(`/api/scheduled-charges/${id}/payment-method`, {
|
|
726
|
+
signal
|
|
727
|
+
}).then((r) => r)
|
|
728
|
+
);
|
|
729
|
+
}
|
|
650
730
|
};
|
|
651
731
|
var webhooks = {
|
|
652
732
|
verify(params) {
|