From b56cee56dcb7de78fbe177db5614565a81b12faa Mon Sep 17 00:00:00 2001 From: Fishbakh-N Date: Fri, 6 Dec 2024 09:42:10 +0200 Subject: [PATCH] add partnerMetadata to donation submission and URL parsing --- .../src/components/widget/hooks/useSubmitDonation.ts | 1 + .../src/components/widget/types/WidgetConfig.ts | 2 ++ .../donate-button-v4/src/helpers/constructDonateUrl.ts | 4 ++++ .../donate-button-v4/src/helpers/parseDonateUrl.ts | 10 +++++++++- 4 files changed, 16 insertions(+), 1 deletion(-) diff --git a/packages/donate-button-v4/src/components/widget/hooks/useSubmitDonation.ts b/packages/donate-button-v4/src/components/widget/hooks/useSubmitDonation.ts index 61076ff4..67424c7c 100644 --- a/packages/donate-button-v4/src/components/widget/hooks/useSubmitDonation.ts +++ b/packages/donate-button-v4/src/components/widget/hooks/useSubmitDonation.ts @@ -54,6 +54,7 @@ export const useSubmitDonation = () => { privateNote, publicTestimony, webhookToken, + partnerMetadata: config.partnerMetadata, designation, requireShareInfo }; diff --git a/packages/donate-button-v4/src/components/widget/types/WidgetConfig.ts b/packages/donate-button-v4/src/components/widget/types/WidgetConfig.ts index d709c014..500b5cb7 100644 --- a/packages/donate-button-v4/src/components/widget/types/WidgetConfig.ts +++ b/packages/donate-button-v4/src/components/widget/types/WidgetConfig.ts @@ -46,6 +46,8 @@ export interface WidgetConfig { webhookToken?: string; + partnerMetadata?: string; + redeemGiftCardInFlow?: boolean; designation?: string; diff --git a/packages/donate-button-v4/src/helpers/constructDonateUrl.ts b/packages/donate-button-v4/src/helpers/constructDonateUrl.ts index c55007df..8e3995dc 100644 --- a/packages/donate-button-v4/src/helpers/constructDonateUrl.ts +++ b/packages/donate-button-v4/src/helpers/constructDonateUrl.ts @@ -23,6 +23,7 @@ interface BaseUrlParams { publicTestimony?: string; utmSource?: string; webhookToken?: string; + partnerMetadata?: string; designation?: string; requireShareInfo?: boolean; } @@ -77,6 +78,7 @@ function getBaseParams({ publicTestimony, utmSource, webhookToken, + partnerMetadata, designation, requireShareInfo }: Pick< @@ -88,6 +90,7 @@ function getBaseParams({ | 'publicTestimony' | 'utmSource' | 'webhookToken' + | 'partnerMetadata' | 'designation' | 'requireShareInfo' >) { @@ -97,6 +100,7 @@ function getBaseParams({ [DonateUrlParameters.PRIVATE_NOTE]: privateNote, [DonateUrlParameters.PUBLIC_TESTIMONY]: publicTestimony, [DonateUrlParameters.PARTNER_WEBHOOK_TOKEN]: webhookToken, + [DonateUrlParameters.PARTNER_METADATA]: partnerMetadata, [DonateUrlParameters.DESIGNATION]: designation, [DonateUrlParameters.REQUIRE_SHARE_INFO]: requireShareInfo, [UTM_QUERY_PARAM.utm_campaign]: 'donate-button', diff --git a/packages/donate-button-v4/src/helpers/parseDonateUrl.ts b/packages/donate-button-v4/src/helpers/parseDonateUrl.ts index 3dbfb21c..afe0210c 100644 --- a/packages/donate-button-v4/src/helpers/parseDonateUrl.ts +++ b/packages/donate-button-v4/src/helpers/parseDonateUrl.ts @@ -113,6 +113,12 @@ export function parseDonateUrl( : `#${primaryColorFromUrl}` : undefined; + const webhookToken = + searchParameters.get(DonateUrlParameters.PARTNER_WEBHOOK_TOKEN) ?? + undefined; + const partnerMetadata = + searchParameters.get(DonateUrlParameters.PARTNER_METADATA) ?? undefined; + if (!nonprofitSlug) { return; } @@ -131,6 +137,8 @@ export function parseDonateUrl( minDonationAmount: minAmount, primaryColor, designation, - requireShareInfo + requireShareInfo, + webhookToken, + partnerMetadata }); }