@paypal/checkout-components 5.0.264 → 5.0.266

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@paypal/checkout-components",
3
- "version": "5.0.264",
3
+ "version": "5.0.266",
4
4
  "description": "PayPal Checkout components, for integrating checkout products.",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -33,62 +33,16 @@ import { getJCBConfig } from "./jcb";
33
33
 
34
34
  function getVendorConfig(): { [$Values<typeof CARD>]: ?CardConfig } {
35
35
  return {
36
- [CARD.VISA]:
37
- !__TREE_SHAKE__ ||
38
- (__FUNDING_ELIGIBILITY__.card &&
39
- __FUNDING_ELIGIBILITY__.card.vendors &&
40
- __FUNDING_ELIGIBILITY__.card.vendors.visa &&
41
- __FUNDING_ELIGIBILITY__.card.vendors.visa.eligible)
42
- ? getVisaConfig()
43
- : null,
44
- [CARD.AMEX]:
45
- !__TREE_SHAKE__ ||
46
- (__FUNDING_ELIGIBILITY__.card &&
47
- __FUNDING_ELIGIBILITY__.card.vendors &&
48
- __FUNDING_ELIGIBILITY__.card.vendors.amex &&
49
- __FUNDING_ELIGIBILITY__.card.vendors.amex.eligible)
50
- ? getAmexConfig()
51
- : null,
52
- [CARD.MASTERCARD]:
53
- !__TREE_SHAKE__ ||
54
- (__FUNDING_ELIGIBILITY__.card &&
55
- __FUNDING_ELIGIBILITY__.card.vendors &&
56
- __FUNDING_ELIGIBILITY__.card.vendors.mastercard &&
57
- __FUNDING_ELIGIBILITY__.card.vendors.mastercard.eligible)
58
- ? getMastercardConfig()
59
- : null,
60
- [CARD.DISCOVER]:
61
- !__TREE_SHAKE__ ||
62
- (__FUNDING_ELIGIBILITY__.card &&
63
- __FUNDING_ELIGIBILITY__.card.vendors &&
64
- __FUNDING_ELIGIBILITY__.card.vendors.discover &&
65
- __FUNDING_ELIGIBILITY__.card.vendors.discover.eligible)
66
- ? getDiscoverConfig()
67
- : null,
68
- [CARD.JCB]:
69
- !__TREE_SHAKE__ ||
70
- (__FUNDING_ELIGIBILITY__.card &&
71
- __FUNDING_ELIGIBILITY__.card.vendors &&
72
- __FUNDING_ELIGIBILITY__.card.vendors.jcb &&
73
- __FUNDING_ELIGIBILITY__.card.vendors.jcb.eligible)
74
- ? getJCBConfig()
75
- : null,
76
- [CARD.ELO]:
77
- !__TREE_SHAKE__ ||
78
- (__FUNDING_ELIGIBILITY__.card &&
79
- __FUNDING_ELIGIBILITY__.card.vendors &&
80
- __FUNDING_ELIGIBILITY__.card.vendors.elo &&
81
- __FUNDING_ELIGIBILITY__.card.vendors.elo.eligible)
82
- ? getEloConfig()
83
- : null,
84
- [CARD.HIPER]:
85
- !__TREE_SHAKE__ ||
86
- (__FUNDING_ELIGIBILITY__.card &&
87
- __FUNDING_ELIGIBILITY__.card.vendors &&
88
- __FUNDING_ELIGIBILITY__.card.vendors.hiper &&
89
- __FUNDING_ELIGIBILITY__.card.vendors.hiper.eligible)
90
- ? getHiperConfig()
91
- : null,
36
+ [CARD.VISA]: getVisaConfig(),
37
+
38
+ [CARD.AMEX]: getAmexConfig(),
39
+
40
+ [CARD.MASTERCARD]: getMastercardConfig(),
41
+
42
+ [CARD.DISCOVER]: getDiscoverConfig(),
43
+ [CARD.JCB]: getJCBConfig(),
44
+ [CARD.ELO]: getEloConfig(),
45
+ [CARD.HIPER]: getHiperConfig(),
92
46
  };
93
47
  }
94
48
 
