@paypal/checkout-components 5.0.243 → 5.0.245

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.243",
3
+ "version": "5.0.245",
4
4
  "description": "PayPal Checkout components, for integrating checkout products.",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -12,7 +12,7 @@
12
12
  "debug": "cross-env NODE_ENV=debug",
13
13
  "delete-size": "rm dist/size.* dist/report.html",
14
14
  "demo": "serve ./demo -l 1337",
15
- "dev": "npm run check-node-version && babel-node $(npm bin)/webpack-dev-server --config webpack.config.dev.js --port 9001 --host localhost.paypal.com --open-page demo/dev/index.htm --https --hot=false --inline=false",
15
+ "dev": "npm run check-node-version && babel-node $(npm bin)/webpack-dev-server --config webpack.config.dev.js --port 9001 --host localhost.paypal.com --open demo/dev/index.htm --https --hot=false",
16
16
  "eslint-find-rules": "eslint-find-rules --current .eslintrc.js --unused --plugin",
17
17
  "flow": "flow",
18
18
  "flow-typed": "rm -rf flow-typed && flow-typed install && rm flow-typed/npm/puppeteer_*",
@@ -61,16 +61,19 @@
61
61
  "license": "Apache-2.0",
62
62
  "readmeFilename": "README.md",
63
63
  "devDependencies": {
64
- "@krakenjs/grumbler-scripts": "^7.0.0",
64
+ "@krakenjs/grumbler-scripts": "^8.0.7",
65
65
  "@krakenjs/sync-browser-mocks": "^3.0.0",
66
66
  "babel-core": "^7.0.0-bridge.0",
67
67
  "bundlemon": "^1.1.0",
68
68
  "conventional-changelog-cli": "^2.0.34",
69
+ "cross-env": "^7.0.3",
69
70
  "flow-bin": "0.155.0",
71
+ "flow-typed": "^3.8.0",
70
72
  "fs-extra": "^10.0.0",
71
73
  "husky": "^7.0.4",
72
74
  "imagemagick": "^0.1.3",
73
75
  "imgur": "^0.3.1",
76
+ "jest": "^29.3.1",
74
77
  "karma": "^6.0.0",
75
78
  "karma-coverage": "^2.0.3",
76
79
  "lint-staged": "^12.3.4",
@@ -1,16 +1,17 @@
1
1
  /* @flow */
2
2
 
3
3
  export const ATTRIBUTE = {
4
- BUTTON: ('data-button' : 'data-button'),
5
- FUNDING_SOURCE: ('data-funding-source' : 'data-funding-source'),
6
- PAYMENT_METHOD_ID: ('data-payment-method-id' : 'data-payment-method-id'),
7
- INSTRUMENT_ID: ('data-instrument-id' : 'data-instrument-id'),
8
- INSTRUMENT_TYPE: ('data-instrument-type' : 'data-instrument-type'),
9
- VERSION: ('data-paypal-smart-button-version' : 'data-paypal-smart-button-version'),
10
- CARD: ('data-card' : 'data-card'),
11
- MENU: ('data-menu' : 'data-menu'),
12
- OPTIONAL: ('optional' : 'optional'),
13
- PAY_NOW: ('data-pay-now' : 'data-pay-now')
4
+ BUTTON: ('data-button' : 'data-button'),
5
+ FUNDING_SOURCE: ('data-funding-source' : 'data-funding-source'),
6
+ PAYMENT_METHOD_ID: ('data-payment-method-id' : 'data-payment-method-id'),
7
+ INSTRUMENT_ID: ('data-instrument-id' : 'data-instrument-id'),
8
+ INSTRUMENT_TYPE: ('data-instrument-type' : 'data-instrument-type'),
9
+ SECONDARY_INSTRUMENT_TYPE: ('data-secondary-instrument-type' : 'data-secondary-instrument-type'),
10
+ VERSION: ('data-paypal-smart-button-version' : 'data-paypal-smart-button-version'),
11
+ CARD: ('data-card' : 'data-card'),
12
+ MENU: ('data-menu' : 'data-menu'),
13
+ OPTIONAL: ('optional' : 'optional'),
14
+ PAY_NOW: ('data-pay-now' : 'data-pay-now')
14
15
  };
15
16
 
16
17
  export const DEFAULT = ('default' : 'default');
@@ -16,7 +16,7 @@ declare var __PAYPAL_CHECKOUT__ : {|
16
16
  __MODAL__ : string,
17
17
  __QRCODE__ : string,
18
18
  __WALLET__ : string,
19
- __PAYMENT_FIELDS__ : string
19
+ __PAYMENT_FIELDS__ : string,
20
20
  |}
21
21
  |};
