@garuhq/node 0.16.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/CHANGELOG.md +99 -0
- package/README.md +15 -14
- package/dist/index.cjs +362 -70
- package/dist/index.d.cts +519 -95
- package/dist/index.d.ts +519 -95
- package/dist/index.js +362 -70
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -98,15 +98,13 @@ declare class HttpClient {
|
|
|
98
98
|
* The resource layer maps friendly → wire at the edge.
|
|
99
99
|
*/
|
|
100
100
|
|
|
101
|
-
type PaymentMethod = 'pix' | 'credit_card' | 'boleto';
|
|
102
101
|
/**
|
|
103
|
-
*
|
|
104
|
-
* (
|
|
105
|
-
*
|
|
106
|
-
* `
|
|
102
|
+
* Stable, friendly charge status. Mirrors what /api/v1/charges returns — the
|
|
103
|
+
* raw processor statuses (payedPix, pendingBoleto, …) are normalized server-side
|
|
104
|
+
* and never surface here. Act on `paid`; `authorized` is card money held but not
|
|
105
|
+
* captured, `refund_pending` is a Pix devolução requested but not yet settled.
|
|
107
106
|
*/
|
|
108
|
-
type
|
|
109
|
-
type ChargeStatus = 'pending' | 'authorized' | 'paid' | 'failed' | 'refunded' | 'cancelled' | 'expired';
|
|
107
|
+
type ChargeStatus = 'pending' | 'authorized' | 'paid' | 'failed' | 'expired' | 'canceled' | 'refund_pending' | 'refunded' | 'chargeback';
|
|
110
108
|
interface Customer {
|
|
111
109
|
/** Full legal name. 3–255 chars. */
|
|
112
110
|
name: string;
|
|
@@ -125,78 +123,122 @@ interface Customer {
|
|
|
125
123
|
/** 2-letter uppercase state code, e.g. `SP`. */
|
|
126
124
|
state?: string;
|
|
127
125
|
}
|
|
128
|
-
interface
|
|
129
|
-
/** 13
|
|
130
|
-
|
|
131
|
-
/**
|
|
132
|
-
cvv: string;
|
|
133
|
-
/** `YYYY-MM`. */
|
|
134
|
-
expirationDate: string;
|
|
135
|
-
/** As printed on the card. */
|
|
126
|
+
interface CardInput {
|
|
127
|
+
/** PAN, 13-19 digits, no spaces. Server-to-server only (PCI scope). */
|
|
128
|
+
number: string;
|
|
129
|
+
/** Holder name exactly as printed. */
|
|
136
130
|
holderName: string;
|
|
137
|
-
/**
|
|
131
|
+
/** Expiry as `YYYY-MM`. */
|
|
132
|
+
expirationDate: string;
|
|
133
|
+
/** 3 or 4 digits. Never stored by Garu. */
|
|
134
|
+
cvv: string;
|
|
135
|
+
/** 1-12. */
|
|
138
136
|
installments: number;
|
|
139
137
|
}
|
|
140
138
|
interface CreateChargeParams {
|
|
141
|
-
/** Customer buying the product. */
|
|
142
|
-
customer: Customer;
|
|
143
139
|
/** UUID of the product being charged. */
|
|
144
140
|
productId: string;
|
|
145
141
|
/** Payment method. */
|
|
146
|
-
paymentMethod:
|
|
147
|
-
/**
|
|
148
|
-
|
|
149
|
-
/** Free-form metadata attached to the charge. */
|
|
150
|
-
additionalInfo?: string;
|
|
151
|
-
/** Original checkout link, if any. */
|
|
152
|
-
link?: string | null;
|
|
153
|
-
/** Associated affiliate ID, if any. */
|
|
154
|
-
affiliateId?: number | null;
|
|
155
|
-
/** Subscription price ID (`price_*`), for subscription charges only. */
|
|
156
|
-
priceId?: string | null;
|
|
157
|
-
/** Optional pre-created checkout session token. */
|
|
158
|
-
checkoutSessionToken?: string;
|
|
142
|
+
paymentMethod: ChargePaymentMethod;
|
|
143
|
+
/** Customer buying the product. */
|
|
144
|
+
customer: Customer;
|
|
159
145
|
/**
|
|
160
|
-
*
|
|
161
|
-
*
|
|
146
|
+
* Required when `paymentMethod` is `creditCard`. This is a raw PAN + CVV, so
|
|
147
|
+
* call the SDK only from your server, never a browser or app — it puts you in
|
|
148
|
+
* PCI DSS scope.
|
|
162
149
|
*/
|
|
150
|
+
card?: CardInput;
|
|
151
|
+
/** Optional pre-created checkout session token, for attribution. */
|
|
152
|
+
checkoutSessionToken?: string;
|
|
153
|
+
/** Free-form metadata attached to the charge. */
|
|
154
|
+
additionalInfo?: string;
|
|
155
|
+
/** Idempotency key. If omitted, the SDK generates a UUIDv4. Valid 24h. */
|
|
163
156
|
idempotencyKey?: string;
|
|
164
157
|
}
|
|
158
|
+
type ChargePaymentMethod = 'pix' | 'boleto' | 'creditCard';
|
|
165
159
|
interface Charge {
|
|
166
|
-
id
|
|
160
|
+
/** Public identifier. Use this everywhere; there is no numeric id. */
|
|
161
|
+
uuid: string;
|
|
167
162
|
status: ChargeStatus;
|
|
163
|
+
paymentMethod: ChargePaymentMethod;
|
|
164
|
+
/** Product base price, in decimal BRL / reais. */
|
|
168
165
|
amount: number;
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
166
|
+
/**
|
|
167
|
+
* What the customer is actually charged, in reais. Equals `amount` for PIX,
|
|
168
|
+
* boleto and 1x card; higher for installment card sales (fator markup). Use
|
|
169
|
+
* this to reconcile, not `amount`.
|
|
170
|
+
*/
|
|
171
|
+
chargedTotal: number;
|
|
172
|
+
installments: number;
|
|
173
|
+
product: {
|
|
174
|
+
uuid: string;
|
|
175
|
+
name: string;
|
|
176
|
+
} | null;
|
|
177
|
+
/** `document` is partially masked. */
|
|
178
|
+
customer: {
|
|
179
|
+
name: string;
|
|
180
|
+
email: string;
|
|
181
|
+
document: string;
|
|
182
|
+
} | null;
|
|
183
|
+
/** Present for PIX: the copy-paste EMV code to render as a QR. */
|
|
184
|
+
pix: {
|
|
185
|
+
code: string;
|
|
186
|
+
} | null;
|
|
187
|
+
/** Present for boleto: the barcode line and a Garu-hosted PDF URL. */
|
|
188
|
+
boleto: {
|
|
189
|
+
barcodeLine: string;
|
|
190
|
+
pdfUrl: string;
|
|
191
|
+
} | null;
|
|
192
|
+
/** Present for card: only brand, last4 and the authorization code. */
|
|
193
|
+
card: {
|
|
194
|
+
brand: string | null;
|
|
195
|
+
last4: string | null;
|
|
196
|
+
authorizationCode: string | null;
|
|
197
|
+
} | null;
|
|
198
|
+
/** Set once refunded. `refundedAt` is null while a Pix devolução is unsettled. */
|
|
199
|
+
refund: {
|
|
200
|
+
amount: number;
|
|
201
|
+
reason: string | null;
|
|
202
|
+
refundedAt: string | null;
|
|
203
|
+
} | null;
|
|
172
204
|
/** ISO-8601. */
|
|
173
|
-
|
|
174
|
-
/**
|
|
175
|
-
|
|
176
|
-
id: number;
|
|
177
|
-
uuid?: string;
|
|
178
|
-
name?: string;
|
|
179
|
-
};
|
|
180
|
-
[key: string]: unknown;
|
|
205
|
+
createdAt: string;
|
|
206
|
+
/** ISO-8601. Only set for boleto (due date); null for PIX and card. */
|
|
207
|
+
expiresAt: string | null;
|
|
181
208
|
}
|
|
182
209
|
interface RefundChargeParams {
|
|
183
|
-
/**
|
|
210
|
+
/**
|
|
211
|
+
* Partial refund in **decimal BRL / reais** (e.g. `10.00`) — NOT centavos.
|
|
212
|
+
* Omit for a full refund. Passing `1000` for "R$ 10,00" refunds a thousand
|
|
213
|
+
* reais.
|
|
214
|
+
*
|
|
215
|
+
* For a Pix Automático charge this starts an asynchronous devolução: the
|
|
216
|
+
* charge moves to `refund_pending` and only reaches `refunded` once the
|
|
217
|
+
* transfer settles.
|
|
218
|
+
*/
|
|
184
219
|
amount?: number;
|
|
185
220
|
/** Free-form reason stored on the refund. */
|
|
186
221
|
reason?: string;
|
|
187
|
-
idempotencyKey?: string;
|
|
188
222
|
}
|
|
189
223
|
interface ListChargesParams {
|
|
190
224
|
/** Page number (1-based). Default: 1. */
|
|
191
225
|
page?: number;
|
|
192
|
-
/** Items per page (1
|
|
226
|
+
/** Items per page (1-100). Default: 20. */
|
|
193
227
|
limit?: number;
|
|
194
|
-
/** Filter by status (e.g. `paid`, `pending`). */
|
|
195
|
-
status?:
|
|
228
|
+
/** Filter by friendly status (e.g. `paid`, `pending`). */
|
|
229
|
+
status?: ChargeStatus;
|
|
230
|
+
/** Filter by payment method. */
|
|
231
|
+
paymentMethod?: ChargePaymentMethod;
|
|
232
|
+
/** Filter by product UUID. */
|
|
233
|
+
productId?: string;
|
|
234
|
+
/** Charges created at or after this ISO-8601 instant. */
|
|
235
|
+
createdAfter?: string;
|
|
236
|
+
/** Charges created at or before this ISO-8601 instant. */
|
|
237
|
+
createdBefore?: string;
|
|
196
238
|
/** Search by customer name, email, or document. */
|
|
197
239
|
search?: string;
|
|
198
|
-
/**
|
|
199
|
-
|
|
240
|
+
/** Sort order. Default `-createdAt` (newest first). */
|
|
241
|
+
sort?: 'createdAt' | '-createdAt' | 'amount' | '-amount';
|
|
200
242
|
}
|
|
201
243
|
interface PaginatedList<T> {
|
|
202
244
|
data: T[];
|
|
@@ -207,7 +249,18 @@ interface PaginatedList<T> {
|
|
|
207
249
|
totalPages: number;
|
|
208
250
|
};
|
|
209
251
|
}
|
|
210
|
-
|
|
252
|
+
interface ChargeList {
|
|
253
|
+
data: Charge[];
|
|
254
|
+
/** Items on this page. */
|
|
255
|
+
count: number;
|
|
256
|
+
/** Total matches across all pages. */
|
|
257
|
+
totalCount: number;
|
|
258
|
+
totalPages: number;
|
|
259
|
+
}
|
|
260
|
+
/** Result of cancelling a charge. */
|
|
261
|
+
interface CancelChargeResult {
|
|
262
|
+
canceled: boolean;
|
|
263
|
+
}
|
|
211
264
|
interface CustomerRecord {
|
|
212
265
|
id: number;
|
|
213
266
|
name: string;
|
|
@@ -547,13 +600,6 @@ interface Product {
|
|
|
547
600
|
updatedAt: string;
|
|
548
601
|
[key: string]: unknown;
|
|
549
602
|
}
|
|
550
|
-
/** One entry in a product's credit-card installment breakdown. */
|
|
551
|
-
interface Installment {
|
|
552
|
-
/** Number of parcelas. */
|
|
553
|
-
quantity: number;
|
|
554
|
-
/** Amount charged per installment, in reais (BRL), with the fator markup applied. */
|
|
555
|
-
value: number;
|
|
556
|
-
}
|
|
557
603
|
/**
|
|
558
604
|
* List envelope returned by `products.list()`. Flat (not `{ data, meta }`) —
|
|
559
605
|
* matches the `/api/v1/products` response.
|
|
@@ -812,29 +858,190 @@ interface SetProductPortalConfigParams {
|
|
|
812
858
|
customCancellationMessage?: string | null;
|
|
813
859
|
customWelcomeText?: string | null;
|
|
814
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
|
+
}
|
|
815
1022
|
|
|
816
1023
|
/**
|
|
817
|
-
* Charges —
|
|
1024
|
+
* Charges — create and manage payments against a product.
|
|
818
1025
|
*
|
|
819
|
-
*
|
|
820
|
-
*
|
|
821
|
-
*
|
|
822
|
-
*
|
|
1026
|
+
* Backed by `/api/v1/charges`, the versioned public contract. A charge is keyed
|
|
1027
|
+
* by `uuid`; there is no numeric id. Create returns everything needed to render
|
|
1028
|
+
* a transparent checkout: the PIX EMV (`pix.code`), the boleto line and a
|
|
1029
|
+
* Garu-hosted PDF (`boleto`), or the card authorization (`card`).
|
|
823
1030
|
*/
|
|
824
1031
|
declare class Charges {
|
|
825
1032
|
private readonly http;
|
|
826
1033
|
constructor(http: HttpClient);
|
|
827
1034
|
/**
|
|
828
|
-
* Create a charge (PIX,
|
|
1035
|
+
* Create a charge (PIX, boleto, or credit card).
|
|
829
1036
|
*
|
|
830
|
-
*
|
|
831
|
-
* `idempotencyKey`, the SDK generates a UUIDv4. Safe to retry: the
|
|
832
|
-
*
|
|
1037
|
+
* Attaches an `X-Idempotency-Key` header automatically — if you don't pass
|
|
1038
|
+
* `idempotencyKey`, the SDK generates a UUIDv4. Safe to retry: the same key
|
|
1039
|
+
* returns the original charge for 24h.
|
|
833
1040
|
*
|
|
834
1041
|
* @example
|
|
835
|
-
* // PIX charge
|
|
1042
|
+
* // PIX — render charge.pix.code as a QR in your own checkout
|
|
836
1043
|
* const charge = await garu.charges.create({
|
|
837
|
-
* productId: '
|
|
1044
|
+
* productId: 'a1b2c3d4-e5f6-7890-abcd-ef1234567890',
|
|
838
1045
|
* paymentMethod: 'pix',
|
|
839
1046
|
* customer: {
|
|
840
1047
|
* name: 'Maria Silva',
|
|
@@ -843,53 +1050,266 @@ declare class Charges {
|
|
|
843
1050
|
* phone: '11987654321'
|
|
844
1051
|
* }
|
|
845
1052
|
* });
|
|
846
|
-
*
|
|
1053
|
+
* console.log(charge.uuid, charge.pix?.code);
|
|
847
1054
|
*
|
|
848
1055
|
* @example
|
|
849
|
-
* // Credit card
|
|
1056
|
+
* // Credit card, 2 installments. Server-to-server only (PCI scope).
|
|
850
1057
|
* const charge = await garu.charges.create({
|
|
851
|
-
* productId: '
|
|
852
|
-
* paymentMethod: '
|
|
1058
|
+
* productId: 'a1b2c3d4-e5f6-7890-abcd-ef1234567890',
|
|
1059
|
+
* paymentMethod: 'creditCard',
|
|
853
1060
|
* customer: { name: 'Maria Silva', email: 'maria@exemplo.com.br', document: '12345678909', phone: '11987654321' },
|
|
854
|
-
*
|
|
855
|
-
*
|
|
856
|
-
* cvv: '123',
|
|
857
|
-
* expirationDate: '2030-12',
|
|
1061
|
+
* card: {
|
|
1062
|
+
* number: '4111111111111111',
|
|
858
1063
|
* holderName: 'MARIA SILVA',
|
|
859
|
-
*
|
|
1064
|
+
* expirationDate: '2030-12',
|
|
1065
|
+
* cvv: '123',
|
|
1066
|
+
* installments: 2
|
|
860
1067
|
* }
|
|
861
1068
|
* });
|
|
1069
|
+
* // charge.amount is the base price; charge.chargedTotal is what was charged.
|
|
862
1070
|
*/
|
|
863
1071
|
create(params: CreateChargeParams): Promise<Charge>;
|
|
864
1072
|
/**
|
|
865
|
-
*
|
|
1073
|
+
* Retrieve a charge by uuid.
|
|
866
1074
|
*
|
|
867
1075
|
* @example
|
|
868
|
-
* const
|
|
869
|
-
*
|
|
1076
|
+
* const charge = await garu.charges.retrieve('6f1c9b2e-4a7d-4f0b-9a3e-1d2c3b4a5e6f');
|
|
1077
|
+
* if (charge.status === 'paid') fulfil(charge);
|
|
1078
|
+
*/
|
|
1079
|
+
retrieve(uuid: string): Promise<Charge>;
|
|
1080
|
+
/**
|
|
1081
|
+
* List charges for the authenticated account, newest first by default.
|
|
1082
|
+
*
|
|
1083
|
+
* @example
|
|
1084
|
+
* const { data, totalCount } = await garu.charges.list({ status: 'paid', limit: 50 });
|
|
1085
|
+
* console.log(`${data.length} of ${totalCount} paid charges`);
|
|
870
1086
|
*/
|
|
871
1087
|
list(params?: ListChargesParams): Promise<ChargeList>;
|
|
872
1088
|
/**
|
|
873
|
-
*
|
|
1089
|
+
* Refund a charge, fully or partially. `amount` is in reais.
|
|
1090
|
+
*
|
|
1091
|
+
* For a Pix Automático charge the refund is a devolução: it returns with the
|
|
1092
|
+
* charge in `refund_pending`, reaching `refunded` only once the transfer
|
|
1093
|
+
* settles.
|
|
1094
|
+
*
|
|
1095
|
+
* @example
|
|
1096
|
+
* await garu.charges.refund('6f1c9b2e-...'); // full
|
|
1097
|
+
* await garu.charges.refund('6f1c9b2e-...', { amount: 10.0 }); // R$10,00
|
|
1098
|
+
*/
|
|
1099
|
+
refund(uuid: string, params?: RefundChargeParams): Promise<Charge>;
|
|
1100
|
+
/**
|
|
1101
|
+
* Cancel an unpaid charge.
|
|
1102
|
+
*
|
|
1103
|
+
* @example
|
|
1104
|
+
* const { canceled } = await garu.charges.cancel('6f1c9b2e-...');
|
|
1105
|
+
*/
|
|
1106
|
+
cancel(uuid: string): Promise<CancelChargeResult>;
|
|
1107
|
+
private get;
|
|
1108
|
+
private post;
|
|
1109
|
+
}
|
|
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.
|
|
874
1188
|
*
|
|
875
1189
|
* @example
|
|
876
|
-
* const
|
|
877
|
-
* if (
|
|
1190
|
+
* const result = await garu.installmentPlans.reissueInstallment(uuid, 4);
|
|
1191
|
+
* if (result.status === 'emitted') {
|
|
1192
|
+
* send(result.installment!.boleto!.barcodeLine);
|
|
1193
|
+
* }
|
|
878
1194
|
*/
|
|
879
|
-
|
|
1195
|
+
reissueInstallment(uuid: string, number: number): Promise<ReissueInstallmentResult>;
|
|
880
1196
|
/**
|
|
881
|
-
*
|
|
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.
|
|
882
1200
|
*
|
|
883
1201
|
* @example
|
|
884
|
-
*
|
|
885
|
-
*
|
|
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.
|
|
886
1215
|
*
|
|
887
1216
|
* @example
|
|
888
|
-
*
|
|
889
|
-
*
|
|
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
|
+
* });
|
|
890
1311
|
*/
|
|
891
|
-
|
|
892
|
-
private buildCreateBody;
|
|
1312
|
+
reject(uuid: string, params?: ResolveRefundRequestParams): Promise<RefundRequest>;
|
|
893
1313
|
}
|
|
894
1314
|
|
|
895
1315
|
/**
|
|
@@ -1442,6 +1862,10 @@ interface GaruOptions {
|
|
|
1442
1862
|
*/
|
|
1443
1863
|
declare class Garu {
|
|
1444
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;
|
|
1445
1869
|
readonly customers: Customers;
|
|
1446
1870
|
readonly meta: Meta;
|
|
1447
1871
|
readonly products: Products;
|
|
@@ -1505,4 +1929,4 @@ declare class GaruServerError extends GaruAPIError {
|
|
|
1505
1929
|
constructor(message: string, status: number, requestId: string | null, body: unknown);
|
|
1506
1930
|
}
|
|
1507
1931
|
|
|
1508
|
-
export { type CancelAtPeriodEndScheduledChargeParams, type CancelRecurrenceScheduledChargeParams, type
|
|
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 };
|