@paypal/checkout-components 5.0.208 → 5.0.209

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,10 +1,10 @@
1
1
  {
2
2
  "name": "@paypal/checkout-components",
3
- "version": "5.0.208",
3
+ "version": "5.0.209",
4
4
  "description": "PayPal Checkout components, for integrating checkout products.",
5
5
  "main": "index.js",
6
6
  "engines": {
7
- "node": ">=14.13.1",
7
+ "node": ">=14.13.1 <16",
8
8
  "npm": ">=6"
9
9
  },
10
10
  "scripts": {
@@ -62,13 +62,13 @@
62
62
  "license": "Apache-2.0",
63
63
  "readmeFilename": "README.md",
64
64
  "devDependencies": {
65
+ "@krakenjs/grumbler-scripts": "^6.0.2",
65
66
  "@krakenjs/sync-browser-mocks": "^3.0.0",
66
67
  "babel-core": "^7.0.0-bridge.0",
67
68
  "bundlemon": "^1.1.0",
68
69
  "conventional-changelog-cli": "^2.0.34",
69
70
  "flow-bin": "0.155.0",
70
71
  "fs-extra": "^10.0.0",
71
- "grumbler-scripts": "^5.0.1",
72
72
  "husky": "^7.0.4",
73
73
  "imagemagick": "^0.1.3",
74
74
  "imgur": "^0.3.1",
@@ -81,7 +81,7 @@
81
81
  "pixelmatch": "^5.2.1",
82
82
  "pngjs": "^6.0.0",
83
83
  "prettier": "^2.5.1",
84
- "prettier-plugin-sh": "^0.8.1",
84
+ "prettier-plugin-sh": "^0.10.0",
85
85
  "puppeteer": "^1.20.0",
86
86
  "serve": "^13.0.0"
87
87
  },
@@ -19,3 +19,8 @@ declare var __PAYPAL_CHECKOUT__ : {|
19
19
  __PAYMENT_FIELDS__ : string
20
20
  |}
21
21
  |};
22
+
23
+ declare var __INLINE_CHECKOUT_ELIGIBILITY__ : {|
24
+ eligible : boolean,
25
+ ineligibilityReason : string
26
+ |};
package/src/types.js CHANGED
@@ -67,3 +67,8 @@ export type LazyExport<T> = {|
67
67
  export type LazyProtectedExport<T> = {|
68
68
  __get__ : () => ?T
69
69
  |};
70
+
71
+ export type InlineXOEligibilityType = {|
72
+ eligible : boolean,
73
+ ineligibilityReason : string
74
+ |};
@@ -44,8 +44,9 @@ type IndividualButtonProps = {|
44
44
 
45
45
  export function Button({ fundingSource, style, multiple, locale, env, fundingEligibility, i, nonce, flow, vault,
46
46
  userIDToken, personalization, onClick = noop, content, tagline, commit, experiment, instrument, experience } : IndividualButtonProps) : ElementNode {
47
-
48
- const inlineExperience = experience === EXPERIENCE.INLINE;
47
+
48
+ const { custom, layout, shape } = style;
49
+ const inlineExperience = experience === EXPERIENCE.INLINE && custom;
49
50
  const fundingConfig = getFundingConfig()[fundingSource];
50
51
 
51
52
  if (!fundingConfig) {
@@ -95,8 +96,6 @@ export function Button({ fundingSource, style, multiple, locale, env, fundingEli
95
96
  preventClickFocus(el);
96
97
  }
97
98
  };
98
-
99
- const { custom, layout, shape } = style;
100
99
 
101
100
  const labelText = typeof fundingConfig.labelText === 'function' ? fundingConfig.labelText({ content, fundingEligibility }) : (fundingConfig.labelText || fundingSource);
102
101
 
@@ -101,8 +101,8 @@ export function Buttons(props : ButtonsProps) : ElementNode {
101
101
  const { wallet, fundingSource, style, locale, remembered, env, fundingEligibility, platform, commit, vault,
102
102
  nonce, components, onShippingChange, personalization, userIDToken, content, flow, experiment, applePaySupport,
103
103
  supportsPopups, supportedNativeBrowser, experience } = normalizeButtonProps(props);
104
- const { layout, shape, tagline } = style;
105
- const inlineExperience = experience === EXPERIENCE.INLINE;
104
+ const { custom, layout, shape, tagline } = style;
105
+ const inlineExperience = experience === EXPERIENCE.INLINE && custom;
106
106
 
107
107
  let fundingSources = determineEligibleFunding({ fundingSource, layout, remembered, platform, fundingEligibility, components, onShippingChange, flow, wallet, applePaySupport, supportsPopups, supportedNativeBrowser, experiment });
108
108
  const multiple = fundingSources.length > 1;
@@ -184,18 +184,15 @@ export type Personalization = {|
184
184
  |}
185
185
  |};
186
186
 
187
- export type ApplePayErrorCode = 'shippingContactInvalid' | 'billingContactInvalid' | 'addressUnserviceable' | 'unknown';
188
- export type ApplePayContactField = 'phoneNumber' | 'emailAddress' | 'givenName' | 'familyName' | 'phoneticGivenName' | 'phoneticFamilyName' | 'addressLines' | 'subLocality' | 'locality' | 'postalCode' | 'subAdministrativeArea' | 'administrativeArea' | 'country' | 'countryCode';
189
-
187
+ // https://developer.apple.com/documentation/apple_pay_on_the_web/applepayerror/2970147-applepayerror
190
188
  export type ApplePayError = {|
191
- code : ApplePayErrorCode,
192
- contactField : ApplePayContactField,
193
- message : string
189
+ code : string, // https://developer.apple.com/documentation/apple_pay_on_the_web/applepayerrorcode
190
+ contactField : string, // https://developer.apple.com/documentation/apple_pay_on_the_web/applepayerrorcontactfield
191
+ message : string // custom error message
194
192
  |};
195
193
 
196
- export type ApplePayLineItemType = 'final' | 'pending';
197
194
  export type ApplePayLineItem = {|
198
- type? : ApplePayLineItemType,
195
+ type? : string, // 'final' | 'pending'
199
196
  label? : string,
200
197
  amount? : string
201
198
  |};
@@ -208,7 +205,7 @@ export type ApplePayShippingMethod = {|
208
205
  |};
209
206
 
210
207
  export type ApplePayShippingContactUpdate = {|
211
- errors? : $ReadOnlyArray<ApplePayErrorCode>,
208
+ errors? : $ReadOnlyArray<ApplePayError>,
212
209
  newShippingMethods? : $ReadOnlyArray<ApplePayShippingMethod>,
213
210
  newTotal : ApplePayLineItem,
214
211
  newLineItems? : $ReadOnlyArray<ApplePayLineItem>
@@ -288,6 +285,8 @@ export type ButtonProps = {|
288
285
  createOrder : CreateOrder,
289
286
  createBillingAgreement : CreateBillingAgreement,
290
287
  createSubscription : CreateSubscription,
288
+ currency : string,
289
+ disableFunding? : $ReadOnlyArray<$Values<typeof FUNDING>>,
291
290
  oncancel : OnCancel,
292
291
  onApprove : OnApprove,
293
292
  onComplete : OnComplete,
@@ -309,6 +308,7 @@ export type ButtonProps = {|
309
308
  onShippingChange : ?OnShippingChange,
310
309
  clientAccessToken? : ?string,
311
310
  nonce : string,
311
+ merchantID? : $ReadOnlyArray<string>,
312
312
  merchantRequestedPopupsDisabled : ?boolean,
313
313
  userIDToken : ?string,
314
314
  flow : $Values<typeof BUTTON_FLOW>,
@@ -17,11 +17,13 @@ import { getSessionID, storageState, sessionState } from '../../lib';
17
17
  import { normalizeButtonStyle, type ButtonProps } from '../../ui/buttons/props';
18
18
  import { isFundingEligible } from '../../funding';
19
19
  import { EXPERIENCE } from '../../constants';
20
+ import { type InlineXOEligibilityType } from '../../types';
20
21
 
21
22
  import { containerTemplate } from './container';
22
23
  import { PrerenderedButtons } from './prerender';
23
24
  import { applePaySession, determineFlow, isSupportedNativeBrowser, createVenmoExperiment,
24
- createNoPaylaterExperiment, getRenderedButtons, getButtonSize, getButtonExperiments } from './util';
25
+ createNoPaylaterExperiment, getRenderedButtons, getButtonSize, getButtonExperiments, isInlineXOEligible } from './util';
26
+
25
27
 
26
28
  export type ButtonsComponent = ZoidComponent<ButtonProps>;
27
29
 
@@ -608,10 +610,22 @@ export const getButtonsComponent : () => ButtonsComponent = memoize(() => {
608
610
  required: false,
609
611
  type: 'string',
610
612
  value: ({ props }) => {
611
- const { style: { custom }, fundingEligibility } = props;
612
- const isInlineXO = (custom && (custom.label || custom.css)) && fundingEligibility[FUNDING.CARD]?.eligible;
613
+ const { commit, createBillingAgreement, currency, disableFunding = [], fundingEligibility, locale, merchantID = [], style: { layout }, vault } = props || {};
613
614
 
614
- return isInlineXO ? EXPERIENCE.INLINE : '';
615
+ const inlineCheckoutEligibility : InlineXOEligibilityType = __INLINE_CHECKOUT_ELIGIBILITY__ || {
616
+ eligible: false
617
+ };
618
+ return inlineCheckoutEligibility && isInlineXOEligible({ props: {
619
+ commit,
620
+ createBillingAgreement,
621
+ currency,
622
+ disableFunding,
623
+ fundingEligibility,
624
+ layout,
625
+ locale,
626
+ merchantID,
627
+ vault
628
+ } }) ? EXPERIENCE.INLINE : '';
615
629
  }
616
630
  },
617
631
 
@@ -1,7 +1,7 @@
1
1
  /* @flow */
2
2
  import { supportsPopups as userAgentSupportsPopups, isAndroid, isChrome, isIos, isSafari, isSFVC, type Experiment, isDevice, isTablet, getElement, isLocalStorageEnabled } from '@krakenjs/belter/src';
3
- import { ENV, FUNDING } from '@paypal/sdk-constants/src';
4
- import { getEnableFunding, getDisableFunding, createExperiment, getFundingEligibility, getPlatform, getComponents, getEnv } from '@paypal/sdk-client/src';
3
+ import { COUNTRY, CURRENCY, ENV, FPTI_KEY, FUNDING, type LocaleType } from '@paypal/sdk-constants/src';
4
+ import { getEnableFunding, getDisableFunding, getLogger, createExperiment, getFundingEligibility, getPlatform, getComponents, getEnv, type FundingEligibilityType } from '@paypal/sdk-client/src';
5
5
  import { getRefinedFundingEligibility } from '@paypal/funding-components/src';
6
6
 
7
7
  import type { Experiment as EligibilityExperiment } from '../../types';
@@ -172,12 +172,10 @@ export function applePaySession() : ?ApplePaySessionConfigRequest {
172
172
  }
173
173
 
174
174
  const convertErrorsFromUpdate = (update) => {
175
- if (update.errors && update.errors.length) {
176
- // $FlowFixMe
177
- return update.errors.map(error => new window.ApplePayError(error.code, error.contactField, error.message));
178
- }
179
-
180
- return update;
175
+ return {
176
+ ...update,
177
+ errors: (update.errors || []).map(error => new window.ApplePayError(error.code, error.contactField, error.message))
178
+ };
181
179
  };
182
180
 
183
181
  return (version, request) => {
@@ -298,3 +296,40 @@ export function getButtonSize (props : ButtonProps, container : string | HTMLEle
298
296
  }
299
297
  }
300
298
  }
299
+
300
+ type InlineCheckoutEligibilityProps = {|
301
+ commit : boolean,
302
+ createBillingAgreement? : Function,
303
+ currency : string,
304
+ disableFunding : $ReadOnlyArray<$Values<typeof FUNDING>>,
305
+ fundingEligibility : FundingEligibilityType,
306
+ layout : $Values<typeof BUTTON_LAYOUT>,
307
+ locale : LocaleType,
308
+ merchantID? : $ReadOnlyArray<string>,
309
+ vault : boolean
310
+ |};
311
+
312
+ export function isInlineXOEligible({ props } : {| props : InlineCheckoutEligibilityProps |}) : boolean {
313
+ const { commit, currency, createBillingAgreement, disableFunding, fundingEligibility, layout, locale, merchantID, vault } = props;
314
+
315
+ const isEligible = (
316
+ locale.country === COUNTRY.US &&
317
+ commit === true &&
318
+ !createBillingAgreement &&
319
+ currency === CURRENCY.USD &&
320
+ (disableFunding?.indexOf(FUNDING.CARD) === -1) &&
321
+ (fundingEligibility?.card?.eligible || false) &&
322
+ layout === BUTTON_LAYOUT.VERTICAL &&
323
+ merchantID?.length === 0 &&
324
+ vault === false
325
+ );
326
+
327
+ getLogger()
328
+ .info('isInlineXOEligible props', { props: JSON.stringify(props) })
329
+ .info('isInlineXOEligible eligible', { eligible: String(isEligible) })
330
+ .track({
331
+ [ FPTI_KEY.TRANSITION ]: `inline_xo_eligibility_${ String(isEligible) }`
332
+ }).flush();
333
+
334
+ return isEligible;
335
+ }