@paypal/checkout-components 5.0.302-alpha.0 → 5.0.303-alpha.0

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.302-alpha.0",
3
+ "version": "5.0.303-alpha.0",
4
4
  "description": "PayPal Checkout components, for integrating checkout products.",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -110,8 +110,8 @@
110
110
  "@krakenjs/post-robot": "^11.0.0",
111
111
  "@krakenjs/zalgo-promise": "^2.0.0",
112
112
  "@krakenjs/zoid": "^10.3.1",
113
- "@paypal/accelerated-checkout-loader": "^1.0.0",
114
113
  "@paypal/common-components": "^1.0.35",
114
+ "@paypal/connect-loader-component": "1.1.1",
115
115
  "@paypal/funding-components": "^1.0.31",
116
116
  "@paypal/sdk-client": "^4.0.181",
117
117
  "@paypal/sdk-constants": "^1.0.141",
@@ -1,5 +1,5 @@
1
1
  /* @flow */
2
- import { loadAxo } from "@paypal/accelerated-checkout-loader/dist/loader.esm";
2
+ import { loadAxo } from "@paypal/connect-loader-component";
3
3
  import { stringifyError } from "@krakenjs/belter/src";
4
4
  import {
5
5
  getClientID,
@@ -1,8 +1,7 @@
1
1
  /* @flow */
2
2
 
3
3
  import { getUserIDToken, getSDKToken } from "@paypal/sdk-client/src";
4
- // eslint-disable-next-line import/no-namespace
5
- import * as axo from "@paypal/accelerated-checkout-loader/dist/loader.esm";
4
+ import { loadAxo } from "@paypal/connect-loader-component";
6
5
  import { describe, expect, test, vi } from "vitest";
7
6
 
8
7
  import {
@@ -31,6 +30,12 @@ vi.mock("@paypal/sdk-client/src", () => {
31
30
  };
32
31
  });
33
32
 
33
+ vi.mock("@paypal/connect-loader-component", () => {
34
+ return {
35
+ loadAxo: vi.fn(),
36
+ };
37
+ });
38
+
34
39
  describe("getConnectComponent: returns ConnectComponent", () => {
35
40
  const mockAxoMetadata = { someData: "data" };
36
41
  const mockProps = { someProp: "value" };
@@ -43,7 +48,7 @@ describe("getConnectComponent: returns ConnectComponent", () => {
43
48
  },
44
49
  };
45
50
 
46
- vi.spyOn(axo, "loadAxo").mockResolvedValue({ metadata: mockAxoMetadata });
51
+ loadAxo.mockResolvedValue({ metadata: mockAxoMetadata });
47
52
  });
48
53
 
49
54
  test("uses user id token if no sdk token is present", async () => {
@@ -92,7 +97,7 @@ describe("getConnectComponent: returns ConnectComponent", () => {
92
97
 
93
98
  test("loadAxo failure is handled", async () => {
94
99
  const errorMessage = "Something went wrong";
95
- axo.loadAxo.mockRejectedValue(errorMessage);
100
+ loadAxo.mockRejectedValue(errorMessage);
96
101
 
97
102
  await expect(() => getConnectComponent(mockProps)).rejects.toThrow(
98
103
  errorMessage
@@ -110,7 +115,7 @@ describe("getConnectComponent: returns ConnectComponent", () => {
110
115
 
111
116
  test("minified is set according to debug value", async () => {
112
117
  await getConnectComponent(mockProps);
113
- expect(axo.loadAxo).toHaveBeenCalledWith({
118
+ expect(loadAxo).toHaveBeenCalledWith({
114
119
  minified: true,
115
120
  btSdkVersion: "3.97.3-connect-alpha.6.1",
116
121
  metadata: undefined,
@@ -7,6 +7,7 @@ import {
7
7
  getClientID,
8
8
  getMerchantID as getSDKMerchantID,
9
9
  } from "@paypal/sdk-client/src";
10
+ import { FUNDING } from "@paypal/sdk-constants/src";
10
11
 
11
12
  import type {
12
13
  ButtonVariables,
@@ -208,6 +209,14 @@ export const buildHostedButtonOnApprove = ({
208
209
  merchant_id: merchantId,
209
210
  context_id: data.orderID,
210
211
  }),
212
+ }).then((response) => {
213
+ // The "Debit or Credit Card" button does not open a popup
214
+ // so we need to redirect to the thank you page for buyers who complete
215
+ // a checkout via "Debit or Credit Card".
216
+ if (data.paymentSource === FUNDING.CARD) {
217
+ window.location = `${baseUrl}/ncp/payment/${hostedButtonId}/${data.orderID}`;
218
+ }
219
+ return response;
211
220
  });
212
221
  };
213
222
  };
@@ -264,6 +264,28 @@ describe("buildHostedButtonOnApprove", () => {
264
264
  );
265
265
  expect.assertions(1);
266
266
  });
267
+
268
+ describe("inline guest", () => {
269
+ const onApprove = buildHostedButtonOnApprove({
270
+ hostedButtonId,
271
+ merchantId,
272
+ });
273
+ // $FlowIssue
274
+ request.mockImplementation(() =>
275
+ // eslint-disable-next-line compat/compat
276
+ Promise.resolve({
277
+ body: {},
278
+ })
279
+ );
280
+
281
+ test("redirects from the merchant's site to a thank you page", async () => {
282
+ expect(window.location.href).toBe("http://localhost:3000/");
283
+ await onApprove({ orderID, paymentSource: "card" });
284
+ expect(window.location).toBe(
285
+ "https://example.com/ncp/payment/B1234567890/EC-1234567890"
286
+ );
287
+ });
288
+ });
267
289
  });
268
290
 
269
291
  /* eslint-enable no-restricted-globals, promise/no-native */
@@ -7,6 +7,7 @@ import {
7
7
  getCardFormComponent,
8
8
  type CardFormComponent,
9
9
  } from "../zoid/card-form";
10
+ import { getQRCodeComponent, type QRCodeComponent } from "../zoid/qr-code";
10
11
  import { getCheckoutComponent, type CheckoutComponent } from "../zoid/checkout";
11
12
  import type { LazyExport, LazyProtectedExport } from "../types";
12
13
  import { protectedExport } from "../lib";
@@ -23,6 +24,10 @@ export const CardForm: LazyProtectedExport<CardFormComponent> = {
23
24
  __get__: () => protectedExport(getCardFormComponent()),
24
25
  };
25
26
 
27
+ export const QRCode: LazyProtectedExport<QRCodeComponent> = {
28
+ __get__: () => protectedExport(getQRCodeComponent()),
29
+ };
30
+
26
31
  export function setup() {
27
32
  getButtonsComponent();
28
33
  getCheckoutComponent();