@paypal/checkout-components 5.0.416 → 5.0.420

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -10,7 +10,12 @@ import {
10
10
  } from "@paypal/sdk-logos/src";
11
11
  import { DISPLAY_ONLY_VALUES, PLATFORM } from "@paypal/sdk-constants/src";
12
12
 
13
- import { BUTTON_COLOR, BUTTON_LAYOUT, BUTTON_FLOW } from "../../constants";
13
+ import {
14
+ BUTTON_COLOR,
15
+ BUTTON_LAYOUT,
16
+ BUTTON_FLOW,
17
+ DEFAULT,
18
+ } from "../../constants";
14
19
  import { DEFAULT_FUNDING_CONFIG, type FundingSourceConfig } from "../common";
15
20
 
16
21
  import { WalletLabel, Label } from "./template";
@@ -87,9 +92,6 @@ export function getVenmoConfig(): FundingSourceConfig {
87
92
  BUTTON_COLOR.SILVER,
88
93
  BUTTON_COLOR.BLACK,
89
94
  BUTTON_COLOR.WHITE,
90
- BUTTON_COLOR.REBRAND_BLACK,
91
- BUTTON_COLOR.REBRAND_BLUE,
92
- BUTTON_COLOR.REBRAND_WHITE,
93
95
  ],
94
96
 
95
97
  logoColors: {
@@ -97,22 +99,30 @@ export function getVenmoConfig(): FundingSourceConfig {
97
99
  [BUTTON_COLOR.SILVER]: LOGO_COLOR.BLUE,
98
100
  [BUTTON_COLOR.BLACK]: LOGO_COLOR.WHITE,
99
101
  [BUTTON_COLOR.WHITE]: LOGO_COLOR.BLUE,
100
- [BUTTON_COLOR.REBRAND_WHITE]: LOGO_COLOR.BLUE,
101
- [BUTTON_COLOR.REBRAND_BLACK]: LOGO_COLOR.WHITE,
102
- [BUTTON_COLOR.REBRAND_BLUE]: LOGO_COLOR.WHITE,
103
102
  },
104
- textColors: {
105
- ...DEFAULT_FUNDING_CONFIG.textColors,
106
- [BUTTON_COLOR.REBRAND_BLUE]: BUTTON_COLOR.WHITE,
103
+
104
+ logoColorsRebrand: {
105
+ [BUTTON_COLOR.BLUE]: LOGO_COLOR.WHITE,
106
+ [BUTTON_COLOR.BLACK]: LOGO_COLOR.WHITE,
107
+ [BUTTON_COLOR.WHITE]: LOGO_COLOR.BLUE,
108
+ },
109
+
110
+ textColorsRebrand: {
111
+ ...DEFAULT_FUNDING_CONFIG.textColorsRebrand,
112
+ [BUTTON_COLOR.BLUE]: BUTTON_COLOR.WHITE,
107
113
  },
108
114
 
109
115
  secondaryColors: {
110
116
  ...DEFAULT_FUNDING_CONFIG.secondaryColors,
111
-
112
117
  [BUTTON_COLOR.GOLD]: BUTTON_COLOR.BLUE,
113
118
  [BUTTON_COLOR.BLUE]: BUTTON_COLOR.SILVER,
114
119
  [BUTTON_COLOR.SILVER]: BUTTON_COLOR.BLUE,
115
- [BUTTON_COLOR.REBRAND_BLUE]: BUTTON_COLOR.REBRAND_BLUE,
120
+ },
121
+
122
+ secondaryColorsRebrand: {
123
+ ...DEFAULT_FUNDING_CONFIG.secondaryColorsRebrand,
124
+ [DEFAULT]: BUTTON_COLOR.BLUE,
125
+ [BUTTON_COLOR.BLUE]: BUTTON_COLOR.BLUE,
116
126
  },
117
127
  };
118
128
  }
@@ -31,7 +31,7 @@ import {
31
31
  TEXT_COLOR,
32
32
  BUTTON_FLOW,
33
33
  } from "../../constants";
34
- import { getFundingConfig } from "../../funding";
34
+ import { getFundingConfig, getFundingSourceColors } from "../../funding";
35
35
 
