@garuhq/node 1.0.0 → 1.1.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.d.cts CHANGED
@@ -600,13 +600,6 @@ interface Product {
600
600
  updatedAt: string;
601
601
  [key: string]: unknown;
602
602
  }
603
- /** One entry in a product's credit-card installment breakdown. */
604
- interface Installment {
605
- /** Number of parcelas. */
606
- quantity: number;
607
- /** Amount charged per installment, in reais (BRL), with the fator markup applied. */
608
- value: number;
609
- }
610
603
  /**
611
604
  * List envelope returned by `products.list()`. Flat (not `{ data, meta }`) —
612
605
  * matches the `/api/v1/products` response.
@@ -865,6 +858,167 @@ interface SetProductPortalConfigParams {
865
858
  customCancellationMessage?: string | null;
866
859
  customWelcomeText?: string | null;
867
860
  }
861
+ type InstallmentPlanStatus = 'pending_activation' | 'active' | 'completed' | 'defaulted' | 'canceled' | 'refunded';
862
+ type InstallmentStatus = 'scheduled' | 'due_today' | 'processing' | 'paid' | 'overdue' | 'failed' | 'canceled';
863
+ /** One entry in a product's credit-card installment breakdown. */
864
+ interface Installment {
865
+ /** Number of parcelas. */
866
+ quantity: number;
867
+ /** Amount charged per installment, in reais (BRL), with the fator markup applied. */
868
+ value: number;
869
+ }
870
+ /** One monthly slip of a carnê. */
871
+ interface Installment {
872
+ /** 1-based position in the plan. */
873
+ number: number;
874
+ amount: number;
875
+ /** YYYY-MM-DD in São Paulo time. */
876
+ dueDate: string;
877
+ status: InstallmentStatus;
878
+ paidAt: string | null;
879
+ /**
880
+ * Null until the slip is registered. Parcelas 2..N are emitted month by
881
+ * month, so most of a fresh plan has no barcode yet.
882
+ */
883
+ boleto: {
884
+ barcodeLine: string;
885
+ pdfUrl: string;
886
+ } | null;
887
+ reissueCount: number;
888
+ }
889
+ interface InstallmentPlan {
890
+ uuid: string;
891
+ status: InstallmentPlanStatus;
892
+ installments: number;
893
+ installmentsPaid: number;
894
+ /** The cash price the buyer would have paid in one go. */
895
+ baseValue: number;
896
+ /** Interest multiplier snapshotted at sale time; never recomputed. */
897
+ fator: number;
898
+ installmentAmount: number;
899
+ /** `installmentAmount × installments` — what the carnê bills in total. */
900
+ totalScheduled: number;
901
+ /**
902
+ * What has actually cleared. May exceed `totalScheduled` once a bank adds
903
+ * multa or mora, which is why the two are separate fields.
904
+ */
905
+ totalCollected: number;
906
+ firstDueDate: string;
907
+ graceDays: number | null;
908
+ cancelReason: string | null;
909
+ product: {
910
+ uuid: string;
911
+ name: string;
912
+ } | null;
913
+ customer: {
914
+ name: string;
915
+ email: string;
916
+ document: string;
917
+ } | null;
918
+ activatedAt: string | null;
919
+ completedAt: string | null;
920
+ canceledAt: string | null;
921
+ createdAt: string;
922
+ /** Present on retrieve and create; omitted from list responses. */
923
+ installmentsDetail?: Installment[];
924
+ }
925
+ interface InstallmentPlanList {
926
+ data: InstallmentPlan[];
927
+ count: number;
928
+ totalCount: number;
929
+ totalPages: number;
930
+ }
931
+ interface CreateInstallmentPlanParams {
932
+ /** Public uuid of a product with carnê enabled. */
933
+ productId: string;
934
+ /** Numeric customer id, as returned by `garu.customers.create`. */
935
+ customerId: number;
936
+ /** 2..12. One parcela is not a carnê. */
937
+ installments: number;
938
+ /** YYYY-MM-DD. Defaults to today; must be within 90 days. */
939
+ firstDueDate?: string;
940
+ /**
941
+ * The affiliate who made this sale. Fixed at sale time: every later parcela
942
+ * inherits it, so omitting it pays that affiliate nothing for the whole
943
+ * carnê.
944
+ */
945
+ affiliateId?: number;
946
+ /** Auto-generated when omitted. */
947
+ idempotencyKey?: string;
948
+ }
949
+ interface ListInstallmentPlansParams {
950
+ page?: number;
951
+ limit?: number;
952
+ status?: InstallmentPlanStatus | InstallmentPlanStatus[];
953
+ customerId?: number;
954
+ productId?: string;
955
+ /** Filters on the FIRST parcela's due date, which identifies the plan. */
956
+ dueFrom?: string;
957
+ dueTo?: string;
958
+ }
959
+ interface PostponeInstallmentParams {
960
+ /** YYYY-MM-DD. Moves this parcela only; its siblings keep their dates. */
961
+ newDueDate: string;
962
+ }
963
+ interface ReissueInstallmentResult {
964
+ status: string;
965
+ reason: string | null;
966
+ installment: Installment | null;
967
+ }
968
+ interface CancelInstallmentPlanParams {
969
+ note?: string;
970
+ }
971
+ type RefundRequestStatus = 'pending' | 'confirmed' | 'rejected';
972
+ /**
973
+ * A refund Garu has been ASKED to make and has not made. Garu never moves this
974
+ * money: a boleto cannot be reversed and Celcoin exposes no Pix devolução, so
975
+ * the funds already settled to the seller and the return is a bank transfer
976
+ * only they can make.
977
+ */
978
+ interface RefundRequest {
979
+ uuid: string;
980
+ status: RefundRequestStatus;
981
+ /** Amount the seller is being asked to return, in reais. */
982
+ amount: number;
983
+ reason: string | null;
984
+ /** Exactly one of these is set. */
985
+ installmentPlanId: string | null;
986
+ chargeId: string | null;
987
+ requestedBy: {
988
+ type: string;
989
+ id?: number | string | null;
990
+ };
991
+ resolvedBy: {
992
+ type: string;
993
+ id?: number | string | null;
994
+ } | null;
995
+ sellerNote: string | null;
996
+ resolvedAt: string | null;
997
+ createdAt: string;
998
+ }
999
+ interface RefundRequestList {
1000
+ data: RefundRequest[];
1001
+ count: number;
1002
+ totalCount: number;
1003
+ totalPages: number;
1004
+ }
1005
+ interface RequestPlanRefundParams {
1006
+ /** Defaults to everything the carnê has collected. */
1007
+ amount?: number;
1008
+ reason?: string;
1009
+ }
1010
+ interface ListRefundRequestsParams {
1011
+ page?: number;
1012
+ limit?: number;
1013
+ status?: RefundRequestStatus | RefundRequestStatus[];
1014
+ /** Filter by carnê uuid. */
1015
+ planId?: string;
1016
+ /** Filter by charge uuid (Pix and boleto requests). */
1017
+ chargeId?: string;
1018
+ }
1019
+ interface ResolveRefundRequestParams {
1020
+ note?: string;
1021
+ }
868
1022
 
