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

Add ApplePay & Payment Cards to Epic CTA's #988

Merged
merged 24 commits into from
Nov 8, 2023
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
d676ad2
intial wiring
paul-daniel-dempsey Oct 12, 2023
1846a90
applePay buttons created
paul-daniel-dempsey Oct 13, 2023
bcee091
AU_2022 to AU ticker rename
paul-daniel-dempsey Oct 13, 2023
5ea7e75
applePay button styled above and below desktop breakpoint
paul-daniel-dempsey Oct 16, 2023
940cdfb
entry point added for applePay browser check
paul-daniel-dempsey Oct 16, 2023
9dde5a1
applePay session detection added for https pages only
paul-daniel-dempsey Oct 17, 2023
a187bff
reminder shown below applePay below desktop size
paul-daniel-dempsey Oct 17, 2023
c50b78d
applePay button children area widened at mobile breakpoint
paul-daniel-dempsey Oct 18, 2023
56e9771
ophan 'contributions-epic-ctas-applepay' button click tracking added
paul-daniel-dempsey Oct 18, 2023
32154d9
alt title accessibility voice over tags added
paul-daniel-dempsey Oct 18, 2023
8640847
applePayWallet session detection added
paul-daniel-dempsey Oct 19, 2023
3d96476
force applepaywallet
paul-daniel-dempsey Oct 19, 2023
8e6515e
force console logs
paul-daniel-dempsey Oct 19, 2023
ffe8360
removed force applepaywallet kept console logs
paul-daniel-dempsey Oct 20, 2023
ecef437
ophan 'contributions-epic-applepay-view' tracking added
paul-daniel-dempsey Oct 20, 2023
10d309b
Merge branch 'main' into pd-epic-apple-pay
paul-daniel-dempsey Oct 31, 2023
1dfefeb
rebase ChoiceCardSelection import correction
paul-daniel-dempsey Oct 31, 2023
78ca465
feat: Enable Ophan to track when ApplePay is authorised
paul-daniel-dempsey Nov 3, 2023
dfb9a8c
fix: checks in epic named/containing APPLE-PAY, Ophan 'contributions-…
paul-daniel-dempsey Nov 3, 2023
28c291e
fix: ApplePay click event firing when pressed
paul-daniel-dempsey Nov 6, 2023
8e16cfc
fix: seperated ApplePay CTA's
paul-daniel-dempsey Nov 6, 2023
029f531
fix: ApplePaySvg unused styles removed, ButtonApplePay colors importa…
paul-daniel-dempsey Nov 6, 2023
13eab35
fix: SecondaryCtaButtonApplePay button component used
paul-daniel-dempsey Nov 7, 2023
168ea61
fix: minimised ButtonApplePay props, ApplePayButton css simplified fr…
paul-daniel-dempsey Nov 7, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/dotcom/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"outDir": "dist"
},
"include": [
"src/index.ts"
"src/index.ts",
"src/window.d.ts",
],
}
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,6 @@ AusAnniversaryMoment2023.args = {
total: 4_000,
goal: 50_000,
},
name: 'AU_2022',
name: 'AU',
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ WithImage.args = {
total: 4_000,
goal: 50_000,
},
name: 'AU_2022',
name: 'AU',
},
design,
};
Expand All @@ -183,7 +183,7 @@ WithChoiceCards.args = {
total: 4_000,
goal: 50_000,
},
name: 'AU_2022',
name: 'AU',
},
design: {
...design,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,6 @@ WithTicker.args = {
total: 4_000,
goal: 50_000,
},
name: 'AU_2022',
name: 'AU',
},
};
55 changes: 55 additions & 0 deletions packages/modules/src/modules/epics/ApplePaySvg.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import React from 'react';
import { css, SerializedStyles } from '@emotion/react';
import { space } from '@guardian/src-foundations';
import { from } from '@guardian/src-foundations/mq';

const applePayStyles = css`
display: block;
height: 1.1rem;
width: auto;
margin-top: ${space[2]}px;
/* margin-left: ${space[1]}px; */
paul-daniel-dempsey marked this conversation as resolved.
Show resolved Hide resolved

${from.tablet} {
/* margin-left: ${space[1]}px; */
paul-daniel-dempsey marked this conversation as resolved.
Show resolved Hide resolved
paul-daniel-dempsey marked this conversation as resolved.
Show resolved Hide resolved
height: 1.25rem;
}
`;

