@paypal/checkout-components 5.0.295 → 5.0.296

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.295",
3
+ "version": "5.0.296",
4
4
  "description": "PayPal Checkout components, for integrating checkout products.",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -28,7 +28,7 @@
28
28
  "reinstall": "rimraf flow-typed && rimraf node_modules && npm install && flow-typed install",
29
29
  "release": "./scripts/publish.sh",
30
30
  "start": "npm run webpack -- --progress --watch",
31
- "test": "npm run format:check && npm run test:unit && npm run jest-ssr && npm run karma && npm run jest-screenshot",
31
+ "test": "npm run format:check && npm run test:unit && npm run jest-ssr && npm run karma",
32
32
  "test:unit": "vitest run",
33
33
  "percy-screenshot": "npx playwright install && babel-node ./test/percy/server/createButtonConfigs.js && percy exec -- playwright test --config=./test/percy/playwright.config.js --reporter=dot --pass-with-no-tests",
34
34
  "typecheck": "npm run flow-typed && npm run flow",
@@ -150,11 +150,18 @@ export function getShopperInsightsComponent(): ShopperInsightsComponent {
150
150
  false;
151
151
  const isVenmoRecommended =
152
152
  (venmo?.eligible_in_paypal_network && venmo?.recommended) || false;
153
+ const fptiRecommendedPaymentPayload = {
154
+ paypal: isPayPalRecommended ? "1" : "0",
155
+ venmo: isVenmoRecommended ? "1" : "0",
156
+ };
153
157
 
154
158
  getLogger().track({
155
159
  [FPTI_KEY.TRANSITION]: FPTI_TRANSITION.SHOPPER_INSIGHTS_API_SUCCESS,
156
160
  [FPTI_KEY.EVENT_NAME]: FPTI_TRANSITION.SHOPPER_INSIGHTS_API_SUCCESS,
157
161
  [FPTI_KEY.RESPONSE_DURATION]: (Date.now() - startTime).toString(),
162
+ [FPTI_KEY.RECOMMENDED_PAYMENT]: JSON.stringify(
163
+ fptiRecommendedPaymentPayload
164
+ ),
158
165
  });
159
166
 
160
167
  sendCountMetric({
@@ -34,7 +34,7 @@ export type ButtonVariables = $ReadOnlyArray<{|
34
34
 
35
35
  export type CreateOrder = (data: {|
36
36
  paymentSource: string,
37
- |}) => ZalgoPromise<string>;
37
+ |}) => ZalgoPromise<string | void>;
38
38
 
39
39
  export type OnApprove = (data: {|
40
40
  orderID: string,
@@ -1,14 +1,11 @@
1
1
  /* @flow */
2
2
 
3
- import { request, memoize, popup, supportsPopups } from "@krakenjs/belter/src";
3
+ import { request, memoize } from "@krakenjs/belter/src";
4
4
  import {
5
5
  getSDKHost,
6
6
  getClientID,
7
7
  getMerchantID as getSDKMerchantID,
8
8
  } from "@paypal/sdk-client/src";
9
- import { FUNDING } from "@paypal/sdk-constants/src";
10
-
11
- import { DEFAULT_POPUP_SIZE } from "../zoid/checkout";
12
9
 
13
10
  import type {
14
11
  ButtonVariables,
@@ -115,6 +112,7 @@ export const buildHostedButtonCreateOrder = ({
115
112
  return (data) => {
116
113
  const userInputs =
117
114
  window[`__pp_form_fields_${hostedButtonId}`]?.getUserInputs?.() || {};
115
+ const onError = window[`__pp_form_fields_${hostedButtonId}`]?.onError;
118
116
  return createAccessToken(getClientID()).then((accessToken) => {
119
117
  return request({
120
118
  url: `${apiUrl}/v1/checkout/links/${hostedButtonId}/create-context`,
@@ -126,9 +124,9 @@ export const buildHostedButtonCreateOrder = ({
126
124
  merchant_id: merchantId,
127
125
  ...userInputs,
128
126
  }),
129
- }).then(({ body }) => {
130
- return body.context_id;
131
- });
127
+ })
128
+ .then(({ body }) => body.context_id || onError(body.name))
129
+ .catch(() => onError("REQUEST_FAILED"));
132
130
  });
133
131
  };
134
132
  };
@@ -148,22 +146,6 @@ export const buildHostedButtonOnApprove = ({
148
146
  merchant_id: merchantId,
149
147
  context_id: data.orderID,
150
148
  }),
151
- }).then((response) => {
152
- // The "Debit or Credit Card" button does not open a popup
153
- // so we need to open a new popup for buyers who complete
154
- // a checkout via "Debit or Credit Card".
155
- if (data.paymentSource === FUNDING.CARD) {
156
- const url = `${baseUrl}/ncp/payment/${hostedButtonId}/${data.orderID}`;
157
- if (supportsPopups()) {
158
- popup(url, {
159
- width: DEFAULT_POPUP_SIZE.WIDTH,
160
- height: DEFAULT_POPUP_SIZE.HEIGHT,
161
- });
162
- } else {
163
- window.location = url;
164
- }
165
- }
166
- return response;
167
149
  });
168
150
  });
