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.

save script

Steven Tey5d47e8e8c1f8
diff --git a/apps/web/scripts/update-payment-failed.ts b/apps/web/scripts/update-payment-failed.ts
new file mode 100644
index 0000000000..53dacb940b
--- /dev/null
+++ b/apps/web/scripts/update-payment-failed.ts
@@ -0,0 +1,48 @@
+import { prisma } from "@/lib/prisma";
+import "dotenv-flow/config";
+import * as fs from "fs";
+import * as Papa from "papaparse";
+
+const stripeCustomers: { stripeId: string; paymentFailedAt: string }[] = [];
+
+async function main() {
+ Papa.parse(fs.createReadStream("unified_payments.csv", "utf-8"), {
+ header: true,
+ step: (result: { data: any }) => {
+ stripeCustomers.push({
+ stripeId: result.data["Customer ID"],
+ paymentFailedAt: result.data["Created date (UTC)"],
+ });
+ },
+ complete: async () => {
+ const validWorkspaces = await prisma.project.findMany({
+ where: {
+ stripeId: {
+ in: stripeCustomers.map((c) => c.stripeId),
+ },
+ plan: {
+ not: "free",
+ },
+ },
+ });
+
+ const workspaceToUpdate = validWorkspaces.map((w) => {
+ const stripeCustomer = stripeCustomers.find(
+ (c) => c.stripeId === w.stripeId,
+ );
+ return {
+ id: w.id,
+ slug: w.slug,
+ plan: w.plan,
+ stripeId: w.stripeId,
+ paymentFailedAt: stripeCustomer?.paymentFailedAt,
+ };
+ });
+
+ console.log({ stripeCustomers: stripeCustomers.length });
+ console.table(workspaceToUpdate.slice(0, 10));
+ },
+ });
+}
+
+main();