type ApplePayProps = {
cssOverrides?: SerializedStyles;
};

export const ApplePaySvg = ({ cssOverrides }: ApplePayProps): JSX.Element => {
return (
<svg
width="45"
height="19"
viewBox="0 0 45 19"
css={[applePayStyles, cssOverrides]}
fill="none"
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M8.57013 2.45014C9.09745 1.79058 9.45529 0.904978 9.36091 0C8.58899 0.0383834 7.647 0.509265 7.10164 1.16935C6.61196 1.7346 6.17856 2.65729 6.29154 3.52433C7.15807 3.59949 8.02379 3.0912 8.57013 2.45014Z"
fill="white"
/>
<path
d="M9.35118 3.69368C8.09278 3.61872 7.02283 4.40788 6.42188 4.40788C5.8206 4.40788 4.90034 3.73145 3.90501 3.74969C2.60953 3.76871 1.40747 4.50119 0.75007 5.66617C-0.602096 7.99671 0.393234 11.4537 1.70814 13.3518C2.34669 14.2908 3.11625 15.3248 4.13027 15.2877C5.08834 15.2501 5.46387 14.6673 6.62845 14.6673C7.79217 14.6673 8.13044 15.2877 9.14462 15.2689C10.1964 15.2501 10.8539 14.3294 11.4924 13.3894C12.2249 12.3189 12.5248 11.2853 12.5437 11.2286C12.5248 11.2098 10.5157 10.439 10.497 8.12784C10.4781 6.19267 12.0744 5.27219 12.1496 5.21511C11.2481 3.88179 9.83951 3.73145 9.35118 3.69368Z"
fill="white"
/>
<path
d="M20.308 1.07471C23.0431 1.07471 24.9477 2.96005 24.9477 5.70496C24.9477 8.45968 23.0039 10.3548 20.2394 10.3548H17.2111V15.1707H15.0232V1.07471L20.308 1.07471ZM17.2111 8.51827H19.7217C21.6266 8.51827 22.7108 7.4927 22.7108 5.71476C22.7108 3.93701 21.6266 2.92104 19.7314 2.92104H17.2111V8.51827Z"
fill="white"
/>
<path
d="M25.519 12.2498C25.519 10.4523 26.8964 9.34849 29.3387 9.2117L32.1518 9.0457V8.25452C32.1518 7.11156 31.3801 6.42778 30.0909 6.42778C28.8695 6.42778 28.1076 7.01377 27.9222 7.93213H25.9294C26.0466 6.07599 27.629 4.70844 30.1689 4.70844C32.6598 4.70844 34.252 6.02719 34.252 8.08833V15.1705H32.2298V13.4806H32.1812C31.5854 14.6235 30.2861 15.3463 28.9381 15.3463C26.9258 15.3463 25.519 14.0959 25.519 12.2498ZM32.1518 11.3218V10.511L29.6217 10.6672C28.3616 10.7552 27.6486 11.312 27.6486 12.1912C27.6486 13.0898 28.391 13.6759 29.5241 13.6759C30.9991 13.6759 32.1518 12.66 32.1518 11.3218Z"
fill="white"
/>
<path
d="M36.162 18.9511V17.2416C36.318 17.2806 36.6696 17.2806 36.8456 17.2806C37.8223 17.2806 38.3499 16.8704 38.6721 15.8154C38.6721 15.7958 38.8579 15.1902 38.8579 15.1804L35.146 4.89417H37.4315L40.0302 13.2561H40.0691L42.6678 4.89417H44.8949L41.0458 15.7078C40.167 18.1989 39.1511 18.9999 37.0215 18.9999C36.8456 18.9999 36.318 18.9803 36.162 18.9511Z"
fill="white"
/>
</svg>
);
};
8 changes: 5 additions & 3 deletions packages/modules/src/modules/epics/Button.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { css } from '@emotion/react';
import { SerializedStyles, css } from '@emotion/react';
import { palette } from '@guardian/src-foundations';
import { ThemeProvider } from '@emotion/react';
import { Button as DSButton, LinkButton } from '@guardian/src-button';
Expand Down Expand Up @@ -36,6 +36,7 @@ type Props = {
priority?: 'primary' | 'secondary';
showArrow?: boolean;
isTertiary?: boolean;
cssOverrides?: SerializedStyles;
};

