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.

send the PartnerStack import email when Stripe is not connected

Pedro Ladeirab3893c1b885d
diff --git a/apps/web/lib/partnerstack/update-stripe-customers.ts b/apps/web/lib/partnerstack/update-stripe-customers.ts
index aeca4af72c..d424eede28 100644
--- a/apps/web/lib/partnerstack/update-stripe-customers.ts
+++ b/apps/web/lib/partnerstack/update-stripe-customers.ts
@@ -39,71 +39,70 @@ export async function updateStripeCustomers(
},
});
- if (!workspace.stripeConnectId) {
- console.error(
- `Workspace ${workspace.id} has no stripeConnectId. Skipping...`,
- );
- return;
- }
-
- let hasMore = true;
- let processedBatches = 0;
- let currentStartingAfter = startingAfter;
-
- while (hasMore && processedBatches < MAX_BATCHES) {
- const customers = await prisma.customer.findMany({
- where: {
- projectId: workspace.id,
- stripeCustomerId: null,
- email: {
- not: null,
+ if (workspace.stripeConnectId) {
+ let hasMore = true;
+ let processedBatches = 0;
+ let currentStartingAfter = startingAfter;
+
+ while (hasMore && processedBatches < MAX_BATCHES) {
+ const customers = await prisma.customer.findMany({
+ where: {
+ projectId: workspace.id,
+ stripeCustomerId: null,
+ email: {
+ not: null,
+ },
},
- },
- select: {
- id: true,
- name: true,
- email: true,
- },
- orderBy: {
- id: "asc",
- },
- take: CUSTOMERS_PER_BATCH,
- skip: currentStartingAfter ? 1 : 0,
- ...(currentStartingAfter && {
- cursor: {
- id: currentStartingAfter,
+ select: {
+ id: true,
+ name: true,
+ email: true,
},
- }),
- });
+ orderBy: {
+ id: "asc",
+ },
+ take: CUSTOMERS_PER_BATCH,
+ skip: currentStartingAfter ? 1 : 0,
+ ...(currentStartingAfter && {
+ cursor: {
+ id: currentStartingAfter,
+ },
+ }),
+ });
- if (customers.length === 0) {
- hasMore = false;
- break;
- }
+ if (customers.length === 0) {
+ hasMore = false;
+ break;
+ }
- await Promise.allSettled(
- customers.map((customer) =>
- searchStripeAndUpdateCustomer({
- workspace,
- customer,
- importId,
- }),
- ),
- );
+ await Promise.allSettled(
+ customers.map((customer) =>
+ searchStripeAndUpdateCustomer({
+ workspace,
+ customer,
+ importId,
+ }),
+ ),
+ );
- await sleep(2000);
+ await sleep(2000);
- processedBatches++;
- currentStartingAfter = customers[customers.length - 1].id;
- }
+ processedBatches++;
+ currentStartingAfter = customers[customers.length - 1].id;
+ }
- if (hasMore) {
- await partnerStackImporter.queue({
- ...payload,
- startingAfter: currentStartingAfter,
- action: "update-stripe-customers",
- });
- return;
+ if (hasMore) {
+ await partnerStackImporter.queue({
+ ...payload,
+ startingAfter: currentStartingAfter,
+ action: "update-stripe-customers",
+ });
+ return;
+ }
+ } else {
+ console.error(
+ `Workspace ${workspace.id} has no stripeConnectId. Skipping Stripe customer matching.`,
+ );
}
const workspaceUser = await prisma.projectUsers.findUniqueOrThrow({