Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

Update route.ts

Kiran K1d2af5b1b623
diff --git a/apps/web/app/api/workspaces/[idOrSlug]/billing/payment-methods/route.ts b/apps/web/app/api/workspaces/[idOrSlug]/billing/payment-methods/route.ts
index d7242eb6e6..28a0ebb07f 100644
--- a/apps/web/app/api/workspaces/[idOrSlug]/billing/payment-methods/route.ts
+++ b/apps/web/app/api/workspaces/[idOrSlug]/billing/payment-methods/route.ts
@@ -1,3 +1,4 @@
+import { DubApiError } from "@/lib/api/errors";
import { parseRequestBody } from "@/lib/api/utils";
import { withWorkspace } from "@/lib/auth";
import { stripe } from "@/lib/stripe";
@@ -6,9 +7,30 @@ import { NextResponse } from "next/server";
import { z } from "zod";
const addPaymentMethodSchema = z.object({
- method: z.enum(["card", "us_bank_account"]).optional(),
+ method: z
+ .enum([
+ "card",
+ "us_bank_account",
+ "acss_debit",
+ "sepa_debit",
+ "au_becs_debit",
+ ])
+ .optional(),
});
+const stripePaymentMethodOptions = {
+ us_bank_account: {},
+ acss_debit: {
+ currency: "usd",
+ mandate_options: {
+ payment_schedule: "sporadic",
+ transaction_type: "business",
+ },
+ },
+ sepa_debit: {},
+ au_becs_debit: {},
+};
+
// GET /api/workspaces/[idOrSlug]/billing/payment-methods - get all payment methods
export const GET = withWorkspace(async ({ workspace }) => {
if (!workspace.stripeId) {
@@ -38,7 +60,10 @@ export const GET = withWorkspace(async ({ workspace }) => {
// POST /api/workspaces/[idOrSlug]/billing/payment-methods - add a payment method for the workspace
export const POST = withWorkspace(async ({ workspace, req }) => {
if (!workspace.stripeId) {
- return NextResponse.json({ error: "Workspace does not have a Stripe ID" });
+ throw new DubApiError({
+ code: "bad_request",
+ message: "Workspace does not have a Stripe ID.",
+ });
}
const { method } = addPaymentMethodSchema.parse(await parseRequestBody(req));
@@ -59,6 +84,7 @@ export const POST = withWorkspace(async ({ workspace, req }) => {
mode: "setup",
customer: workspace.stripeId,
payment_method_types: [method],
+ currency: "usd",
success_url: `${APP_DOMAIN}/${workspace.slug}/settings/billing`,
cancel_url: `${APP_DOMAIN}/${workspace.slug}/settings/billing`,
});