36
36
  import type {
37
37
  ButtonStyle,
@@ -106,9 +106,6 @@ export function Button({
106
106
  throw new Error(`Can not find funding config for ${fundingSource}`);
107
107
  }
108
108
 
109
- const colors = fundingConfig.colors;
110
- const secondaryColors = fundingConfig.secondaryColors || {};
111
-
112
109
  let {
113
110
  color,
114
111
  period,
@@ -117,9 +114,13 @@ export function Button({
117
114
  shouldApplyPayNowOrLaterLabel,
118
115
  } = style;
119
116
 
117
+ const { colors, logoColors, secondaryColors, textColors } =
118
+ getFundingSourceColors({ fundingConfig, shouldApplyRebrandedStyles });
119
+ const { logoColorsPP } = fundingConfig;
120
+
120
121
  // if no color option is passed in via style props
121
122
  if (color === "" || typeof color === "undefined") {
122
- // if a single button is rendered, we set color to first option in the fundingSource config
123
+ // if a single button is rendered, we set color to first option in the valid color set
123
124
  color = colors[0];
124
125
 
125
126
  // if multiple buttons are being rendered (smart stack), we set default color as gold > first
@@ -137,20 +138,15 @@ export function Button({
137
138
  // The secondary colors are used to render the smart stack (multiple buttons)
138
139
  // they keep track of the mapping of the color style prop to the
139
140
  if (multiple && i > 0) {
140
- if (
141
- secondaryColors[color] &&
142
- colors.indexOf(secondaryColors[color] !== -1)
143
- ) {
141
+ if (secondaryColors[color] && colors.includes(secondaryColors[color])) {
144
142
  color = secondaryColors[color];
145
- } else if (colors.indexOf(secondaryColors[BUTTON_COLOR.DEFAULT]) !== -1) {
143
+ } else if (colors.includes(secondaryColors[BUTTON_COLOR.DEFAULT])) {
146
144
  color = secondaryColors[BUTTON_COLOR.DEFAULT];
147
145
  } else {
148
146
  color = colors[0];
149
147
  }
150
148
  }
151
149
 
152
- const { logoColors, logoColorsPP, textColors } = fundingConfig;
153
-
154
150
  const logoColor =
155
151
  logoColors[color] || logoColors[LOGO_COLOR.DEFAULT] || LOGO_COLOR.DEFAULT;
156
152
  const logoColorPP = logoColorsPP
@@ -289,6 +285,7 @@ export function Button({
289
285
  <div
290
286
  class={[
291
287
  CLASS.BUTTON_ROW,
288
+ `${shouldApplyRebrandedStyles ? CLASS.BUTTON_REBRAND : ""}`,
292
289
  `${CLASS.NUMBER}-${i}`,
293
290
  `${CLASS.LAYOUT}-${layout}`,
294
291
  `${CLASS.NUMBER}-${
@@ -5,7 +5,7 @@ import { node, type ChildType } from "@krakenjs/jsx-pragmatic/src";
5
5
  import { type LocaleType } from "@paypal/sdk-constants/src";
6
6
  import { LOGO_COLOR, LOGO_CLASS } from "@paypal/sdk-logos/src";
7
7
 
8
- import { CLASS, BUTTON_COLOR_REBRAND } from "../../constants";
8
+ import { CLASS, BUTTON_COLOR } from "../../constants";
9
9
  import { Text } from "../text";
10
10
 
11
11
  import { buttonContent } from "./content";
@@ -50,15 +50,15 @@ function getPoweredByConfig(): {|
50
50
  |} {
51
51
  return {
52
52
  logoColors: {
53
- [BUTTON_COLOR_REBRAND.REBRAND_BLUE]: LOGO_COLOR.BLACK,
54
- [BUTTON_COLOR_REBRAND.REBRAND_BLACK]: LOGO_COLOR.BLACK,
55
- [BUTTON_COLOR_REBRAND.REBRAND_WHITE]: LOGO_COLOR.BLACK,
53
+ [BUTTON_COLOR.BLUE]: LOGO_COLOR.BLACK,
54
+ [BUTTON_COLOR.BLACK]: LOGO_COLOR.BLACK,
55
+ [BUTTON_COLOR.WHITE]: LOGO_COLOR.BLACK,
56
56
  },
57
57
 
58
58
  textColors: {
59
- [BUTTON_COLOR_REBRAND.REBRAND_BLUE]: "#000000",
60
- [BUTTON_COLOR_REBRAND.REBRAND_BLACK]: "#000000",
61
- [BUTTON_COLOR_REBRAND.REBRAND_WHITE]: "#000000",
59
+ [BUTTON_COLOR.BLUE]: "#000000",
60
+ [BUTTON_COLOR.BLACK]: "#000000",
61
+ [BUTTON_COLOR.WHITE]: "#000000",
62
62
  },
63
63
  };
64
64
  }
@@ -66,7 +66,7 @@ function getPoweredByConfig(): {|
66
66
  export function PoweredByPayPal({
67
67
  locale: { lang },
68
68
  nonce,
69
- buttonColor = BUTTON_COLOR_REBRAND.REBRAND_BLUE,
69
+ buttonColor = BUTTON_COLOR.BLUE,
70
70
  shouldApplyRebrandedStyles = false,
71
71
  }: PoweredByPayPalProps): ChildType {
72
72
  const { PoweredBy } = buttonContent[lang];
@@ -26,6 +26,7 @@ import {
26
26
  CARD,
27
27
  COMPONENTS,
28
28
  DISPLAY_ONLY_VALUES,
29
+ type BrandVersion,
29
30
  } from "@paypal/sdk-constants/src";
30
31
  import { type CrossDomainWindowType } from "@krakenjs/cross-domain-utils/src";
31
32
  import { LOGO_COLOR } from "@paypal/sdk-logos/src";
@@ -36,7 +37,6 @@ import type { ContentType, Wallet, Experiment } from "../../types";
36
37
  import {
37
38
  BUTTON_LABEL,
38
39
  BUTTON_COLOR,
39
- BUTTON_COLOR_REBRAND,
40
40
  BUTTON_LAYOUT,
41
41
  BUTTON_SHAPE,
42
42
  BUTTON_SIZE,
@@ -47,7 +47,11 @@ import {
47
47
  MESSAGE_POSITION,
48
48
  MESSAGE_ALIGN,
49
49
  } from "../../constants";
50
- import { getFundingConfig, isFundingEligible } from "../../funding";
50
+ import {
51
+ getFundingConfig,
52
+ isFundingEligible,
53
+ getFundingSourceColors,
54
+ } from "../../funding";
51
55
  import { componentContent } from "../../funding/content";
52
56
  import type { StateGetSet } from "../../lib/session";
53
57
 
@@ -334,6 +338,8 @@ export type ButtonStyle = {|
334
338
  isButtonColorABTestMerchant: boolean,
335
339
  isPayNowOrLaterLabelEligible: boolean,
336
340
  shouldApplyPayNowOrLaterLabel: boolean,
341
+ requestedButtonColor?: $Values<typeof BUTTON_COLOR>,
342
+ brandVersion: BrandVersion,
337
343
  |};
338
344
 
339
345
  export type ButtonStyleInputs = {|
@@ -527,6 +533,7 @@ type ButtonColor = {|
527
533
  shouldApplyRebrandedStyles: boolean,
528
534
  color: $Values<typeof BUTTON_COLOR>,
529
535
  isButtonColorABTestMerchant: boolean,
536
+ brandVersion: BrandVersion,
530
537
  |};
531
538
 
532
539
  type ColorABTestStorage = {|
@@ -561,6 +568,7 @@ type GetColorForFullRedesignArgs = {|
561
568
  type GetDefaultColorForFundingSourceArgs = {|
562
569
  fundingSource: ?$Values<typeof FUNDING>,
563
570
  style: ?ButtonStyle,
571
+ shouldApplyRebrandedStyles: boolean,
564
572
  |};
565
573
 
566
574
  type GetButtonColorExperienceArgs = {|
@@ -653,6 +661,7 @@ export type ButtonProps = {|
653
661
  messageMarkup?: string,
654
662
  hideSubmitButtonForCardForm?: boolean,
655
663
  userAgent: string,
664
+ buttonColor: ButtonColor,
656
665
  |};
657
666
 
658
667
  // eslint-disable-next-line flowtype/require-exact-type
@@ -782,6 +791,14 @@ export function getBNPLLabelForABTest({
782
791
  return shouldApplyPayNowOrLaterLabel;
783
792
  }
784
793
 
794
+ export function getBrandVersion({
795
+ shouldApplyRebrandedStyles,
796
+ }: {|
797
+ shouldApplyRebrandedStyles: boolean,
798
+ |}): BrandVersion {
799
+ return shouldApplyRebrandedStyles ? "v2" : "v1";
800
+ }
801
+
785
802
  export function determineRandomButtonColor({
786
803
  buttonColorInput,
787
804
  }: {|
@@ -790,15 +807,11 @@ export function determineRandomButtonColor({
790
807
  let shouldApplyRebrandedStyles;
791
808
  let buttonColor;
792
809
 
793
- const randomButtonColor = Math.floor(Math.random() * 3);
810
+ const randomButtonColor = Math.floor(Math.random() * 2);
794
811
 
795
812
  switch (randomButtonColor) {
796
813
  case 0:
797
- buttonColor = BUTTON_COLOR.REBRAND_BLUE;
798
- shouldApplyRebrandedStyles = true;
799
- break;
800
- case 1:
801
- buttonColor = BUTTON_COLOR.REBRAND_DARKBLUE;
814
+ buttonColor = BUTTON_COLOR.BLUE;
802
815
  shouldApplyRebrandedStyles = true;
803
816
  break;
804
817
  default:
@@ -812,6 +825,7 @@ export function determineRandomButtonColor({
812
825
  shouldApplyRebrandedStyles,
813
826
  color: buttonColor,
814
827
  isButtonColorABTestMerchant: true,
828
+ brandVersion: getBrandVersion({ shouldApplyRebrandedStyles }),
815
829
  };
816
830
  }
817
831
 
@@ -820,29 +834,28 @@ export function throwErrorForInvalidButtonColor({
820
834
  fundingSourceColors,
821
835
  invalidButtonColor,
822
836
  }: ThrowErrorForInvalidButtonColorArgs) {
823
- const rebrandedColors = Object.values(BUTTON_COLOR_REBRAND);
824
- const filteredColors = fundingSourceColors.filter(
825
- (fundingConfigColor) => !rebrandedColors.includes(fundingConfigColor)
826
- );
827
-
828
837
  // Throw an error if color specified by merchant is not valid for the funding source
829
838
  throw new Error(
830
839
  `Unexpected style.color for ${
831
840
  fundingSource || FUNDING.PAYPAL
832
- } button: ${invalidButtonColor}, expected ${filteredColors.join(", ")}`
841
+ } button: ${invalidButtonColor}, expected ${fundingSourceColors.join(", ")}`
833
842
  );
834
843
  }
835
844
 
836
845
  export function getDefaultColorForFundingSource({
837
846
  fundingSource,
838
847
  style,
848
+ shouldApplyRebrandedStyles,
839
849
  }: GetDefaultColorForFundingSourceArgs): $Values<typeof BUTTON_COLOR> {
840
850
  // $FlowFixMe this is handled if the fundingSource is undefined
841
851
  const fundingSourceConfig = getFundingConfig()[fundingSource];
842
852
  const { color: buttonColorInput } = style || {};
843
853
 
844
854
  if (fundingSourceConfig) {
845
- const { colors } = fundingSourceConfig;
855
+ const { colors } = getFundingSourceColors({
856
+ fundingConfig: fundingSourceConfig,
857
+ shouldApplyRebrandedStyles,
858
+ });
846
859
 
847
860
  if (!buttonColorInput) {
848
861
  // return the default color for the funding source
@@ -896,20 +909,13 @@ export function getColorForFullRedesign({
896
909
  fundingSource,
897
910
  }: GetColorForFullRedesignArgs): ButtonColor {
898
911
  const rebrandColorMap = {
899
- [BUTTON_COLOR.BLUE]: BUTTON_COLOR.REBRAND_BLUE,
900
- [BUTTON_COLOR.DARKBLUE]: BUTTON_COLOR.REBRAND_BLUE,
901
- [BUTTON_COLOR.GOLD]: BUTTON_COLOR.REBRAND_BLUE,
902
- [BUTTON_COLOR.BLACK]: BUTTON_COLOR.REBRAND_BLACK,
903
- [BUTTON_COLOR.WHITE]: BUTTON_COLOR.REBRAND_WHITE,
904
- [BUTTON_COLOR.SILVER]: BUTTON_COLOR.REBRAND_WHITE,
912
+ [BUTTON_COLOR.BLUE]: BUTTON_COLOR.BLUE,
913
+ [BUTTON_COLOR.DARKBLUE]: BUTTON_COLOR.BLUE,
914
+ [BUTTON_COLOR.GOLD]: BUTTON_COLOR.BLUE,
915
+ [BUTTON_COLOR.BLACK]: BUTTON_COLOR.BLACK,
916
+ [BUTTON_COLOR.WHITE]: BUTTON_COLOR.WHITE,
917
+ [BUTTON_COLOR.SILVER]: BUTTON_COLOR.WHITE,
905
918
  [BUTTON_COLOR.DEFAULT]: BUTTON_COLOR.DEFAULT,
906
-
907
- // normalizeButtonStyle gets called multiple times and
908
- // it can be called after color is already be mapped to rebranded style
909
- [BUTTON_COLOR.REBRAND_BLUE]: BUTTON_COLOR.REBRAND_BLUE,
910
- [BUTTON_COLOR.REBRAND_DARKBLUE]: BUTTON_COLOR.REBRAND_DARKBLUE,
911
- [BUTTON_COLOR.REBRAND_BLACK]: BUTTON_COLOR.REBRAND_BLACK,
912
- [BUTTON_COLOR.REBRAND_WHITE]: BUTTON_COLOR.REBRAND_WHITE,
913
919
  };
914
920
 
915
921
  // if color is invalid, buttonColor will be undefined
@@ -924,6 +930,7 @@ export function getColorForFullRedesign({
924
930
  const defaultButtonColor = getDefaultColorForFundingSource({
925
931
  fundingSource,
926
932
  style,
933
+ shouldApplyRebrandedStyles: true,
927
934
  });
928
935
 
929
936
  buttonColor = rebrandColorMap[defaultButtonColor] || defaultButtonColor;
@@ -933,6 +940,7 @@ export function getColorForFullRedesign({
933
940
  color: buttonColor,
934
941
  shouldApplyRebrandedStyles: true,
935
942
  isButtonColorABTestMerchant: false,
943
+ brandVersion: getBrandVersion({ shouldApplyRebrandedStyles: true }),
936
944
  };
937
945
  }
938
946
 
@@ -991,8 +999,10 @@ export function getButtonColor({
991
999
  color: getDefaultColorForFundingSource({
992
1000
  fundingSource,
993
1001
  style,
1002
+ shouldApplyRebrandedStyles: false,
994
1003
  }),
995
1004
  isButtonColorABTestMerchant: false,
1005
+ brandVersion: getBrandVersion({ shouldApplyRebrandedStyles: false }),
996
1006
  };
997
1007
  }
998
1008
  }
@@ -1075,8 +1085,12 @@ export function normalizeButtonStyle(
1075
1085
 
1076
1086
  props = props || getDefaultButtonPropsInput();
1077
1087
  const { fundingSource, buttonColor } = props;
1078
- const { color, shouldApplyRebrandedStyles, isButtonColorABTestMerchant } =
1079
- buttonColor || {};
1088
+ const {
1089
+ color,
1090
+ shouldApplyRebrandedStyles,
1091
+ isButtonColorABTestMerchant,
1092
+ brandVersion,
1093
+ } = buttonColor || {};
1080
1094
 
1081
1095
  const FUNDING_CONFIG = getFundingConfig();
1082
1096
  const fundingConfig =
@@ -1102,10 +1116,9 @@ export function normalizeButtonStyle(
1102
1116
  disableMaxWidth,
1103
1117
  disableMaxHeight,
1104
1118
  borderRadius,
1119
+ color: requestedButtonColor,
1105
1120
  } = style;
1106
1121
 
1107
- const rebrandedColors = Object.values(BUTTON_COLOR_REBRAND);
1108
-
1109
1122
  // $FlowFixMe
1110
1123
  if (tagline === "false") {
1111
1124
  // $FlowFixMe
@@ -1120,16 +1133,16 @@ export function normalizeButtonStyle(
1120
1133
  throw new Error(`Invalid label: ${label}`);
1121
1134
  }
1122
1135
 
1123
- if (color && fundingConfig.colors.indexOf(color) === -1) {
1124
- // We don't want to include rebranded colors in the error message
1125
- const filteredColors = fundingConfig.colors.filter(
1126
- (fundingConfigColor) => !rebrandedColors.includes(fundingConfigColor)
1127
- );
1136
+ const { colors: validColors } = getFundingSourceColors({
1137
+ fundingConfig,
1138
+ shouldApplyRebrandedStyles,
1139
+ });
1128
1140
 
1141
+ if (color && validColors.indexOf(color) === -1) {
1129
1142
  throw new Error(
1130
- `Unexpected style.color for ${
1131
- fundingSource || FUNDING.PAYPAL
1132
- } button: ${color}, expected ${filteredColors.join(", ")}`
1143
+ `Unexpected style.color for ${fundingSource || FUNDING.PAYPAL} button: ${
1144
+ requestedButtonColor || color
1145
+ }, expected ${validColors.join(", ")}`
1133
1146
  );
1134
1147
  }
1135
1148
 
@@ -1229,6 +1242,8 @@ export function normalizeButtonStyle(
1229
1242
  isButtonColorABTestMerchant,
1230
1243
  isPayNowOrLaterLabelEligible,
1231
1244
  shouldApplyPayNowOrLaterLabel,
1245
+ requestedButtonColor,
1246
+ brandVersion,
1232
1247
  };
1233
1248
  }
1234
1249