better-auth-asaas 0.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/README.md +214 -0
- package/dist/asaas.d.ts +193 -0
- package/dist/asaas.d.ts.map +1 -0
- package/dist/asaas.js +118 -0
- package/dist/asaas.js.map +1 -0
- package/dist/client.d.ts +3 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +7 -0
- package/dist/client.js.map +1 -0
- package/dist/endpoints/customer.d.ts +32 -0
- package/dist/endpoints/customer.d.ts.map +1 -0
- package/dist/endpoints/customer.js +14 -0
- package/dist/endpoints/customer.js.map +1 -0
- package/dist/endpoints/payment.d.ts +335 -0
- package/dist/endpoints/payment.d.ts.map +1 -0
- package/dist/endpoints/payment.js +166 -0
- package/dist/endpoints/payment.js.map +1 -0
- package/dist/endpoints/subscription.d.ts +172 -0
- package/dist/endpoints/subscription.d.ts.map +1 -0
- package/dist/endpoints/subscription.js +158 -0
- package/dist/endpoints/subscription.js.map +1 -0
- package/dist/endpoints/webhook.d.ts +8 -0
- package/dist/endpoints/webhook.d.ts.map +1 -0
- package/dist/endpoints/webhook.js +120 -0
- package/dist/endpoints/webhook.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/plugin.d.ts +652 -0
- package/dist/plugin.d.ts.map +1 -0
- package/dist/plugin.js +72 -0
- package/dist/plugin.js.map +1 -0
- package/dist/schemas.d.ts +139 -0
- package/dist/schemas.d.ts.map +1 -0
- package/dist/schemas.js +112 -0
- package/dist/schemas.js.map +1 -0
- package/dist/types.d.ts +137 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +62 -0
package/README.md
ADDED
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
# better-auth-asaas
|
|
2
|
+
|
|
3
|
+
A [Better Auth](https://www.better-auth.com/) plugin that integrates with [Asaas](https://www.asaas.com/), the Brazilian payment gateway.
|
|
4
|
+
|
|
5
|
+
> **Currency:** Asaas operates exclusively in **BRL (Brazilian Reais, R$)**. All `value` fields throughout this plugin are in BRL.
|
|
6
|
+
|
|
7
|
+
## Features
|
|
8
|
+
|
|
9
|
+
- π **Auto-creates an Asaas customer** when a user signs up
|
|
10
|
+
- π **Links** `asaasCustomerId` to the user record automatically
|
|
11
|
+
- π³ **Subscription management** β create & cancel subscriptions (Boleto, Pix, Credit Card)
|
|
12
|
+
- π **Webhook handler** β keeps local subscription status in sync with Asaas events
|
|
13
|
+
- π¬ **Billing event hooks** β disable ALL Asaas-side notifications (Email, SMS, WhatsApp, Voice robot, Correios) and handle everything yourself via any provider (Resend, SendGrid, Nodemailerβ¦)
|
|
14
|
+
- π **Session-protected endpoints** β all billing actions require an authenticated session
|
|
15
|
+
- ποΈ **Sandbox support** β test safely with your Asaas sandbox account
|
|
16
|
+
|
|
17
|
+
## Installation
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
npm install better-auth-asaas
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Setup
|
|
24
|
+
|
|
25
|
+
### Server
|
|
26
|
+
|
|
27
|
+
```ts
|
|
28
|
+
// auth.ts
|
|
29
|
+
import { betterAuth } from "better-auth";
|
|
30
|
+
import { asaas } from "better-auth-asaas";
|
|
31
|
+
|
|
32
|
+
export const auth = betterAuth({
|
|
33
|
+
plugins: [
|
|
34
|
+
asaas({
|
|
35
|
+
apiKey: process.env.ASAAS_API_KEY!,
|
|
36
|
+
sandbox: process.env.NODE_ENV !== "production",
|
|
37
|
+
}),
|
|
38
|
+
],
|
|
39
|
+
});
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
### Client
|
|
43
|
+
|
|
44
|
+
```ts
|
|
45
|
+
// auth-client.ts
|
|
46
|
+
import { createAuthClient } from "better-auth/client";
|
|
47
|
+
import { asaasClient } from "better-auth-asaas/client";
|
|
48
|
+
|
|
49
|
+
export const authClient = createAuthClient({
|
|
50
|
+
plugins: [asaasClient()],
|
|
51
|
+
});
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
### Database migration
|
|
55
|
+
|
|
56
|
+
Run Better Auth's migration to add the `asaasCustomerId` column to the `user` table and create the `asaasSubscription` table:
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
npx better-auth migrate
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## Usage
|
|
63
|
+
|
|
64
|
+
### Get Asaas customer
|
|
65
|
+
|
|
66
|
+
```ts
|
|
67
|
+
const { data } = await authClient.asaas.getCustomer();
|
|
68
|
+
console.log(data.customer); // AsaasCustomer | null
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### Create a subscription with a free trial
|
|
72
|
+
|
|
73
|
+
Pass `trialDays` instead of `nextDueDate` β the plugin computes the billing start date automatically. The subscription is **ACTIVE immediately**; Asaas simply won't generate the first charge until the trial ends.
|
|
74
|
+
|
|
75
|
+
```ts
|
|
76
|
+
const { data } = await authClient.asaas.subscriptionCreate({
|
|
77
|
+
billingType: "PIX",
|
|
78
|
+
value: 49.9,
|
|
79
|
+
trialDays: 14, // free for 14 days, then billed monthly
|
|
80
|
+
cycle: "MONTHLY",
|
|
81
|
+
description: "Pro plan (with trial)",
|
|
82
|
+
});
|
|
83
|
+
// data.trialEndsAt β date billing kicks in
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
### Create a subscription
|
|
87
|
+
|
|
88
|
+
> **Currency:** All `value` fields are in **BRL (Brazilian Reais, R$)**. Asaas is a Brazilian payment gateway and only operates in BRL.
|
|
89
|
+
|
|
90
|
+
```ts
|
|
91
|
+
const { data } = await authClient.asaas.subscriptionCreate({
|
|
92
|
+
billingType: "PIX",
|
|
93
|
+
value: 49.9,
|
|
94
|
+
nextDueDate: "2026-03-01",
|
|
95
|
+
cycle: "MONTHLY",
|
|
96
|
+
description: "Pro plan",
|
|
97
|
+
});
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
### Cancel a subscription
|
|
101
|
+
|
|
102
|
+
```ts
|
|
103
|
+
await authClient.asaas.subscriptionCancel({
|
|
104
|
+
subscriptionId: "sub_xxx",
|
|
105
|
+
});
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
### Webhook
|
|
109
|
+
|
|
110
|
+
Register `https://your-app.com/api/auth/asaas/webhook` as the webhook URL in your Asaas dashboard. The plugin will automatically keep subscription statuses in sync.
|
|
111
|
+
|
|
112
|
+
## Billing event handlers
|
|
113
|
+
|
|
114
|
+
By default, **all** Asaas-side customer notifications are disabled on every customer created by this plugin β that includes Email, SMS, WhatsApp, Voice robot (robΓ΄ de voz), and Correios. This saves you the per-notification fees Asaas charges for each channel.
|
|
115
|
+
|
|
116
|
+
You receive the raw webhook events via the `events` option and decide how to act on them (send emails, pause access, trigger CRM flows, etc.).
|
|
117
|
+
|
|
118
|
+
```ts
|
|
119
|
+
import { Resend } from "resend"; // or any provider
|
|
120
|
+
|
|
121
|
+
const resend = new Resend(process.env.RESEND_API_KEY);
|
|
122
|
+
|
|
123
|
+
export const auth = betterAuth({
|
|
124
|
+
plugins: [
|
|
125
|
+
asaas({
|
|
126
|
+
apiKey: process.env.ASAAS_API_KEY!,
|
|
127
|
+
sandbox: true,
|
|
128
|
+
events: {
|
|
129
|
+
// Set to false to re-enable Asaas-side notifications for all channels
|
|
130
|
+
// disableAsaasNotifications: false,
|
|
131
|
+
|
|
132
|
+
// ββ Payment lifecycle ββββββββββββββββββββββββββββββββββββββββββββββββ
|
|
133
|
+
|
|
134
|
+
// New charge created. For PIX: pixQrCode (encodedImage + payload) is included.
|
|
135
|
+
onPaymentCreated: async ({ payment, pixQrCode }) => {
|
|
136
|
+
await resend.emails.send({
|
|
137
|
+
from: "billing@myapp.com",
|
|
138
|
+
to: "user@myapp.com", // look up from your DB using payment.customer
|
|
139
|
+
subject: "New charge created",
|
|
140
|
+
html: pixQrCode
|
|
141
|
+
? `<p>R$ ${payment!.value} β scan the PIX QR code below.</p>
|
|
142
|
+
<img src="data:image/png;base64,${pixQrCode.encodedImage}" />`
|
|
143
|
+
: `<p>A new charge of R$ ${payment!.value} was created.</p>`,
|
|
144
|
+
});
|
|
145
|
+
},
|
|
146
|
+
|
|
147
|
+
// ~10 days before due date. PIX QR code included if applicable.
|
|
148
|
+
onPaymentDueSoon: async ({ payment }) => { /* send reminder */ },
|
|
149
|
+
|
|
150
|
+
// Due today and still unpaid
|
|
151
|
+
onPaymentDue: async ({ payment }) => { /* send urgent reminder */ },
|
|
152
|
+
|
|
153
|
+
// Overdue β fires on due date +1 day, then every 7 days
|
|
154
|
+
onPaymentOverdue: async ({ payment }) => { /* send dunning email, pause access */ },
|
|
155
|
+
|
|
156
|
+
// Payment confirmed / received
|
|
157
|
+
onPaymentConfirmed: async ({ payment }) => { /* send receipt, restore access */ },
|
|
158
|
+
|
|
159
|
+
// Payment refunded
|
|
160
|
+
onPaymentRefunded: async ({ payment }) => { /* send refund confirmation */ },
|
|
161
|
+
|
|
162
|
+
// Chargeback requested or under dispute
|
|
163
|
+
onPaymentChargeback: async ({ payment }) => { /* alert team, pause account */ },
|
|
164
|
+
|
|
165
|
+
// ββ Subscription lifecycle βββββββββββββββββββββββββββββββββββββββββββ
|
|
166
|
+
|
|
167
|
+
// New subscription created β great for onboarding / welcome sequence
|
|
168
|
+
onSubscriptionCreated: async ({ subscription }) => { /* send welcome email */ },
|
|
169
|
+
|
|
170
|
+
// Subscription renewed (new billing cycle auto-generated by Asaas)
|
|
171
|
+
onSubscriptionRenewed: async ({ subscription }) => { /* send renewal confirmation */ },
|
|
172
|
+
|
|
173
|
+
// Subscription canceled β trigger win-back campaign
|
|
174
|
+
onSubscriptionCanceled: async ({ subscription }) => { /* send cancellation email, revoke access */ },
|
|
175
|
+
|
|
176
|
+
// Catch-all for any Asaas event not handled above
|
|
177
|
+
onOtherEvent: async ({ event }) => {
|
|
178
|
+
console.log("Unhandled Asaas event:", event);
|
|
179
|
+
},
|
|
180
|
+
},
|
|
181
|
+
}),
|
|
182
|
+
],
|
|
183
|
+
});
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
> **Asaas webhook events mapped:**
|
|
187
|
+
> | Handler | Asaas event(s) | When it fires |
|
|
188
|
+
> |---|---|---|
|
|
189
|
+
> | `onPaymentCreated` | `PAYMENT_CREATED` | New charge generated (one-time or subscription cycle) |
|
|
190
|
+
> | `onPaymentDueSoon` | `PAYMENT_DUE_DATE_REMINDER` | ~10 days before due date |
|
|
191
|
+
> | `onPaymentDue` | `PAYMENT_OVERDUE` (due today) | Due today, still unpaid |
|
|
192
|
+
> | `onPaymentOverdue` | `PAYMENT_OVERDUE` (past due) | Overdue β repeats every 7 days |
|
|
193
|
+
> | `onPaymentConfirmed` | `PAYMENT_CONFIRMED` / `PAYMENT_RECEIVED` | Payment confirmed |
|
|
194
|
+
> | `onPaymentRefunded` | `PAYMENT_REFUNDED` / `PAYMENT_PARTIALLY_REFUNDED` | Refund issued |
|
|
195
|
+
> | `onPaymentChargeback` | `PAYMENT_CHARGEBACK_*` | Chargeback requested or in dispute |
|
|
196
|
+
> | `onSubscriptionCreated` | `SUBSCRIPTION_CREATED` | New subscription activated |
|
|
197
|
+
> | `onSubscriptionRenewed` | `SUBSCRIPTION_RENEWED` | New billing cycle started |
|
|
198
|
+
> | `onSubscriptionCanceled` | `SUBSCRIPTION_DELETED` | Subscription canceled |
|
|
199
|
+
|
|
200
|
+
## Plugin options
|
|
201
|
+
|
|
202
|
+
| Option | Type | Required | Description |
|
|
203
|
+
|---|---|---|---|
|
|
204
|
+
| `apiKey` | `string` | β
| Your Asaas API key |
|
|
205
|
+
| `sandbox` | `boolean` | | Use sandbox environment (default: `true`) |
|
|
206
|
+
| `userAgent` | `string` | | Value sent as `User-Agent` header (default: `"better-auth-asaas"`). Mandatory for Asaas accounts created after 06/11/2024. |
|
|
207
|
+
| `disableAutoCreateCustomer` | `boolean` | | Skip auto-creating customer on sign-up |
|
|
208
|
+
| `onCustomerCreated` | `(customerId, userId) => void` | | Callback after customer is created |
|
|
209
|
+
| `events` | `AsaasEventHandlers` | | Billing event handlers β see [Billing event handlers](#billing-event-handlers) |
|
|
210
|
+
| `events.disableAsaasNotifications` | `boolean` | | Disable ALL Asaas-side notifications β Email, SMS, WhatsApp, Voice, Correios (default: `true`) |
|
|
211
|
+
|
|
212
|
+
## License
|
|
213
|
+
|
|
214
|
+
MIT
|
package/dist/asaas.d.ts
ADDED
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
export interface AsaasClientOptions {
|
|
2
|
+
apiKey: string;
|
|
3
|
+
sandbox?: boolean;
|
|
4
|
+
/** Sent as the User-Agent header. Required for accounts created after 06/11/2024. */
|
|
5
|
+
userAgent?: string;
|
|
6
|
+
}
|
|
7
|
+
export interface AsaasCustomer {
|
|
8
|
+
id: string;
|
|
9
|
+
name: string;
|
|
10
|
+
email: string;
|
|
11
|
+
cpfCnpj?: string;
|
|
12
|
+
phone?: string;
|
|
13
|
+
mobilePhone?: string;
|
|
14
|
+
address?: string;
|
|
15
|
+
addressNumber?: string;
|
|
16
|
+
complement?: string;
|
|
17
|
+
province?: string;
|
|
18
|
+
city?: string;
|
|
19
|
+
state?: string;
|
|
20
|
+
postalCode?: string;
|
|
21
|
+
externalReference?: string;
|
|
22
|
+
notificationDisabled?: boolean;
|
|
23
|
+
}
|
|
24
|
+
export type AsaasCustomerInput = Omit<AsaasCustomer, "id">;
|
|
25
|
+
export type AsaasBillingType = "BOLETO" | "CREDIT_CARD" | "PIX" | "UNDEFINED";
|
|
26
|
+
export interface AsaasSubscriptionInput {
|
|
27
|
+
customer: string;
|
|
28
|
+
billingType: AsaasBillingType;
|
|
29
|
+
value: number;
|
|
30
|
+
nextDueDate: string;
|
|
31
|
+
cycle?: "WEEKLY" | "BIWEEKLY" | "MONTHLY" | "BIMONTHLY" | "QUARTERLY" | "SEMIANNUALLY" | "YEARLY";
|
|
32
|
+
description?: string;
|
|
33
|
+
externalReference?: string;
|
|
34
|
+
creditCard?: {
|
|
35
|
+
holderName: string;
|
|
36
|
+
number: string;
|
|
37
|
+
expiryMonth: string;
|
|
38
|
+
expiryYear: string;
|
|
39
|
+
ccv: string;
|
|
40
|
+
};
|
|
41
|
+
creditCardHolderInfo?: {
|
|
42
|
+
name: string;
|
|
43
|
+
email: string;
|
|
44
|
+
cpfCnpj: string;
|
|
45
|
+
postalCode: string;
|
|
46
|
+
addressNumber: string;
|
|
47
|
+
phone?: string;
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
export interface AsaasSubscription {
|
|
51
|
+
id: string;
|
|
52
|
+
customer: string;
|
|
53
|
+
billingType: AsaasBillingType;
|
|
54
|
+
value: number;
|
|
55
|
+
nextDueDate: string;
|
|
56
|
+
cycle: string;
|
|
57
|
+
description?: string;
|
|
58
|
+
status: "ACTIVE" | "INACTIVE" | "EXPIRED";
|
|
59
|
+
}
|
|
60
|
+
export interface AsaasPaymentInput {
|
|
61
|
+
customer: string;
|
|
62
|
+
billingType: AsaasBillingType;
|
|
63
|
+
value: number;
|
|
64
|
+
dueDate: string;
|
|
65
|
+
description?: string;
|
|
66
|
+
externalReference?: string;
|
|
67
|
+
installmentCount?: number;
|
|
68
|
+
installmentValue?: number;
|
|
69
|
+
discount?: {
|
|
70
|
+
value: number;
|
|
71
|
+
dueDateLimitDays?: number;
|
|
72
|
+
type?: "FIXED" | "PERCENTAGE";
|
|
73
|
+
};
|
|
74
|
+
interest?: {
|
|
75
|
+
value: number;
|
|
76
|
+
};
|
|
77
|
+
fine?: {
|
|
78
|
+
value: number;
|
|
79
|
+
};
|
|
80
|
+
postalService?: boolean;
|
|
81
|
+
creditCard?: {
|
|
82
|
+
holderName: string;
|
|
83
|
+
number: string;
|
|
84
|
+
expiryMonth: string;
|
|
85
|
+
expiryYear: string;
|
|
86
|
+
ccv: string;
|
|
87
|
+
};
|
|
88
|
+
creditCardHolderInfo?: {
|
|
89
|
+
name: string;
|
|
90
|
+
email: string;
|
|
91
|
+
cpfCnpj: string;
|
|
92
|
+
postalCode: string;
|
|
93
|
+
addressNumber: string;
|
|
94
|
+
phone?: string;
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
export interface AsaasPayment {
|
|
98
|
+
id: string;
|
|
99
|
+
customer: string;
|
|
100
|
+
billingType: AsaasBillingType;
|
|
101
|
+
value: number;
|
|
102
|
+
netValue?: number;
|
|
103
|
+
status: "PENDING" | "RECEIVED" | "CONFIRMED" | "OVERDUE" | "REFUNDED" | "RECEIVED_IN_CASH" | "REFUND_REQUESTED" | "CHARGEBACK_REQUESTED" | "CHARGEBACK_DISPUTE" | "AWAITING_CHARGEBACK_REVERSAL" | "DUNNING_REQUESTED" | "DUNNING_RECEIVED" | "AWAITING_RISK_ANALYSIS";
|
|
104
|
+
dueDate: string;
|
|
105
|
+
originalDueDate?: string;
|
|
106
|
+
description?: string;
|
|
107
|
+
externalReference?: string;
|
|
108
|
+
invoiceUrl?: string;
|
|
109
|
+
bankSlipUrl?: string;
|
|
110
|
+
pixQrCodeId?: string;
|
|
111
|
+
pixTransaction?: string;
|
|
112
|
+
deleted: boolean;
|
|
113
|
+
}
|
|
114
|
+
export interface AsaasWebhookEvent {
|
|
115
|
+
event: string;
|
|
116
|
+
payment?: Record<string, unknown>;
|
|
117
|
+
subscription?: Record<string, unknown>;
|
|
118
|
+
}
|
|
119
|
+
export declare class AsaasClient {
|
|
120
|
+
private readonly baseUrl;
|
|
121
|
+
private readonly apiKey;
|
|
122
|
+
private readonly userAgent;
|
|
123
|
+
constructor(options: AsaasClientOptions);
|
|
124
|
+
private request;
|
|
125
|
+
createCustomer(data: AsaasCustomerInput): Promise<AsaasCustomer>;
|
|
126
|
+
getCustomer(id: string): Promise<AsaasCustomer>;
|
|
127
|
+
createSubscription(data: AsaasSubscriptionInput): Promise<AsaasSubscription>;
|
|
128
|
+
cancelSubscription(id: string): Promise<{
|
|
129
|
+
deleted: boolean;
|
|
130
|
+
id: string;
|
|
131
|
+
}>;
|
|
132
|
+
getSubscription(id: string): Promise<AsaasSubscription>;
|
|
133
|
+
/**
|
|
134
|
+
* Lists all payments Asaas auto-generated for a subscription.
|
|
135
|
+
* Each billing cycle produces one payment. For PIX, use getPixQrCode() on the PENDING one.
|
|
136
|
+
*/
|
|
137
|
+
getSubscriptionPayments(subscriptionId: string, params?: {
|
|
138
|
+
limit?: number;
|
|
139
|
+
offset?: number;
|
|
140
|
+
}): Promise<{
|
|
141
|
+
object: "list";
|
|
142
|
+
hasMore: boolean;
|
|
143
|
+
totalCount: number;
|
|
144
|
+
limit: number;
|
|
145
|
+
offset: number;
|
|
146
|
+
data: AsaasPayment[];
|
|
147
|
+
}>;
|
|
148
|
+
listCustomers(params?: {
|
|
149
|
+
limit?: number;
|
|
150
|
+
offset?: number;
|
|
151
|
+
name?: string;
|
|
152
|
+
email?: string;
|
|
153
|
+
}): Promise<{
|
|
154
|
+
object: "list";
|
|
155
|
+
hasMore: boolean;
|
|
156
|
+
totalCount: number;
|
|
157
|
+
limit: number;
|
|
158
|
+
offset: number;
|
|
159
|
+
data: AsaasCustomer[];
|
|
160
|
+
}>;
|
|
161
|
+
deleteCustomer(id: string): Promise<{
|
|
162
|
+
deleted: boolean;
|
|
163
|
+
id: string;
|
|
164
|
+
}>;
|
|
165
|
+
createPayment(data: AsaasPaymentInput): Promise<AsaasPayment>;
|
|
166
|
+
getPayment(id: string): Promise<AsaasPayment>;
|
|
167
|
+
listPayments(params?: {
|
|
168
|
+
customer?: string;
|
|
169
|
+
status?: string;
|
|
170
|
+
billingType?: AsaasBillingType;
|
|
171
|
+
limit?: number;
|
|
172
|
+
offset?: number;
|
|
173
|
+
}): Promise<{
|
|
174
|
+
object: "list";
|
|
175
|
+
hasMore: boolean;
|
|
176
|
+
totalCount: number;
|
|
177
|
+
limit: number;
|
|
178
|
+
offset: number;
|
|
179
|
+
data: AsaasPayment[];
|
|
180
|
+
}>;
|
|
181
|
+
deletePayment(id: string): Promise<{
|
|
182
|
+
deleted: boolean;
|
|
183
|
+
id: string;
|
|
184
|
+
}>;
|
|
185
|
+
/** Returns both the base64 PNG QR code image and the Pix Copia e Cola payload string. */
|
|
186
|
+
getPixQrCode(paymentId: string): Promise<{
|
|
187
|
+
encodedImage: string;
|
|
188
|
+
payload: string;
|
|
189
|
+
expirationDate: string;
|
|
190
|
+
success: boolean;
|
|
191
|
+
}>;
|
|
192
|
+
}
|
|
193
|
+
//# sourceMappingURL=asaas.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"asaas.d.ts","sourceRoot":"","sources":["../src/asaas.ts"],"names":[],"mappings":"AAIA,MAAM,WAAW,kBAAkB;IACjC,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,qFAAqF;IACrF,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,aAAa;IAC5B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,oBAAoB,CAAC,EAAE,OAAO,CAAC;CAChC;AAED,MAAM,MAAM,kBAAkB,GAAG,IAAI,CAAC,aAAa,EAAE,IAAI,CAAC,CAAC;AAE3D,MAAM,MAAM,gBAAgB,GAAG,QAAQ,GAAG,aAAa,GAAG,KAAK,GAAG,WAAW,C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ACjB,UAAU,EAAE,MAAM,CAAC;QACnB,KAAK,EAAE,MAAM,CAAC;QACd,MAAM,EAAE,MAAM,CAAC;QACf,IAAI,EAAE,YAAY,EAAE,CAAC;KACtB,CAAC;IAWF,aAAa,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC;QAAE,OAAO,EAAE,OAAO,CAAC;QAAC,EAAE,EAAE,MAAM,CAAA;KAAE,CAAC;IAMpE,yFAAyF;IACzF,YAAY,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC;QACvC,YAAY,EAAE,MAAM,CAAC;QACrB,OAAO,EAAE,MAAM,CAAC;QAChB,cAAc,EAAE,MAAM,CAAC;QACvB,OAAO,EAAE,OAAO,CAAC;KAClB,CAAC;CAGH"}
|
package/dist/asaas.js
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
// Asaas API base URLs
|
|
2
|
+
const ASAAS_SANDBOX_URL = "https://api-sandbox.asaas.com/v3";
|
|
3
|
+
const ASAAS_PRODUCTION_URL = "https://api.asaas.com/v3";
|
|
4
|
+
export class AsaasClient {
|
|
5
|
+
baseUrl;
|
|
6
|
+
apiKey;
|
|
7
|
+
userAgent;
|
|
8
|
+
constructor(options) {
|
|
9
|
+
this.apiKey = options.apiKey;
|
|
10
|
+
this.baseUrl = options.sandbox !== false ? ASAAS_SANDBOX_URL : ASAAS_PRODUCTION_URL;
|
|
11
|
+
this.userAgent = options.userAgent ?? "better-auth-asaas";
|
|
12
|
+
}
|
|
13
|
+
async request(path, init = {}) {
|
|
14
|
+
const url = `${this.baseUrl}${path}`;
|
|
15
|
+
const res = await fetch(url, {
|
|
16
|
+
...init,
|
|
17
|
+
headers: {
|
|
18
|
+
"Content-Type": "application/json",
|
|
19
|
+
"User-Agent": this.userAgent,
|
|
20
|
+
access_token: this.apiKey,
|
|
21
|
+
...init.headers,
|
|
22
|
+
},
|
|
23
|
+
});
|
|
24
|
+
if (!res.ok) {
|
|
25
|
+
const body = await res.text();
|
|
26
|
+
throw new Error(`Asaas API error ${res.status}: ${body}`);
|
|
27
|
+
}
|
|
28
|
+
return res.json();
|
|
29
|
+
}
|
|
30
|
+
createCustomer(data) {
|
|
31
|
+
return this.request("/customers", {
|
|
32
|
+
method: "POST",
|
|
33
|
+
body: JSON.stringify(data),
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
getCustomer(id) {
|
|
37
|
+
return this.request(`/customers/${id}`);
|
|
38
|
+
}
|
|
39
|
+
createSubscription(data) {
|
|
40
|
+
return this.request("/subscriptions", {
|
|
41
|
+
method: "POST",
|
|
42
|
+
body: JSON.stringify(data),
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
cancelSubscription(id) {
|
|
46
|
+
return this.request(`/subscriptions/${id}`, {
|
|
47
|
+
method: "DELETE",
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
getSubscription(id) {
|
|
51
|
+
return this.request(`/subscriptions/${id}`);
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Lists all payments Asaas auto-generated for a subscription.
|
|
55
|
+
* Each billing cycle produces one payment. For PIX, use getPixQrCode() on the PENDING one.
|
|
56
|
+
*/
|
|
57
|
+
getSubscriptionPayments(subscriptionId, params) {
|
|
58
|
+
const qs = new URLSearchParams();
|
|
59
|
+
if (params?.limit != null)
|
|
60
|
+
qs.set("limit", String(params.limit));
|
|
61
|
+
if (params?.offset != null)
|
|
62
|
+
qs.set("offset", String(params.offset));
|
|
63
|
+
const query = qs.toString();
|
|
64
|
+
return this.request(`/subscriptions/${subscriptionId}/payments${query ? `?${query}` : ""}`);
|
|
65
|
+
}
|
|
66
|
+
listCustomers(params) {
|
|
67
|
+
const qs = new URLSearchParams();
|
|
68
|
+
if (params?.limit != null)
|
|
69
|
+
qs.set("limit", String(params.limit));
|
|
70
|
+
if (params?.offset != null)
|
|
71
|
+
qs.set("offset", String(params.offset));
|
|
72
|
+
if (params?.name)
|
|
73
|
+
qs.set("name", params.name);
|
|
74
|
+
if (params?.email)
|
|
75
|
+
qs.set("email", params.email);
|
|
76
|
+
const query = qs.toString();
|
|
77
|
+
return this.request(`/customers${query ? `?${query}` : ""}`);
|
|
78
|
+
}
|
|
79
|
+
deleteCustomer(id) {
|
|
80
|
+
return this.request(`/customers/${id}`, {
|
|
81
|
+
method: "DELETE",
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
createPayment(data) {
|
|
85
|
+
return this.request("/payments", {
|
|
86
|
+
method: "POST",
|
|
87
|
+
body: JSON.stringify(data),
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
getPayment(id) {
|
|
91
|
+
return this.request(`/payments/${id}`);
|
|
92
|
+
}
|
|
93
|
+
listPayments(params) {
|
|
94
|
+
const qs = new URLSearchParams();
|
|
95
|
+
if (params?.customer)
|
|
96
|
+
qs.set("customer", params.customer);
|
|
97
|
+
if (params?.status)
|
|
98
|
+
qs.set("status", params.status);
|
|
99
|
+
if (params?.billingType)
|
|
100
|
+
qs.set("billingType", params.billingType);
|
|
101
|
+
if (params?.limit != null)
|
|
102
|
+
qs.set("limit", String(params.limit));
|
|
103
|
+
if (params?.offset != null)
|
|
104
|
+
qs.set("offset", String(params.offset));
|
|
105
|
+
const query = qs.toString();
|
|
106
|
+
return this.request(`/payments${query ? `?${query}` : ""}`);
|
|
107
|
+
}
|
|
108
|
+
deletePayment(id) {
|
|
109
|
+
return this.request(`/payments/${id}`, {
|
|
110
|
+
method: "DELETE",
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
/** Returns both the base64 PNG QR code image and the Pix Copia e Cola payload string. */
|
|
114
|
+
getPixQrCode(paymentId) {
|
|
115
|
+
return this.request(`/payments/${paymentId}/pixQrCode`);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
//# sourceMappingURL=asaas.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"asaas.js","sourceRoot":"","sources":["../src/asaas.ts"],"names":[],"mappings":"AAAA,sBAA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
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAGA,MAAM,CAAC,MAAM,WAAW,GAAG,GAA2B,EAAE;IACtD,OAAO;QACL,EAAE,EAAE,OAAO;QACX,kBAAkB,EAAE,EAA8B;KACnD,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { AsaasClient } from "../asaas.js";
|
|
2
|
+
export declare const getCustomerEndpoint: (asaas: AsaasClient) => import("better-call").StrictEndpoint<"/asaas/customer", {
|
|
3
|
+
method: "GET";
|
|
4
|
+
use: ((inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<{
|
|
5
|
+
session: {
|
|
6
|
+
session: Record<string, any> & {
|
|
7
|
+
id: string;
|
|
8
|
+
createdAt: Date;
|
|
9
|
+
updatedAt: Date;
|
|
10
|
+
userId: string;
|
|
11
|
+
expiresAt: Date;
|
|
12
|
+
token: string;
|
|
13
|
+
ipAddress?: string | null | undefined;
|
|
14
|
+
userAgent?: string | null | undefined;
|
|
15
|
+
};
|
|
16
|
+
user: Record<string, any> & {
|
|
17
|
+
id: string;
|
|
18
|
+
createdAt: Date;
|
|
19
|
+
updatedAt: Date;
|
|
20
|
+
email: string;
|
|
21
|
+
emailVerified: boolean;
|
|
22
|
+
name: string;
|
|
23
|
+
image?: string | null | undefined;
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
}>)[];
|
|
27
|
+
}, {
|
|
28
|
+
customer: null;
|
|
29
|
+
} | {
|
|
30
|
+
customer: import("../asaas.js").AsaasCustomer;
|
|
31
|
+
}>;
|
|
32
|
+
//# sourceMappingURL=customer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"customer.d.ts","sourceRoot":"","sources":["../../src/endpoints/customer.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE/C,eAAO,MAAM,mBAAmB,GAAI,OAAO,WAAW;;;;;;;;;;;yBAmB26C,CAAC;yBAA4C,CAAC;;;;;;;;;qBAAwN,CAAC;;;;;;;;EADruD,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { createAuthEndpoint, sessionMiddleware } from "better-auth/api";
|
|
2
|
+
export const getCustomerEndpoint = (asaas) => createAuthEndpoint("/asaas/customer", {
|
|
3
|
+
method: "GET",
|
|
4
|
+
use: [sessionMiddleware],
|
|
5
|
+
}, async (ctx) => {
|
|
6
|
+
const { user } = ctx.context.session;
|
|
7
|
+
const asaasCustomerId = user.asaasCustomerId;
|
|
8
|
+
if (!asaasCustomerId) {
|
|
9
|
+
return ctx.json({ customer: null });
|
|
10
|
+
}
|
|
11
|
+
const customer = await asaas.getCustomer(asaasCustomerId);
|
|
12
|
+
return ctx.json({ customer });
|
|
13
|
+
});
|
|
14
|
+
//# sourceMappingURL=customer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"customer.js","sourceRoot":"","sources":["../../src/endpoints/customer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAGxE,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,KAAkB,EAAE,EAAE,CACxD,kBAAkB,CAChB,iBAAiB,EACjB;IACE,MAAM,EAAE,KAAK;IACb,GAAG,EAAE,CAAC,iBAAiB,CAAC;CACzB,EACD,KAAK,EAAE,GAAG,EAAE,EAAE;IACZ,MAAM,EAAE,IAAI,EAAE,GAAG,GAAG,CAAC,OAAO,CAAC,OAAO,CAAC;IACrC,MAAM,eAAe,GAAI,IAAgC,CAAC,eAAqC,CAAC;IAEhG,IAAI,CAAC,eAAe,EAAE,CAAC;QACrB,OAAO,GAAG,CAAC,IAAI,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC;IACtC,CAAC;IAED,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,WAAW,CAAC,eAAe,CAAC,CAAC;IAC1D,OAAO,GAAG,CAAC,IAAI,CAAC,EAAE,QAAQ,EAAE,CAAC,CAAC;AAChC,CAAC,CACF,CAAC"}
|