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.

Fix Rewardful importer

Steven Tey24042bdc9d61
diff --git a/apps/web/lib/rewardful/import-referrals.ts b/apps/web/lib/rewardful/import-referrals.ts
index f3c58343eb..fda46ff55d 100644
--- a/apps/web/lib/rewardful/import-referrals.ts
+++ b/apps/web/lib/rewardful/import-referrals.ts
@@ -18,7 +18,8 @@ export async function importReferrals({
programId: string;
page: number;
}) {
- const { token, userId } = await rewardfulImporter.getCredentials(programId);
+ const { token, userId, campaignId } =
+ await rewardfulImporter.getCredentials(programId);
const rewardfulApi = new RewardfulApi({ token });
@@ -51,6 +52,7 @@ export async function importReferrals({
referral,
workspace,
program,
+ campaignId,
}),
),
);
@@ -96,11 +98,25 @@ async function createReferral({
referral,
workspace,
program,
+ campaignId,
}: {
referral: RewardfulReferral;
workspace: Project;
program: Program;
+ campaignId: string;
}) {
+ if (
+ referral.affiliate?.campaign &&
+ referral.affiliate.campaign.id !== campaignId
+ ) {
+ console.log(
+ "Referral not in campaign",
+ referral.affiliate?.campaign?.id,
+ campaignId,
+ );
+ return;
+ }
+
const link = await prisma.link.findUnique({
where: {
domain_key: {
@@ -115,6 +131,11 @@ async function createReferral({
return;
}
+ if (!referral.stripe_customer_id) {
+ console.log("No Stripe customer ID provided for referral");
+ return;
+ }
+
const customerFound = await prisma.customer.findUnique({
where: {
stripeCustomerId: referral.stripe_customer_id,
diff --git a/apps/web/lib/rewardful/types.ts b/apps/web/lib/rewardful/types.ts
index 4d46b4b19f..bfa5c4c626 100644
--- a/apps/web/lib/rewardful/types.ts
+++ b/apps/web/lib/rewardful/types.ts
@@ -46,6 +46,7 @@ export interface RewardfulAffiliate {
created_at: string;
updated_at: string;
links: RewardfulLink[];
+ campaign?: RewardfulCampaign;
}
export interface RewardfulReferral {