@abacatepay/types 0.0.3

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/README.md ADDED
@@ -0,0 +1,112 @@
1
+ <h1 align="center">AbacatePay API Types</h1>
2
+ <p align="center">Tipagens oficiais e helpers modernos para integrar com a API da AbacatePay.</p>
3
+
4
+ <p align="center">
5
+ <a href="https://www.npmjs.com/package/@abacatepay/types"><img src="https://img.shields.io/npm/v/@abacatepay/types" /></a>
6
+ <a href="https://www.npmjs.com/package/@abacatepay/types"><img src="https://img.shields.io/npm/dm/@abacatepay/types" /></a>
7
+ <img src="https://img.shields.io/badge/built%20for-bun%20%26%20node-0b7" />
8
+ <img src="https://img.shields.io/badge/types-TypeScript-3178c6" />
9
+ <img src="https://img.shields.io/badge/license-MIT-lightgray" />
10
+ </p>
11
+
12
+ <h2 align="center">📦 Instalação</h2>
13
+
14
+ ```bash
15
+ npm install @abacatepay/types
16
+ ```
17
+
18
+ <h2 align="center">Como a AbacatePay API Types documenta</h2>
19
+
20
+ Antes de tudo, você deve específicar a versão da API que você deseja importar os tipos. Coloque `/v*` no final da importação, sendo `*` a versão que deseja usar:
21
+
22
+ ```ts
23
+ import { APICustomer } from '@abacatepay/types/v1'
24
+ ```
25
+
26
+ Para tipos globais como `API_BASE_URL`, `API_VERSION`, `version` e `Routes`, apenas import normalmente sem a versão.
27
+
28
+ ```ts
29
+ import { version } from '@abacatepay/types'
30
+ ```
31
+
32
+ - Prefixo `API*`
33
+ Representa estruturas gerais da API (Objetos retornados, modelos internos etc.).
34
+
35
+ - Prefixo `Webhook*`
36
+ Representa payloads recebidos pelos eventos de webhook.
37
+ Documentação: https://docs.abacatepay.com/pages/webhooks
38
+
39
+ - Prefixo `REST<HTTPMethod>*`
40
+ Tipos usados em requisições diretas à API.
41
+ - Sufixo Body → corpo enviado na requisição
42
+ Ex.: `RESTPostCreateNewChargeBody`
43
+
44
+ - Sufixo `QueryParams` → parâmetros de query
45
+ Ex.: `RESTGetCheckQRCodePixStatusQueryParams`
46
+
47
+ - Sufixo `Data` → dados retornados pela API
48
+ Ex.: `RESTGetListCouponsData`
49
+
50
+ - O pacote **NÃO adiciona tipos além do que existe na documentação oficial**.
51
+ Cada tipo reflete exatamente o que está documentado aqui:
52
+ https://docs.abacatepay.com/pages/introduction
53
+
54
+ - Campos marcados com `@unstable`
55
+ São campos que não têm definição formal na documentação, mas cujo tipo foi inferido com base nos exemplos oficiais.
56
+ (Ex.: `WebhookWithdrawDoneEvent.billing.kind`)
57
+
58
+ <h2 align="center">Quickstart</h2>
59
+
60
+ <p align="center"><strong>Crie um novo cupom</strong></p>
61
+
62
+ ```ts
63
+ import {
64
+ API_BASE,
65
+ API_VERSION,
66
+ type APICoupon,
67
+ type RESTPostCreateCouponBody,
68
+ Routes,
69
+ } from '@abacatepay/types/v1';
70
+
71
+ async function createCoupon(body: RESTPostCreateCouponBody) {
72
+ const path = `${API_BASE_URL}/${API_VERSION}/${Routes.createCoupon()}`;
73
+
74
+ const response = await fetch(path, {
75
+ method: 'POST',
76
+ body: JSON.stringify(body),
77
+ });
78
+
79
+ const data: APICoupon = await response.json();
80
+
81
+ return data;
82
+ }
83
+ ```
84
+
85
+ <p align="center"><strong>Crie um servidor e escute eventos de Webhooks do Aabacate</strong></p>
86
+
87
+ ```ts
88
+ import { type WebhookEvent, WebhookEventType } from '@abacatepay/types/v1';
89
+
90
+ Bun.serve({
91
+ routes: {
92
+ async '/webhooks/abacate'(request) {
93
+ const { data, event }: WebhookEvent = await request.json();
94
+
95
+ switch (event) {
96
+ case WebhookEventType.BillingPaid:
97
+ console.log(`Um novo pagamento de ${data.payment.amount} foi feito`);
98
+
99
+ break;
100
+ case WebhookEventType.WithdrawDone:
101
+ console.log(`Um novo saque foi feito ${data.transaction.receiptUrl}`);
102
+
103
+ break;
104
+ case WebhookEventType.WithdrawFailed:
105
+ console.log(`O saque com o ID ${data.transaction.id} falhou`);
106
+ }
107
+
108
+ return new Response('OK');
109
+ },
110
+ },
111
+ });
112
+ ```
@@ -0,0 +1,2 @@
1
+ export { API_BASE_URL, Routes } from './routes';
2
+ export { API_VERSION, version } from './version';
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ export { API_BASE_URL, Routes } from './routes';
2
+ export { API_VERSION, version } from './version';
@@ -0,0 +1,68 @@
1
+ import type { RESTGetCheckQRCodePixStatusQueryParams, RESTGetSearchWithdrawQueryParams, RESTPostSimulatePaymentQueryParams } from './v1/rest';
2
+ export declare const API_BASE_URL = "https://api.abacatepay.com/";
3
+ export declare const Routes: {
4
+ /**
5
+ * POST - https://api.abacatepay.com/v1/customer/create
6
+ */
7
+ createCustomer(): "/customer/create";
8
+ /**
9
+ * GET - https://api.abacatepay.com/v1/customer/list
10
+ */
11
+ listCustomers(): "/customer/list";
12
+ /**
13
+ * POST - https://api.abacatepay.com/v1/billing/create
14
+ */
15
+ createCharge(): "/billing/create";
16
+ /**
17
+ * GET - https://api.abacatepay.com/v1/billing/list
18
+ */
19
+ listCharges(): "/billing/list";
20
+ /**
21
+ * POST - https://api.abacatepay.com/v1/pixQrCode/create
22
+ */
23
+ createPIXQRCode(): "/pixQrCode/create";
24
+ /**
25
+ * POST - https://api.abacatepay.com/v1/pixQrCode/simulate-payment
26
+ */
27
+ simulatePayment({ id }: RESTPostSimulatePaymentQueryParams): `/pixQrCode/simulate-payment?id=${string}`;
28
+ /**
29
+ * GET - https://api.abacatepay.com/v1/pixQrCode/check
30
+ */
31
+ checkQRCodePIXStatus({ id }: RESTGetCheckQRCodePixStatusQueryParams): `/pixQrCode/check?id=${string}`;
32
+ /**
33
+ * POST - https://api.abacatepay.com/v1/coupon/create
34
+ */
35
+ createCoupon(): "/coupon/create";
36
+ /**
37
+ * GET - https://api.abacatepay.com/v1/coupon/list
38
+ */
39
+ listCoupons(): "/coupon/list";
40
+ /**
41
+ * POST - https://api.abacatepay.com/v1/withdraw/create
42
+ */
43
+ createWithdraw(): "/withdraw/create";
44
+ /**
45
+ * GET - https://api.abacatepay.com/v1/withdraw/get
46
+ */
47
+ getWithdraw({ externalId }: RESTGetSearchWithdrawQueryParams): `/withdraw/get?externalId=${string}`;
48
+ /**
49
+ * GET - https://api.abacatepay.com/v1/withdraw/list
50
+ */
51
+ listWithdraw(): "/withdraw/list";
52
+ /**
53
+ * GET - https://api.abacatepay.com/v1/store/get
54
+ */
55
+ store(): "/store/get";
56
+ /**
57
+ * GET - https://api.abacatepay.com/v1/public-mrr/mrr
58
+ */
59
+ getMRR(): "/public-mrr/mrr";
60
+ /**
61
+ * GET - https://api.abacatepay.com/v1/public-mrr/merchant-info
62
+ */
63
+ merchant(): "/public-mrr/merchant-info";
64
+ /**
65
+ * GET - https://api.abacatepay.com/v1/public-mrr/renevue
66
+ */
67
+ renevue(): "/public-mrr/revenue";
68
+ };
package/dist/routes.js ADDED
@@ -0,0 +1,99 @@
1
+ export const API_BASE_URL = 'https://api.abacatepay.com/';
2
+ export const Routes = {
3
+ /**
4
+ * POST - https://api.abacatepay.com/v1/customer/create
5
+ */
6
+ createCustomer() {
7
+ return '/customer/create';
8
+ },
9
+ /**
10
+ * GET - https://api.abacatepay.com/v1/customer/list
11
+ */
12
+ listCustomers() {
13
+ return '/customer/list';
14
+ },
15
+ /**
16
+ * POST - https://api.abacatepay.com/v1/billing/create
17
+ */
18
+ createCharge() {
19
+ return '/billing/create';
20
+ },
21
+ /**
22
+ * GET - https://api.abacatepay.com/v1/billing/list
23
+ */
24
+ listCharges() {
25
+ return '/billing/list';
26
+ },
27
+ /**
28
+ * POST - https://api.abacatepay.com/v1/pixQrCode/create
29
+ */
30
+ createPIXQRCode() {
31
+ return '/pixQrCode/create';
32
+ },
33
+ /**
34
+ * POST - https://api.abacatepay.com/v1/pixQrCode/simulate-payment
35
+ */
36
+ simulatePayment({ id }) {
37
+ return `/pixQrCode/simulate-payment?id=${id}`;
38
+ },
39
+ /**
40
+ * GET - https://api.abacatepay.com/v1/pixQrCode/check
41
+ */
42
+ checkQRCodePIXStatus({ id }) {
43
+ return `/pixQrCode/check?id=${id}`;
44
+ },
45
+ /**
46
+ * POST - https://api.abacatepay.com/v1/coupon/create
47
+ */
48
+ createCoupon() {
49
+ return '/coupon/create';
50
+ },
51
+ /**
52
+ * GET - https://api.abacatepay.com/v1/coupon/list
53
+ */
54
+ listCoupons() {
55
+ return '/coupon/list';
56
+ },
57
+ /**
58
+ * POST - https://api.abacatepay.com/v1/withdraw/create
59
+ */
60
+ createWithdraw() {
61
+ return '/withdraw/create';
62
+ },
63
+ /**
64
+ * GET - https://api.abacatepay.com/v1/withdraw/get
65
+ */
66
+ getWithdraw({ externalId }) {
67
+ return `/withdraw/get?externalId=${externalId}`;
68
+ },
69
+ /**
70
+ * GET - https://api.abacatepay.com/v1/withdraw/list
71
+ */
72
+ listWithdraw() {
73
+ return '/withdraw/list';
74
+ },
75
+ /**
76
+ * GET - https://api.abacatepay.com/v1/store/get
77
+ */
78
+ store() {
79
+ return '/store/get';
80
+ },
81
+ /**
82
+ * GET - https://api.abacatepay.com/v1/public-mrr/mrr
83
+ */
84
+ getMRR() {
85
+ return '/public-mrr/mrr';
86
+ },
87
+ /**
88
+ * GET - https://api.abacatepay.com/v1/public-mrr/merchant-info
89
+ */
90
+ merchant() {
91
+ return '/public-mrr/merchant-info';
92
+ },
93
+ /**
94
+ * GET - https://api.abacatepay.com/v1/public-mrr/renevue
95
+ */
96
+ renevue() {
97
+ return '/public-mrr/revenue';
98
+ },
99
+ };
@@ -0,0 +1,134 @@
1
+ import type { APICoupon } from './coupon';
2
+ import type { APICustomer } from './customer';
3
+ /**
4
+ * https://docs.abacatepay.com/pages/payment/reference#estrutura
5
+ */
6
+ export interface APICharge {
7
+ /**
8
+ * Unique billing ID at AbacatePay.
9
+ */
10
+ id: string;
11
+ /**
12
+ * Billing frequency. It can be `ONE_TIME` or `MULTIPLE_PAYMENTS`.
13
+ *
14
+ * @see {@link PaymentFrequency}
15
+ */
16
+ frequency: PaymentFrequency;
17
+ /**
18
+ * URL for your customer to make payment for the charge.
19
+ */
20
+ url: string;
21
+ /**
22
+ * Billing status. Can be `PENDING`, `EXPIRED`, `CANCELLED`, `PAID`, `REFUNDED`.
23
+ *
24
+ * @see {@link PaymentStatus}
25
+ */
26
+ status: PaymentStatus;
27
+ /**
28
+ * Indicates whether the charge was created in a development (true) or production (false) environment.
29
+ */
30
+ devMode: boolean;
31
+ /**
32
+ * Supported payment types: `PIX` and `CARD` (beta).
33
+ *
34
+ * @see {@link PaymentMethod}
35
+ */
36
+ methods: PaymentMethod[];
37
+ /**
38
+ * List of products included in the charge.
39
+ */
40
+ products: APIProduct[];
41
+ /**
42
+ * Customer you are billing. Optional. See structure reference [here](https://docs.abacatepay.com/pages/payment/client/reference.mdx).
43
+ */
44
+ customer: APICustomer;
45
+ /**
46
+ * Object with metadata about the charge.
47
+ */
48
+ metadata: {
49
+ /**
50
+ * Fee applied by AbacatePay.
51
+ */
52
+ fee: number;
53
+ /**
54
+ * URL that the customer will be redirected to when clicking the “back” button.
55
+ */
56
+ returnUrl: string;
57
+ /**
58
+ * URL that the customer will be redirected to when making payment.
59
+ */
60
+ completionUrl: string;
61
+ };
62
+ /**
63
+ * Date and time of next charge, or null for one-time charges.
64
+ */
65
+ nextBilling: string | null;
66
+ /**
67
+ * Whether or not to allow coupons for billing.
68
+ */
69
+ allowCoupons: boolean | null;
70
+ /**
71
+ * Coupons allowed in billing. Coupons are only considered if `allowCoupons` is true.
72
+ */
73
+ coupons: APICoupon[];
74
+ /**
75
+ * Charge creation date and time.
76
+ */
77
+ createdAt: string;
78
+ /**
79
+ * Charge last updated date and time.
80
+ */
81
+ updatedAt: string;
82
+ }
83
+ export interface APIProduct {
84
+ /**
85
+ * The product id on your system. We use this id to create your product on AbacatePay automatically, so make sure your id is unique.
86
+ *
87
+ * @example "prod-1234"
88
+ */
89
+ externalId: string;
90
+ /**
91
+ * Product name.
92
+ *
93
+ * @example "Assinatura de Programa Fitness"
94
+ */
95
+ name: string;
96
+ /**
97
+ * Quantity of product being purchased.
98
+ *
99
+ * @example 2
100
+ */
101
+ quantity: number;
102
+ /**
103
+ * Price per unit of product in cents. The minimum is 100 (1 BRL).
104
+ */
105
+ price: number;
106
+ /**
107
+ * Detailed product description.
108
+ */
109
+ description?: string;
110
+ }
111
+ /**
112
+ * https://docs.abacatepay.com/pages/payment/reference#atributos
113
+ */
114
+ export declare enum PaymentStatus {
115
+ Pending = "PENDING",
116
+ Expired = "EXPIRED",
117
+ Cancelled = "CANCELLED",
118
+ Paid = "PAID",
119
+ Refunded = "REFUNDED"
120
+ }
121
+ /**
122
+ * https://docs.abacatepay.com/pages/payment/create#body-methods
123
+ */
124
+ export declare enum PaymentMethod {
125
+ Pix = "PIX",
126
+ Card = "CARD"
127
+ }
128
+ /**
129
+ * https://docs.abacatepay.com/pages/payment/create#body-frequency
130
+ */
131
+ export declare enum PaymentFrequency {
132
+ OneTime = "ONE_TIME",
133
+ Multiple = "MULTIPLE_PAYMENTS"
134
+ }
@@ -0,0 +1,27 @@
1
+ /**
2
+ * https://docs.abacatepay.com/pages/payment/reference#atributos
3
+ */
4
+ export var PaymentStatus;
5
+ (function (PaymentStatus) {
6
+ PaymentStatus["Pending"] = "PENDING";
7
+ PaymentStatus["Expired"] = "EXPIRED";
8
+ PaymentStatus["Cancelled"] = "CANCELLED";
9
+ PaymentStatus["Paid"] = "PAID";
10
+ PaymentStatus["Refunded"] = "REFUNDED";
11
+ })(PaymentStatus || (PaymentStatus = {}));
12
+ /**
13
+ * https://docs.abacatepay.com/pages/payment/create#body-methods
14
+ */
15
+ export var PaymentMethod;
16
+ (function (PaymentMethod) {
17
+ PaymentMethod["Pix"] = "PIX";
18
+ PaymentMethod["Card"] = "CARD";
19
+ })(PaymentMethod || (PaymentMethod = {}));
20
+ /**
21
+ * https://docs.abacatepay.com/pages/payment/create#body-frequency
22
+ */
23
+ export var PaymentFrequency;
24
+ (function (PaymentFrequency) {
25
+ PaymentFrequency["OneTime"] = "ONE_TIME";
26
+ PaymentFrequency["Multiple"] = "MULTIPLE_PAYMENTS";
27
+ })(PaymentFrequency || (PaymentFrequency = {}));
@@ -0,0 +1,56 @@
1
+ /**
2
+ * https://docs.abacatepay.com/pages/coupon/reference#estrutura
3
+ */
4
+ export interface APICoupon {
5
+ /**
6
+ * Unique coupon code that your customers will use to apply the discount.
7
+ */
8
+ id: string;
9
+ /**
10
+ * Type of discount applied by the coupon.
11
+ */
12
+ discountKind: CouponDiscountKind;
13
+ /**
14
+ * Discount amount. For `PERCENTAGE` use numbers from 1-100 (ex: 10 = 10%). For `FIXED` use the value in cents (ex: 500 = R$5.00).
15
+ */
16
+ discount: number;
17
+ /**
18
+ * Limit on the number of times the coupon can be used. Use `-1` for unlimited coupons or a specific number to limit usage.
19
+ */
20
+ maxRedeems: number;
21
+ /**
22
+ * Counter of how many times the coupon has been used by customers.
23
+ */
24
+ redeemsCount: 0;
25
+ /**
26
+ * Coupon status.
27
+ */
28
+ status: 'ACTIVE' | 'DELETED' | 'DISABLED';
29
+ /**
30
+ * Indicates whether the coupon was created in a development (true) or production (false) environment.
31
+ */
32
+ devMode: boolean;
33
+ /**
34
+ * Internal description of the coupon for your organization and control.
35
+ */
36
+ notes?: string;
37
+ /**
38
+ * Coupon creation date and time.
39
+ */
40
+ createdAt: string;
41
+ /**
42
+ * Coupon last updated date and time.
43
+ */
44
+ updatedAt: string;
45
+ /**
46
+ * Object to store additional information about the coupon, such as campaign, category, or other data relevant to your organization.
47
+ */
48
+ metadata?: Record<string, unknown>;
49
+ }
50
+ /**
51
+ * https://docs.abacatepay.com/pages/coupon/reference#atributos
52
+ */
53
+ export declare enum CouponDiscountKind {
54
+ Percentage = "PERCENTAGE",
55
+ Fixed = "FIXED"
56
+ }
@@ -0,0 +1,8 @@
1
+ /**
2
+ * https://docs.abacatepay.com/pages/coupon/reference#atributos
3
+ */
4
+ export var CouponDiscountKind;
5
+ (function (CouponDiscountKind) {
6
+ CouponDiscountKind["Percentage"] = "PERCENTAGE";
7
+ CouponDiscountKind["Fixed"] = "FIXED";
8
+ })(CouponDiscountKind || (CouponDiscountKind = {}));
@@ -0,0 +1,30 @@
1
+ /**
2
+ * https://docs.abacatepay.com/pages/client/reference#estrutura
3
+ */
4
+ export interface APICustomer {
5
+ /**
6
+ * Unique customer identifier.
7
+ */
8
+ id: string;
9
+ /**
10
+ * Customer data.
11
+ */
12
+ metadata: {
13
+ /**
14
+ * Customer's full name.
15
+ */
16
+ name: string;
17
+ /**
18
+ * Customer's email.
19
+ */
20
+ email: string;
21
+ /**
22
+ * Customer's CPF or CNPJ.
23
+ */
24
+ taxId: string;
25
+ /**
26
+ * Customer's cell phone.
27
+ */
28
+ cellphone: string;
29
+ };
30
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,57 @@
1
+ import type { PaymentStatus } from './charge';
2
+ export interface APIQRCodePIX {
3
+ /**
4
+ * Unique billing identifier.
5
+ */
6
+ id: string;
7
+ /**
8
+ * Charge amount in cents (e.g. 4000 = R$40.00).
9
+ */
10
+ amount: number;
11
+ /**
12
+ * Billing status. Can be `PENDING`, `EXPIRED`, `CANCELLED`, `PAID`, `REFUNDED`.
13
+ *
14
+ * @see {@link PaymentStatus}
15
+ */
16
+ status: PaymentStatus;
17
+ /**
18
+ * Indicates whether the charge is in a testing (true) or production (false) environment.
19
+ */
20
+ devMode: boolean;
21
+ /**
22
+ * Payment method.
23
+ */
24
+ method: 'PIX';
25
+ /**
26
+ * PIX code (copy-and-paste) for payment.
27
+ */
28
+ brCode: string;
29
+ /**
30
+ * PIX code in Base64 format (Useful for displaying in images).
31
+ */
32
+ brCodeBase64: string;
33
+ /**
34
+ * Platform fee in cents. Example: 80 means R$0.80.
35
+ */
36
+ platformFee: number;
37
+ /**
38
+ * Payment description.
39
+ */
40
+ description: string;
41
+ /**
42
+ * Payment metadata.
43
+ */
44
+ metadata: Record<string, unknown>;
45
+ /**
46
+ * QRCode PIX creation date and time.
47
+ */
48
+ createdAt: string;
49
+ /**
50
+ * QRCode PIX last updated date and time.
51
+ */
52
+ updatedAt: string;
53
+ /**
54
+ * QRCode expiration date and time.
55
+ */
56
+ expiresAt: string;
57
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,36 @@
1
+ /**
2
+ * https://docs.abacatepay.com/pages/store/reference#estrutura
3
+ */
4
+ export interface APIStore {
5
+ /**
6
+ * Unique identifier for your store on AbacatePay.
7
+ */
8
+ id: string;
9
+ /**
10
+ * Name of your store/company.
11
+ *
12
+ * @example "Minha Loja Online"
13
+ */
14
+ name: string;
15
+ /**
16
+ * Object containing information about your account balances.
17
+ *
18
+ * @remarks All balance values ​​are returned in cents. To convert to Reais, divide by 100. For example: 15000 cents = R$150.00
19
+ */
20
+ balance: {
21
+ /**
22
+ * Balance available for withdrawal in cents.
23
+ */
24
+ available: number;
25
+ /**
26
+ * Balance pending confirmation in cents.
27
+ */
28
+ pending: number;
29
+ /**
30
+ * Balance blocked in disputes in cents.
31
+ *
32
+ * @remarks The blocked balance represents amounts that are in dispute or under review. These amounts are not available for withdrawal until the situation is resolved.
33
+ */
34
+ blocked: number;
35
+ };
36
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,55 @@
1
+ /**
2
+ * https://docs.abacatepay.com/pages/withdraw/reference#estrutura
3
+ */
4
+ export interface APIWithdraw {
5
+ /**
6
+ * Unique ID of the AbacatePay withdrawal transaction.
7
+ */
8
+ id: string;
9
+ /**
10
+ * Current status of the withdrawal transaction.
11
+ */
12
+ status: WithdrawStatus;
13
+ /**
14
+ * Indicates whether the loot was created in a development environment (sandbox) or production. AbacatePay currently only supports withdrawals in production.
15
+ */
16
+ devMode: boolean;
17
+ /**
18
+ * Withdrawal transaction receipt URL.
19
+ */
20
+ receiptUrl: string;
21
+ /**
22
+ * Transaction type. It will always be 'WITHDRAW'.
23
+ */
24
+ kind: 'WITHDRAW';
25
+ /**
26
+ * Withdrawal value in cents.
27
+ */
28
+ amount: number;
29
+ /**
30
+ * Platform fee charged for withdrawal in cents.
31
+ */
32
+ platformFee: number;
33
+ /**
34
+ * Unique identifier of the withdrawal in your system. Optional.
35
+ */
36
+ externalId?: string;
37
+ /**
38
+ * Date and time of withdrawal creation.
39
+ */
40
+ createdAt: string;
41
+ /**
42
+ * Date and time of last withdrawal update.
43
+ */
44
+ updatedAt: string;
45
+ }
46
+ /**
47
+ * https://docs.abacatepay.com/pages/withdraw/reference#atributos
48
+ */
49
+ export declare enum WithdrawStatus {
50
+ Pending = "PENDING",
51
+ Expired = "EXPIRED",
52
+ Cancelled = "CANCELLED",
53
+ Complete = "COMPLETE",
54
+ Refunded = "REFUNDED"
55
+ }
@@ -0,0 +1,11 @@
1
+ /**
2
+ * https://docs.abacatepay.com/pages/withdraw/reference#atributos
3
+ */
4
+ export var WithdrawStatus;
5
+ (function (WithdrawStatus) {
6
+ WithdrawStatus["Pending"] = "PENDING";
7
+ WithdrawStatus["Expired"] = "EXPIRED";
8
+ WithdrawStatus["Cancelled"] = "CANCELLED";
9
+ WithdrawStatus["Complete"] = "COMPLETE";
10
+ WithdrawStatus["Refunded"] = "REFUNDED";
11
+ })(WithdrawStatus || (WithdrawStatus = {}));
@@ -0,0 +1,8 @@
1
+ export * from './entities/charge';
2
+ export * from './entities/coupon';
3
+ export * from './entities/customer';
4
+ export * from './entities/pix';
5
+ export * from './entities/store';
6
+ export * from './entities/withdraw';
7
+ export * from './rest';
8
+ export * from './webhook';
@@ -0,0 +1,8 @@
1
+ export * from './entities/charge';
2
+ export * from './entities/coupon';
3
+ export * from './entities/customer';
4
+ export * from './entities/pix';
5
+ export * from './entities/store';
6
+ export * from './entities/withdraw';
7
+ export * from './rest';
8
+ export * from './webhook';
@@ -0,0 +1,367 @@
1
+ import type { APICharge, APICoupon, APICustomer, APIQRCodePIX, APIStore, APIWithdraw, CouponDiscountKind, PaymentFrequency, PaymentMethod, PaymentStatus } from '.';
2
+ type APIResponse<Data> = {
3
+ /**
4
+ * The data of the response
5
+ */
6
+ data: Data;
7
+ error: null;
8
+ } | {
9
+ data: null;
10
+ /**
11
+ * Error message returned from the API
12
+ */
13
+ error: string;
14
+ };
15
+ /**
16
+ * https://api.abacatepay.com/v1/customer/create
17
+ *
18
+ * @reference https://docs.abacatepay.com/pages/client/create
19
+ */
20
+ export type RESTPostCreateCustomerBody = APICustomer['metadata'];
21
+ /**
22
+ * https://api.abacatepay.com/v1/customer/create
23
+ *
24
+ * @reference https://docs.abacatepay.com/pages/client/create
25
+ */
26
+ export type RESTPostCreateCustomerData = APIResponse<APICustomer>;
27
+ /**
28
+ * https://api.abacatepay.com/v1/billing/create
29
+ *
30
+ * @reference https://docs.abacatepay.com/pages/payment/create
31
+ */
32
+ export interface RESTPostCreateNewChargeBody {
33
+ /**
34
+ * Payment methods that will be used. Currently, only `PIX` is supported, `CARD` is in beta.
35
+ *
36
+ * @see {@link PaymentMethod}
37
+ */
38
+ methods: PaymentMethod[];
39
+ /**
40
+ * Defines the type of billing frequency. For one-time charges, use `ONE_TIME`. For charges that can be paid more than once, use `MULTIPLE_PAYMENTS`.
41
+ *
42
+ * @see {@link PaymentFrequency}
43
+ */
44
+ frequency: PaymentFrequency;
45
+ /**
46
+ * List of products your customer is paying for.
47
+ */
48
+ products: {
49
+ /**
50
+ * The product id on your system. We use this id to create your product on AbacatePay automatically, so make sure your id is unique.
51
+ *
52
+ * @example "prod-1234"
53
+ */
54
+ externalId: string;
55
+ /**
56
+ * Product name.
57
+ *
58
+ * @example "Assinatura de Programa Fitness"
59
+ */
60
+ name: string;
61
+ /**
62
+ * Quantity of product being purchased.
63
+ *
64
+ * @example 2
65
+ */
66
+ quantity: number;
67
+ /**
68
+ * Price per unit of product in cents. The minimum is 100 (1 BRL).
69
+ */
70
+ price: number;
71
+ /**
72
+ * Detailed product description.
73
+ */
74
+ description?: string;
75
+ }[];
76
+ /**
77
+ * URL to redirect the customer if they click on the "Back" option.
78
+ */
79
+ returnUrl: string;
80
+ /**
81
+ * URL to redirect the customer when payment is completed.
82
+ */
83
+ completionUrl: string;
84
+ /**
85
+ * The ID of a customer already registered in your store.
86
+ */
87
+ customerId?: string;
88
+ /**
89
+ * /**
90
+ * Your customer's data to create it.
91
+ * The customer object is not mandatory, but when entering any `customer` information, all `name`, `cellphone`, `email` and `taxId` fields are mandatory.
92
+ */
93
+ customer?: APICustomer['metadata'];
94
+ /**
95
+ * If true coupons can be used in billing.
96
+ *
97
+ * @default false
98
+ */
99
+ allowCoupons?: boolean;
100
+ /**
101
+ * List of coupons available for resem used with billing (0-50 max.).
102
+ */
103
+ coupons?: string[];
104
+ /**
105
+ * If you have a unique identifier for your billing application, completely optional.
106
+ */
107
+ externalId?: string;
108
+ /**
109
+ * Optional billing metadata.
110
+ */
111
+ metadata?: Record<string, unknown>;
112
+ }
113
+ /**
114
+ * https://api.abacatepay.com/v1/billing/create
115
+ *
116
+ * @reference https://docs.abacatepay.com/pages/payment/create
117
+ */
118
+ export type RESTPostCreateNewChargeData = APIResponse<APICharge>;
119
+ /**
120
+ * https://api.abacatepay.com/v1/pixQrCode/create
121
+ *
122
+ * @reference https://docs.abacatepay.com/pages/pix-qrcode/create
123
+ */
124
+ export interface RESTPostCreateQRCodePixBody extends Pick<RESTPostCreateNewChargeBody, 'customer' | 'metadata'> {
125
+ /**
126
+ * Charge amount in cents.
127
+ */
128
+ amount: number;
129
+ /**
130
+ * Billing expiration time in seconds.
131
+ */
132
+ expiresIn?: number;
133
+ /**
134
+ * Message that will appear when paying the PIX.
135
+ */
136
+ description?: string;
137
+ }
138
+ /**
139
+ * https://api.abacatepay.com/v1/pixQrCode/create
140
+ *
141
+ * @reference https://docs.abacatepay.com/pages/pix-qrcode/create
142
+ */
143
+ export type RESTPostCreateQRCodePixData = APIResponse<APIQRCodePIX>;
144
+ /**
145
+ * https://api.abacatepay.com/v1/pixQrCode/simulate-payment
146
+ *
147
+ * @reference https://docs.abacatepay.com/pages/pix-qrcode/simulate-payment
148
+ */
149
+ export interface RESTPostSimulatePaymentQueryParams {
150
+ /**
151
+ * QRCode Pix ID.
152
+ */
153
+ id: string;
154
+ }
155
+ /**
156
+ * https://api.abacatepay.com/v1/pixQrCode/simulate-payment
157
+ *
158
+ * @reference https://docs.abacatepay.com/pages/pix-qrcode/simulate-payment
159
+ */
160
+ export type RESTPostSimulatePaymentData = APIResponse<APIQRCodePIX>;
161
+ /**
162
+ * https://api.abacatepay.com/v1/pixQrCode/check
163
+ *
164
+ * @reference https://docs.abacatepay.com/pages/pix-qrcode/check
165
+ */
166
+ export interface RESTGetCheckQRCodePixStatusQueryParams {
167
+ /**
168
+ * QRCode Pix ID.
169
+ */
170
+ id: string;
171
+ }
172
+ /**
173
+ * https://api.abacatepay.com/v1/pixQrCode/check
174
+ *
175
+ * @reference https://docs.abacatepay.com/pages/pix-qrcode/check
176
+ */
177
+ export type RESTGetCheckQRCodePixStatusData = APIResponse<{
178
+ /**
179
+ * QRCode Pix expiration date.
180
+ */
181
+ expiresAt: string;
182
+ /**
183
+ * Information about the progress of QRCode Pix.
184
+ */
185
+ status: PaymentStatus;
186
+ }>;
187
+ /**
188
+ * https://api.abacatepay.com/v1/billing/list
189
+ *
190
+ * @reference https://docs.abacatepay.com/pages/payment/list
191
+ */
192
+ export type RESTGetListBillingsData = APIResponse<APICharge[]>;
193
+ /**
194
+ * https://api.abacatepay.com/v1/customer/list
195
+ *
196
+ * @reference https://docs.abacatepay.com/pages/client/list
197
+ */
198
+ export type RESTGetListCustomersData = APIResponse<APICustomer[]>;
199
+ /**
200
+ * https://api.abacatepay.com/v1/coupon/create
201
+ *
202
+ * @reference https://docs.abacatepay.com/pages/coupon/create
203
+ */
204
+ export interface RESTPostCreateCouponBody {
205
+ /**
206
+ * Coupon data.
207
+ */
208
+ data: {
209
+ /**
210
+ * Unique coupon identifier.
211
+ *
212
+ * @example "DEYVIN_20"
213
+ */
214
+ code: string;
215
+ /**
216
+ * Discount amount to be applied.
217
+ */
218
+ discount: number;
219
+ /**
220
+ * Type of discount applied, percentage or fixed.
221
+ *
222
+ * @see {@link CouponDiscountKind}
223
+ */
224
+ discountKind: CouponDiscountKind;
225
+ /**
226
+ * Coupon description
227
+ */
228
+ notes?: string;
229
+ /**
230
+ * Number of times the coupon can be redeemed. -1 means this coupon can be redeemed without limits.
231
+ *
232
+ * @default -1
233
+ */
234
+ maxRedeems?: number;
235
+ /**
236
+ * Key value object for coupon metadata.
237
+ */
238
+ metadata?: Record<string, unknown>;
239
+ };
240
+ }
241
+ /**
242
+ * https://api.abacatepay.com/v1/coupon/create
243
+ *
244
+ * @reference https://docs.abacatepay.com/pages/coupon/create
245
+ */
246
+ export type RESTPostCreateCouponData = APIResponse<APICoupon>;
247
+ /**
248
+ * https://api.abacatepay.com/v1/withdraw/create
249
+ *
250
+ * @reference https://docs.abacatepay.com/pages/withdraw/create
251
+ */
252
+ export interface RESTPostCreateNewWithdrawBody {
253
+ /**
254
+ * Unique identifier of the withdrawal in your system.
255
+ */
256
+ externalId: string;
257
+ /**
258
+ * Withdrawal method available.
259
+ */
260
+ method: 'PIX';
261
+ /**
262
+ * Withdrawal value in cents (Min 350).
263
+ */
264
+ amount: number;
265
+ /**
266
+ * PIX key data to receive the withdrawal.
267
+ */
268
+ pix: {
269
+ /**
270
+ * PIX key type.
271
+ */
272
+ type: 'CPF' | 'CNPJ' | 'PHONE' | 'EMAIL' | 'RANDOM' | 'BR_CODE';
273
+ /**
274
+ * PIX key value.
275
+ */
276
+ key: string;
277
+ };
278
+ /**
279
+ * Optional description of the withdrawal.
280
+ */
281
+ description?: string;
282
+ }
283
+ /**
284
+ * https://api.abacatepay.com/v1/withdraw/create
285
+ *
286
+ * @reference https://docs.abacatepay.com/pages/withdraw/create
287
+ */
288
+ export type RESTPostCreateNewWithdrawData = APIResponse<APIWithdraw>;
289
+ /**
290
+ * https://api.abacatepay.com/v1/withdraw/get
291
+ *
292
+ * @reference https://docs.abacatepay.com/pages/withdraw/get
293
+ */
294
+ export interface RESTGetSearchWithdrawQueryParams {
295
+ /**
296
+ * Unique identifier of the withdrawal in your system.
297
+ */
298
+ externalId: string;
299
+ }
300
+ /**
301
+ * https://api.abacatepay.com/v1/public-mrr/revenue
302
+ *
303
+ * @reference https://docs.abacatepay.com/pages/trustMRR/list
304
+ */
305
+ export interface RESTGetRevenueByPeriodQueryParams {
306
+ /**
307
+ * Period start date (YYYY-MM-DD format).
308
+ */
309
+ startDate: string;
310
+ /**
311
+ * Period end date (YYYY-MM-DD format).
312
+ */
313
+ endDate: string;
314
+ }
315
+ /**
316
+ * https://api.abacatepay.com/v1/public-mrr/merchant-info
317
+ *
318
+ * @reference https://docs.abacatepay.com/pages/trustMRR/get
319
+ */
320
+ export type RESTGetMerchantData = APIResponse<{
321
+ /**
322
+ * Store name.
323
+ */
324
+ name: string;
325
+ /**
326
+ * Store website.
327
+ */
328
+ website: string;
329
+ /**
330
+ * Store creation date.
331
+ */
332
+ createdAt: string;
333
+ }>;
334
+ /**
335
+ * https://api.abacatepay.com/v1/public-mrr/mrr
336
+ *
337
+ * @reference https://docs.abacatepay.com/pages/trustMRR/mrr
338
+ */
339
+ export type RESTGetMRRData = APIResponse<{
340
+ /**
341
+ * Monthly recurring revenue in cents. Value 0 indicates that there is no recurring revenue at the moment.
342
+ */
343
+ mrr: number;
344
+ /**
345
+ * Total active subscriptions. Value 0 indicates that there are no currently active subscriptions.
346
+ */
347
+ totalActiveSubscriptions: number;
348
+ }>;
349
+ /**
350
+ * https://api.abacatepay.com/v1/store/get
351
+ *
352
+ * @reference https://docs.abacatepay.com/pages/store/get
353
+ */
354
+ export type RESTGetStoreDetailsData = APIResponse<APIStore>;
355
+ /**
356
+ * https://api.abacatepay.com/v1/withdraw/list
357
+ *
358
+ * @reference https://docs.abacatepay.com/pages/withdraw/list
359
+ */
360
+ export type RESTGetListWithdrawsData = APIResponse<APIWithdraw[]>;
361
+ /**
362
+ * https://api.abacatepay.com/v1/coupon/list
363
+ *
364
+ * @reference https://docs.abacatepay.com/pages/coupon/list
365
+ */
366
+ export type RESTGetListCouponsData = APIResponse<APICoupon[]>;
367
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,161 @@
1
+ import type { APIProduct, PaymentFrequency, PaymentMethod, PaymentStatus } from './entities/charge';
2
+ import type { APICustomer } from './entities/customer';
3
+ import type { APIWithdraw, WithdrawStatus } from './entities/withdraw';
4
+ export interface BaseWebhookEvent<Type extends WebhookEventType, Data extends object> {
5
+ /**
6
+ * The data received in the event.
7
+ */
8
+ data: Data;
9
+ /**
10
+ * Unique identifier for the webhook.
11
+ */
12
+ id: string;
13
+ /**
14
+ * This field identifies the type of event received.
15
+ */
16
+ event: Type;
17
+ /**
18
+ * Indicates whether the event occurred in the development environment.
19
+ */
20
+ devMode: boolean;
21
+ }
22
+ /**
23
+ * https://docs.abacatepay.com/pages/webhooks#withdraw-failed
24
+ */
25
+ export type WebhookWithdrawFailedEvent = BaseWebhookEvent<WebhookEventType.WithdrawFailed, {
26
+ /**
27
+ * Transaction data.
28
+ */
29
+ transaction: Omit<APIWithdraw, 'status'> & {
30
+ /**
31
+ * Status of the withdraw. Always `WithdrawStatus.Cancelled`.
32
+ *
33
+ * @see {@link WithdrawStatus.Cancelled}
34
+ */
35
+ status: WithdrawStatus.Cancelled;
36
+ };
37
+ }>;
38
+ /**
39
+ * https://docs.abacatepay.com/pages/webhooks#withdraw-done
40
+ */
41
+ export type WebhookWithdrawDoneEvent = BaseWebhookEvent<WebhookEventType.WithdrawDone, {
42
+ /**
43
+ * Transaction data.
44
+ */
45
+ transaction: Omit<APIWithdraw, 'status'> & {
46
+ /**
47
+ * Status of the withdraw. Always `WithdrawStatus.Complete`.
48
+ *
49
+ * @see {@link WithdrawStatus.Complete}
50
+ */
51
+ status: WithdrawStatus.Complete;
52
+ };
53
+ }>;
54
+ /**
55
+ * https://docs.abacatepay.com/pages/webhooks#billing-paid
56
+ */
57
+ export type WebhookBillingPaidEvent = BaseWebhookEvent<WebhookEventType.BillingPaid, {
58
+ /**
59
+ * Payment data.
60
+ */
61
+ payment: {
62
+ /**
63
+ * Charge amount in cents (e.g. 4000 = R$40.00).
64
+ */
65
+ amount: number;
66
+ /**
67
+ * The fee charged by AbacatePay.
68
+ */
69
+ fee: 80;
70
+ /**
71
+ * Payment method.
72
+ *
73
+ * @see {@link PaymentMethod}
74
+ */
75
+ method: PaymentMethod;
76
+ };
77
+ } & ({
78
+ pixQrCode: {
79
+ /**
80
+ * Charge amount in cents (e.g. 4000 = R$40.00).
81
+ */
82
+ amount: number;
83
+ /**
84
+ * Unique billing identifier.
85
+ */
86
+ id: string;
87
+ /**
88
+ * Kind of the payment
89
+ */
90
+ kind: 'PIX';
91
+ /**
92
+ * Billing status, can only be `PAID` here
93
+ *
94
+ * @see {@link PaymentStatus.Paid}
95
+ */
96
+ status: PaymentStatus.Paid;
97
+ };
98
+ } | {
99
+ billing: {
100
+ /**
101
+ * Charge amount in cents (e.g. 4000 = R$40.00).
102
+ */
103
+ amount: number;
104
+ /**
105
+ * Counpons used in the billing.
106
+ */
107
+ couponsUsed: string[];
108
+ /**
109
+ * Customer of the charge.
110
+ */
111
+ customer: APICustomer;
112
+ /**
113
+ * Payment frequency.
114
+ *
115
+ * @see {@link PaymentFrequency}
116
+ */
117
+ frequency: PaymentFrequency;
118
+ /**
119
+ * Unique billing identifier.
120
+ */
121
+ id: string;
122
+ /**
123
+ * Payment methods?
124
+ *
125
+ * @unstable
126
+ */
127
+ kind: PaymentMethod[];
128
+ /**
129
+ * Charge amount in cents.
130
+ *
131
+ * @unstable
132
+ */
133
+ paidAmount: number;
134
+ /**
135
+ * Products used in the billing.
136
+ */
137
+ products: (Pick<APIProduct, 'quantity' | 'externalId'> & {
138
+ id: string;
139
+ })[];
140
+ /**
141
+ * Status of the payment. Always `PaymentStatus.Paid`.
142
+ *
143
+ * @see {@link PaymentStatus.Paid}
144
+ */
145
+ status: PaymentStatus.Paid;
146
+ };
147
+ })>;
148
+ /**
149
+ * https://docs.abacatepay.com/pages/webhooks
150
+ *
151
+ * Any field that contains the tag "@unstable" means that the field is an assumption, it is uncertain (Since AbacatePay does not provide any information about).
152
+ */
153
+ export type WebhookEvent = WebhookWithdrawDoneEvent | WebhookWithdrawFailedEvent | WebhookBillingPaidEvent;
154
+ /**
155
+ * https://docs.abacatepay.com/pages/webhooks
156
+ */
157
+ export declare enum WebhookEventType {
158
+ WithdrawFailed = "withdraw.failed",
159
+ WithdrawDone = "withdraw.done",
160
+ BillingPaid = "billing.paid"
161
+ }
@@ -0,0 +1,9 @@
1
+ /**
2
+ * https://docs.abacatepay.com/pages/webhooks
3
+ */
4
+ export var WebhookEventType;
5
+ (function (WebhookEventType) {
6
+ WebhookEventType["WithdrawFailed"] = "withdraw.failed";
7
+ WebhookEventType["WithdrawDone"] = "withdraw.done";
8
+ WebhookEventType["BillingPaid"] = "billing.paid";
9
+ })(WebhookEventType || (WebhookEventType = {}));
@@ -0,0 +1,2 @@
1
+ export declare const version: "0.0.3";
2
+ export declare const API_VERSION: "1";
@@ -0,0 +1,4 @@
1
+ // Auto-generated in build (DO NOT edit)
2
+ export const version = '0.0.3';
3
+ // Current AbacatePay API version - https://docs.abacatepay.com/pages/introduction
4
+ export const API_VERSION = '1';
package/package.json ADDED
@@ -0,0 +1,44 @@
1
+ {
2
+ "version": "0.0.3",
3
+ "name": "@abacatepay/types",
4
+ "description": "Abacate Pay API typings that are always up to date.",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "import": "./dist/index.js",
11
+ "types": "./dist/index.d.ts"
12
+ },
13
+ "./v1": {
14
+ "import": "./dist/v1/index.js",
15
+ "types": "./dist/v1/index.d.ts"
16
+ }
17
+ },
18
+ "typesVersions": {
19
+ "*": {
20
+ "v1": [
21
+ "dist/v1/index.d.ts"
22
+ ]
23
+ }
24
+ },
25
+ "files": [
26
+ "dist"
27
+ ],
28
+ "scripts": {
29
+ "gen:version": "bun run scripts/version.ts",
30
+ "build": "bun run gen:version && tsc",
31
+ "prepublishOnly": "bun run build",
32
+ "fmt": "bunx biome check --write . && clear"
33
+ },
34
+ "devDependencies": {
35
+ "@biomejs/biome": "^2.3.8",
36
+ "typescript": "^5.9.3"
37
+ },
38
+ "keywords": [
39
+ "api",
40
+ "abacatepay",
41
+ "types",
42
+ "typescript"
43
+ ]
44
+ }