869
1023
  /**
870
1024
  * Charges — create and manage payments against a product.
@@ -954,6 +1108,210 @@ declare class Charges {
954
1108
  private post;
955
1109
  }
956
1110
 
1111
+ /**
1112
+ * Boleto parcelado (carnê) — one product sold as N monthly bank slips.
1113
+ *
1114
+ * This is seller-financed consumer credit, not a card instalment. Nobody
1115
+ * guarantees a boleto: if the buyer stops paying at parcela 4, the seller
1116
+ * keeps four parcelas and loses the rest. Garu emits the slips, chases them
1117
+ * and reports, but carries none of the default risk.
1118
+ *
1119
+ * Only the FIRST boleto exists at creation. The rest are emitted month by
1120
+ * month, and the sale activates when parcela 1 compensates — a plan is not a
1121
+ * sale until the buyer has paid something.
1122
+ */
1123
+ declare class InstallmentPlans {
1124
+ private readonly http;
1125
+ constructor(http: HttpClient);
1126
+ /**
1127
+ * Sell a product as a carnê. Auto-attaches `X-Idempotency-Key` (UUIDv4 if
1128
+ * you don't pass `idempotencyKey`), which matters more here than anywhere
1129
+ * else in the API: this call registers a REAL boleto at the bank, so a
1130
+ * blind retry can put two payable barcodes in one buyer's hands.
1131
+ *
1132
+ * @example
1133
+ * const carne = await garu.installmentPlans.create({
1134
+ * productId: '40381e8e-6ee7-4b8e-9393-766a6e2109d2',
1135
+ * customerId: 4821,
1136
+ * installments: 12
1137
+ * });
1138
+ * // A R$1.200 product at fator 1,30 bills R$130,00 a month:
1139
+ * carne.totalScheduled; // 1560
1140
+ * carne.installmentAmount; // 130
1141
+ * carne.installmentsDetail?.[0]; // parcela 1, with its barcode
1142
+ *
1143
+ * @example
1144
+ * // Attribute the sale to an affiliate. Fixed at sale time: every later
1145
+ * // parcela inherits it, so omitting it pays them nothing for the whole
1146
+ * // carnê. The affiliate must already be active on this product.
1147
+ * await garu.installmentPlans.create({
1148
+ * productId: '40381e8e-6ee7-4b8e-9393-766a6e2109d2',
1149
+ * customerId: 4821,
1150
+ * installments: 6,
1151
+ * firstDueDate: '2026-10-05',
1152
+ * affiliateId: 5
1153
+ * });
1154
+ */
1155
+ create(params: CreateInstallmentPlanParams): Promise<InstallmentPlan>;
1156
+ /**
1157
+ * List carnês, newest first. `dueFrom`/`dueTo` filter on the FIRST
1158
+ * parcela's due date, which is what identifies the plan; filtering on every
1159
+ * parcela would return one carnê twelve times.
1160
+ *
1161
+ * @example
1162
+ * const atRisk = await garu.installmentPlans.list({ status: 'defaulted' });
1163
+ *
1164
+ * @example
1165
+ * const live = await garu.installmentPlans.list({
1166
+ * status: ['active', 'pending_activation'],
1167
+ * customerId: 4821,
1168
+ * limit: 50
1169
+ * });
1170
+ */
1171
+ list(params?: ListInstallmentPlansParams): Promise<InstallmentPlanList>;
1172
+ /**
1173
+ * Retrieve one carnê with every parcela: due date, status, barcode line and
1174
+ * boleto PDF.
1175
+ *
1176
+ * @example
1177
+ * const carne = await garu.installmentPlans.get(uuid);
1178
+ * const unpaid = carne.installmentsDetail?.filter((i) => i.status !== 'paid');
1179
+ * carne.totalCollected; // what has actually cleared, not what was billed
1180
+ */
1181
+ get(uuid: string): Promise<InstallmentPlan>;
1182
+ /**
1183
+ * Issue a segunda via for one parcela, once the current slip has expired.
1184
+ *
1185
+ * A boleto stays payable at any bank until its due date plus five days, so
1186
+ * Garu refuses while the old barcode is still live — two live barcodes for
1187
+ * one parcela is how a buyer pays it twice. Once per parcela per day.
1188
+ *
1189
+ * @example
1190
+ * const result = await garu.installmentPlans.reissueInstallment(uuid, 4);
1191
+ * if (result.status === 'emitted') {
1192
+ * send(result.installment!.boleto!.barcodeLine);
1193
+ * }
1194
+ */
1195
+ reissueInstallment(uuid: string, number: number): Promise<ReissueInstallmentResult>;
1196
+ /**
1197
+ * Move one parcela to a later date. Its siblings keep theirs — this
1198
+ * postpones a payment, it does not restructure the carnê. A slip already
1199
+ * emitted stays payable on its original date until it expires.
1200
+ *
1201
+ * @example
1202
+ * await garu.installmentPlans.postponeInstallment(uuid, 4, {
1203
+ * newDueDate: '2026-12-20'
1204
+ * });
1205
+ */
1206
+ postponeInstallment(uuid: string, number: number, params: PostponeInstallmentParams): Promise<Installment>;
1207
+ /**
1208
+ * Record a parcela as paid, for when the buyer paid the slip but the
1209
+ * webhook never arrived.
1210
+ *
1211
+ * Garu asks the provider to confirm the charge really compensated before
1212
+ * recording it, because this settles the transaction and pays affiliate and
1213
+ * co-producer commissions. A provider outage refuses the action rather than
1214
+ * trusting the assertion.
1215
+ *
1216
+ * @example
1217
+ * const parcela = await garu.installmentPlans.markInstallmentPaid(uuid, 3);
1218
+ * parcela.status; // 'paid'
1219
+ */
1220
+ markInstallmentPaid(uuid: string, number: number): Promise<Installment>;
1221
+ /**
1222
+ * Cancel the carnê. Emission and reminders stop and open slips are
1223
+ * cancelled at the provider.
1224
+ *
1225
+ * Money already collected is NOT returned — open a refund request for that.
1226
+ * A cancelled carnê is never revived by a late payment; that money opens a
1227
+ * refund request instead.
1228
+ *
1229
+ * @example
1230
+ * await garu.installmentPlans.cancel(uuid, { note: 'Comprador desistiu' });
1231
+ */
1232
+ cancel(uuid: string, params?: CancelInstallmentPlanParams): Promise<InstallmentPlan>;
1233
+ /**
1234
+ * Ask for this carnê to be refunded.
1235
+ *
1236
+ * Garu does NOT move the money. A boleto cannot be reversed and the funds
1237
+ * already settled to you, so this records the request and notifies your
1238
+ * team. Transfer the money to the buyer yourself, then close it with
1239
+ * `garu.refundRequests.confirm`.
1240
+ *
1241
+ * @example
1242
+ * const request = await garu.installmentPlans.requestRefund(uuid, {
1243
+ * reason: 'Produto não entregue'
1244
+ * });
1245
+ * request.status; // 'pending' — nothing has moved yet
1246
+ * request.amount; // defaults to everything the carnê collected
1247
+ */
1248
+ requestRefund(uuid: string, params?: RequestPlanRefundParams): Promise<RefundRequest>;
1249
+ }
1250
+
1251
+ /**
1252
+ * Refunds Garu has been asked to make and cannot make for you.
1253
+ *
1254
+ * A boleto cannot be reversed at all, and Celcoin exposes no Pix devolução.
1255
+ * Either way the funds already settled to you, so the return is a bank
1256
+ * transfer only you can make. This resource records the request, notifies
1257
+ * your team, and waits for you to assert the money went back. Garu records
1258
+ * the assertion; it never observes the transfer.
1259
+ *
1260
+ * Card and Woovi Pix never appear here — they have real automated reversals
1261
+ * (`garu.charges.refund`).
1262
+ */
1263
+ declare class RefundRequests {
1264
+ private readonly http;
1265
+ constructor(http: HttpClient);
1266
+ /**
1267
+ * List refund requests, newest first. Covers carnê and Pix/boleto alike.
1268
+ *
1269
+ * @example
1270
+ * // Everything you still owe a buyer.
1271
+ * const owed = await garu.refundRequests.list({ status: 'pending' });
1272
+ * const total = owed.data.reduce((sum, r) => sum + r.amount, 0);
1273
+ *
1274
+ * @example
1275
+ * const forThisCarne = await garu.refundRequests.list({ planId: carne.uuid });
1276
+ */
1277
+ list(params?: ListRefundRequestsParams): Promise<RefundRequestList>;
1278
+ /**
1279
+ * Retrieve one refund request.
1280
+ *
1281
+ * @example
1282
+ * const request = await garu.refundRequests.get(uuid);
1283
+ * request.installmentPlanId ?? request.chargeId; // exactly one is set
1284
+ */
1285
+ get(uuid: string): Promise<RefundRequest>;
1286
+ /**
1287
+ * Record that you returned the money. Call this AFTER transferring it.
1288
+ *
1289
+ * Confirming closes a carnê as refunded, stops remaining parcelas, cancels
1290
+ * open slips at the provider and claws back the affiliate and co-producer
1291
+ * commissions on the parcelas that cleared. For a Pix or boleto charge it
1292
+ * marks the charge reversed and fires `transaction.refunded`. Idempotent:
1293
+ * confirming twice does not claw back twice.
1294
+ *
1295
+ * @example
1296
+ * // 1. You send the money to the buyer, out of band.
1297
+ * // 2. Then tell Garu it happened.
1298
+ * await garu.refundRequests.confirm(uuid, {
1299
+ * note: 'Pix devolvido em 14/08, e2e E12345678'
1300
+ * });
1301
+ */
1302
+ confirm(uuid: string, params?: ResolveRefundRequestParams): Promise<RefundRequest>;
1303
+ /**
1304
+ * Decline the request. The carnê is untouched and keeps running.
1305
+ * Idempotent.
1306
+ *
1307
+ * @example
1308
+ * await garu.refundRequests.reject(uuid, {
1309
+ * note: 'Produto entregue e retirado na loja em 02/08'
1310
+ * });
1311
+ */
1312
+ reject(uuid: string, params?: ResolveRefundRequestParams): Promise<RefundRequest>;
1313
+ }
1314
+
957
1315
  /**
958
1316
  * Customers — manage your customer base.
959
1317
  *
@@ -1504,6 +1862,10 @@ interface GaruOptions {
1504
1862
  */
