Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: dynamic messages - pass merchant id from cpnw callback, flush logger #2381

Merged
merged 13 commits into from
Jun 12, 2024
64 changes: 55 additions & 9 deletions src/zoid/buttons/component.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -716,10 +716,25 @@ export const getButtonsComponent: () => ButtonsComponent = memoize(() => {
messageType,
offerCountryCode,
creditProductIdentifier,
merchantID: serverMerchantId,
}) => {
const { message, clientID, merchantID, currency, buttonSessionID } =
props;
const {
message,
clientID,
currency,
buttonSessionID,
merchantID: partnerMerchantId,
} = props;
const amount = message?.amount;
const isPartnerMerchantIdEmpty =
!partnerMerchantId ||
partnerMerchantId.length === 0 ||
partnerMerchantId[0] === "";
// check to see if a partner merchant id integration exists
// if not grab the server merchant id
const merchantID = isPartnerMerchantIdEmpty
? serverMerchantId
: partnerMerchantId?.join();

getLogger()
.info("button_message_click")
Expand All @@ -730,7 +745,7 @@ export const getButtonsComponent: () => ButtonsComponent = memoize(() => {
[FPTI_KEY.CONTEXT_ID]: buttonSessionID,
[FPTI_KEY.CONTEXT_TYPE]: "button_session_id",
[FPTI_KEY.EVENT_NAME]: "message_click",
[FPTI_KEY.SELLER_ID]: merchantID?.join(","),
[FPTI_KEY.SELLER_ID]: merchantID,
Seavenly marked this conversation as resolved.
Show resolved Hide resolved
[FPTI_KEY.BUTTON_MESSAGE_OFFER_TYPE]: offerType,
[FPTI_KEY.BUTTON_MESSAGE_CREDIT_PRODUCT_IDENTIFIER]:
creditProductIdentifier,
Expand All @@ -741,7 +756,8 @@ export const getButtonsComponent: () => ButtonsComponent = memoize(() => {
[FPTI_KEY.BUTTON_MESSAGE_OFFER_COUNTRY]: offerCountryCode,
[FPTI_KEY.BUTTON_MESSAGE_CURRENCY]: currency,
[FPTI_KEY.BUTTON_MESSAGE_AMOUNT]: amount,
});
})
.flush();

const modalInstance = await getModal(clientID, merchantID);
return modalInstance?.show({
Expand All @@ -757,11 +773,20 @@ export const getButtonsComponent: () => ButtonsComponent = memoize(() => {
type: "function",
required: false,
value: ({ props }) => {
return () => {
return ({ merchantID: serverMerchantId }) => {
const { clientID, merchantID: partnerMerchantId } = props;
const isPartnerMerchantIdEmpty =
!partnerMerchantId ||
partnerMerchantId.length === 0 ||
partnerMerchantId[0] === "";
// check to see if a partner merchant id integration exists
// if not grab the server merchant id
const merchantID = isPartnerMerchantIdEmpty
? serverMerchantId
: partnerMerchantId?.join();
Seavenly marked this conversation as resolved.
Show resolved Hide resolved
// offerType, messageType, offerCountryCode, and creditProductIdentifier are passed in and may be used in an upcoming message hover logging feature

// lazy loads the modal, to be memoized and executed onMessageClick
const { clientID, merchantID } = props;
return getModal(clientID, merchantID);
};
},
Expand All @@ -776,8 +801,29 @@ export const getButtonsComponent: () => ButtonsComponent = memoize(() => {
messageType,
offerCountryCode,
creditProductIdentifier,
merchantID: serverMerchantId,
}) => {
const { message, buttonSessionID, currency, merchantID } = props;
// merchantID that comes from props is an array
const {
message,
buttonSessionID,
currency,
merchantID: partnerMerchantId,
} = props;
const isPartnerMerchantIdEmpty =
!partnerMerchantId ||
partnerMerchantId.length === 0 ||
partnerMerchantId[0] === "";
// check to see if a partner merchant id integration exists
// if not grab the server merchant id
const merchantID = isPartnerMerchantIdEmpty
? serverMerchantId
: partnerMerchantId?.join();

// override with server id if partner does not exist
getLogger().addTrackingBuilder(() => ({
[FPTI_KEY.SELLER_ID]: merchantID,
Seavenly marked this conversation as resolved.
Show resolved Hide resolved
}));

getLogger()
.info("button_message_render")
Expand All @@ -788,7 +834,6 @@ export const getButtonsComponent: () => ButtonsComponent = memoize(() => {
[FPTI_KEY.CONTEXT_ID]: buttonSessionID,
[FPTI_KEY.CONTEXT_TYPE]: "button_session_id",
[FPTI_KEY.EVENT_NAME]: "message_render",
[FPTI_KEY.SELLER_ID]: merchantID?.join(","),
[FPTI_KEY.BUTTON_MESSAGE_OFFER_TYPE]: offerType,
[FPTI_KEY.BUTTON_MESSAGE_CREDIT_PRODUCT_IDENTIFIER]:
creditProductIdentifier,
Expand All @@ -799,7 +844,8 @@ export const getButtonsComponent: () => ButtonsComponent = memoize(() => {
[FPTI_KEY.BUTTON_MESSAGE_CURRENCY]: currency,
[FPTI_KEY.BUTTON_MESSAGE_OFFER_COUNTRY]: offerCountryCode,
[FPTI_KEY.BUTTON_MESSAGE_AMOUNT]: message?.amount,
});
})
.flush();
};
},
},
Expand Down
4 changes: 2 additions & 2 deletions src/zoid/buttons/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ function buildModalBundleUrl(): string {

export const getModal: (
clientID: string,
merchantID: $ReadOnlyArray<string> | void
merchantID?: string | void
Seavenly marked this conversation as resolved.
Show resolved Hide resolved
) => Object = memoize(async (clientID, merchantID) => {
try {
const namespace = getNamespace();
Expand All @@ -396,7 +396,7 @@ export const getModal: (

return window[namespace].MessagesModal({
account: `client-id:${clientID}`,
merchantId: merchantID?.join(",") || undefined,
merchantId: merchantID || undefined,
});
} catch (err) {
// $FlowFixMe flow doesn't seem to understand that the reset function property exists on the function object itself
Expand Down
12 changes: 6 additions & 6 deletions test/integration/tests/button/message.js
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ describe(`paypal button message`, () => {
message: {},
test: {
onRender({ hoverMessage }) {
hoverMessage()
hoverMessage({ merchantID: "123" })
.then(() => {
assert.equal(getNamespace(), window.namespace);
done();
Expand All @@ -475,7 +475,7 @@ describe(`paypal button message`, () => {
message: {},
test: {
onRender({ hoverMessage }) {
hoverMessage()
hoverMessage({ merchantID: "123" })
.then(() => {
assert.ok(
Object.keys(window.paypal.MessagesModal.mock.calledWith)
Expand All @@ -487,7 +487,7 @@ describe(`paypal button message`, () => {
);
assert.ok(
typeof window.paypal.MessagesModal.mock.calledWith
.merchantId === "undefined"
.merchantId === "string"
);
done();
})
Expand All @@ -506,7 +506,7 @@ describe(`paypal button message`, () => {
},
test: {
onRender({ clickMessage, hoverMessage }) {
hoverMessage()
hoverMessage({ merchantID: "123" })
.then(() => {
return clickMessage(props).then(() => {
assert.equal(
Expand Down Expand Up @@ -539,10 +539,10 @@ describe(`paypal button message`, () => {
},
test: {
onRender({ clickMessage, hoverMessage }) {
hoverMessage()
hoverMessage({ merchantID: "123" })
.then(() => {
return clickMessage(props).then(() => {
return hoverMessage().then(() => {
return hoverMessage({ merchantID: "123" }).then(() => {
return clickMessage(props).then(() => {
assert.equal(window.paypal.MessagesModal.mock.calls, 1);
done();
Expand Down
4 changes: 2 additions & 2 deletions test/integration/windows/button/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,8 @@ if (onRender) {
click() {
getElement(".paypal-button", document).click();
},
hoverMessage(): ZalgoPromise<void> | void {
return window.xprops.onMessageHover();
hoverMessage({ merchantID }): ZalgoPromise<void> | void {
return window.xprops.onMessageHover({ merchantID });
Seavenly marked this conversation as resolved.
Show resolved Hide resolved
},
clickMessage({ offerType, messageType }): ZalgoPromise<void> | void {
return window.xprops.onMessageClick({ offerType, messageType });
Expand Down