// Overrides for tertiary button
Expand All @@ -56,6 +57,7 @@ export const Button: ReactComponent<Props> = (allProps: Props) => {
showArrow = false,
priority = 'primary',
isTertiary,
cssOverrides,
...props
} = allProps;

Expand All @@ -72,7 +74,7 @@ export const Button: ReactComponent<Props> = (allProps: Props) => {
target="_blank"
rel="noopener noreferrer"
priority={isTertiary ? 'primary' : priority}
css={isTertiary ? tertiaryButtonOverrides : undefined}
css={isTertiary ? [tertiaryButtonOverrides, cssOverrides] : cssOverrides}
{...props}
>
{children}
Expand All @@ -87,7 +89,7 @@ export const Button: ReactComponent<Props> = (allProps: Props) => {
icon={showArrow ? <SvgArrowRightStraight /> : undefined}
onClick={(): void => onClickAction()}
priority={isTertiary ? 'primary' : priority}
css={isTertiary ? tertiaryButtonOverrides : undefined}
css={isTertiary ? [tertiaryButtonOverrides, cssOverrides] : cssOverrides}
{...props}
>
{children}
Expand Down
84 changes: 84 additions & 0 deletions packages/modules/src/modules/epics/ButtonApplePay.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import React from 'react';
import { SerializedStyles, css } from '@emotion/react';
import { palette } from '@guardian/src-foundations';
import { ThemeProvider } from '@emotion/react';
import { LinkButton } from '@guardian/src-button';
import type { ReactComponent } from '../../types';
import { from } from '@guardian/src-foundations/mq';

type LinkButtonColourStyles = {
text: string;
background: string;
hover: string;
border: string;
widthSvg: string;
};

const buttonStyles: Record<string, LinkButtonColourStyles> = {
primary: {
text: palette.neutral[100],
background: palette.neutral[7],
hover: palette.neutral[20],
border: palette.neutral[7],
widthSvg: `42px`,
},
secondary: {
text: palette.neutral[7],
background: palette.neutral[93],
hover: palette.neutral[86],
border: palette.neutral[0],
widthSvg: `140px`,
},
};

type Url = string;

type Props = {
onClickAction: Url;
children: React.ReactElement | string;
icon: React.ReactElement;
priority?: 'primary' | 'secondary';
title?: string;
};

const linkButtonColorStyles = (buttonStyles: LinkButtonColourStyles): SerializedStyles => css`
width: 100%;
justify-content: center;
padding: 0 10px;
border: 1px solid ${buttonStyles.border}!important;
paul-daniel-dempsey marked this conversation as resolved.
Show resolved Hide resolved
background-color: ${buttonStyles.background} !important;
color: ${buttonStyles.text} !important;

${from.mobileMedium} {
padding: 0 20px;
}

:hover {
background-color: ${buttonStyles.hover} !important;
}

svg {
width: ${buttonStyles.widthSvg};
}
`;

export const ButtonApplePay: ReactComponent<Props> = (allProps: Props) => {
const { onClickAction, children, icon, priority = 'primary', title, ...props } = allProps;
return (
<ThemeProvider theme={buttonStyles}>
<LinkButton
href={onClickAction}
icon={icon}
iconSide="right"
target="_blank"
rel="noopener noreferrer"
priority={priority}
css={linkButtonColorStyles(buttonStyles[priority])}
title={title ?? ''}
{...props}
>
{children}
</LinkButton>
</ThemeProvider>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,80 @@ WithChoiceCardsAndSignInLink.args = {
},
};

export const WithReminderChoiceCardsAndApplePay = Template.bind({});
WithReminderChoiceCardsAndApplePay.args = {
variant: {
...props.variant,
name: 'V1_APPLE_PAY',
showChoiceCards: true,
showApplePay: true,
choiceCardAmounts: {
testName: 'Storybook_test',
variantName: 'Control',
defaultContributionType: 'MONTHLY',
displayContributionType: ['ONE_OFF', 'MONTHLY', 'ANNUAL'],
amountsCardData: {
ONE_OFF: {
amounts: [5, 10, 15, 20],
defaultAmount: 5,
hideChooseYourAmount: false,
},
MONTHLY: {
amounts: [6, 12],
defaultAmount: 12,
hideChooseYourAmount: true,
},
ANNUAL: {
amounts: [50, 100, 150, 200],
defaultAmount: 100,
hideChooseYourAmount: true,
},
},
},
secondaryCta: {
type: SecondaryCtaType.ContributionsReminder,
},
showReminderFields: {
reminderCta: 'Remind me in May',
reminderPeriod: '2020-05-01',
reminderLabel: 'May',
},
},
};

export const WithChoiceCardsAndApplePay = Template.bind({});
WithChoiceCardsAndApplePay.args = {
variant: {
...props.variant,
name: 'V1_APPLE_PAY',
showChoiceCards: true,
showApplePay: true,
choiceCardAmounts: {
testName: 'Storybook_test',
variantName: 'Control',
defaultContributionType: 'MONTHLY',
displayContributionType: ['ONE_OFF', 'MONTHLY', 'ANNUAL'],
amountsCardData: {
ONE_OFF: {
amounts: [5, 10, 15, 20],
defaultAmount: 5,
hideChooseYourAmount: false,
},
MONTHLY: {
amounts: [6, 12],
defaultAmount: 12,
hideChooseYourAmount: true,
},
ANNUAL: {
amounts: [50, 100, 150, 200],
defaultAmount: 100,
hideChooseYourAmount: true,
},
},
},
},
};

export const WithSignInLink = Template.bind({});
WithSignInLink.args = {
variant: {
Expand Down
22 changes: 21 additions & 1 deletion packages/modules/src/modules/epics/ContributionsEpic.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { ContributionsEpicSignInCta } from './ContributionsEpicSignInCta';
import NewsletterSignup from './NewsletterSignup';
import { ContributionsEpicCtas } from './ContributionsEpicCtas';
import type { ReactComponent } from '../../types';
import { isValidApplePayWalletSession } from '../utils/applePay';

// CSS Styling
// -------------------------------------------
Expand Down Expand Up @@ -250,7 +251,25 @@ const ContributionsEpic: ReactComponent<EpicProps> = ({
hasConsentForArticleCount,
stage,
}: EpicProps) => {
const { image, tickerSettings, showChoiceCards, choiceCardAmounts } = variant;
const [showApplePayButton, setShowApplePayButton] = useState(false);
const { image, tickerSettings, showChoiceCards, choiceCardAmounts, showApplePay, name } =
variant;

useEffect(() => {
/** Pre-defined storybook Epic variant name with either
1. showApplePay overide (storybook)
2. valid ApplePay with Wallet browser https session */
const showApplePayValid = name === 'V1_APPLE_PAY' && showApplePay;
if (showApplePayValid) {
setShowApplePayButton(showApplePay);
} else {
console.log(`useEffect.isValidApplePayWalletSession STARTED`);
isValidApplePayWalletSession().then((result) => {
console.log(`useEffect.isValidApplePayWalletSession ENDED -> ${result}`);
setShowApplePayButton(name === 'V1_APPLE_PAY' && result);
});
}
}, []);

const [choiceCardSelection, setChoiceCardSelection] = useState<
ChoiceCardSelection | undefined
Expand Down Expand Up @@ -427,6 +446,7 @@ const ContributionsEpic: ReactComponent<EpicProps> = ({
onReminderOpen={onReminderOpen}
fetchEmail={fetchEmail}
submitComponentEvent={submitComponentEvent}
showApplePayButton={showApplePayButton}
showChoiceCards={showChoiceCards}
amountsTestName={choiceCardAmounts?.testName}
amountsVariantName={choiceCardAmounts?.variantName}
Expand Down
Loading
Loading