@paypal/checkout-components 5.0.285 → 5.0.286-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/__sdk__.js CHANGED
@@ -62,6 +62,10 @@ module.exports = {
62
62
  entry: "./src/interface/wallet",
63
63
  globals,
64
64
  },
65
+ connect: {
66
+ entry: "./src/connect/interface",
67
+ globals
68
+ },
65
69
  // @deprecated - renamed to payment-fields to be removed
66
70
  fields: {
67
71
  entry: "./src/interface/fields",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@paypal/checkout-components",
3
- "version": "5.0.285",
3
+ "version": "5.0.286-alpha.0",
4
4
  "description": "PayPal Checkout components, for integrating checkout products.",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -109,6 +109,7 @@
109
109
  "@krakenjs/zoid": "^10.3.1",
110
110
  "@paypal/common-components": "^1.0.35",
111
111
  "@paypal/funding-components": "^1.0.31",
112
+ "@paypal/connect-loader-component": "^1.1.0",
112
113
  "@paypal/sdk-client": "^4.0.176",
113
114
  "@paypal/sdk-constants": "^1.0.133",
114
115
  "@paypal/sdk-logos": "^2.2.6"
@@ -0,0 +1,46 @@
1
+ /* @flow */
2
+ import { loadAxo } from "@paypal/connect-loader-component";
3
+ import {
4
+ getClientID,
5
+ getClientMetadataID,
6
+ getUserIDToken,
7
+ } from "@paypal/sdk-client/src";
8
+
9
+ // eslint-disable-next-line flowtype/no-weak-types
10
+ export type ConnectComponent = any;
11
+ // TODO: What's the expected structure/approach for this interface. It's not a zoid
12
+ // scenario, so what do we return?
13
+ // -> Looks like it returns a function that accepts the props
14
+ // How do we define the input of merchant params here?
15
+ // $FlowFixMe
16
+ export const getConnectComponent = async (merchantProps) => {
17
+ const cmid = getClientMetadataID();
18
+ const clientID = getClientID();
19
+ const userIdToken = getUserIDToken();
20
+ // TODO: Sort out integration specifics for inputs
21
+ try {
22
+ const loadResult = await loadAxo({
23
+ platform: "PPCP",
24
+ btSdkVersion: "3.97.3-connect-alpha.6.1",
25
+ minified: false,
26
+ });
27
+
28
+ // FPTI: sdkversion, fraudnet info
29
+ return await window.braintree.connect.create({
30
+ ...loadResult.metadata, // returns a localeURL for assets
31
+ ...merchantProps, // AXO specific props
32
+ platformOptions: {
33
+ platform: "PPCP",
34
+ userIdToken, // <merchant-specified-via-data-user-id-token>
35
+ clientID, // <merchant-specified-to-SDK-on-query-param>
36
+ clientMetadataID: cmid, // <merchant-specified-via-data-client-metadata-id>
37
+ fraudnet: () => {
38
+ return "";
39
+ }, // Pattern TBD
40
+ },
41
+ });
42
+ } catch (error) {
43
+ // FPTI Log here
44
+ return new Error(error);
45
+ }
46
+ };
@@ -0,0 +1,74 @@
1
+ /* @flow */
2
+
3
+ import {
4
+ getClientID,
5
+ getClientMetadataID,
6
+ getUserIDToken,
7
+ } from "@paypal/sdk-client/src";
8
+ import { loadAxo } from "@paypal/connect-loader-component";
9
+ import { describe, expect, test, vi } from "vitest";
10
+
11
+ import { getConnectComponent } from "./component";
12
+
13
+ describe("getConnectComponent: returns ConnectComponent", () => {
14
+ const mockAxoMetadata = { someData: "data" };
15
+ const mockProps = { someProp: "value" };
16
+ beforeEach(() => {
17
+ window.braintree = {
18
+ connect: {
19
+ create: vi.fn(),
20
+ },
21
+ };
22
+
23
+ vi.mock("@paypal/sdk-client/src", () => {
24
+ return {
25
+ getClientID: vi.fn(() => "mock-client-id"),
26
+ getClientMetadataID: vi.fn(() => "mock-cmid"),
27
+ getUserIDToken: vi.fn(() => "mock-uid"),
28
+ };
29
+ });
30
+
31
+ vi.mock("@paypal/connect-loader-component", () => {
32
+ return {
33
+ loadAxo: vi.fn(),
34
+ };
35
+ });
36
+
37
+ loadAxo.mockResolvedValue({ metadata: mockAxoMetadata });
38
+
39
+ // getClientID.mockReturnValue("mock-client-id");
40
+ // getClientMetadataID.mockReturnValue("mock-cmid");
41
+ // getUserIDToken.mockReturnValue("mock-uid");
42
+ });
43
+
44
+ test("loadAxo and window.braintree.connect.create are called with proper data", async () => {
45
+ await getConnectComponent(mockProps);
46
+
47
+ expect(getClientID).toHaveBeenCalled();
48
+ expect(getClientMetadataID).toHaveBeenCalled();
49
+ expect(getUserIDToken).toHaveBeenCalled();
50
+ expect(loadAxo).toHaveBeenCalled();
51
+
52
+ expect(window.braintree.connect.create).toHaveBeenCalledWith({
53
+ ...mockAxoMetadata,
54
+ ...mockProps,
55
+ platformOptions: {
56
+ platform: "PPCP",
57
+ clientID: "mock-client-id",
58
+ clientMetadataID: "mock-cmid",
59
+ userIdToken: "mock-uid",
60
+ fraudnet: expect.any(Function),
61
+ },
62
+ });
63
+ });
64
+
65
+ test("loadAxo failure is handled", async () => {
66
+ const errorMessage = "Something went wrong";
67
+ loadAxo.mockRejectedValue(errorMessage);
68
+
69
+ const error = await getConnectComponent(mockProps);
70
+
71
+ expect(error).toBeInstanceOf(Error);
72
+ expect(error.message).toEqual(errorMessage);
73
+ });
74
+ });
@@ -0,0 +1,16 @@
1
+ /* eslint-disable flowtype/no-weak-types */
2
+ /* @flow */
3
+ // flow-disable
4
+
5
+ import { getConnectComponent, type ConnectComponent } from "./component";
6
+
7
+ type ConnectThing = (merchantProps: any) => ConnectComponent;
8
+ // $FlowFixMe
9
+ export const Connect: ConnectThing = async (
10
+ merchantProps: any
11
+ ): ConnectComponent => {
12
+ // $FlowFixMe
13
+ return await getConnectComponent(merchantProps);
14
+ };
15
+
16
+ /* eslint-enable flowtype/no-weak-types */
@@ -0,0 +1,19 @@
1
+ /* @flow */
2
+
3
+ import { describe, expect, vi } from "vitest";
4
+
5
+ import { getConnectComponent } from "./component";
6
+ import { Connect } from "./interface";
7
+
8
+ describe("interface.js", () => {
9
+ vi.mock("./component", () => {
10
+ return {
11
+ getConnectComponent: vi.fn(),
12
+ };
13
+ });
14
+ it("should call getConnectComponent with merchant props", async () => {
15
+ const merchantProps = { props: "someProps" };
16
+ await Connect(merchantProps);
17
+ expect(getConnectComponent).toBeCalledWith(merchantProps);
18
+ });
19
+ });