169
151
  };
@@ -1,7 +1,7 @@
1
1
  /* @flow */
2
2
 
3
3
  import { test, expect, vi } from "vitest";
4
- import { request, popup, supportsPopups } from "@krakenjs/belter/src";
4
+ import { request } from "@krakenjs/belter/src";
5
5
  import { ZalgoPromise } from "@krakenjs/zalgo-promise/src";
6
6
 
7
7
  import {
@@ -14,8 +14,6 @@ vi.mock("@krakenjs/belter/src", async () => {
14
14
  return {
15
15
  ...(await vi.importActual("@krakenjs/belter/src")),
16
16
  request: vi.fn(),
17
- popup: vi.fn(),
18
- supportsPopups: vi.fn(),
19
17
  };
20
18
  });
21
19
 
@@ -101,6 +99,31 @@ test("buildHostedButtonCreateOrder", async () => {
101
99
  expect.assertions(1);
102
100
  });
103
101
 
102
+ test("buildHostedButtonCreateOrder error handling", async () => {
103
+ const createOrder = buildHostedButtonCreateOrder({
104
+ hostedButtonId,
105
+ merchantId,
106
+ });
107
+
108
+ // $FlowIssue
109
+ request.mockImplementation(() =>
110
+ ZalgoPromise.resolve({
111
+ body: {
112
+ name: "RESOURCE_NOT_FOUND",
113
+ },
114
+ })
115
+ );
116
+
117
+ const onError = vi.fn();
118
+ window[`__pp_form_fields_${hostedButtonId}`] = {
119
+ onError,
120
+ };
121
+
122
+ await createOrder({ paymentSource: "paypal" });
123
+ expect(onError).toHaveBeenCalledWith("RESOURCE_NOT_FOUND");
124
+ expect.assertions(1);
125
+ });
126
+
104
127
  describe("buildHostedButtonOnApprove", () => {
105
128
  test("makes a request to the Hosted Buttons API", async () => {
106
129
  const onApprove = buildHostedButtonOnApprove({
@@ -126,32 +149,4 @@ describe("buildHostedButtonOnApprove", () => {
126
149
  );
127
150
  expect.assertions(1);
128
151
  });
129
-
130
- test("provides its own popup for inline guest", async () => {
131
- const onApprove = buildHostedButtonOnApprove({
132
- hostedButtonId,
133
- merchantId,
134
- });
135
- // $FlowIssue
136
- request.mockImplementation(() =>
137
- ZalgoPromise.resolve({
138
- body: {},
139
- })
140
- );
141
-
142
- // $FlowIssue
143
- supportsPopups.mockImplementation(() => true);
144
- await onApprove({ orderID, paymentSource: "card" });
145
- expect(popup).toHaveBeenCalled();
146
-
147
- // but redirects if popups are not supported
148
- // $FlowIssue
149
- supportsPopups.mockImplementation(() => false);
150
- await onApprove({ orderID, paymentSource: "card" });
151
- expect(window.location).toMatch(
152
- `/ncp/payment/${hostedButtonId}/${orderID}`
153
- );
154
-
155
- expect.assertions(2);
156
- });
157
152
  });
@@ -78,7 +78,7 @@ export function MarksElement({
78
78
  <style>
79
79
  {`
80
80
  .${CLASS.TEXT} {
81
- font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
81
+ font-family: PayPalOpen-Regular, Helvetica, Arial, "Liberation Sans", sans-serif;
82
82
  font-size: 12px;
83
83
  vertical-align: middle;
84
84
  }
@@ -192,7 +192,7 @@ export function DivideLogoTextComponent({
192
192
  position: absolute;
193
193
  opacity: 0;
194
194
  color: #142C8E;
195
- font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
195
+ font-family: PayPalOpen-Regular, Helvetica, Arial, "Liberation Sans", sans-serif;
196
196
  font-size: 14px;
197
197
  }
198
198
 
@@ -131,7 +131,7 @@ export function InlineLogoTextComponent({
131
131
  position: absolute;
132
132
  opacity: 0;
133
133
  color: #142C8E;
134
- font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
134
+ font-family: PayPalOpen-Regular, Helvetica, Arial, "Liberation Sans", sans-serif;
135
135
  font-size: 14px;
136
136
  }
137
137
 
@@ -15,7 +15,7 @@ const POWERED_BY_PAYPAL_STYLE = `
15
15
  text-align: center;
16
16
  margin: 10px auto;
17
17
  height: 14px;
18
- font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
18
+ font-family: PayPalOpen-Regular, Helvetica, Arial, "Liberation Sans", sans-serif;
19
19
  font-size: 11px;
20
20
  font-weight: normal;
21
21
  font-style: italic;
@@ -15,7 +15,7 @@ export const buttonStyle = `
15
15
  margin: 0;
16
16
  background: 0;
17
17
  border: 0;
18
- font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
18
+ font-family: PayPalOpen-Regular, Helvetica, Arial, "Liberation Sans", sans-serif;
19
19
  text-transform: none;
20
20
  font-weight: 500;
21
21
  font-smoothing: antialiased;
@@ -42,7 +42,6 @@ export const buttonStyle = `
42
42
  }
43
43
 
44
44
  .${CLASS.CONTAINER}.${CLASS.ENV}-${ENV.TEST} .${CLASS.TEXT} {
45
- font-family: Arial !important;
46
45
  background: rgba(0, 0, 0, 0.5) !important;
47
46
  color: transparent !important;
48
47
  text-shadow: none !important;
@@ -4,6 +4,7 @@ import { CLASS } from "../../../constants";
4
4
 
5
5
  export const pageStyle = `
6
6
  html, body {
7
+ font-family: PayPalOpen-Regular, Helvetica, Arial, "Liberation Sans", sans-serif;
7
8
  padding: 0;
8
9
  margin: 0;
9
10
  width: 100%;
@@ -38,6 +38,7 @@ import {
38
38
  getVersion,
39
39
  getDisableSetCookie,
40
40
  getExperimentation,
41
+ getSDKAttribute,
41
42
  } from "@paypal/sdk-client/src";
42
43
  import {
43
44
  rememberFunding,
@@ -60,6 +61,7 @@ import {
60
61
  QUERY_BOOL,
61
62
  ENV,
62
63
  FPTI_KEY,
64
+ SDK_SETTINGS,
63
65
  } from "@paypal/sdk-constants/src";
64
66
  import { node, dom } from "@krakenjs/jsx-pragmatic/src";
65
67
 
@@ -860,6 +862,13 @@ export const getButtonsComponent: () => ButtonsComponent = memoize(() => {
860
862
  queryParam: true,
861
863
  },
862
864
 
865
+ pageType: {
866
+ type: "string",
867
+ required: false,
868
+ queryParam: true,
869
+ value: () => getSDKAttribute(SDK_SETTINGS.PAGE_TYPE),
870
+ },
871
+
863
872
  displayOnly: {
864
873
  type: "array",
865
874
  queryParam: true,