1505
1863
  declare class Garu {
1506
1864
  readonly charges: Charges;
1865
+ /** Boleto parcelado (carnê): one product sold as N monthly bank slips. */
1866
+ readonly installmentPlans: InstallmentPlans;
1867
+ /** Refunds Garu has been asked to make and cannot make for you. */
1868
+ readonly refundRequests: RefundRequests;
1507
1869
  readonly customers: Customers;
1508
1870
  readonly meta: Meta;
1509
1871
  readonly products: Products;
@@ -1567,4 +1929,4 @@ declare class GaruServerError extends GaruAPIError {
1567
1929
  constructor(message: string, status: number, requestId: string | null, body: unknown);
1568
1930
  }
1569
1931
 
1570
- export { type CancelAtPeriodEndScheduledChargeParams, type CancelChargeResult, type CancelRecurrenceScheduledChargeParams, type CardInput, type ChangePaymentMethodScheduledChargeParams, type Charge, type ChargeList, type ChargeNowOutcome, type ChargeNowReason, type ChargeNowResult, type ChargePaymentMethod, type ChargeStatus, type CreateChargeParams, type CreateCustomerParams, type CreateProductParams, type CreateScheduledChargeParams, type Customer, type CustomerList, type CustomerRecord, type FailurePayload, Garu, GaruAPIError, GaruAuthenticationError, GaruConnectionError, GaruError, type GaruErrorCode, type GaruFailureCode, GaruNotFoundError, type GaruOptions, GaruPermissionError, GaruRateLimitError, GaruServerError, GaruSignatureVerificationError, GaruValidationError, type ListChargesParams, type ListCustomersParams, type ListProductsParams, type ListScheduledChargeAttemptsParams, type ListScheduledChargesParams, type ListWebhookEventsParams, type MarkPaidScheduledChargeParams, type MetaFeatures, type MetaResponse, type PaginatedList, type PauseScheduledChargeParams, type PaymentMethodExpiredPayload, type PaymentMethodExpiringPayload, type PostponeScheduledChargeParams, type Product, type ProductList, type ProductPortalConfig, type RecurrenceConfig, type RecurrenceInterval, type RefundChargeParams, type ResendWebhookEventParams, type ScheduledChargeActor, type ScheduledChargeAttempt, type ScheduledChargeAttemptList, type ScheduledChargeAttemptSource, type ScheduledChargeAttemptStatus, type ScheduledChargeDetail, type ScheduledChargeEvent, type ScheduledChargeEventType, type ScheduledChargeLinkedTransaction, type ScheduledChargeList, type ScheduledChargeRecord, type ScheduledChargeStatus, type ScheduledChargeType, type ScheduledPaymentMethod, type SetProductPortalConfigParams, type UpdateCustomerParams, type UpdateProductParams, type VerifiedWebhook, type VerifyWebhookParams, type WebhookEvent, type WebhookEventEndpoint, type WebhookEventList, type WebhookEventStatus, webhooks };
1932
+ export { type CancelAtPeriodEndScheduledChargeParams, type CancelChargeResult, type CancelInstallmentPlanParams, type CancelRecurrenceScheduledChargeParams, type CardInput, type ChangePaymentMethodScheduledChargeParams, type Charge, type ChargeList, type ChargeNowOutcome, type ChargeNowReason, type ChargeNowResult, type ChargePaymentMethod, type ChargeStatus, type CreateChargeParams, type CreateCustomerParams, type CreateInstallmentPlanParams, type CreateProductParams, type CreateScheduledChargeParams, type Customer, type CustomerList, type CustomerRecord, type FailurePayload, Garu, GaruAPIError, GaruAuthenticationError, GaruConnectionError, GaruError, type GaruErrorCode, type GaruFailureCode, GaruNotFoundError, type GaruOptions, GaruPermissionError, GaruRateLimitError, GaruServerError, GaruSignatureVerificationError, GaruValidationError, type Installment, type InstallmentPlan, type InstallmentPlanList, type InstallmentPlanStatus, type InstallmentStatus, type ListChargesParams, type ListCustomersParams, type ListInstallmentPlansParams, type ListProductsParams, type ListRefundRequestsParams, type ListScheduledChargeAttemptsParams, type ListScheduledChargesParams, type ListWebhookEventsParams, type MarkPaidScheduledChargeParams, type MetaFeatures, type MetaResponse, type PaginatedList, type PauseScheduledChargeParams, type PaymentMethodExpiredPayload, type PaymentMethodExpiringPayload, type PostponeInstallmentParams, type PostponeScheduledChargeParams, type Product, type ProductList, type ProductPortalConfig, type RecurrenceConfig, type RecurrenceInterval, type RefundChargeParams, type RefundRequest, type RefundRequestList, type RefundRequestStatus, type ReissueInstallmentResult, type RequestPlanRefundParams, type ResendWebhookEventParams, type ResolveRefundRequestParams, type ScheduledChargeActor, type ScheduledChargeAttempt, type ScheduledChargeAttemptList, type ScheduledChargeAttemptSource, type ScheduledChargeAttemptStatus, type ScheduledChargeDetail, type ScheduledChargeEvent, type ScheduledChargeEventType, type ScheduledChargeLinkedTransaction, type ScheduledChargeList, type ScheduledChargeRecord, type ScheduledChargeStatus, type ScheduledChargeType, type ScheduledPaymentMethod, type SetProductPortalConfigParams, type UpdateCustomerParams, type UpdateProductParams, type VerifiedWebhook, type VerifyWebhookParams, type WebhookEvent, type WebhookEventEndpoint, type WebhookEventList, type WebhookEventStatus, webhooks };