22
22
 
@@ -24,3 +24,6 @@ declare var __INLINE_CHECKOUT_ELIGIBILITY__ : {|
24
24
  eligible : boolean,
25
25
  ineligibilityReason : string
26
26
  |};
27
+
28
+ declare var __WEB__: boolean;
29
+ declare var __TREE_SHAKE__: boolean;
@@ -170,10 +170,14 @@ export function getCardConfig() : FundingSourceConfig {
170
170
 
171
171
  WalletLabel,
172
172
 
173
- showWalletMenu: ({ instrument }) => {
173
+ showWalletMenu: ({ instrument, userIDToken }) => {
174
174
  if (instrument.branded) {
175
175
  return false;
176
176
  } else {
177
+ if (!instrument.tokenID?.match(/-/) && userIDToken) {
178
+ return false
179
+ }
180
+
177
181
  return true;
178
182
  }
179
183
  }
@@ -81,7 +81,8 @@ export type WalletLabelOptions = {|
81
81
  vault : boolean,
82
82
  nonce? : ?string,
83
83
  textColor : $Values<typeof TEXT_COLOR>,
84
- fundingSource : $Values<typeof FUNDING>
84
+ fundingSource : $Values<typeof FUNDING>,
85
+ showPayLabel : boolean
85
86
  |};
86
87
 
87
88
  export type TagOptions = {|
@@ -120,7 +121,7 @@ export type FundingSourceConfig = {|
120
121
  logoColors : { [$Values<typeof BUTTON_COLOR>] : $Values<typeof LOGO_COLOR> },
121
122
  shapes : $ReadOnlyArray<$Values<typeof BUTTON_SHAPE>>,
122
123
  labelText? : string | (({| content : ?ContentType, fundingEligibility : ?FundingEligibilityType |}) => string),
123
- showWalletMenu : ({| instrument : WalletInstrument |}) => boolean
124
+ showWalletMenu : ({| instrument : WalletInstrument, userIDToken : ?string |}) => boolean
124
125
  |};
125
126
 
126
127
  export function BasicLabel({ logo, label, period, locale: { lang } } : LabelOptions) : ChildType {
@@ -68,6 +68,24 @@
68
68
  margin-left: auto;
69
69
  }
70
70
 
71
+ .show-pay-label {
72
+ all: inherit;
73
+ }
74
+
75
+ .show-instruments-on-file {
76
+ margin: auto;
77
+ display: flex;
78
+ }
79
+
80
+ .fi-container {
81
+ display: flex;
82
+ }
83
+
84
+ .balance, .fi-logo, .fi-label {
85
+ display: flex;
86
+ align-items: center;
87
+ }
88
+
71
89
  @media only screen and (max-width: 150px) {
72
90
  text-align: center;
73
91
  display: inline-block;
@@ -234,8 +234,87 @@ export function WalletLabelOld(opts : WalletLabelOptions) : ?ChildType {
234
234
  );
235
235
  }
236
236
 
237
+ function ShowPayLabel(opts) : ?ChildType {
238
+ const {instrument, content, payNow, textColor, logo, label } = opts;
239
+
240
+ return (
241
+ <div class='show-pay-label'>
242
+ <div class='pay-label' optional={ 2 }>
243
+ <Space />
244
+ {
245
+ (instrument && content)
246
+ ? <Text>{ payNow ? content.payNow : content.payWith }</Text>
247
+ : <Text><PlaceHolder chars={ 7 } color={ textColor } /></Text>
248
+ }
249
+ <Space />
250
+ </div>
251
+ <div class='logo' optional={ 1 }>
252
+ {
253
+ (instrument && logo)
254
+ ? logo
255
+ : <Text><PlaceHolder chars={ 4 } color={ textColor } /></Text>
256
+ }
257
+ </div>
258
+ <div class='label'>
259
+ <Space />
260
+ {
261
+ (instrument && label)
262
+ ? <Text>{ label }</Text>
263
+ : <Text><PlaceHolder chars={ 6 } color={ textColor } /></Text>
264
+ }
265
+ </div>
266
+ </div>
267
+ );
268
+ }
269
+
270
+ function ShowInstrumentsOnFile(opts) : ?ChildType {
271
+ const { instrument, textColor, logo, label, content } = opts;
272
+
273
+ return (
274
+ <div class='show-instruments-on-file'>
275
+ {
276
+ instrument?.secondaryInstruments?.[0]
277
+ ? (
278
+ <div class='balance'>
279
+ <Text>{ content?.balance } &</Text>
280
+ <Space />
281
+ </div>
282
+ )
283
+ : null
284
+ }
285
+ {
286
+ (instrument?.type === "balance")
287
+ ? (
288
+ <div class='paypal-balance'>
289
+ <Text>{ content?.payPalBalance }</Text>
290
+ </div>
291
+ )
292
+ : (
293
+ <div class='fi-container'>
294
+ <div class='fi-logo' optional={ 1 }>
295
+ {
296
+ (instrument && logo)
297
+ ? logo
298
+ : <Text><PlaceHolder chars={ 4 } color={ textColor } /></Text>
299
+ }
300
+ </div>
301
+ <div class='fi-label'>
302
+ <Space />
303
+ {
304
+ (instrument && label)
305
+ ? <Text>{ label }</Text>
306
+ : <Text><PlaceHolder chars={ 6 } color={ textColor } /></Text>
307
+ }
308
+ </div>
309
+ </div>
310
+ )
311
+ }
312
+ </div>
313
+ );
314
+ }
315
+
237
316
  export function WalletLabel(opts : WalletLabelOptions) : ?ChildType {
238
- const { logoColor, instrument, content, commit, vault, textColor, fundingSource } = opts;
317
+ const { logoColor, instrument, content, commit, vault, textColor, fundingSource, showPayLabel } = opts;
239
318
 
240
319
  if (instrument && !instrument.type) {
241
320
  return WalletLabelOld(opts);
@@ -305,31 +384,24 @@ export function WalletLabel(opts : WalletLabelOptions) : ?ChildType {
305
384
  )
306
385
  : null
307
386
  }
308
-
309
- <div class='pay-label' optional={ 2 }>
310
- <Space />
311
- {
312
- (instrument && content)
313
- ? <Text>{ payNow ? content.payNow : content.payWith }</Text>
314
- : <Text><PlaceHolder chars={ 7 } color={ textColor } /></Text>
315
- }
316
- <Space />
317
- </div>
318
- <div class='logo' optional={ 1 }>
319
- {
320
- (instrument && logo)
321
- ? logo
322
- : <Text><PlaceHolder chars={ 4 } color={ textColor } /></Text>
323
- }
324
- </div>
325
- <div class='label'>
326
- <Space />
327
- {
328
- (instrument && label)
329
- ? <Text>{ label }</Text>
330
- : <Text><PlaceHolder chars={ 6 } color={ textColor } /></Text>
331
- }
332
- </div>
387
+ {
388
+ showPayLabel
389
+ ? <ShowPayLabel
390
+ instrument={ instrument }
391
+ content={ content }
392
+ payNow={ payNow }
393
+ textColor={ textColor }
394
+ logo={ logo }
395
+ label={ label }
396
+ />
397
+ : <ShowInstrumentsOnFile
398
+ instrument={ instrument }
399
+ textColor={ textColor }
400
+ logo={ logo }
401
+ label={ label }
402
+ content={ content }
403
+ />
404
+ }
333
405
  </div>
334
406
  </Style>
335
407
  );
package/src/types.js CHANGED
@@ -2,6 +2,12 @@
2
2
 
3
3
  import { CARD, WALLET_INSTRUMENT } from '@paypal/sdk-constants/src';
4
4
 
5
+ export type SecondaryInstruments = $ReadOnlyArray<{|
6
+ type : string,
7
+ label : string,
8
+ instrumentID : string
9
+ |}>;
10
+
5
11
  export type WalletInstrument = {|
6
12
  type? : $Values<typeof WALLET_INSTRUMENT>,
7
13
  label? : string,
@@ -10,7 +16,8 @@ export type WalletInstrument = {|
10
16
  tokenID? : string,
11
17
  vendor? : $Values<typeof CARD>,
12
18
  oneClick : boolean,
13
- branded : boolean
19
+ branded : boolean,
20
+ secondaryInstruments? : SecondaryInstruments
14
21
  |};
15
22
 
16
23
  export type WalletPaymentType = {|
@@ -38,7 +45,8 @@ export type ContentType = {|
38
45
  credit : string,
39
46
  payWith : string,
40
47
  payLater : string,
41
- flex : string
48
+ flex : string,
49
+ payPalBalance: string
42
50
  |};
43
51
 
44
52
  export type Experiment = {|
@@ -41,11 +41,12 @@ type IndividualButtonProps = {|
41
41
  vault : boolean,
42
42
  merchantFundingSource : ?$Values<typeof FUNDING>,
43
43
  instrument : ?WalletInstrument,
44
- experience? : string
44
+ experience? : string,
45
+ showPayLabel : boolean
45
46
  |};
46
47
 
47
48
  export function Button({ fundingSource, style, multiple, locale, env, fundingEligibility, i, nonce, flow, vault,
48
- userIDToken, personalization, onClick = noop, content, tagline, commit, experiment, instrument, experience } : IndividualButtonProps) : ElementNode {
49
+ userIDToken, personalization, onClick = noop, content, tagline, commit, experiment, instrument, experience, showPayLabel } : IndividualButtonProps) : ElementNode {
49
50
 
50
51
  const { custom, layout, shape } = style;
51
52
  const inlineExperience = experience === EXPERIENCE.INLINE && custom && custom.label;
@@ -174,7 +175,7 @@ export function Button({ fundingSource, style, multiple, locale, env, fundingEli
174
175
 
175
176
  if (
176
177
  WalletLabel &&
177
- flow === BUTTON_FLOW.PURCHASE &&
178
+ (!showPayLabel || flow === BUTTON_FLOW.PURCHASE) &&
178
179
  (instrument || (__WEB__ && userIDToken && (fundingSource === FUNDING.PAYPAL || fundingSource === FUNDING.VENMO)))
179
180
  ) {
180
181
  labelNode = (
@@ -189,13 +190,14 @@ export function Button({ fundingSource, style, multiple, locale, env, fundingEli
189
190
  vault={ vault }
190
191
  textColor={ textColor }
191
192
  fundingSource={ fundingSource }
193
+ showPayLabel={ showPayLabel }
192
194
  />
193
195
  );
194
196
 
195
197
  isWallet = true;
196
198
  }
197
199
 
198
- const shouldShowWalletMenu = isWallet && instrument && showWalletMenu({ instrument });
200
+ const shouldShowWalletMenu = isWallet && instrument && showWalletMenu({ instrument, userIDToken });
199
201
 
200
202
  return (
201
203
  <div
@@ -218,11 +220,12 @@ export function Button({ fundingSource, style, multiple, locale, env, fundingEli
218
220
  <div
219
221
  role='link'
220
222
  { ...{
221
- [ ATTRIBUTE.BUTTON ]: true,
222
- [ ATTRIBUTE.FUNDING_SOURCE ]: fundingSource,
223
- [ ATTRIBUTE.PAYMENT_METHOD_ID ]: instrument ? instrument.tokenID : null,
224
- [ ATTRIBUTE.INSTRUMENT_ID ]: instrument ? instrument.instrumentID : null,
225
- [ ATTRIBUTE.INSTRUMENT_TYPE ]: instrument ? instrument.type : null
223
+ [ ATTRIBUTE.BUTTON ]: true,
224
+ [ ATTRIBUTE.FUNDING_SOURCE ]: fundingSource,
225
+ [ ATTRIBUTE.PAYMENT_METHOD_ID ]: instrument ? instrument.tokenID : null,
226
+ [ ATTRIBUTE.INSTRUMENT_ID ]: instrument ? instrument.instrumentID : null,
227
+ [ ATTRIBUTE.INSTRUMENT_TYPE ]: instrument ? instrument.type : null,
228
+ [ ATTRIBUTE.SECONDARY_INSTRUMENT_TYPE ]: instrument?.secondaryInstruments ? instrument.secondaryInstruments[0].type : null
226
229
  } }
227
230
  class={ [
228
231
  CLASS.BUTTON,
@@ -104,7 +104,7 @@ export function Buttons(props : ButtonsProps) : ElementNode {
104
104
  const { onClick = noop } = props;
105
105
  const { wallet, fundingSource, style, locale, remembered, env, fundingEligibility, platform, commit, vault,
106
106
  nonce, components, onShippingChange, onShippingAddressChange, onShippingOptionsChange, personalization, userIDToken, content, flow, experiment, applePaySupport,
107
- supportsPopups, supportedNativeBrowser, experience } = normalizeButtonProps(props);
107
+ supportsPopups, supportedNativeBrowser, experience, showPayLabel } = normalizeButtonProps(props);
108
108
  const { custom, layout, shape, tagline } = style;
109
109
 
110
110
  const inlineExperience = experience === EXPERIENCE.INLINE && custom && custom.label && custom.label.length !== 0;
@@ -192,6 +192,7 @@ export function Buttons(props : ButtonsProps) : ElementNode {
192
192
  vault={ vault }
193
193
  instrument={ instruments[source] }
194
194
  experience={ experience }
195
+ showPayLabel={ showPayLabel }
195
196
  />
196
197
  ))
197
198
  }
@@ -1,4 +1,4 @@
1
- /* eslint-disable max-lines, eslint-comments/disable-enable-pair */
1
+ /* eslint-disable eslint-comments/disable-enable-pair */
2
2
  /* @flow */
3
3
 
4
4
  import { ZalgoPromise } from '@krakenjs/zalgo-promise/src';
@@ -393,7 +393,8 @@ export type RenderButtonProps = {|
393
393
  applePaySupport : boolean,
394
394
  supportsPopups : boolean,
395
395
  supportedNativeBrowser : boolean,
396
- experience : string
396
+ experience : string,
397
+ showPayLabel : boolean
397
398
  |};
398
399
 
399
400
  export type PrerenderDetails = {|
@@ -489,7 +490,8 @@ export type ButtonPropsInputs = {
489
490
  applePaySupport : boolean,
490
491
  supportsPopups : boolean,
491
492
  supportedNativeBrowser : boolean,
492
- experience : string
493
+ experience : string,
494
+ showPayLabel : boolean
493
495
  };
494
496
 
495
497
  export const DEFAULT_STYLE = {
@@ -659,7 +661,8 @@ export function normalizeButtonProps(props : ?ButtonPropsInputs) : RenderButtonP
659
661
  applePaySupport = false,
660
662
  supportsPopups = false,
661
663
  supportedNativeBrowser = false,
662
- experience = ''
664
+ experience = '',
665
+ showPayLabel = true
663
666
  } = props;
664
667
 
665
668
  const { country, lang } = locale;
@@ -702,5 +705,5 @@ export function normalizeButtonProps(props : ?ButtonPropsInputs) : RenderButtonP
702
705
 
703
706
  return { clientID, fundingSource, style, locale, remembered, env, fundingEligibility, platform, clientAccessToken,
704
707
  buttonSessionID, commit, sessionID, nonce, components, onShippingChange, onShippingAddressChange, onShippingOptionsChange, personalization, content, wallet, flow,
705
- experiment, vault, userIDToken, applePay, applePaySupport, supportsPopups, supportedNativeBrowser, experience };
708
+ experiment, vault, userIDToken, applePay, applePaySupport, supportsPopups, supportedNativeBrowser, experience, showPayLabel };
706
709
  }
@@ -225,6 +225,12 @@ export function getCheckoutComponent() : CheckoutComponent {
225
225
  sameDomain: true
226
226
  },
227
227
 
228
+ onSmartWalletEligible: {
229
+ type: 'function',
230
+ required: false,
231
+ sameDomain: true
232
+ },
233
+
228
234
  accessToken: {
229
235
  type: 'string',
230
236
  required: false