@@ -105,9 +59,6 @@ export function getCardConfig(): FundingSourceConfig {
105
59
  eligible: ({ components, fundingSource, fundingEligibility, wallet }) => {
106
60
  const cardEligibility = fundingEligibility.card;
107
61
 
108
- const hostedFieldsRequested = Boolean(
109
- components.indexOf(COMPONENTS.HOSTED_FIELDS) !== -1
110
- );
111
62
  const cardEligible = Boolean(cardEligibility && cardEligibility.eligible);
112
63
  const cardBranded = Boolean(cardEligibility && cardEligibility.branded);
113
64
  const cardVaulted = Boolean(
@@ -122,23 +73,43 @@ export function getCardConfig(): FundingSourceConfig {
122
73
  return false;
123
74
  }
124
75
 
125
- // If card is branded, always show card buttons
76
+ /*
77
+ *
78
+ * the next 5 if statements are in a very important order. Each if statement relies on the one above
79
+ * to verify we are not in a situation where card fields should or should not be shown. Switching the
80
+ * order of these if statements could break merchant integrations
81
+ *
82
+ * 1. If funding eligibility says branded: true for card, it means that the merchant is not
83
+ * eligible for unbranded experiences. In that case, the card button should always be eligible
84
+ * 2. If the merchant is attempting to render a standalone card, we should mark it as eligible
85
+ * since it is outside of the smart stack
86
+ * 3. If the merchant is using the new card-fields component, the card button should be ineligible
87
+ * because we should not mix branded and unbranded experiences
88
+ * 4. If there is a vaulted card in the buyer's wallet we should show the button. This is very important
89
+ * because the old hosted card fields (hosted-fields) uses the card button as its return buyer experience
90
+ * this is why this check happens before checking if hosted-fields was requested
91
+ * 5. If hosted-fields were requested, we shouldn't show the card button because we shouldn't mix branded and
92
+ * unbranded experience. The exception is for vaulted cards explained in the point above
93
+ *
94
+ */
95
+
126
96
  if (cardBranded) {
127
97
  return true;
128
98
  }
129
99
 
130
- // If there's a vaulted card, always show card button
131
- if (cardVaulted) {
100
+ if (fundingSource === FUNDING.CARD) {
132
101
  return true;
133
102
  }
134
103
 
135
- // If standalone card is selected, always show card button
136
- if (fundingSource === FUNDING.CARD) {
104
+ if (components.includes("card-fields")) {
105
+ return false;
106
+ }
107
+
108
+ if (cardVaulted) {
137
109
  return true;
138
110
  }
139
111
 
140
- // If hosted fields is requested, do not show card buttons
141
- if (hostedFieldsRequested) {
112
+ if (components.includes(COMPONENTS.HOSTED_FIELDS)) {
142
113
  return false;
143
114
  }
144
115
 
@@ -0,0 +1,132 @@
1
+ /* @flow */
2
+ import { describe, test, expect } from "vitest";
3
+ import { FUNDING, COMPONENTS } from "@paypal/sdk-constants/src";
4
+
5
+ import { getCardConfig } from "./config";
6
+
7
+ const getEligibility = ({
8
+ eligible = true,
9
+ branded = false,
10
+ vendors = {},
11
+ } = {}) => ({
12
+ card: {
13
+ eligible,
14
+ branded,
15
+ vendors,
16
+ },
17
+ });
18
+
19
+ const getWallet = ({ card = [] } = {}) => ({
20
+ card: {
21
+ instruments: card,
22
+ },
23
+ credit: {
24
+ instruments: [],
25
+ },
26
+ paypal: {
27
+ instruments: [],
28
+ },
29
+ venmo: {
30
+ instruments: [],
31
+ },
32
+ });
33
+
34
+ describe("card eligibility", () => {
35
+ // $FlowIssue .eligible is marked as optional in type
36
+ const getCardConfigEligible = (...args) => getCardConfig().eligible(...args);
37
+
38
+ test("should not be eligible when funding eligibility is false", () => {
39
+ expect(
40
+ getCardConfigEligible({
41
+ components: [],
42
+ fundingSource: FUNDING.PAYPAL,
43
+ fundingEligibility: getEligibility({ eligible: false }),
44
+ // $FlowIssue
45
+ wallet: getWallet(),
46
+ })
47
+ ).toEqual(false);
48
+ });
49
+
50
+ test("should be eligible if card funding eligibility says branded is true", () => {
51
+ expect(
52
+ getCardConfigEligible({
53
+ components: [],
54
+ fundingSource: FUNDING.PAYPAL,
55
+ fundingEligibility: getEligibility({ branded: true }),
56
+ wallet: getWallet(),
57
+ })
58
+ ).toEqual(true);
59
+ });
60
+
61
+ test("should be eligible if standalone card was rendered", () => {
62
+ expect(
63
+ getCardConfigEligible({
64
+ components: [],
65
+ fundingSource: FUNDING.CARD,
66
+ fundingEligibility: getEligibility(),
67
+ wallet: getWallet(),
68
+ })
69
+ ).toEqual(true);
70
+ });
71
+
72
+ test("should be ineligible if card-fields were requested", () => {
73
+ expect(
74
+ getCardConfigEligible({
75
+ // $FlowIssue need to add the new card fields as a constant
76
+ components: ["card-fields"],
77
+ fundingSource: FUNDING.PAYPAL,
78
+ fundingEligibility: getEligibility(),
79
+ wallet: getWallet(),
80
+ })
81
+ ).toEqual(false);
82
+ });
83
+
84
+ test("should be ineligible if card-fields were requested, even if there is a vaulted instrument", () => {
85
+ expect(
86
+ getCardConfigEligible({
87
+ // $FlowIssue need to add the new card fields as a constant
88
+ components: ["card-fields"],
89
+ fundingSource: FUNDING.PAYPAL,
90
+ fundingEligibility: getEligibility(),
91
+ wallet: getWallet({
92
+ card: ["some instrument"],
93
+ }),
94
+ })
95
+ ).toEqual(false);
96
+ });
97
+
98
+ test("should be eligible if there is a vaulted card", () => {
99
+ expect(
100
+ getCardConfigEligible({
101
+ components: [],
102
+ fundingSource: FUNDING.PAYPAL,
103
+ fundingEligibility: getEligibility(),
104
+ wallet: getWallet({
105
+ card: ["some instrument"],
106
+ }),
107
+ })
108
+ ).toEqual(true);
109
+ });
110
+
111
+ test("should be ineligible if hosted-fields was requested", () => {
112
+ expect(
113
+ getCardConfigEligible({
114
+ components: [COMPONENTS.HOSTED_FIELDS],
115
+ fundingSource: FUNDING.PAYPAL,
116
+ fundingEligibility: getEligibility(),
117
+ wallet: getWallet(),
118
+ })
119
+ ).toEqual(false);
120
+ });
121
+
122
+ test("should default to true", () => {
123
+ expect(
124
+ getCardConfigEligible({
125
+ components: [],
126
+ fundingSource: FUNDING.PAYPAL,
127
+ fundingEligibility: getEligibility(),
128
+ wallet: getWallet(),
129
+ })
130
+ ).toEqual(true);
131
+ });
132
+ });
@@ -126,10 +126,10 @@ export type FundingSourceConfig = {|
126
126
  vendors?: { [$Values<typeof CARD>]: ?CardConfig },
127
127
  eligible?: ({|
128
128
  components: $ReadOnlyArray<$Values<typeof COMPONENTS>>,
129
- experiment: ?Experiment,
129
+ experiment?: ?Experiment,
130
130
  fundingEligibility: FundingEligibilityType,
131
131
  fundingSource: ?$Values<typeof FUNDING>,
132
- layout: ?$Values<typeof BUTTON_LAYOUT>,
132
+ layout?: ?$Values<typeof BUTTON_LAYOUT>,
133
133
  wallet: ?Wallet,
134
134
  |}) => boolean,
135
135
  Logo: (LogoOptions) => ChildType,
@@ -35,162 +35,32 @@ export function getFundingConfig(): {
35
35
  } {
36
36
  return inlineMemoize(getFundingConfig, () => {
37
37
  return {
38
- [FUNDING.PAYPAL]:
39
- !__TREE_SHAKE__ ||
40
- (typeof __FUNDING_ELIGIBILITY__.paypal !== "undefined" &&
41
- __FUNDING_ELIGIBILITY__.paypal.eligible)
42
- ? getPayPalConfig()
43
- : null,
44
- [FUNDING.VENMO]:
45
- !__TREE_SHAKE__ ||
46
- (typeof __FUNDING_ELIGIBILITY__.venmo !== "undefined" &&
47
- __FUNDING_ELIGIBILITY__.venmo.eligible)
48
- ? getVenmoConfig()
49
- : null,
50
- [FUNDING.APPLEPAY]:
51
- !__TREE_SHAKE__ ||
52
- (typeof __FUNDING_ELIGIBILITY__.applepay !== "undefined" &&
53
- __FUNDING_ELIGIBILITY__.applepay.eligible)
54
- ? getApplePayConfig()
55
- : null,
56
- [FUNDING.ITAU]:
57
- !__TREE_SHAKE__ ||
58
- (typeof __FUNDING_ELIGIBILITY__.itau !== "undefined" &&
59
- __FUNDING_ELIGIBILITY__.itau.eligible)
60
- ? getItauConfig()
61
- : null,
62
- [FUNDING.CREDIT]:
63
- !__TREE_SHAKE__ ||
64
- (typeof __FUNDING_ELIGIBILITY__.credit !== "undefined" &&
65
- __FUNDING_ELIGIBILITY__.credit.eligible)
66
- ? getCreditConfig()
67
- : null,
68
- [FUNDING.PAYLATER]:
69
- !__TREE_SHAKE__ ||
70
- (typeof __FUNDING_ELIGIBILITY__.paylater !== "undefined" &&
71
- __FUNDING_ELIGIBILITY__.paylater.eligible)
72
- ? getPaylaterConfig()
73
- : null,
74
- [FUNDING.CARD]:
75
- !__TREE_SHAKE__ ||
76
- (typeof __FUNDING_ELIGIBILITY__.card !== "undefined" &&
77
- __FUNDING_ELIGIBILITY__.card.eligible)
78
- ? getCardConfig()
79
- : null,
80
- [FUNDING.IDEAL]:
81
- !__TREE_SHAKE__ ||
82
- (typeof __FUNDING_ELIGIBILITY__.ideal !== "undefined" &&
83
- __FUNDING_ELIGIBILITY__.ideal.eligible)
84
- ? getIdealConfig()
85
- : null,
86
- [FUNDING.SEPA]:
87
- !__TREE_SHAKE__ ||
88
- (typeof __FUNDING_ELIGIBILITY__.sepa !== "undefined" &&
89
- __FUNDING_ELIGIBILITY__.sepa.eligible)
90
- ? getSepaConfig()
91
- : null,
92
- [FUNDING.BANCONTACT]:
93
- !__TREE_SHAKE__ ||
94
- (typeof __FUNDING_ELIGIBILITY__.bancontact !== "undefined" &&
95
- __FUNDING_ELIGIBILITY__.bancontact.eligible)
96
- ? getBancontactConfig()
97
- : null,
98
- [FUNDING.GIROPAY]:
99
- !__TREE_SHAKE__ ||
100
- (typeof __FUNDING_ELIGIBILITY__.giropay !== "undefined" &&
101
- __FUNDING_ELIGIBILITY__.giropay.eligible)
102
- ? getGiropayConfig()
103
- : null,
104
- [FUNDING.SOFORT]:
105
- !__TREE_SHAKE__ ||
106
- (typeof __FUNDING_ELIGIBILITY__.sofort !== "undefined" &&
107
- __FUNDING_ELIGIBILITY__.sofort.eligible)
108
- ? getSofortConfig()
109
- : null,
110
- [FUNDING.EPS]:
111
- !__TREE_SHAKE__ ||
112
- (typeof __FUNDING_ELIGIBILITY__.eps !== "undefined" &&
113
- __FUNDING_ELIGIBILITY__.eps.eligible)
114
- ? getEpsConfig()
115
- : null,
116
- [FUNDING.MYBANK]:
117
- !__TREE_SHAKE__ ||
118
- (typeof __FUNDING_ELIGIBILITY__.mybank !== "undefined" &&
119
- __FUNDING_ELIGIBILITY__.mybank.eligible)
120
- ? getMybankConfig()
121
- : null,
122
- [FUNDING.P24]:
123
- !__TREE_SHAKE__ ||
124
- (typeof __FUNDING_ELIGIBILITY__.p24 !== "undefined" &&
125
- __FUNDING_ELIGIBILITY__.p24.eligible)
126
- ? getP24Config()
127
- : null,
128
- [FUNDING.PAYU]:
129
- !__TREE_SHAKE__ ||
130
- (typeof __FUNDING_ELIGIBILITY__.payu !== "undefined" &&
131
- __FUNDING_ELIGIBILITY__.payu.eligible)
132
- ? getPayuConfig()
133
- : null,
134
- [FUNDING.BLIK]:
135
- !__TREE_SHAKE__ ||
136
- (typeof __FUNDING_ELIGIBILITY__.blik !== "undefined" &&
137
- __FUNDING_ELIGIBILITY__.blik.eligible)
138
- ? getBlikConfig()
139
- : null,
140
- [FUNDING.TRUSTLY]:
141
- !__TREE_SHAKE__ ||
142
- (typeof __FUNDING_ELIGIBILITY__.trustly !== "undefined" &&
143
- __FUNDING_ELIGIBILITY__.trustly.eligible)
144
- ? getTrustlyConfig()
145
- : null,
146
- [FUNDING.WECHATPAY]:
147
- !__TREE_SHAKE__ ||
148
- (typeof __FUNDING_ELIGIBILITY__.wechatpay !== "undefined" &&
149
- __FUNDING_ELIGIBILITY__.wechatpay.eligible)
150
- ? getWechatpayConfig()
151
- : null,
152
- [FUNDING.OXXO]:
153
- !__TREE_SHAKE__ ||
154
- (typeof __FUNDING_ELIGIBILITY__.oxxo !== "undefined" &&
155
- __FUNDING_ELIGIBILITY__.oxxo.eligible)
156
- ? getOxxoConfig()
157
- : null,
158
- [FUNDING.BOLETO]:
159
- !__TREE_SHAKE__ ||
160
- (typeof __FUNDING_ELIGIBILITY__.boleto !== "undefined" &&
161
- __FUNDING_ELIGIBILITY__.boleto.eligible)
162
- ? getBoletoConfig()
163
- : null,
164
- [FUNDING.BOLETOBANCARIO]:
165
- !__TREE_SHAKE__ ||
166
- (typeof __FUNDING_ELIGIBILITY__.boletobancario !== "undefined" &&
167
- __FUNDING_ELIGIBILITY__.boletobancario.eligible)
168
- ? getBoletoConfig()
169
- : null,
170
- [FUNDING.MERCADOPAGO]:
171
- !__TREE_SHAKE__ ||
172
- (typeof __FUNDING_ELIGIBILITY__.mercadopago !== "undefined" &&
173
- __FUNDING_ELIGIBILITY__.mercadopago.eligible)
174
- ? getMercadopagoConfig()
175
- : null,
176
- [FUNDING.MULTIBANCO]:
177
- !__TREE_SHAKE__ ||
178
- (typeof __FUNDING_ELIGIBILITY__.multibanco !== "undefined" &&
179
- __FUNDING_ELIGIBILITY__.multibanco.eligible)
180
- ? getMultibancoConfig()
181
- : null,
182
- [FUNDING.SATISPAY]:
183
- !__TREE_SHAKE__ ||
184
- (typeof __FUNDING_ELIGIBILITY__.satispay !== "undefined" &&
185
- __FUNDING_ELIGIBILITY__.satispay.eligible)
186
- ? getSatispayConfig()
187
- : null,
188
- [FUNDING.PAIDY]:
189
- !__TREE_SHAKE__ ||
190
- (typeof __FUNDING_ELIGIBILITY__.paidy !== "undefined" &&
191
- __FUNDING_ELIGIBILITY__.paidy.eligible)
192
- ? getPaidyConfig()
193
- : null,
38
+ [FUNDING.PAYPAL]: getPayPalConfig(),
39
+ [FUNDING.VENMO]: getVenmoConfig(),
40
+ [FUNDING.APPLEPAY]: getApplePayConfig(),
41
+ [FUNDING.ITAU]: getItauConfig(),
42
+ [FUNDING.CREDIT]: getCreditConfig(),
43
+ [FUNDING.PAYLATER]: getPaylaterConfig(),
44
+ [FUNDING.CARD]: getCardConfig(),
45
+ [FUNDING.IDEAL]: getIdealConfig(),
46
+ [FUNDING.SEPA]: getSepaConfig(),
47
+ [FUNDING.BANCONTACT]: getBancontactConfig(),
48
+ [FUNDING.GIROPAY]: getGiropayConfig(),
49
+ [FUNDING.SOFORT]: getSofortConfig(),
50
+ [FUNDING.EPS]: getEpsConfig(),
51
+ [FUNDING.MYBANK]: getMybankConfig(),
52
+ [FUNDING.P24]: getP24Config(),
53
+ [FUNDING.PAYU]: getPayuConfig(),
54
+ [FUNDING.BLIK]: getBlikConfig(),
55
+ [FUNDING.TRUSTLY]: getTrustlyConfig(),
56
+ [FUNDING.WECHATPAY]: getWechatpayConfig(),
57
+ [FUNDING.OXXO]: getOxxoConfig(),
58
+ [FUNDING.BOLETO]: getBoletoConfig(),
59
+ [FUNDING.BOLETOBANCARIO]: getBoletoConfig(),
60
+ [FUNDING.MERCADOPAGO]: getMercadopagoConfig(),
61
+ [FUNDING.MULTIBANCO]: getMultibancoConfig(),
62
+ [FUNDING.SATISPAY]: getSatispayConfig(),
63
+ [FUNDING.PAIDY]: getPaidyConfig(),
194
64
  };
195
65
  });
196
66
  }