@dodopayments/better-auth 1.5.0 → 1.6.1
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 +75 -5
- package/dist/{chunk-R5TTSJK4.js → chunk-527Y7FSE.js} +28 -19
- package/dist/chunk-527Y7FSE.js.map +1 -0
- package/dist/client.d.cts +1 -1
- package/dist/client.d.ts +1 -1
- package/dist/hooks/customer.cjs +27 -18
- package/dist/hooks/customer.cjs.map +1 -1
- package/dist/hooks/customer.d.cts +1 -1
- package/dist/hooks/customer.d.ts +1 -1
- package/dist/hooks/customer.js +1 -1
- package/dist/index.cjs +27 -18
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/plugins/checkout.d.cts +1 -1
- package/dist/plugins/checkout.d.ts +1 -1
- package/dist/plugins/portal.d.cts +1 -1
- package/dist/plugins/portal.d.ts +1 -1
- package/dist/plugins/webhooks.d.cts +1 -1
- package/dist/plugins/webhooks.d.ts +1 -1
- package/dist/{types-4JE4OwKb.d.cts → types-3pb2RGTM.d.cts} +12 -1
- package/dist/{types-B9rx1bt7.d.ts → types-DygjjcRn.d.ts} +12 -1
- package/dist/types.cjs.map +1 -1
- package/dist/types.d.cts +1 -1
- package/dist/types.d.ts +1 -1
- package/package.json +1 -1
- package/dist/chunk-R5TTSJK4.js.map +0 -1
package/README.md
CHANGED
|
@@ -188,6 +188,19 @@ webhooks({
|
|
|
188
188
|
- **`client`** (required) - DodoPayments client instance
|
|
189
189
|
- **`createCustomerOnSignUp`** (optional) - Auto-create customers on user signup
|
|
190
190
|
- **`use`** (required) - Array of plugins to enable (checkout, portal, webhooks)
|
|
191
|
+
- **`getCustomerParams`** (optional) - Function that receives the BetterAuth `User` and returns extra fields to attach to the DodoPayments customer on creation and update (e.g. `metadata`, `phone_number`)
|
|
192
|
+
|
|
193
|
+
```typescript
|
|
194
|
+
dodopayments({
|
|
195
|
+
client: dodoPayments,
|
|
196
|
+
createCustomerOnSignUp: true,
|
|
197
|
+
use: [portal()],
|
|
198
|
+
getCustomerParams: (user) => ({
|
|
199
|
+
metadata: { userId: user.id },
|
|
200
|
+
phone_number: user.phoneNumber ?? null,
|
|
201
|
+
}),
|
|
202
|
+
})
|
|
203
|
+
```
|
|
191
204
|
|
|
192
205
|
### Checkout Plugin Options
|
|
193
206
|
|
|
@@ -256,6 +269,11 @@ export const { auth, endpoints, client } = BetterAuth({
|
|
|
256
269
|
client: dodoPayments,
|
|
257
270
|
createCustomerOnSignUp: true, // Auto-create customers on signup
|
|
258
271
|
use: [], // We'll add plugins here in Stage 2
|
|
272
|
+
// Optional: attach metadata or phone_number to DodoPayments customer records
|
|
273
|
+
// getCustomerParams: (user) => ({
|
|
274
|
+
// metadata: { userId: user.id },
|
|
275
|
+
// phone_number: user.phoneNumber ?? null,
|
|
276
|
+
// }),
|
|
259
277
|
}),
|
|
260
278
|
],
|
|
261
279
|
});
|
|
@@ -485,9 +503,6 @@ use: [
|
|
|
485
503
|
onSubscriptionRenewed: async (payload) => {
|
|
486
504
|
console.log("Subscription renewed:", payload);
|
|
487
505
|
},
|
|
488
|
-
onSubscriptionPaused: async (payload) => {
|
|
489
|
-
console.log("Subscription paused:", payload);
|
|
490
|
-
},
|
|
491
506
|
onSubscriptionPlanChanged: async (payload) => {
|
|
492
507
|
console.log("Subscription plan changed:", payload);
|
|
493
508
|
},
|
|
@@ -500,10 +515,52 @@ use: [
|
|
|
500
515
|
onSubscriptionExpired: async (payload) => {
|
|
501
516
|
console.log("Subscription expired:", payload);
|
|
502
517
|
},
|
|
518
|
+
onSubscriptionUpdated: async (payload) => {
|
|
519
|
+
console.log("Subscription updated:", payload);
|
|
520
|
+
},
|
|
503
521
|
// License key event handlers
|
|
504
522
|
onLicenseKeyCreated: async (payload) => {
|
|
505
523
|
console.log("License key created:", payload);
|
|
506
524
|
},
|
|
525
|
+
// Abandoned checkout event handlers
|
|
526
|
+
onAbandonedCheckoutDetected: async (payload) => {
|
|
527
|
+
console.log("Abandoned checkout detected:", payload);
|
|
528
|
+
},
|
|
529
|
+
onAbandonedCheckoutRecovered: async (payload) => {
|
|
530
|
+
console.log("Abandoned checkout recovered:", payload);
|
|
531
|
+
},
|
|
532
|
+
// Dunning event handlers
|
|
533
|
+
onDunningStarted: async (payload) => {
|
|
534
|
+
console.log("Dunning started:", payload);
|
|
535
|
+
},
|
|
536
|
+
onDunningRecovered: async (payload) => {
|
|
537
|
+
console.log("Dunning recovered:", payload);
|
|
538
|
+
},
|
|
539
|
+
// Credit event handlers
|
|
540
|
+
onCreditAdded: async (payload) => {
|
|
541
|
+
console.log("Credit added:", payload);
|
|
542
|
+
},
|
|
543
|
+
onCreditDeducted: async (payload) => {
|
|
544
|
+
console.log("Credit deducted:", payload);
|
|
545
|
+
},
|
|
546
|
+
onCreditExpired: async (payload) => {
|
|
547
|
+
console.log("Credit expired:", payload);
|
|
548
|
+
},
|
|
549
|
+
onCreditRolledOver: async (payload) => {
|
|
550
|
+
console.log("Credit rolled over:", payload);
|
|
551
|
+
},
|
|
552
|
+
onCreditRolloverForfeited: async (payload) => {
|
|
553
|
+
console.log("Credit rollover forfeited:", payload);
|
|
554
|
+
},
|
|
555
|
+
onCreditOverageCharged: async (payload) => {
|
|
556
|
+
console.log("Credit overage charged:", payload);
|
|
557
|
+
},
|
|
558
|
+
onCreditManualAdjustment: async (payload) => {
|
|
559
|
+
console.log("Credit manual adjustment:", payload);
|
|
560
|
+
},
|
|
561
|
+
onCreditBalanceLow: async (payload) => {
|
|
562
|
+
console.log("Credit balance low:", payload);
|
|
563
|
+
},
|
|
507
564
|
}),
|
|
508
565
|
],
|
|
509
566
|
|
|
@@ -525,12 +582,24 @@ Supported Webhook Event Handlers:
|
|
|
525
582
|
- onSubscriptionActive: Subscription became active
|
|
526
583
|
- onSubscriptionOnHold: Subscription was put on hold
|
|
527
584
|
- onSubscriptionRenewed: Subscription was renewed
|
|
528
|
-
- onSubscriptionPaused: Subscription was paused
|
|
529
585
|
- onSubscriptionPlanChanged: Subscription plan was changed
|
|
530
586
|
- onSubscriptionCancelled: Subscription was cancelled
|
|
531
587
|
- onSubscriptionFailed: Subscription failed
|
|
532
588
|
- onSubscriptionExpired: Subscription expired
|
|
589
|
+
- onSubscriptionUpdated: Subscription was updated
|
|
533
590
|
- onLicenseKeyCreated: License key was created
|
|
591
|
+
- onAbandonedCheckoutDetected: Abandoned checkout was detected
|
|
592
|
+
- onAbandonedCheckoutRecovered: Abandoned checkout was recovered
|
|
593
|
+
- onDunningStarted: Dunning process started
|
|
594
|
+
- onDunningRecovered: Dunning process recovered
|
|
595
|
+
- onCreditAdded: Credit was added
|
|
596
|
+
- onCreditDeducted: Credit was deducted
|
|
597
|
+
- onCreditExpired: Credit expired
|
|
598
|
+
- onCreditRolledOver: Credit was rolled over
|
|
599
|
+
- onCreditRolloverForfeited: Credit rollover was forfeited
|
|
600
|
+
- onCreditOverageCharged: Credit overage was charged
|
|
601
|
+
- onCreditManualAdjustment: Credit manual adjustment was made
|
|
602
|
+
- onCreditBalanceLow: Credit balance is low
|
|
534
603
|
|
|
535
604
|
COMBINING SELECTED PLUGINS:
|
|
536
605
|
|
|
@@ -583,5 +652,6 @@ IMPORTANT NOTES:
|
|
|
583
652
|
8. The webhook endpoint is automatically created and secured with signature verification (if webhooks plugin is selected)
|
|
584
653
|
9. Customer portal and subscription listing require user authentication (if portal plugin is selected)
|
|
585
654
|
10. Handle errors appropriately and test webhook functionality in development before going live
|
|
586
|
-
11.
|
|
655
|
+
11. Use getCustomerParams to attach metadata or phone_number to DodoPayments customer records — the function receives the BetterAuth User object and runs on every customer creation and update
|
|
656
|
+
12. Present all external setup tasks as clear TODO lists with specific environment variable names
|
|
587
657
|
```
|
|
@@ -8,15 +8,20 @@ var onUserCreate = (options) => async (user, ctx) => {
|
|
|
8
8
|
});
|
|
9
9
|
const existingCustomer = customers.items[0];
|
|
10
10
|
let customerId;
|
|
11
|
+
const additionalParams = options.getCustomerParams ? await options.getCustomerParams(user) : void 0;
|
|
11
12
|
if (existingCustomer) {
|
|
12
13
|
await options.client.customers.update(existingCustomer.customer_id, {
|
|
13
|
-
name: user.name
|
|
14
|
+
name: user.name,
|
|
15
|
+
metadata: additionalParams?.metadata,
|
|
16
|
+
phone_number: additionalParams?.phone_number
|
|
14
17
|
});
|
|
15
18
|
customerId = existingCustomer.customer_id;
|
|
16
19
|
} else {
|
|
17
20
|
const newCustomer = await options.client.customers.create({
|
|
18
21
|
email: user.email,
|
|
19
|
-
name: user.name
|
|
22
|
+
name: user.name,
|
|
23
|
+
metadata: additionalParams?.metadata,
|
|
24
|
+
phone_number: additionalParams?.phone_number
|
|
20
25
|
}, { idempotencyKey: user.id });
|
|
21
26
|
customerId = newCustomer.customer_id;
|
|
22
27
|
}
|
|
@@ -42,24 +47,28 @@ var onUserCreate = (options) => async (user, ctx) => {
|
|
|
42
47
|
var onUserUpdate = (options) => async (user, ctx) => {
|
|
43
48
|
if (ctx && options.createCustomerOnSignUp) {
|
|
44
49
|
try {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
50
|
+
let customerId = user.dodoCustomerId;
|
|
51
|
+
if (!customerId) {
|
|
52
|
+
const customers = await options.client.customers.list({
|
|
53
|
+
email: user.email
|
|
54
|
+
});
|
|
55
|
+
const existingCustomer = customers.items[0];
|
|
56
|
+
if (!existingCustomer) return;
|
|
57
|
+
customerId = existingCustomer.customer_id;
|
|
58
|
+
ctx.context.internalAdapter.updateUser(user.id, {
|
|
59
|
+
dodoCustomerId: customerId
|
|
60
|
+
}).catch((e) => {
|
|
61
|
+
ctx.context.logger.warn(
|
|
62
|
+
`DodoPayments: failed to backfill dodoCustomerId for user ${user.id}. Error: ${e instanceof Error ? e.message : e}`
|
|
63
|
+
);
|
|
52
64
|
});
|
|
53
|
-
if (!user.dodoCustomerId) {
|
|
54
|
-
ctx.context.internalAdapter.updateUser(user.id, {
|
|
55
|
-
dodoCustomerId: existingCustomer.customer_id
|
|
56
|
-
}).catch((e) => {
|
|
57
|
-
ctx.context.logger.warn(
|
|
58
|
-
`DodoPayments: failed to backfill dodoCustomerId for user ${user.id}. Error: ${e instanceof Error ? e.message : e}`
|
|
59
|
-
);
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
65
|
}
|
|
66
|
+
const additionalParams = options.getCustomerParams ? await options.getCustomerParams(user) : void 0;
|
|
67
|
+
await options.client.customers.update(customerId, {
|
|
68
|
+
name: user.name,
|
|
69
|
+
metadata: additionalParams?.metadata,
|
|
70
|
+
phone_number: additionalParams?.phone_number
|
|
71
|
+
});
|
|
63
72
|
} catch (e) {
|
|
64
73
|
if (e instanceof Error) {
|
|
65
74
|
ctx.context.logger.error(
|
|
@@ -78,4 +87,4 @@ export {
|
|
|
78
87
|
onUserCreate,
|
|
79
88
|
onUserUpdate
|
|
80
89
|
};
|
|
81
|
-
//# sourceMappingURL=chunk-
|
|
90
|
+
//# sourceMappingURL=chunk-527Y7FSE.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/hooks/customer.ts"],"sourcesContent":["import type { GenericEndpointContext, User } from \"better-auth\";\nimport { APIError } from \"better-auth/api\";\nimport type { DodoPaymentsOptions } from \"../types\";\n\nexport const onUserCreate =\n (options: DodoPaymentsOptions) =>\n async (user: User, ctx: GenericEndpointContext | null) => {\n if (ctx && options.createCustomerOnSignUp) {\n try {\n const customers = await options.client.customers.list({\n email: user.email,\n });\n const existingCustomer = customers.items[0];\n\n let customerId: string;\n\n const additionalParams = options.getCustomerParams\n ? await options.getCustomerParams(user)\n : undefined;\n\n if (existingCustomer) {\n await options.client.customers.update(existingCustomer.customer_id, {\n name: user.name,\n metadata: additionalParams?.metadata,\n phone_number: additionalParams?.phone_number,\n });\n customerId = existingCustomer.customer_id;\n } else {\n const newCustomer = await options.client.customers.create({\n email: user.email,\n name: user.name,\n metadata: additionalParams?.metadata,\n phone_number: additionalParams?.phone_number,\n }, { idempotencyKey: user.id });\n customerId = newCustomer.customer_id;\n }\n\n ctx.context.internalAdapter.updateUser(user.id, {\n dodoCustomerId: customerId,\n }).catch((e: unknown) => {\n ctx.context.logger.warn(\n `DodoPayments: failed to store dodoCustomerId for user ${user.id}. Error: ${e instanceof Error ? e.message : e}`,\n );\n });\n } catch (e: unknown) {\n if (e instanceof Error) {\n throw new APIError(\"INTERNAL_SERVER_ERROR\", {\n message: `DodoPayments customer creation failed. Error: ${e.message}`,\n });\n }\n\n throw new APIError(\"INTERNAL_SERVER_ERROR\", {\n message: `DodoPayments customer creation failed. Error: ${e}`,\n });\n }\n }\n };\n\nexport const onUserUpdate =\n (options: DodoPaymentsOptions) =>\n async (user: User, ctx: GenericEndpointContext | null) => {\n if (ctx && options.createCustomerOnSignUp) {\n try {\n let customerId = (user as User & { dodoCustomerId?: string }).dodoCustomerId;\n\n if (!customerId) {\n // Fallback to email lookup if dodoCustomerId is not stored yet\n const customers = await options.client.customers.list({\n email: user.email,\n });\n const existingCustomer = customers.items[0];\n\n if (!existingCustomer) return;\n\n customerId = existingCustomer.customer_id;\n\n // Backfill dodoCustomerId\n ctx.context.internalAdapter.updateUser(user.id, {\n dodoCustomerId: customerId,\n }).catch((e: unknown) => {\n ctx.context.logger.warn(\n `DodoPayments: failed to backfill dodoCustomerId for user ${user.id}. Error: ${e instanceof Error ? e.message : e}`,\n );\n });\n }\n\n const additionalParams = options.getCustomerParams\n ? await options.getCustomerParams(user)\n : undefined;\n\n await options.client.customers.update(customerId, {\n name: user.name,\n metadata: additionalParams?.metadata,\n phone_number: additionalParams?.phone_number,\n });\n } catch (e: unknown) {\n if (e instanceof Error) {\n ctx.context.logger.error(\n `DodoPayments customer update failed. Error: ${e.message}`,\n );\n } else {\n ctx.context.logger.error(\n `DodoPayments customer update failed. Error: ${e}`,\n );\n }\n }\n }\n };\n"],"mappings":";AACA,SAAS,gBAAgB;AAGlB,IAAM,eACX,C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ACX,CAAC,YACD,OAAO,MAAY,QAAuC;AACxD,MAAI,OAAO,QAAQ,wBAAwB;AACzC,QAAI;AACF,UAAI,aAAc,KAA4C;AAE9D,UAAI,CAAC,YAAY;AAEf,cAAM,YAAY,MAAM,QAAQ,OAAO,UAAU,KAAK;AAAA,UACpD,OAAO,KAAK;AAAA,QACd,CAAC;AACD,cAAM,mBAAmB,UAAU,MAAM,CAAC;AAE1C,YAAI,CAAC,iBAAkB;AAEvB,qBAAa,iBAAiB;AAG9B,YAAI,QAAQ,gBAAgB,WAAW,KAAK,IAAI;AAAA,UAC9C,gBAAgB;AAAA,QAClB,CAAC,EAAE,MAAM,CAAC,MAAe;AACvB,cAAI,QAAQ,OAAO;AAAA,YACjB,4DAA4D,KAAK,EAAE,YAAY,aAAa,QAAQ,EAAE,UAAU,CAAC;AAAA,UACnH;AAAA,QACF,CAAC;AAAA,MACH;AAEA,YAAM,mBAAmB,QAAQ,oBAC7B,MAAM,QAAQ,kBAAkB,IAAI,IACpC;AAEJ,YAAM,QAAQ,OAAO,UAAU,OAAO,YAAY;AAAA,QAChD,MAAM,KAAK;AAAA,QACX,UAAU,kBAAkB;AAAA,QAC5B,cAAc,kBAAkB;AAAA,MAClC,CAAC;AAAA,IACH,SAAS,GAAY;AACnB,UAAI,aAAa,OAAO;AACtB,YAAI,QAAQ,OAAO;AAAA,UACjB,+CAA+C,EAAE,OAAO;AAAA,QAC1D;AAAA,MACF,OAAO;AACL,YAAI,QAAQ,OAAO;AAAA,UACjB,+CAA+C,CAAC;AAAA,QAClD;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
|
package/dist/client.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { dodopaymentsClient } from './index.cjs';
|
|
2
|
-
export { C as CreateCheckoutResponse, a as CustomerPortalResponse, e as DodoPaymentsEndpoints, D as DodoPaymentsOptions, P as PaymentItems, b as Product, S as SubscriptionItems, W as WebhookResponse } from './types-
|
|
2
|
+
export { C as CreateCheckoutResponse, a as CustomerPortalResponse, e as DodoPaymentsEndpoints, D as DodoPaymentsOptions, P as PaymentItems, b as Product, S as SubscriptionItems, W as WebhookResponse } from './types-3pb2RGTM.cjs';
|
|
3
3
|
import 'dodopayments/resources/usage-events.mjs';
|
|
4
4
|
import 'better-auth';
|
|
5
5
|
import 'zod/v3';
|
package/dist/client.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { dodopaymentsClient } from './index.js';
|
|
2
|
-
export { C as CreateCheckoutResponse, a as CustomerPortalResponse, e as DodoPaymentsEndpoints, D as DodoPaymentsOptions, P as PaymentItems, b as Product, S as SubscriptionItems, W as WebhookResponse } from './types-
|
|
2
|
+
export { C as CreateCheckoutResponse, a as CustomerPortalResponse, e as DodoPaymentsEndpoints, D as DodoPaymentsOptions, P as PaymentItems, b as Product, S as SubscriptionItems, W as WebhookResponse } from './types-DygjjcRn.js';
|
|
3
3
|
import 'dodopayments/resources/usage-events.mjs';
|
|
4
4
|
import 'better-auth';
|
|
5
5
|
import 'zod/v3';
|
package/dist/hooks/customer.cjs
CHANGED
|
@@ -33,15 +33,20 @@ var onUserCreate = (options) => async (user, ctx) => {
|
|
|
33
33
|
});
|
|
34
34
|
const existingCustomer = customers.items[0];
|
|
35
35
|
let customerId;
|
|
36
|
+
const additionalParams = options.getCustomerParams ? await options.getCustomerParams(user) : void 0;
|
|
36
37
|
if (existingCustomer) {
|
|
37
38
|
await options.client.customers.update(existingCustomer.customer_id, {
|
|
38
|
-
name: user.name
|
|
39
|
+
name: user.name,
|
|
40
|
+
metadata: additionalParams?.metadata,
|
|
41
|
+
phone_number: additionalParams?.phone_number
|
|
39
42
|
});
|
|
40
43
|
customerId = existingCustomer.customer_id;
|
|
41
44
|
} else {
|
|
42
45
|
const newCustomer = await options.client.customers.create({
|
|
43
46
|
email: user.email,
|
|
44
|
-
name: user.name
|
|
47
|
+
name: user.name,
|
|
48
|
+
metadata: additionalParams?.metadata,
|
|
49
|
+
phone_number: additionalParams?.phone_number
|
|
45
50
|
}, { idempotencyKey: user.id });
|
|
46
51
|
customerId = newCustomer.customer_id;
|
|
47
52
|
}
|
|
@@ -67,24 +72,28 @@ var onUserCreate = (options) => async (user, ctx) => {
|
|
|
67
72
|
var onUserUpdate = (options) => async (user, ctx) => {
|
|
68
73
|
if (ctx && options.createCustomerOnSignUp) {
|
|
69
74
|
try {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
75
|
+
let customerId = user.dodoCustomerId;
|
|
76
|
+
if (!customerId) {
|
|
77
|
+
const customers = await options.client.customers.list({
|
|
78
|
+
email: user.email
|
|
79
|
+
});
|
|
80
|
+
const existingCustomer = customers.items[0];
|
|
81
|
+
if (!existingCustomer) return;
|
|
82
|
+
customerId = existingCustomer.customer_id;
|
|
83
|
+
ctx.context.internalAdapter.updateUser(user.id, {
|
|
84
|
+
dodoCustomerId: customerId
|
|
85
|
+
}).catch((e) => {
|
|
86
|
+
ctx.context.logger.warn(
|
|
87
|
+
`DodoPayments: failed to backfill dodoCustomerId for user ${user.id}. Error: ${e instanceof Error ? e.message : e}`
|
|
88
|
+
);
|
|
77
89
|
});
|
|
78
|
-
if (!user.dodoCustomerId) {
|
|
79
|
-
ctx.context.internalAdapter.updateUser(user.id, {
|
|
80
|
-
dodoCustomerId: existingCustomer.customer_id
|
|
81
|
-
}).catch((e) => {
|
|
82
|
-
ctx.context.logger.warn(
|
|
83
|
-
`DodoPayments: failed to backfill dodoCustomerId for user ${user.id}. Error: ${e instanceof Error ? e.message : e}`
|
|
84
|
-
);
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
90
|
}
|
|
91
|
+
const additionalParams = options.getCustomerParams ? await options.getCustomerParams(user) : void 0;
|
|
92
|
+
await options.client.customers.update(customerId, {
|
|
93
|
+
name: user.name,
|
|
94
|
+
metadata: additionalParams?.metadata,
|
|
95
|
+
phone_number: additionalParams?.phone_number
|
|
96
|
+
});
|
|
88
97
|
} catch (e) {
|
|
89
98
|
if (e instanceof Error) {
|
|
90
99
|
ctx.context.logger.error(
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/hooks/customer.ts"],"sourcesContent":["import type { GenericEndpointContext, User } from \"better-auth\";\nimport { APIError } from \"better-auth/api\";\nimport type { DodoPaymentsOptions } from \"../types\";\n\nexport const onUserCreate =\n (options: DodoPaymentsOptions) =>\n async (user: User, ctx: GenericEndpointContext | null) => {\n if (ctx && options.createCustomerOnSignUp) {\n try {\n const customers = await options.client.customers.list({\n email: user.email,\n });\n const existingCustomer = customers.items[0];\n\n let customerId: string;\n\n if (existingCustomer) {\n await options.client.customers.update(existingCustomer.customer_id, {\n name: user.name,\n });\n customerId = existingCustomer.customer_id;\n } else {\n
|
|
1
|
+
{"version":3,"sources":["../../src/hooks/customer.ts"],"sourcesContent":["import type { GenericEndpointContext, User } from \"better-auth\";\nimport { APIError } from \"better-auth/api\";\nimport type { DodoPaymentsOptions } from \"../types\";\n\nexport const onUserCreate =\n (options: DodoPaymentsOptions) =>\n async (user: User, ctx: GenericEndpointContext | null) => {\n if (ctx && options.createCustomerOnSignUp) {\n try {\n const customers = await options.client.customers.list({\n email: user.email,\n });\n const existingCustomer = customers.items[0];\n\n let customerId: string;\n\n const additionalParams = options.getCustomerParams\n ? await options.getCustomerParams(user)\n : undefined;\n\n if (existingCustomer) {\n await options.client.customers.update(existingCustomer.customer_id, {\n name: user.name,\n metadata: additionalParams?.metadata,\n phone_number: additionalParams?.phone_number,\n });\n customerId = existingCustomer.customer_id;\n } else {\n const newCustomer = await options.client.customers.create({\n email: user.email,\n name: user.name,\n metadata: additionalParams?.metadata,\n phone_number: additionalParams?.phone_number,\n }, { idempotencyKey: user.id });\n customerId = newCustomer.customer_id;\n }\n\n ctx.context.internalAdapter.updateUser(user.id, {\n dodoCustomerId: customerId,\n }).catch((e: unknown) => {\n ctx.context.logger.warn(\n `DodoPayments: failed to store dodoCustomerId for user ${user.id}. Error: ${e instanceof Error ? e.message : e}`,\n );\n });\n } catch (e: unknown) {\n if (e instanceof Error) {\n throw new APIError(\"INTERNAL_SERVER_ERROR\", {\n message: `DodoPayments customer creation failed. Error: ${e.message}`,\n });\n }\n\n throw new APIError(\"INTERNAL_SERVER_ERROR\", {\n message: `DodoPayments customer creation failed. Error: ${e}`,\n });\n }\n }\n };\n\nexport const onUserUpdate =\n (options: DodoPaymentsOptions) =>\n async (user: User, ctx: GenericEndpointContext | null) => {\n if (ctx && options.createCustomerOnSignUp) {\n try {\n let customerId = (user as User & { dodoCustomerId?: string }).dodoCustomerId;\n\n if (!customerId) {\n // Fallback to email lookup if dodoCustomerId is not stored yet\n const customers = await options.client.customers.list({\n email: user.email,\n });\n const existingCustomer = customers.items[0];\n\n if (!existingCustomer) return;\n\n customerId = existingCustomer.customer_id;\n\n // Backfill dodoCustomerId\n ctx.context.internalAdapter.updateUser(user.id, {\n dodoCustomerId: customerId,\n }).catch((e: unknown) => {\n ctx.context.logger.warn(\n `DodoPayments: failed to backfill dodoCustomerId for user ${user.id}. Error: ${e instanceof Error ? e.message : e}`,\n );\n });\n }\n\n const additionalParams = options.getCustomerParams\n ? await options.getCustomerParams(user)\n : undefined;\n\n await options.client.customers.update(customerId, {\n name: user.name,\n metadata: additionalParams?.metadata,\n phone_number: additionalParams?.phone_number,\n });\n } catch (e: unknown) {\n if (e instanceof Error) {\n ctx.context.logger.error(\n `DodoPayments customer update failed. Error: ${e.message}`,\n );\n } else {\n ctx.context.logger.error(\n `DodoPayments customer update failed. Error: ${e}`,\n );\n }\n }\n }\n };\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,iBAAyB;AAGlB,IAAM,eACX,CAAC,YACD,OAAO,MAAY,QAAuC;AACxD,MAAI,OAAO,QAAQ,wBAAwB;AACzC,QAAI;AACF,YAAM,YAAY,MAAM,QAAQ,OAAO,UAAU,KAA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AAC,YAAY;AAEf,cAAM,YAAY,MAAM,QAAQ,OAAO,UAAU,KAAK;AAAA,UACpD,OAAO,KAAK;AAAA,QACd,CAAC;AACD,cAAM,mBAAmB,UAAU,MAAM,CAAC;AAE1C,YAAI,CAAC,iBAAkB;AAEvB,qBAAa,iBAAiB;AAG9B,YAAI,QAAQ,gBAAgB,WAAW,KAAK,IAAI;AAAA,UAC9C,gBAAgB;AAAA,QAClB,CAAC,EAAE,MAAM,CAAC,MAAe;AACvB,cAAI,QAAQ,OAAO;AAAA,YACjB,4DAA4D,KAAK,EAAE,YAAY,aAAa,QAAQ,EAAE,UAAU,CAAC;AAAA,UACnH;AAAA,QACF,CAAC;AAAA,MACH;AAEA,YAAM,mBAAmB,QAAQ,oBAC7B,MAAM,QAAQ,kBAAkB,IAAI,IACpC;AAEJ,YAAM,QAAQ,OAAO,UAAU,OAAO,YAAY;AAAA,QAChD,MAAM,KAAK;AAAA,QACX,UAAU,kBAAkB;AAAA,QAC5B,cAAc,kBAAkB;AAAA,MAClC,CAAC;AAAA,IACH,SAAS,GAAY;AACnB,UAAI,aAAa,OAAO;AACtB,YAAI,QAAQ,OAAO;AAAA,UACjB,+CAA+C,EAAE,OAAO;AAAA,QAC1D;AAAA,MACF,OAAO;AACL,YAAI,QAAQ,OAAO;AAAA,UACjB,+CAA+C,CAAC;AAAA,QAClD;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { User, GenericEndpointContext } from 'better-auth';
|
|
2
|
-
import { D as DodoPaymentsOptions } from '../types-
|
|
2
|
+
import { D as DodoPaymentsOptions } from '../types-3pb2RGTM.cjs';
|
|
3
3
|
import 'dodopayments';
|
|
4
4
|
import 'zod/v3';
|
|
5
5
|
import '@dodopayments/core/webhook';
|
package/dist/hooks/customer.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { User, GenericEndpointContext } from 'better-auth';
|
|
2
|
-
import { D as DodoPaymentsOptions } from '../types-
|
|
2
|
+
import { D as DodoPaymentsOptions } from '../types-DygjjcRn.js';
|
|
3
3
|
import 'dodopayments';
|
|
4
4
|
import 'zod/v3';
|
|
5
5
|
import '@dodopayments/core/webhook';
|
package/dist/hooks/customer.js
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -39,15 +39,20 @@ var onUserCreate = (options) => async (user, ctx) => {
|
|
|
39
39
|
});
|
|
40
40
|
const existingCustomer = customers.items[0];
|
|
41
41
|
let customerId;
|
|
42
|
+
const additionalParams = options.getCustomerParams ? await options.getCustomerParams(user) : void 0;
|
|
42
43
|
if (existingCustomer) {
|
|
43
44
|
await options.client.customers.update(existingCustomer.customer_id, {
|
|
44
|
-
name: user.name
|
|
45
|
+
name: user.name,
|
|
46
|
+
metadata: additionalParams?.metadata,
|
|
47
|
+
phone_number: additionalParams?.phone_number
|
|
45
48
|
});
|
|
46
49
|
customerId = existingCustomer.customer_id;
|
|
47
50
|
} else {
|
|
48
51
|
const newCustomer = await options.client.customers.create({
|
|
49
52
|
email: user.email,
|
|
50
|
-
name: user.name
|
|
53
|
+
name: user.name,
|
|
54
|
+
metadata: additionalParams?.metadata,
|
|
55
|
+
phone_number: additionalParams?.phone_number
|
|
51
56
|
}, { idempotencyKey: user.id });
|
|
52
57
|
customerId = newCustomer.customer_id;
|
|
53
58
|
}
|
|
@@ -73,24 +78,28 @@ var onUserCreate = (options) => async (user, ctx) => {
|
|
|
73
78
|
var onUserUpdate = (options) => async (user, ctx) => {
|
|
74
79
|
if (ctx && options.createCustomerOnSignUp) {
|
|
75
80
|
try {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
81
|
+
let customerId = user.dodoCustomerId;
|
|
82
|
+
if (!customerId) {
|
|
83
|
+
const customers = await options.client.customers.list({
|
|
84
|
+
email: user.email
|
|
85
|
+
});
|
|
86
|
+
const existingCustomer = customers.items[0];
|
|
87
|
+
if (!existingCustomer) return;
|
|
88
|
+
customerId = existingCustomer.customer_id;
|
|
89
|
+
ctx.context.internalAdapter.updateUser(user.id, {
|
|
90
|
+
dodoCustomerId: customerId
|
|
91
|
+
}).catch((e) => {
|
|
92
|
+
ctx.context.logger.warn(
|
|
93
|
+
`DodoPayments: failed to backfill dodoCustomerId for user ${user.id}. Error: ${e instanceof Error ? e.message : e}`
|
|
94
|
+
);
|
|
83
95
|
});
|
|
84
|
-
if (!user.dodoCustomerId) {
|
|
85
|
-
ctx.context.internalAdapter.updateUser(user.id, {
|
|
86
|
-
dodoCustomerId: existingCustomer.customer_id
|
|
87
|
-
}).catch((e) => {
|
|
88
|
-
ctx.context.logger.warn(
|
|
89
|
-
`DodoPayments: failed to backfill dodoCustomerId for user ${user.id}. Error: ${e instanceof Error ? e.message : e}`
|
|
90
|
-
);
|
|
91
|
-
});
|
|
92
|
-
}
|
|
93
96
|
}
|
|
97
|
+
const additionalParams = options.getCustomerParams ? await options.getCustomerParams(user) : void 0;
|
|
98
|
+
await options.client.customers.update(customerId, {
|
|
99
|
+
name: user.name,
|
|
100
|
+
metadata: additionalParams?.metadata,
|
|
101
|
+
phone_number: additionalParams?.phone_number
|
|
102
|
+
});
|
|
94
103
|
} catch (e) {
|
|
95
104
|
if (e instanceof Error) {
|
|
96
105
|
ctx.context.logger.error(
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/hooks/customer.ts","../src/client.ts","../src/plugins/portal.ts","../src/utils.ts","../src/plugins/checkout.ts","../src/plugins/webhooks.ts","../src/plugins/usage.ts"],"sourcesContent":["import type { BetterAuthPlugin } from \"better-auth\";\nimport { onUserCreate, onUserUpdate } from \"./hooks/customer\";\nimport type { DodoPaymentsEndpoints, DodoPaymentsOptions } from \"./types\";\n\n// Re-export public types explicitly for wider TS compatibility\nexport type {\n Product,\n DodoPaymentsPlugin,\n DodoPaymentsPlugins,\n DodoPaymentsEndpoints,\n DodoPaymentsOptions,\n PaymentItems,\n SubscriptionItems,\n CustomerPortalResponse,\n CreateCheckoutResponse,\n WebhookResponse,\n} from \"./types\";\n\nexport { dodopaymentsClient } from \"./client\";\n\nexport { portal } from \"./plugins/portal\";\nexport { checkout, CheckoutOptions } from \"./plugins/checkout\";\nexport { webhooks } from \"./plugins/webhooks\";\nexport { usage } from \"./plugins/usage\";\n\nexport const dodopayments = (options: DodoPaymentsOptions) => {\n const plugins = options.use\n .map((use) => use(options.client))\n .reduce((acc, plugin) => {\n Object.assign(acc, plugin);\n return acc;\n }, {} as DodoPaymentsEndpoints);\n\n return {\n id: \"dodopayments\",\n schema: {\n user: {\n fields: {\n dodoCustomerId: {\n type: \"string\",\n required: false,\n input: false,\n },\n },\n },\n },\n endpoints: {\n ...plugins,\n },\n init() {\n return {\n options: {\n databaseHooks: {\n user: {\n create: {\n after: onUserCreate(options),\n },\n update: {\n after: onUserUpdate(options),\n },\n },\n },\n },\n };\n },\n } satisfies BetterAuthPlugin;\n};\n","import type { GenericEndpointContext, User } from \"better-auth\";\nimport { APIError } from \"better-auth/api\";\nimport type { DodoPaymentsOptions } from \"../types\";\n\nexport const onUserCreate =\n (options: DodoPaymentsOptions) =>\n async (user: User, ctx: GenericEndpointContext | null) => {\n if (ctx && options.createCustomerOnSignUp) {\n try {\n const customers = await options.client.customers.list({\n email: user.email,\n });\n const existingCustomer = customers.items[0];\n\n let customerId: string;\n\n if (existingCustomer) {\n await options.client.customers.update(existingCustomer.customer_id, {\n name: user.name,\n });\n customerId = existingCustomer.customer_id;\n } else {\n // TODO: Add metadata to customer object via\n // getCustomerCreateParams option when it becomes\n // available in the API\n const newCustomer = await options.client.customers.create({\n email: user.email,\n name: user.name,\n }, { idempotencyKey: user.id });\n customerId = newCustomer.customer_id;\n }\n\n ctx.context.internalAdapter.updateUser(user.id, {\n dodoCustomerId: customerId,\n }).catch((e: unknown) => {\n ctx.context.logger.warn(\n `DodoPayments: failed to store dodoCustomerId for user ${user.id}. Error: ${e instanceof Error ? e.message : e}`,\n );\n });\n } catch (e: unknown) {\n if (e instanceof Error) {\n throw new APIError(\"INTERNAL_SERVER_ERROR\", {\n message: `DodoPayments customer creation failed. Error: ${e.message}`,\n });\n }\n\n throw new APIError(\"INTERNAL_SERVER_ERROR\", {\n message: `DodoPayments customer creation failed. Error: ${e}`,\n });\n }\n }\n };\n\nexport const onUserUpdate =\n (options: DodoPaymentsOptions) =>\n async (user: User, ctx: GenericEndpointContext | null) => {\n if (ctx && options.createCustomerOnSignUp) {\n try {\n const customers = await options.client.customers.list({\n email: user.email,\n });\n const existingCustomer = customers.items[0];\n\n if (existingCustomer) {\n // TODO: Add metadata to customer object via\n // getCustomerCreateParams option when it becomes\n // available in the API\n await options.client.customers.update(existingCustomer.customer_id, {\n name: user.name,\n });\n\n // Backfill dodoCustomerId if it doesn't exist\n if (!(user as User & { dodoCustomerId?: string }).dodoCustomerId) {\n ctx.context.internalAdapter.updateUser(user.id, {\n dodoCustomerId: existingCustomer.customer_id,\n }).catch((e: unknown) => {\n ctx.context.logger.warn(\n `DodoPayments: failed to backfill dodoCustomerId for user ${user.id}. Error: ${e instanceof Error ? e.message : e}`,\n );\n });\n }\n }\n } catch (e: unknown) {\n if (e instanceof Error) {\n ctx.context.logger.error(\n `DodoPayments customer update failed. Error: ${e.message}`,\n );\n } else {\n ctx.context.logger.error(\n `DodoPayments customer update failed. Error: ${e}`,\n );\n }\n }\n }\n };\n","import type { BetterAuthClientPlugin } from \"better-auth\";\nimport type { dodopayments } from \"./index\";\n\nexport const dodopaymentsClient = () => {\n return {\n id: \"dodopayments-client\",\n $InferServerPlugin: {} as ReturnType<typeof dodopayments>,\n } satisfies BetterAuthClientPlugin;\n};\n\nexport type {\n Product,\n DodoPaymentsEndpoints,\n DodoPaymentsOptions,\n PaymentItems,\n SubscriptionItems,\n CustomerPortalResponse,\n CreateCheckoutResponse,\n WebhookResponse,\n} from \"./types\";\n","import type { DodoPayments } from \"dodopayments\";\nimport { APIError, createAuthEndpoint, sessionMiddleware } from \"better-auth/api\";\nimport { z } from \"zod/v3\";\nimport {\n CustomerPortalResponse,\n PaymentItems,\n SubscriptionItems,\n} from \"../types\";\nimport { getOrCreateCustomerId } from \"../utils\";\n\nexport const portal = () => (dodopayments: DodoPayments) => {\n return {\n dodoPortal: createAuthEndpoint(\n \"/dodopayments/customer/portal\",\n {\n method: \"GET\",\n use: [sessionMiddleware],\n },\n async (ctx): Promise<CustomerPortalResponse> => {\n if (!ctx.context.session?.user.id) {\n throw new APIError(\"BAD_REQUEST\", {\n message: \"User not found\",\n });\n }\n\n if (!ctx.context.session?.user.emailVerified) {\n throw new APIError(\"UNAUTHORIZED\", {\n message: \"User email not verified\",\n });\n }\n\n try {\n const customerId = await getOrCreateCustomerId(\n dodopayments,\n ctx.context.session,\n ctx.context.internalAdapter,\n );\n\n const customerSession =\n await dodopayments.customers.customerPortal.create(customerId);\n\n return ctx.json({\n url: customerSession.link,\n redirect: true,\n });\n } catch (e: unknown) {\n if (e instanceof Error) {\n ctx.context.logger.error(\n `DodoPayments customer portal creation failed. Error: ${e.message}`,\n );\n }\n\n throw new APIError(\"INTERNAL_SERVER_ERROR\", {\n message: \"Customer portal creation failed\",\n });\n }\n },\n ),\n dodoSubscriptions: createAuthEndpoint(\n \"/dodopayments/customer/subscriptions/list\",\n {\n method: \"GET\",\n query: z\n .object({\n page: z.coerce.number().optional(),\n limit: z.coerce.number().optional(),\n status: z\n .enum([\n \"active\",\n \"cancelled\",\n \"on_hold\",\n \"pending\",\n \"failed\",\n \"expired\",\n ])\n .optional(),\n })\n .optional(),\n use: [sessionMiddleware],\n },\n async (ctx): Promise<SubscriptionItems> => {\n if (!ctx.context.session.user.id) {\n throw new APIError(\"BAD_REQUEST\", {\n message: \"User not found\",\n });\n }\n\n if (!ctx.context.session?.user.emailVerified) {\n throw new APIError(\"UNAUTHORIZED\", {\n message: \"User email not verified\",\n });\n }\n\n try {\n const customerId = await getOrCreateCustomerId(\n dodopayments,\n ctx.context.session,\n ctx.context.internalAdapter,\n );\n\n const subscriptions = await dodopayments.subscriptions.list({\n customer_id: customerId,\n // page number is 0-indexed\n page_number: ctx.query?.page ? ctx.query.page - 1 : undefined,\n page_size: ctx.query?.limit,\n status: ctx.query?.status,\n });\n\n return ctx.json({ items: subscriptions.items });\n } catch (e: unknown) {\n if (e instanceof Error) {\n ctx.context.logger.error(\n `DodoPayments subscriptions list failed. Error: ${e.message}`,\n );\n }\n\n throw new APIError(\"INTERNAL_SERVER_ERROR\", {\n message: \"DodoPayments subscriptions list failed\",\n });\n }\n },\n ),\n dodoPayments: createAuthEndpoint(\n \"/dodopayments/customer/payments/list\",\n {\n method: \"GET\",\n query: z\n .object({\n page: z.coerce.number().optional(),\n limit: z.coerce.number().optional(),\n status: z\n .enum([\n \"succeeded\",\n \"failed\",\n \"cancelled\",\n \"processing\",\n \"requires_customer_action\",\n \"requires_merchant_action\",\n \"requires_payment_method\",\n \"requires_confirmation\",\n \"requires_capture\",\n \"partially_captured\",\n \"partially_captured_and_capturable\",\n ])\n .optional(),\n })\n .optional(),\n use: [sessionMiddleware],\n },\n async (ctx): Promise<PaymentItems> => {\n if (!ctx.context.session.user.id) {\n throw new APIError(\"BAD_REQUEST\", {\n message: \"User not found\",\n });\n }\n\n if (!ctx.context.session?.user.emailVerified) {\n throw new APIError(\"UNAUTHORIZED\", {\n message: \"User email not verified\",\n });\n }\n\n try {\n const customerId = await getOrCreateCustomerId(\n dodopayments,\n ctx.context.session,\n ctx.context.internalAdapter,\n );\n\n const payments = await dodopayments.payments.list({\n customer_id: customerId,\n // page number is 0-indexed\n page_number: ctx.query?.page ? ctx.query.page - 1 : undefined,\n page_size: ctx.query?.limit,\n status: ctx.query?.status,\n });\n\n return ctx.json({ items: payments.items });\n } catch (e: unknown) {\n if (e instanceof Error) {\n ctx.context.logger.error(\n `DodoPayments orders list failed. Error: ${e.message}`,\n );\n }\n\n throw new APIError(\"INTERNAL_SERVER_ERROR\", {\n message: \"Orders list failed\",\n });\n }\n },\n ),\n };\n};\n\n","import type { DodoPayments } from \"dodopayments\";\n\nexport async function getOrCreateCustomerId(\n dodopayments: DodoPayments,\n session: { user: { id: string; email: string; name: string } & Record<string, unknown> },\n internalAdapter: { updateUser: (id: string, data: Record<string, unknown>) => Promise<unknown> },\n): Promise<string> {\n const dodoCustomerId = session.user[\"dodoCustomerId\"] as string | undefined;\n if (dodoCustomerId) return dodoCustomerId;\n\n // Fallback to get customer from email if dodoCustomerId doesn't exist\n const customers = await dodopayments.customers.list({\n email: session.user.email,\n });\n let customer = customers.items[0];\n\n if (!customer) {\n customer = await dodopayments.customers.create({\n email: session.user.email,\n name: session.user.name,\n }, { idempotencyKey: session.user.id });\n }\n\n internalAdapter\n .updateUser(session.user.id, { dodoCustomerId: customer.customer_id })\n .catch(() => {});\n\n return customer.customer_id;\n}\n","import type DodoPayments from \"dodopayments\";\nimport { APIError, createAuthEndpoint, getSessionFromCtx } from \"better-auth/api\";\nimport { z } from \"zod/v3\";\nimport type { CreateCheckoutResponse, Product } from \"../types\";\nimport {\n buildCheckoutUrl,\n checkoutSessionPayloadSchema,\n dynamicCheckoutBodySchema,\n} from \"@dodopayments/core/checkout\";\n\nexport interface CheckoutOptions {\n /**\n * Optional list of slug -> productId mappings for easy slug checkouts\n */\n products?: Product[] | (() => Promise<Product[]>);\n /**\n * Checkout Success URL\n */\n successUrl?: string;\n /**\n * Only allow authenticated customers to checkout\n */\n authenticatedUsersOnly?: boolean;\n}\n\nexport const checkout =\n (checkoutOptions: CheckoutOptions = {}) =>\n (dodopayments: DodoPayments) => {\n return {\n /**\n * @deprecated\n */\n dodoCheckout: createAuthEndpoint(\n \"/dodopayments/checkout\",\n {\n method: \"POST\",\n body: dynamicCheckoutBodySchema.extend({\n slug: z.string().optional(),\n referenceId: z.string().optional(),\n }),\n requireRequest: true,\n },\n async (ctx): Promise<CreateCheckoutResponse> => {\n const session = await getSessionFromCtx(ctx);\n\n let dodoPaymentsProductId: string | undefined;\n\n if (ctx.body?.slug) {\n const resolvedProducts =\n typeof checkoutOptions.products === \"function\"\n ? await checkoutOptions.products()\n : checkoutOptions.products;\n\n const productId = resolvedProducts?.find(\n (product) => product.slug === ctx.body.slug,\n )?.productId;\n\n if (!productId) {\n throw new APIError(\"BAD_REQUEST\", {\n message: \"Product not found\",\n });\n }\n\n dodoPaymentsProductId = productId;\n } else {\n dodoPaymentsProductId = ctx.body.product_id;\n }\n\n if (checkoutOptions.authenticatedUsersOnly && !session?.user.id) {\n throw new APIError(\"UNAUTHORIZED\", {\n message: \"You must be logged in to checkout\",\n });\n }\n\n try {\n const checkoutUrl = await buildCheckoutUrl({\n body: {\n ...ctx.body,\n product_id: dodoPaymentsProductId,\n customer: {\n email: session?.user.email,\n name: session?.user.name,\n ...ctx.body.customer,\n },\n product_cart: dodoPaymentsProductId\n ? [\n {\n product_id: dodoPaymentsProductId,\n quantity: 1,\n },\n ]\n : undefined,\n metadata: ctx.body.referenceId\n ? {\n referenceId: ctx.body.referenceId,\n ...ctx.body.metadata,\n }\n : ctx.body.metadata,\n },\n bearerToken: dodopayments.bearerToken,\n environment: dodopayments.baseURL.includes(\"test\")\n ? \"test_mode\"\n : \"live_mode\",\n returnUrl: checkoutOptions.successUrl\n ? new URL(\n checkoutOptions.successUrl,\n ctx.request?.url,\n ).toString()\n : undefined,\n type: \"dynamic\",\n });\n\n const redirectUrl = new URL(checkoutUrl);\n\n return ctx.json({\n url: redirectUrl.toString(),\n redirect: true,\n });\n } catch (e: unknown) {\n if (e instanceof Error) {\n ctx.context.logger.error(\n `DodoPayments checkout creation failed. Error: ${e.message}`,\n );\n }\n\n throw new APIError(\"INTERNAL_SERVER_ERROR\", {\n message: \"Checkout creation failed\",\n });\n }\n },\n ),\n dodoCheckoutSession: createAuthEndpoint(\n \"/dodopayments/checkout-session\",\n {\n method: \"POST\",\n body: checkoutSessionPayloadSchema\n .extend({\n slug: z.string().optional(),\n referenceId: z.string().optional(),\n })\n .partial({\n product_cart: true,\n }),\n requireRequest: true,\n },\n async (ctx): Promise<CreateCheckoutResponse> => {\n const session = await getSessionFromCtx(ctx);\n\n let dodoPaymentsProductId: string | undefined;\n\n if (ctx.body?.slug) {\n const resolvedProducts =\n typeof checkoutOptions.products === \"function\"\n ? await checkoutOptions.products()\n : checkoutOptions.products;\n\n const productId = resolvedProducts?.find(\n (product) => product.slug === ctx.body.slug,\n )?.productId;\n\n if (!productId) {\n throw new APIError(\"BAD_REQUEST\", {\n message: \"Product not found\",\n });\n }\n\n dodoPaymentsProductId = productId;\n }\n\n if (checkoutOptions.authenticatedUsersOnly && !session?.user.id) {\n throw new APIError(\"UNAUTHORIZED\", {\n message: \"You must be logged in to checkout\",\n });\n }\n\n // Ensure we have a product_cart\n const product_cart = dodoPaymentsProductId\n ? [{ product_id: dodoPaymentsProductId, quantity: 1 }]\n : ctx.body.product_cart;\n\n if (!product_cart || product_cart.length === 0) {\n throw new APIError(\"BAD_REQUEST\", {\n message: \"Neither product_cart nor slug was provided\",\n });\n }\n\n try {\n const checkoutUrl = await buildCheckoutUrl({\n sessionPayload: {\n ...ctx.body,\n product_cart,\n customer: session?.user.email\n ? {\n email: session?.user.email,\n name: session?.user.name,\n }\n : ctx.body.customer,\n metadata: ctx.body.referenceId\n ? {\n referenceId: ctx.body.referenceId,\n ...ctx.body.metadata,\n }\n : ctx.body.metadata,\n return_url: checkoutOptions.successUrl\n ? new URL(\n checkoutOptions.successUrl,\n ctx.request?.url,\n ).toString()\n : undefined,\n },\n bearerToken: dodopayments.bearerToken,\n environment: dodopayments.baseURL.includes(\"test\")\n ? \"test_mode\"\n : \"live_mode\",\n type: \"session\",\n });\n\n const redirectUrl = new URL(checkoutUrl);\n\n return ctx.json({\n url: redirectUrl.toString(),\n redirect: true,\n });\n } catch (e: unknown) {\n if (e instanceof Error) {\n ctx.context.logger.error(\n `DodoPayments checkout creation failed. Error: ${e.message}`,\n );\n }\n\n throw new APIError(\"INTERNAL_SERVER_ERROR\", {\n message: \"Checkout session creation failed\",\n });\n }\n },\n ),\n };\n };\n","import type { DodoPayments } from \"dodopayments\";\nimport {\n handleWebhookPayload,\n WebhookHandlerConfig,\n} from \"@dodopayments/core/webhook\";\nimport { APIError, createAuthEndpoint } from \"better-auth/api\";\nimport { WebhookPayload } from \"@dodopayments/core/schemas\";\nimport { verifyWebhookPayload } from \"@dodopayments/core/webhook\";\nimport type { WebhookResponse } from \"../types\";\n\nexport const webhooks =\n (options: WebhookHandlerConfig) => (_dodopayments: DodoPayments) => {\n return {\n dodopaymentsWebhooks: createAuthEndpoint(\n \"/dodopayments/webhooks\",\n {\n method: \"POST\",\n metadata: {\n isAction: false,\n },\n cloneRequest: true,\n },\n async (ctx): Promise<WebhookResponse> => {\n const { webhookKey } = options;\n\n if (!ctx.request?.body) {\n throw new APIError(\"INTERNAL_SERVER_ERROR\");\n }\n const buf = await ctx.request.text();\n let event: WebhookPayload;\n try {\n if (!webhookKey) {\n throw new APIError(\"INTERNAL_SERVER_ERROR\", {\n message: \"DodoPayments webhook webhookKey not found\",\n });\n }\n\n const headers = {\n \"webhook-id\": ctx.request.headers.get(\"webhook-id\") as string,\n \"webhook-timestamp\": ctx.request.headers.get(\n \"webhook-timestamp\",\n ) as string,\n \"webhook-signature\": ctx.request.headers.get(\n \"webhook-signature\",\n ) as string,\n };\n\n event = await verifyWebhookPayload({\n webhookKey,\n headers,\n body: buf,\n });\n } catch (err: unknown) {\n if (err instanceof Error) {\n ctx.context.logger.error(`Webhook Error: ${err.message}`);\n throw new APIError(\"BAD_REQUEST\", {\n message: `Webhook Error: ${err.message}`,\n });\n }\n\n throw new APIError(\"BAD_REQUEST\", {\n message: `Webhook Error: ${err}`,\n });\n }\n\n try {\n await handleWebhookPayload(event, options);\n } catch (e: unknown) {\n if (e instanceof Error) {\n ctx.context.logger.error(\n `DodoPayments webhook failed. Error: ${e.message}`,\n );\n }\n\n ctx.context.logger.error(\n `DodoPayments webhook failed. Error: ${e}`,\n );\n\n throw new APIError(\"BAD_REQUEST\", {\n message: \"Webhook error: See server logs for more information.\",\n });\n }\n\n return ctx.json({ received: true });\n },\n ),\n };\n };\n","import {\n APIError,\n createAuthEndpoint,\n sessionMiddleware,\n} from \"better-auth/api\";\nimport type { DodoPayments } from \"dodopayments\";\nimport { Event } from \"dodopayments/resources/usage-events.mjs\";\nimport { z } from \"zod/v3\";\nimport { getOrCreateCustomerId } from \"../utils\";\n\nconst EventInputSchema = z.object({\n event_id: z.string(),\n event_name: z.string(),\n metadata: z\n .record(z.union([z.string(), z.number(), z.boolean()]))\n .nullable()\n .optional(),\n timestamp: z\n // NOTE: coerce because the date object gets converted to a string over network requests\n // but we still want to enforce that it's a Date type\n .date({ coerce: true })\n .transform((d) => d.toISOString())\n .optional()\n .describe(\n \"Custom Timestamp. Defaults to current timestamp in UTC.\\\n Timestamps that are older that 1 hour or after 5 mins from\\\n current timestamp will be rejected.\",\n ),\n});\n\nexport const usage = () => (dodopayments: DodoPayments) => {\n return {\n // Ingest usage data\n dodoUsageIngest: createAuthEndpoint(\n \"/dodopayments/usage/ingest\",\n {\n method: \"POST\",\n body: EventInputSchema,\n use: [sessionMiddleware],\n },\n async (ctx): Promise<{ ingested_count: number }> => {\n if (!ctx.context.session?.user?.id) {\n throw new APIError(\"BAD_REQUEST\", {\n message: \"User not found\",\n });\n }\n\n if (!ctx.context.session?.user.emailVerified) {\n throw new APIError(\"UNAUTHORIZED\", {\n message: \"User email not verified\",\n });\n }\n\n try {\n const customerId = await getOrCreateCustomerId(\n dodopayments,\n ctx.context.session,\n ctx.context.internalAdapter,\n );\n\n const result = await dodopayments.usageEvents.ingest({\n events: [\n {\n event_id: ctx.body.event_id,\n customer_id: customerId,\n event_name: ctx.body.event_name,\n timestamp: ctx.body.timestamp,\n metadata: ctx.body.metadata,\n },\n ],\n });\n\n return ctx.json({ ingested_count: result.ingested_count });\n } catch (e: unknown) {\n if (e instanceof Error) {\n ctx.context.logger.error(\n `User usage ingestion error: ${e.message}`,\n );\n }\n\n throw new APIError(\"INTERNAL_SERVER_ERROR\", {\n message: \"Failed to record the user usage\",\n });\n }\n },\n ),\n\n // List usage meters\n dodoUsageMetersList: createAuthEndpoint(\n \"/dodopayments/usage/meters/list\",\n {\n method: \"GET\",\n query: z\n .object({\n page_number: z.coerce.number().optional(),\n page_size: z.coerce.number().optional(),\n event_name: z.string().optional(),\n meter_id: z.string().optional(),\n start: z.string().optional(),\n end: z.string().optional(),\n })\n .optional(),\n use: [sessionMiddleware],\n },\n async (ctx): Promise<{ items: Event[] }> => {\n if (!ctx.context.session?.user?.id) {\n throw new APIError(\"BAD_REQUEST\", {\n message: \"User not found\",\n });\n }\n\n if (!ctx.context.session?.user.emailVerified) {\n throw new APIError(\"UNAUTHORIZED\", {\n message: \"User email not verified\",\n });\n }\n\n try {\n const customerId = await getOrCreateCustomerId(\n dodopayments,\n ctx.context.session,\n ctx.context.internalAdapter,\n );\n\n const meters = await dodopayments.usageEvents.list({\n customer_id: customerId,\n ...ctx.query,\n });\n\n return ctx.json({ items: meters.items });\n } catch (e: unknown) {\n if (e instanceof Error) {\n ctx.context.logger.error(\n `User usage meter list error: ${e.message}`,\n );\n }\n\n throw new APIError(\"INTERNAL_SERVER_ERROR\", {\n message: \"Failed to fetch the user usage\",\n });\n }\n },\n ),\n };\n};\n\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACCA,iBAAyB;AAGlB,IAAM,eACX,CAAC,YACD,OAAO,MAAY,QAAuC;AACxD,MAAI,OAAO,QAAQ,wBAAwB;AACzC,QAAI;AACF,YAAM,YAAY,MAAM,QAAQ,OAAO,UAAU,KAAK;AAAA,QACpD,OAAO,KAAK;AAAA,MACd,CAAC;AACD,YAAM,mBAAmB,UAAU,MAAM,CAAC;AAE1C,UAAI;AAEJ,UAAI,kBAAkB;AACpB,cAAM,QAAQ,OAAO,UAAU,OAAO,iBAAiB,aAAa;AAAA,UAClE,MAAM,KAAK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AC7B;AAAA,cACA,QAAQ;AAAA,gBACN,OAAO,aAAa,OAAO;AAAA,cAC7B;AAAA,YACF;AAAA,UACF;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;","names":["import_api","dodopayments","dodopayments","import_api","import_v3","dodopayments","import_api","import_webhook","import_api","import_v3","dodopayments"]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/hooks/customer.ts","../src/client.ts","../src/plugins/portal.ts","../src/utils.ts","../src/plugins/checkout.ts","../src/plugins/webhooks.ts","../src/plugins/usage.ts"],"sourcesContent":["import type { BetterAuthPlugin } from \"better-auth\";\nimport { onUserCreate, onUserUpdate } from \"./hooks/customer\";\nimport type { DodoPaymentsEndpoints, DodoPaymentsOptions } from \"./types\";\n\n// Re-export public types explicitly for wider TS compatibility\nexport type {\n Product,\n DodoPaymentsPlugin,\n DodoPaymentsPlugins,\n DodoPaymentsEndpoints,\n DodoPaymentsOptions,\n PaymentItems,\n SubscriptionItems,\n CustomerPortalResponse,\n CreateCheckoutResponse,\n WebhookResponse,\n} from \"./types\";\n\nexport { dodopaymentsClient } from \"./client\";\n\nexport { portal } from \"./plugins/portal\";\nexport { checkout, CheckoutOptions } from \"./plugins/checkout\";\nexport { webhooks } from \"./plugins/webhooks\";\nexport { usage } from \"./plugins/usage\";\n\nexport const dodopayments = (options: DodoPaymentsOptions) => {\n const plugins = options.use\n .map((use) => use(options.client))\n .reduce((acc, plugin) => {\n Object.assign(acc, plugin);\n return acc;\n }, {} as DodoPaymentsEndpoints);\n\n return {\n id: \"dodopayments\",\n schema: {\n user: {\n fields: {\n dodoCustomerId: {\n type: \"string\",\n required: false,\n input: false,\n },\n },\n },\n },\n endpoints: {\n ...plugins,\n },\n init() {\n return {\n options: {\n databaseHooks: {\n user: {\n create: {\n after: onUserCreate(options),\n },\n update: {\n after: onUserUpdate(options),\n },\n },\n },\n },\n };\n },\n } satisfies BetterAuthPlugin;\n};\n","import type { GenericEndpointContext, User } from \"better-auth\";\nimport { APIError } from \"better-auth/api\";\nimport type { DodoPaymentsOptions } from \"../types\";\n\nexport const onUserCreate =\n (options: DodoPaymentsOptions) =>\n async (user: User, ctx: GenericEndpointContext | null) => {\n if (ctx && options.createCustomerOnSignUp) {\n try {\n const customers = await options.client.customers.list({\n email: user.email,\n });\n const existingCustomer = customers.items[0];\n\n let customerId: string;\n\n const additionalParams = options.getCustomerParams\n ? await options.getCustomerParams(user)\n : undefined;\n\n if (existingCustomer) {\n await options.client.customers.update(existingCustomer.customer_id, {\n name: user.name,\n metadata: additionalParams?.metadata,\n phone_number: additionalParams?.phone_number,\n });\n customerId = existingCustomer.customer_id;\n } else {\n const newCustomer = await options.client.customers.create({\n email: user.email,\n name: user.name,\n metadata: additionalParams?.metadata,\n phone_number: additionalParams?.phone_number,\n }, { idempotencyKey: user.id });\n customerId = newCustomer.customer_id;\n }\n\n ctx.context.internalAdapter.updateUser(user.id, {\n dodoCustomerId: customerId,\n }).catch((e: unknown) => {\n ctx.context.logger.warn(\n `DodoPayments: failed to store dodoCustomerId for user ${user.id}. Error: ${e instanceof Error ? e.message : e}`,\n );\n });\n } catch (e: unknown) {\n if (e instanceof Error) {\n throw new APIError(\"INTERNAL_SERVER_ERROR\", {\n message: `DodoPayments customer creation failed. Error: ${e.message}`,\n });\n }\n\n throw new APIError(\"INTERNAL_SERVER_ERROR\", {\n message: `DodoPayments customer creation failed. Error: ${e}`,\n });\n }\n }\n };\n\nexport const onUserUpdate =\n (options: DodoPaymentsOptions) =>\n async (user: User, ctx: GenericEndpointContext | null) => {\n if (ctx && options.createCustomerOnSignUp) {\n try {\n let customerId = (user as User & { dodoCustomerId?: string }).dodoCustomerId;\n\n if (!customerId) {\n // Fallback to email lookup if dodoCustomerId is not stored yet\n const customers = await options.client.customers.list({\n email: user.email,\n });\n const existingCustomer = customers.items[0];\n\n if (!existingCustomer) return;\n\n customerId = existingCustomer.customer_id;\n\n // Backfill dodoCustomerId\n ctx.context.internalAdapter.updateUser(user.id, {\n dodoCustomerId: customerId,\n }).catch((e: unknown) => {\n ctx.context.logger.warn(\n `DodoPayments: failed to backfill dodoCustomerId for user ${user.id}. Error: ${e instanceof Error ? e.message : e}`,\n );\n });\n }\n\n const additionalParams = options.getCustomerParams\n ? await options.getCustomerParams(user)\n : undefined;\n\n await options.client.customers.update(customerId, {\n name: user.name,\n metadata: additionalParams?.metadata,\n phone_number: additionalParams?.phone_number,\n });\n } catch (e: unknown) {\n if (e instanceof Error) {\n ctx.context.logger.error(\n `DodoPayments customer update failed. Error: ${e.message}`,\n );\n } else {\n ctx.context.logger.error(\n `DodoPayments customer update failed. Error: ${e}`,\n );\n }\n }\n }\n };\n","import type { BetterAuthClientPlugin } from \"better-auth\";\nimport type { dodopayments } from \"./index\";\n\nexport const dodopaymentsClient = () => {\n return {\n id: \"dodopayments-client\",\n $InferServerPlugin: {} as ReturnType<typeof dodopayments>,\n } satisfies BetterAuthClientPlugin;\n};\n\nexport type {\n Product,\n DodoPaymentsEndpoints,\n DodoPaymentsOptions,\n PaymentItems,\n SubscriptionItems,\n CustomerPortalResponse,\n CreateCheckoutResponse,\n WebhookResponse,\n} from \"./types\";\n","import type { DodoPayments } from \"dodopayments\";\nimport { APIError, createAuthEndpoint, sessionMiddleware } from \"better-auth/api\";\nimport { z } from \"zod/v3\";\nimport {\n CustomerPortalResponse,\n PaymentItems,\n SubscriptionItems,\n} from \"../types\";\nimport { getOrCreateCustomerId } from \"../utils\";\n\nexport const portal = () => (dodopayments: DodoPayments) => {\n return {\n dodoPortal: createAuthEndpoint(\n \"/dodopayments/customer/portal\",\n {\n method: \"GET\",\n use: [sessionMiddleware],\n },\n async (ctx): Promise<CustomerPortalResponse> => {\n if (!ctx.context.session?.user.id) {\n throw new APIError(\"BAD_REQUEST\", {\n message: \"User not found\",\n });\n }\n\n if (!ctx.context.session?.user.emailVerified) {\n throw new APIError(\"UNAUTHORIZED\", {\n message: \"User email not verified\",\n });\n }\n\n try {\n const customerId = await getOrCreateCustomerId(\n dodopayments,\n ctx.context.session,\n ctx.context.internalAdapter,\n );\n\n const customerSession =\n await dodopayments.customers.customerPortal.create(customerId);\n\n return ctx.json({\n url: customerSession.link,\n redirect: true,\n });\n } catch (e: unknown) {\n if (e instanceof Error) {\n ctx.context.logger.error(\n `DodoPayments customer portal creation failed. Error: ${e.message}`,\n );\n }\n\n throw new APIError(\"INTERNAL_SERVER_ERROR\", {\n message: \"Customer portal creation failed\",\n });\n }\n },\n ),\n dodoSubscriptions: createAuthEndpoint(\n \"/dodopayments/customer/subscriptions/list\",\n {\n method: \"GET\",\n query: z\n .object({\n page: z.coerce.number().optional(),\n limit: z.coerce.number().optional(),\n status: z\n .enum([\n \"active\",\n \"cancelled\",\n \"on_hold\",\n \"pending\",\n \"failed\",\n \"expired\",\n ])\n .optional(),\n })\n .optional(),\n use: [sessionMiddleware],\n },\n async (ctx): Promise<SubscriptionItems> => {\n if (!ctx.context.session.user.id) {\n throw new APIError(\"BAD_REQUEST\", {\n message: \"User not found\",\n });\n }\n\n if (!ctx.context.session?.user.emailVerified) {\n throw new APIError(\"UNAUTHORIZED\", {\n message: \"User email not verified\",\n });\n }\n\n try {\n const customerId = await getOrCreateCustomerId(\n dodopayments,\n ctx.context.session,\n ctx.context.internalAdapter,\n );\n\n const subscriptions = await dodopayments.subscriptions.list({\n customer_id: customerId,\n // page number is 0-indexed\n page_number: ctx.query?.page ? ctx.query.page - 1 : undefined,\n page_size: ctx.query?.limit,\n status: ctx.query?.status,\n });\n\n return ctx.json({ items: subscriptions.items });\n } catch (e: unknown) {\n if (e instanceof Error) {\n ctx.context.logger.error(\n `DodoPayments subscriptions list failed. Error: ${e.message}`,\n );\n }\n\n throw new APIError(\"INTERNAL_SERVER_ERROR\", {\n message: \"DodoPayments subscriptions list failed\",\n });\n }\n },\n ),\n dodoPayments: createAuthEndpoint(\n \"/dodopayments/customer/payments/list\",\n {\n method: \"GET\",\n query: z\n .object({\n page: z.coerce.number().optional(),\n limit: z.coerce.number().optional(),\n status: z\n .enum([\n \"succeeded\",\n \"failed\",\n \"cancelled\",\n \"processing\",\n \"requires_customer_action\",\n \"requires_merchant_action\",\n \"requires_payment_method\",\n \"requires_confirmation\",\n \"requires_capture\",\n \"partially_captured\",\n \"partially_captured_and_capturable\",\n ])\n .optional(),\n })\n .optional(),\n use: [sessionMiddleware],\n },\n async (ctx): Promise<PaymentItems> => {\n if (!ctx.context.session.user.id) {\n throw new APIError(\"BAD_REQUEST\", {\n message: \"User not found\",\n });\n }\n\n if (!ctx.context.session?.user.emailVerified) {\n throw new APIError(\"UNAUTHORIZED\", {\n message: \"User email not verified\",\n });\n }\n\n try {\n const customerId = await getOrCreateCustomerId(\n dodopayments,\n ctx.context.session,\n ctx.context.internalAdapter,\n );\n\n const payments = await dodopayments.payments.list({\n customer_id: customerId,\n // page number is 0-indexed\n page_number: ctx.query?.page ? ctx.query.page - 1 : undefined,\n page_size: ctx.query?.limit,\n status: ctx.query?.status,\n });\n\n return ctx.json({ items: payments.items });\n } catch (e: unknown) {\n if (e instanceof Error) {\n ctx.context.logger.error(\n `DodoPayments orders list failed. Error: ${e.message}`,\n );\n }\n\n throw new APIError(\"INTERNAL_SERVER_ERROR\", {\n message: \"Orders list failed\",\n });\n }\n },\n ),\n };\n};\n\n","import type { DodoPayments } from \"dodopayments\";\n\nexport async function getOrCreateCustomerId(\n dodopayments: DodoPayments,\n session: { user: { id: string; email: string; name: string } & Record<string, unknown> },\n internalAdapter: { updateUser: (id: string, data: Record<string, unknown>) => Promise<unknown> },\n): Promise<string> {\n const dodoCustomerId = session.user[\"dodoCustomerId\"] as string | undefined;\n if (dodoCustomerId) return dodoCustomerId;\n\n // Fallback to get customer from email if dodoCustomerId doesn't exist\n const customers = await dodopayments.customers.list({\n email: session.user.email,\n });\n let customer = customers.items[0];\n\n if (!customer) {\n customer = await dodopayments.customers.create({\n email: session.user.email,\n name: session.user.name,\n }, { idempotencyKey: session.user.id });\n }\n\n internalAdapter\n .updateUser(session.user.id, { dodoCustomerId: customer.customer_id })\n .catch(() => {});\n\n return customer.customer_id;\n}\n","import type DodoPayments from \"dodopayments\";\nimport { APIError, createAuthEndpoint, getSessionFromCtx } from \"better-auth/api\";\nimport { z } from \"zod/v3\";\nimport type { CreateCheckoutResponse, Product } from \"../types\";\nimport {\n buildCheckoutUrl,\n checkoutSessionPayloadSchema,\n dynamicCheckoutBodySchema,\n} from \"@dodopayments/core/checkout\";\n\nexport interface CheckoutOptions {\n /**\n * Optional list of slug -> productId mappings for easy slug checkouts\n */\n products?: Product[] | (() => Promise<Product[]>);\n /**\n * Checkout Success URL\n */\n successUrl?: string;\n /**\n * Only allow authenticated customers to checkout\n */\n authenticatedUsersOnly?: boolean;\n}\n\nexport const checkout =\n (checkoutOptions: CheckoutOptions = {}) =>\n (dodopayments: DodoPayments) => {\n return {\n /**\n * @deprecated\n */\n dodoCheckout: createAuthEndpoint(\n \"/dodopayments/checkout\",\n {\n method: \"POST\",\n body: dynamicCheckoutBodySchema.extend({\n slug: z.string().optional(),\n referenceId: z.string().optional(),\n }),\n requireRequest: true,\n },\n async (ctx): Promise<CreateCheckoutResponse> => {\n const session = await getSessionFromCtx(ctx);\n\n let dodoPaymentsProductId: string | undefined;\n\n if (ctx.body?.slug) {\n const resolvedProducts =\n typeof checkoutOptions.products === \"function\"\n ? await checkoutOptions.products()\n : checkoutOptions.products;\n\n const productId = resolvedProducts?.find(\n (product) => product.slug === ctx.body.slug,\n )?.productId;\n\n if (!productId) {\n throw new APIError(\"BAD_REQUEST\", {\n message: \"Product not found\",\n });\n }\n\n dodoPaymentsProductId = productId;\n } else {\n dodoPaymentsProductId = ctx.body.product_id;\n }\n\n if (checkoutOptions.authenticatedUsersOnly && !session?.user.id) {\n throw new APIError(\"UNAUTHORIZED\", {\n message: \"You must be logged in to checkout\",\n });\n }\n\n try {\n const checkoutUrl = await buildCheckoutUrl({\n body: {\n ...ctx.body,\n product_id: dodoPaymentsProductId,\n customer: {\n email: session?.user.email,\n name: session?.user.name,\n ...ctx.body.customer,\n },\n product_cart: dodoPaymentsProductId\n ? [\n {\n product_id: dodoPaymentsProductId,\n quantity: 1,\n },\n ]\n : undefined,\n metadata: ctx.body.referenceId\n ? {\n referenceId: ctx.body.referenceId,\n ...ctx.body.metadata,\n }\n : ctx.body.metadata,\n },\n bearerToken: dodopayments.bearerToken,\n environment: dodopayments.baseURL.includes(\"test\")\n ? \"test_mode\"\n : \"live_mode\",\n returnUrl: checkoutOptions.successUrl\n ? new URL(\n checkoutOptions.successUrl,\n ctx.request?.url,\n ).toString()\n : undefined,\n type: \"dynamic\",\n });\n\n const redirectUrl = new URL(checkoutUrl);\n\n return ctx.json({\n url: redirectUrl.toString(),\n redirect: true,\n });\n } catch (e: unknown) {\n if (e instanceof Error) {\n ctx.context.logger.error(\n `DodoPayments checkout creation failed. Error: ${e.message}`,\n );\n }\n\n throw new APIError(\"INTERNAL_SERVER_ERROR\", {\n message: \"Checkout creation failed\",\n });\n }\n },\n ),\n dodoCheckoutSession: createAuthEndpoint(\n \"/dodopayments/checkout-session\",\n {\n method: \"POST\",\n body: checkoutSessionPayloadSchema\n .extend({\n slug: z.string().optional(),\n referenceId: z.string().optional(),\n })\n .partial({\n product_cart: true,\n }),\n requireRequest: true,\n },\n async (ctx): Promise<CreateCheckoutResponse> => {\n const session = await getSessionFromCtx(ctx);\n\n let dodoPaymentsProductId: string | undefined;\n\n if (ctx.body?.slug) {\n const resolvedProducts =\n typeof checkoutOptions.products === \"function\"\n ? await checkoutOptions.products()\n : checkoutOptions.products;\n\n const productId = resolvedProducts?.find(\n (product) => product.slug === ctx.body.slug,\n )?.productId;\n\n if (!productId) {\n throw new APIError(\"BAD_REQUEST\", {\n message: \"Product not found\",\n });\n }\n\n dodoPaymentsProductId = productId;\n }\n\n if (checkoutOptions.authenticatedUsersOnly && !session?.user.id) {\n throw new APIError(\"UNAUTHORIZED\", {\n message: \"You must be logged in to checkout\",\n });\n }\n\n // Ensure we have a product_cart\n const product_cart = dodoPaymentsProductId\n ? [{ product_id: dodoPaymentsProductId, quantity: 1 }]\n : ctx.body.product_cart;\n\n if (!product_cart || product_cart.length === 0) {\n throw new APIError(\"BAD_REQUEST\", {\n message: \"Neither product_cart nor slug was provided\",\n });\n }\n\n try {\n const checkoutUrl = await buildCheckoutUrl({\n sessionPayload: {\n ...ctx.body,\n product_cart,\n customer: session?.user.email\n ? {\n email: session?.user.email,\n name: session?.user.name,\n }\n : ctx.body.customer,\n metadata: ctx.body.referenceId\n ? {\n referenceId: ctx.body.referenceId,\n ...ctx.body.metadata,\n }\n : ctx.body.metadata,\n return_url: checkoutOptions.successUrl\n ? new URL(\n checkoutOptions.successUrl,\n ctx.request?.url,\n ).toString()\n : undefined,\n },\n bearerToken: dodopayments.bearerToken,\n environment: dodopayments.baseURL.includes(\"test\")\n ? \"test_mode\"\n : \"live_mode\",\n type: \"session\",\n });\n\n const redirectUrl = new URL(checkoutUrl);\n\n return ctx.json({\n url: redirectUrl.toString(),\n redirect: true,\n });\n } catch (e: unknown) {\n if (e instanceof Error) {\n ctx.context.logger.error(\n `DodoPayments checkout creation failed. Error: ${e.message}`,\n );\n }\n\n throw new APIError(\"INTERNAL_SERVER_ERROR\", {\n message: \"Checkout session creation failed\",\n });\n }\n },\n ),\n };\n };\n","import type { DodoPayments } from \"dodopayments\";\nimport {\n handleWebhookPayload,\n WebhookHandlerConfig,\n} from \"@dodopayments/core/webhook\";\nimport { APIError, createAuthEndpoint } from \"better-auth/api\";\nimport { WebhookPayload } from \"@dodopayments/core/schemas\";\nimport { verifyWebhookPayload } from \"@dodopayments/core/webhook\";\nimport type { WebhookResponse } from \"../types\";\n\nexport const webhooks =\n (options: WebhookHandlerConfig) => (_dodopayments: DodoPayments) => {\n return {\n dodopaymentsWebhooks: createAuthEndpoint(\n \"/dodopayments/webhooks\",\n {\n method: \"POST\",\n metadata: {\n isAction: false,\n },\n cloneRequest: true,\n },\n async (ctx): Promise<WebhookResponse> => {\n const { webhookKey } = options;\n\n if (!ctx.request?.body) {\n throw new APIError(\"INTERNAL_SERVER_ERROR\");\n }\n const buf = await ctx.request.text();\n let event: WebhookPayload;\n try {\n if (!webhookKey) {\n throw new APIError(\"INTERNAL_SERVER_ERROR\", {\n message: \"DodoPayments webhook webhookKey not found\",\n });\n }\n\n const headers = {\n \"webhook-id\": ctx.request.headers.get(\"webhook-id\") as string,\n \"webhook-timestamp\": ctx.request.headers.get(\n \"webhook-timestamp\",\n ) as string,\n \"webhook-signature\": ctx.request.headers.get(\n \"webhook-signature\",\n ) as string,\n };\n\n event = await verifyWebhookPayload({\n webhookKey,\n headers,\n body: buf,\n });\n } catch (err: unknown) {\n if (err instanceof Error) {\n ctx.context.logger.error(`Webhook Error: ${err.message}`);\n throw new APIError(\"BAD_REQUEST\", {\n message: `Webhook Error: ${err.message}`,\n });\n }\n\n throw new APIError(\"BAD_REQUEST\", {\n message: `Webhook Error: ${err}`,\n });\n }\n\n try {\n await handleWebhookPayload(event, options);\n } catch (e: unknown) {\n if (e instanceof Error) {\n ctx.context.logger.error(\n `DodoPayments webhook failed. Error: ${e.message}`,\n );\n }\n\n ctx.context.logger.error(\n `DodoPayments webhook failed. Error: ${e}`,\n );\n\n throw new APIError(\"BAD_REQUEST\", {\n message: \"Webhook error: See server logs for more information.\",\n });\n }\n\n return ctx.json({ received: true });\n },\n ),\n };\n };\n","import {\n APIError,\n createAuthEndpoint,\n sessionMiddleware,\n} from \"better-auth/api\";\nimport type { DodoPayments } from \"dodopayments\";\nimport { Event } from \"dodopayments/resources/usage-events.mjs\";\nimport { z } from \"zod/v3\";\nimport { getOrCreateCustomerId } from \"../utils\";\n\nconst EventInputSchema = z.object({\n event_id: z.string(),\n event_name: z.string(),\n metadata: z\n .record(z.union([z.string(), z.number(), z.boolean()]))\n .nullable()\n .optional(),\n timestamp: z\n // NOTE: coerce because the date object gets converted to a string over network requests\n // but we still want to enforce that it's a Date type\n .date({ coerce: true })\n .transform((d) => d.toISOString())\n .optional()\n .describe(\n \"Custom Timestamp. Defaults to current timestamp in UTC.\\\n Timestamps that are older that 1 hour or after 5 mins from\\\n current timestamp will be rejected.\",\n ),\n});\n\nexport const usage = () => (dodopayments: DodoPayments) => {\n return {\n // Ingest usage data\n dodoUsageIngest: createAuthEndpoint(\n \"/dodopayments/usage/ingest\",\n {\n method: \"POST\",\n body: EventInputSchema,\n use: [sessionMiddleware],\n },\n async (ctx): Promise<{ ingested_count: number }> => {\n if (!ctx.context.session?.user?.id) {\n throw new APIError(\"BAD_REQUEST\", {\n message: \"User not found\",\n });\n }\n\n if (!ctx.context.session?.user.emailVerified) {\n throw new APIError(\"UNAUTHORIZED\", {\n message: \"User email not verified\",\n });\n }\n\n try {\n const customerId = await getOrCreateCustomerId(\n dodopayments,\n ctx.context.session,\n ctx.context.internalAdapter,\n );\n\n const result = await dodopayments.usageEvents.ingest({\n events: [\n {\n event_id: ctx.body.event_id,\n customer_id: customerId,\n event_name: ctx.body.event_name,\n timestamp: ctx.body.timestamp,\n metadata: ctx.body.metadata,\n },\n ],\n });\n\n return ctx.json({ ingested_count: result.ingested_count });\n } catch (e: unknown) {\n if (e instanceof Error) {\n ctx.context.logger.error(\n `User usage ingestion error: ${e.message}`,\n );\n }\n\n throw new APIError(\"INTERNAL_SERVER_ERROR\", {\n message: \"Failed to record the user usage\",\n });\n }\n },\n ),\n\n // List usage meters\n dodoUsageMetersList: createAuthEndpoint(\n \"/dodopayments/usage/meters/list\",\n {\n method: \"GET\",\n query: z\n .object({\n page_number: z.coerce.number().optional(),\n page_size: z.coerce.number().optional(),\n event_name: z.string().optional(),\n meter_id: z.string().optional(),\n start: z.string().optional(),\n end: z.string().optional(),\n })\n .optional(),\n use: [sessionMiddleware],\n },\n async (ctx): Promise<{ items: Event[] }> => {\n if (!ctx.context.session?.user?.id) {\n throw new APIError(\"BAD_REQUEST\", {\n message: \"User not found\",\n });\n }\n\n if (!ctx.context.session?.user.emailVerified) {\n throw new APIError(\"UNAUTHORIZED\", {\n message: \"User email not verified\",\n });\n }\n\n try {\n const customerId = await getOrCreateCustomerId(\n dodopayments,\n ctx.context.session,\n ctx.context.internalAdapter,\n );\n\n const meters = await dodopayments.usageEvents.list({\n customer_id: customerId,\n ...ctx.query,\n });\n\n return ctx.json({ items: meters.items });\n } catch (e: unknown) {\n if (e instanceof Error) {\n ctx.context.logger.error(\n `User usage meter list error: ${e.message}`,\n );\n }\n\n throw new APIError(\"INTERNAL_SERVER_ERROR\", {\n message: \"Failed to fetch the user usage\",\n });\n }\n },\n ),\n };\n};\n\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACCA,iBAAyB;AAGlB,IAAM,eACX,CAAC,YACD,OAAO,MAAY,QAAuC;AACxD,MAAI,OAAO,QAAQ,wBAAwB;AACzC,QAAI;AACF,YAAM,YAAY,MAAM,QAAQ,OAAO,UAAU,KAAK;AAAA,QACpD,OAAO,KAAK;AAAA,MACd,CAAC;AACD,YAAM,mBAAmB,UAAU,MAAM,CAAC;AAE1C,UAAI;AAEJ,YAAM,mBAAmB,QAAQ,oBAC7B,MAAM,QAAQ,kBAAkB,IAAI,IACpC;AAEJ,UAAI,kBAAkB;AACpB,cAAM,QAAQ,OAAO,UAAU,OAAO,iBAAiB,aAAa;AAAA,UAClE,MAAM,KAAK;AAAA,UACX,UAAU,kBAAkB;AAAA,UAC5B,cAAc,kBAAkB;AAAA,QAClC,CAAC;AACD,qBAAa,iBAAiB;AAAA,MAChC,OAAO;AACL,cAAM,cAAc,MAAM,QAAQ,OAAO,UAAU,OAAO;AAAA,UACxD,OAAO,KAAK;AAAA,UACZ,MAAM,KAAK;AAAA,UACX,UAAU,kBAAkB;AAAA,UAC5B,cAAc,kBAAkB;AAAA,QAClC,GAAG,EAAE,gBAAgB,KAAK,GAAG,CAAC;AAC9B,qBAAa,YAAY;AAAA,MAC3B;AAEA,UAAI,QAAQ,gBAAgB,WAAW,KAAK,IAAI;AAAA,QAC9C,gBAAgB;AAAA,MA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","dodopayments","import_api","import_webhook","import_api","import_v3","dodopayments"]}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as dodopayments_resources_usage_events_mjs from 'dodopayments/resources/usage-events.mjs';
|
|
2
2
|
import * as better_auth from 'better-auth';
|
|
3
|
-
import { D as DodoPaymentsOptions, C as CreateCheckoutResponse, a as CustomerPortalResponse, S as SubscriptionItems, P as PaymentItems, W as WebhookResponse } from './types-
|
|
4
|
-
export { g as CheckoutOptions, e as DodoPaymentsEndpoints, c as DodoPaymentsPlugin, d as DodoPaymentsPlugins, b as Product, f as checkout, p as portal, w as webhooks } from './types-
|
|
3
|
+
import { D as DodoPaymentsOptions, C as CreateCheckoutResponse, a as CustomerPortalResponse, S as SubscriptionItems, P as PaymentItems, W as WebhookResponse } from './types-3pb2RGTM.cjs';
|
|
4
|
+
export { g as CheckoutOptions, e as DodoPaymentsEndpoints, c as DodoPaymentsPlugin, d as DodoPaymentsPlugins, b as Product, f as checkout, p as portal, w as webhooks } from './types-3pb2RGTM.cjs';
|
|
5
5
|
import * as zod_v3 from 'zod/v3';
|
|
6
6
|
export { usage } from './plugins/usage.cjs';
|
|
7
7
|
import 'dodopayments';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as dodopayments_resources_usage_events_mjs from 'dodopayments/resources/usage-events.mjs';
|
|
2
2
|
import * as better_auth from 'better-auth';
|
|
3
|
-
import { D as DodoPaymentsOptions, C as CreateCheckoutResponse, a as CustomerPortalResponse, S as SubscriptionItems, P as PaymentItems, W as WebhookResponse } from './types-
|
|
4
|
-
export { g as CheckoutOptions, e as DodoPaymentsEndpoints, c as DodoPaymentsPlugin, d as DodoPaymentsPlugins, b as Product, f as checkout, p as portal, w as webhooks } from './types-
|
|
3
|
+
import { D as DodoPaymentsOptions, C as CreateCheckoutResponse, a as CustomerPortalResponse, S as SubscriptionItems, P as PaymentItems, W as WebhookResponse } from './types-DygjjcRn.js';
|
|
4
|
+
export { g as CheckoutOptions, e as DodoPaymentsEndpoints, c as DodoPaymentsPlugin, d as DodoPaymentsPlugins, b as Product, f as checkout, p as portal, w as webhooks } from './types-DygjjcRn.js';
|
|
5
5
|
import * as zod_v3 from 'zod/v3';
|
|
6
6
|
export { usage } from './plugins/usage.js';
|
|
7
7
|
import 'dodopayments';
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import 'better-auth';
|
|
2
2
|
import 'dodopayments';
|
|
3
3
|
import 'zod/v3';
|
|
4
|
-
export { g as CheckoutOptions, f as checkout } from '../types-
|
|
4
|
+
export { g as CheckoutOptions, f as checkout } from '../types-3pb2RGTM.cjs';
|
|
5
5
|
import '@dodopayments/core/webhook';
|
|
6
6
|
import './usage.cjs';
|
|
7
7
|
import 'dodopayments/resources/usage-events.mjs';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import 'better-auth';
|
|
2
2
|
import 'dodopayments';
|
|
3
3
|
import 'zod/v3';
|
|
4
|
-
export { g as CheckoutOptions, f as checkout } from '../types-
|
|
4
|
+
export { g as CheckoutOptions, f as checkout } from '../types-DygjjcRn.js';
|
|
5
5
|
import '@dodopayments/core/webhook';
|
|
6
6
|
import './usage.js';
|
|
7
7
|
import 'dodopayments/resources/usage-events.mjs';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import 'better-auth';
|
|
2
2
|
import 'dodopayments';
|
|
3
3
|
import 'zod/v3';
|
|
4
|
-
export { p as portal } from '../types-
|
|
4
|
+
export { p as portal } from '../types-3pb2RGTM.cjs';
|
|
5
5
|
import '@dodopayments/core/webhook';
|
|
6
6
|
import './usage.cjs';
|
|
7
7
|
import 'dodopayments/resources/usage-events.mjs';
|
package/dist/plugins/portal.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import 'better-auth';
|
|
2
2
|
import 'dodopayments';
|
|
3
3
|
import 'zod/v3';
|
|
4
|
-
export { p as portal } from '../types-
|
|
4
|
+
export { p as portal } from '../types-DygjjcRn.js';
|
|
5
5
|
import '@dodopayments/core/webhook';
|
|
6
6
|
import './usage.js';
|
|
7
7
|
import 'dodopayments/resources/usage-events.mjs';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import 'better-auth';
|
|
2
2
|
import 'dodopayments';
|
|
3
3
|
import '@dodopayments/core/webhook';
|
|
4
|
-
export { w as webhooks } from '../types-
|
|
4
|
+
export { w as webhooks } from '../types-3pb2RGTM.cjs';
|
|
5
5
|
import 'zod/v3';
|
|
6
6
|
import './usage.cjs';
|
|
7
7
|
import 'dodopayments/resources/usage-events.mjs';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import 'better-auth';
|
|
2
2
|
import 'dodopayments';
|
|
3
3
|
import '@dodopayments/core/webhook';
|
|
4
|
-
export { w as webhooks } from '../types-
|
|
4
|
+
export { w as webhooks } from '../types-DygjjcRn.js';
|
|
5
5
|
import 'zod/v3';
|
|
6
6
|
import './usage.js';
|
|
7
7
|
import 'dodopayments/resources/usage-events.mjs';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import DodoPayments, { DodoPayments as DodoPayments$1 } from 'dodopayments';
|
|
2
2
|
import * as better_auth from 'better-auth';
|
|
3
|
-
import { UnionToIntersection } from 'better-auth';
|
|
3
|
+
import { User, UnionToIntersection } from 'better-auth';
|
|
4
4
|
import { z } from 'zod/v3';
|
|
5
5
|
import { WebhookHandlerConfig } from '@dodopayments/core/webhook';
|
|
6
6
|
import { usage } from './plugins/usage.cjs';
|
|
@@ -677,6 +677,17 @@ interface DodoPaymentsOptions {
|
|
|
677
677
|
* Use DodoPayments plugins
|
|
678
678
|
*/
|
|
679
679
|
use: DodoPaymentsPlugins;
|
|
680
|
+
/**
|
|
681
|
+
* Optionally provide additional fields (e.g. metadata, phone_number) to include when creating
|
|
682
|
+
* or updating a DodoPayments customer.
|
|
683
|
+
*/
|
|
684
|
+
getCustomerParams?: (user: User) => {
|
|
685
|
+
metadata?: Record<string, string>;
|
|
686
|
+
phone_number?: string | null;
|
|
687
|
+
} | Promise<{
|
|
688
|
+
metadata?: Record<string, string>;
|
|
689
|
+
phone_number?: string | null;
|
|
690
|
+
}>;
|
|
680
691
|
}
|
|
681
692
|
type PaymentsList = Awaited<ReturnType<DodoPayments$1["payments"]["list"]>>;
|
|
682
693
|
type SubscriptionsList = Awaited<ReturnType<DodoPayments$1["subscriptions"]["list"]>>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import DodoPayments, { DodoPayments as DodoPayments$1 } from 'dodopayments';
|
|
2
2
|
import * as better_auth from 'better-auth';
|
|
3
|
-
import { UnionToIntersection } from 'better-auth';
|
|
3
|
+
import { User, UnionToIntersection } from 'better-auth';
|
|
4
4
|
import { z } from 'zod/v3';
|
|
5
5
|
import { WebhookHandlerConfig } from '@dodopayments/core/webhook';
|
|
6
6
|
import { usage } from './plugins/usage.js';
|
|
@@ -677,6 +677,17 @@ interface DodoPaymentsOptions {
|
|
|
677
677
|
* Use DodoPayments plugins
|
|
678
678
|
*/
|
|
679
679
|
use: DodoPaymentsPlugins;
|
|
680
|
+
/**
|
|
681
|
+
* Optionally provide additional fields (e.g. metadata, phone_number) to include when creating
|
|
682
|
+
* or updating a DodoPayments customer.
|
|
683
|
+
*/
|
|
684
|
+
getCustomerParams?: (user: User) => {
|
|
685
|
+
metadata?: Record<string, string>;
|
|
686
|
+
phone_number?: string | null;
|
|
687
|
+
} | Promise<{
|
|
688
|
+
metadata?: Record<string, string>;
|
|
689
|
+
phone_number?: string | null;
|
|
690
|
+
}>;
|
|
680
691
|
}
|
|
681
692
|
type PaymentsList = Awaited<ReturnType<DodoPayments$1["payments"]["list"]>>;
|
|
682
693
|
type SubscriptionsList = Awaited<ReturnType<DodoPayments$1["subscriptions"]["list"]>>;
|
package/dist/types.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/types.ts"],"sourcesContent":["import type { DodoPayments } from \"dodopayments\";\n\nimport type { UnionToIntersection } from \"better-auth\";\nimport type { checkout } from \"./plugins/checkout\";\nimport type { portal } from \"./plugins/portal\";\nimport type { webhooks } from \"./plugins/webhooks\";\nimport { usage } from \"./plugins/usage\";\n\nexport type Product = {\n /**\n * Product Id from DodoPayments Product\n */\n productId: string;\n /**\n * Easily identifiable slug for the product\n */\n slug: string;\n};\n\nexport type DodoPaymentsPlugin =\n | ReturnType<typeof checkout>\n | ReturnType<typeof portal>\n | ReturnType<typeof webhooks>\n | ReturnType<typeof usage>;\n\nexport type DodoPaymentsPlugins = [DodoPaymentsPlugin, ...DodoPaymentsPlugin[]];\n\nexport type DodoPaymentsEndpoints = UnionToIntersection<\n ReturnType<DodoPaymentsPlugin>\n>;\n\nexport interface DodoPaymentsOptions {\n /**\n * DodoPayments Client\n */\n client: DodoPayments;\n /**\n * Enable customer creation when a user signs up\n */\n createCustomerOnSignUp?: boolean;\n /**\n * Use DodoPayments plugins\n */\n use: DodoPaymentsPlugins;\n}\n\ntype PaymentsList = Awaited<ReturnType<DodoPayments[\"payments\"][\"list\"]>>;\ntype SubscriptionsList = Awaited<\n ReturnType<DodoPayments[\"subscriptions\"][\"list\"]>\n>;\nexport type PaymentItems = { items: PaymentsList[\"items\"] };\nexport type SubscriptionItems = { items: SubscriptionsList[\"items\"] };\nexport type CustomerPortalResponse = { url: string; redirect: boolean };\nexport type CreateCheckoutResponse = { url: string; redirect: boolean };\nexport type WebhookResponse = { received: boolean };\n"],"mappings":";;;;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/types.ts"],"sourcesContent":["import type { DodoPayments } from \"dodopayments\";\n\nimport type { UnionToIntersection, User } from \"better-auth\";\nimport type { checkout } from \"./plugins/checkout\";\nimport type { portal } from \"./plugins/portal\";\nimport type { webhooks } from \"./plugins/webhooks\";\nimport { usage } from \"./plugins/usage\";\n\nexport type Product = {\n /**\n * Product Id from DodoPayments Product\n */\n productId: string;\n /**\n * Easily identifiable slug for the product\n */\n slug: string;\n};\n\nexport type DodoPaymentsPlugin =\n | ReturnType<typeof checkout>\n | ReturnType<typeof portal>\n | ReturnType<typeof webhooks>\n | ReturnType<typeof usage>;\n\nexport type DodoPaymentsPlugins = [DodoPaymentsPlugin, ...DodoPaymentsPlugin[]];\n\nexport type DodoPaymentsEndpoints = UnionToIntersection<\n ReturnType<DodoPaymentsPlugin>\n>;\n\nexport interface DodoPaymentsOptions {\n /**\n * DodoPayments Client\n */\n client: DodoPayments;\n /**\n * Enable customer creation when a user signs up\n */\n createCustomerOnSignUp?: boolean;\n /**\n * Use DodoPayments plugins\n */\n use: DodoPaymentsPlugins;\n /**\n * Optionally provide additional fields (e.g. metadata, phone_number) to include when creating\n * or updating a DodoPayments customer.\n */\n getCustomerParams?: (user: User) => { metadata?: Record<string, string>; phone_number?: string | null } | Promise<{ metadata?: Record<string, string>; phone_number?: string | null }>;\n}\n\ntype PaymentsList = Awaited<ReturnType<DodoPayments[\"payments\"][\"list\"]>>;\ntype SubscriptionsList = Awaited<\n ReturnType<DodoPayments[\"subscriptions\"][\"list\"]>\n>;\nexport type PaymentItems = { items: PaymentsList[\"items\"] };\nexport type SubscriptionItems = { items: SubscriptionsList[\"items\"] };\nexport type CustomerPortalResponse = { url: string; redirect: boolean };\nexport type CreateCheckoutResponse = { url: string; redirect: boolean };\nexport type WebhookResponse = { received: boolean };\n"],"mappings":";;;;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
|
package/dist/types.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import 'dodopayments';
|
|
2
2
|
import 'better-auth';
|
|
3
|
-
export { C as CreateCheckoutResponse, a as CustomerPortalResponse, e as DodoPaymentsEndpoints, D as DodoPaymentsOptions, c as DodoPaymentsPlugin, d as DodoPaymentsPlugins, P as PaymentItems, b as Product, S as SubscriptionItems, W as WebhookResponse } from './types-
|
|
3
|
+
export { C as CreateCheckoutResponse, a as CustomerPortalResponse, e as DodoPaymentsEndpoints, D as DodoPaymentsOptions, c as DodoPaymentsPlugin, d as DodoPaymentsPlugins, P as PaymentItems, b as Product, S as SubscriptionItems, W as WebhookResponse } from './types-3pb2RGTM.cjs';
|
|
4
4
|
import './plugins/usage.cjs';
|
|
5
5
|
import 'zod/v3';
|
|
6
6
|
import '@dodopayments/core/webhook';
|
package/dist/types.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import 'dodopayments';
|
|
2
2
|
import 'better-auth';
|
|
3
|
-
export { C as CreateCheckoutResponse, a as CustomerPortalResponse, e as DodoPaymentsEndpoints, D as DodoPaymentsOptions, c as DodoPaymentsPlugin, d as DodoPaymentsPlugins, P as PaymentItems, b as Product, S as SubscriptionItems, W as WebhookResponse } from './types-
|
|
3
|
+
export { C as CreateCheckoutResponse, a as CustomerPortalResponse, e as DodoPaymentsEndpoints, D as DodoPaymentsOptions, c as DodoPaymentsPlugin, d as DodoPaymentsPlugins, P as PaymentItems, b as Product, S as SubscriptionItems, W as WebhookResponse } from './types-DygjjcRn.js';
|
|
4
4
|
import './plugins/usage.js';
|
|
5
5
|
import 'zod/v3';
|
|
6
6
|
import '@dodopayments/core/webhook';
|
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/hooks/customer.ts"],"sourcesContent":["import type { GenericEndpointContext, User } from \"better-auth\";\nimport { APIError } from \"better-auth/api\";\nimport type { DodoPaymentsOptions } from \"../types\";\n\nexport const onUserCreate =\n (options: DodoPaymentsOptions) =>\n async (user: User, ctx: GenericEndpointContext | null) => {\n if (ctx && options.createCustomerOnSignUp) {\n try {\n const customers = await options.client.customers.list({\n email: user.email,\n });\n const existingCustomer = customers.items[0];\n\n let customerId: string;\n\n if (existingCustomer) {\n await options.client.customers.update(existingCustomer.customer_id, {\n name: user.name,\n });\n customerId = existingCustomer.customer_id;\n } else {\n // TODO: Add metadata to customer object via\n // getCustomerCreateParams option when it becomes\n // available in the API\n const newCustomer = await options.client.customers.create({\n email: user.email,\n name: user.name,\n }, { idempotencyKey: user.id });\n customerId = newCustomer.customer_id;\n }\n\n ctx.context.internalAdapter.updateUser(user.id, {\n dodoCustomerId: customerId,\n }).catch((e: unknown) => {\n ctx.context.logger.warn(\n `DodoPayments: failed to store dodoCustomerId for user ${user.id}. Error: ${e instanceof Error ? e.message : e}`,\n );\n });\n } catch (e: unknown) {\n if (e instanceof Error) {\n throw new APIError(\"INTERNAL_SERVER_ERROR\", {\n message: `DodoPayments customer creation failed. Error: ${e.message}`,\n });\n }\n\n throw new APIError(\"INTERNAL_SERVER_ERROR\", {\n message: `DodoPayments customer creation failed. Error: ${e}`,\n });\n }\n }\n };\n\nexport const onUserUpdate =\n (options: DodoPaymentsOptions) =>\n async (user: User, ctx: GenericEndpointContext | null) => {\n if (ctx && options.createCustomerOnSignUp) {\n try {\n const customers = await options.client.customers.list({\n email: user.email,\n });\n const existingCustomer = customers.items[0];\n\n if (existingCustomer) {\n // TODO: Add metadata to customer object via\n // getCustomerCreateParams option when it becomes\n // available in the API\n await options.client.customers.update(existingCustomer.customer_id, {\n name: user.name,\n });\n\n // Backfill dodoCustomerId if it doesn't exist\n if (!(user as User & { dodoCustomerId?: string }).dodoCustomerId) {\n ctx.context.internalAdapter.updateUser(user.id, {\n dodoCustomerId: existingCustomer.customer_id,\n }).catch((e: unknown) => {\n ctx.context.logger.warn(\n `DodoPayments: failed to backfill dodoCustomerId for user ${user.id}. Error: ${e instanceof Error ? e.message : e}`,\n );\n });\n }\n }\n } catch (e: unknown) {\n if (e instanceof Error) {\n ctx.context.logger.error(\n `DodoPayments customer update failed. Error: ${e.message}`,\n );\n } else {\n ctx.context.logger.error(\n `DodoPayments customer update failed. Error: ${e}`,\n );\n }\n }\n }\n };\n"],"mappings":";AACA,SAAS,gBAAgB;AAGlB,IAAM,eACX,CAAC,YACD,OAAO,MAAY,QAAuC;AACxD,MAAI,OAAO,QAAQ,wBAAwB;AACzC,QAAI;AACF,YAAM,YAAY,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