Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add support for PPCP AXO Loader #2272

Closed
wants to merge 27 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
e980158
demo axo component
siddy2181 Nov 3, 2023
358c9d4
rename to connect, move code directly for now
cgdibble Nov 6, 2023
b6fa60d
add connect interface unit test file
cgdibble Nov 6, 2023
ccd3a09
remove axo zoid, unit tests
siddy2181 Nov 6, 2023
055b030
add route for connect module
siddy2181 Nov 7, 2023
ccb4b5f
refactor: move axo/connect under src
siddy2181 Nov 7, 2023
294709b
Venmo overlay (#2271)
nbierdeman Nov 7, 2023
f754079
chore(release): 5.0.285 🎉
nbierdeman Nov 7, 2023
699338f
update loader config
siddy2181 Nov 8, 2023
d75daed
proposed payload for PPCP AXO loader
siddy2181 Nov 8, 2023
30bb926
removing sessionId default because we want to require that prop
cgdibble Nov 8, 2023
b43bfac
couple test adjsutments
cgdibble Nov 9, 2023
97a6a06
add tests, cleanup
siddy2181 Nov 9, 2023
743e2ce
update parameters supporting AXO modifications
siddy2181 Nov 14, 2023
0fa02c0
update axoloader version; fix lint,test,typecheck
siddy2181 Nov 14, 2023
c764222
Merge branch 'main' of https://github.com/paypal/paypal-checkout-comp…
siddy2181 Nov 14, 2023
1174669
Inherit overflow from parent for firefox hover/filter side-effect (#2…
sebastianfdz Nov 15, 2023
3a6bf6f
chore(release): 5.0.286 🎉
jshawl Nov 16, 2023
4990156
pass metadata to loadAxo
siddy2181 Nov 20, 2023
93f4dc9
Merge branch 'main' of https://github.com/paypal/paypal-checkout-comp…
siddy2181 Nov 20, 2023
15968cf
update package version for npm publish
siddy2181 Nov 20, 2023
a61744a
update type for Checkout Component
siddy2181 Nov 27, 2023
3b4711b
add some basic analytics
cgdibble Nov 27, 2023
17698f3
test second trycatch, loose metric tests, remove run for vitest
cgdibble Nov 27, 2023
1023547
fix flow and such
cgdibble Nov 28, 2023
708c390
remove debug
cgdibble Nov 28, 2023
1ea9260
fix: axo loader params
siddy2181 Nov 29, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .bundlemonrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
{
"path": "size.min.js",
"compression": "gzip",
"maxPercentIncrease": 3,
"maxPercentIncrease": 3.6,
"maxSize": "76kb"
}
],
Expand Down
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
## <small>5.0.286 (2023-11-16)</small>

* Inherit overflow from parent for firefox hover/filter side-effect (#2274) ([1174669](https://github.com/paypal/paypal-checkout-components/commit/1174669)), closes [#2274](https://github.com/paypal/paypal-checkout-components/issues/2274)



## <small>5.0.285 (2023-11-07)</small>

* Venmo overlay (#2271) ([294709b](https://github.com/paypal/paypal-checkout-components/commit/294709b)), closes [#2271](https://github.com/paypal/paypal-checkout-components/issues/2271)



## <small>5.0.284 (2023-11-02)</small>

* Update CODE_OF_CONDUCT.md (#2268) ([6caee02](https://github.com/paypal/paypal-checkout-components/commit/6caee02)), closes [#2268](https://github.com/paypal/paypal-checkout-components/issues/2268)
Expand Down
4 changes: 4 additions & 0 deletions __sdk__.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ module.exports = {
entry: "./src/interface/wallet",
globals,
},
connect: {
entry: "./src/connect/interface",
globals
},
// @deprecated - renamed to payment-fields to be removed
fields: {
entry: "./src/interface/fields",
Expand Down
2 changes: 1 addition & 1 deletion dist/button.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/test/button.js

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@paypal/checkout-components",
"version": "5.0.284",
"version": "5.0.288",
"description": "PayPal Checkout components, for integrating checkout products.",
"main": "index.js",
"scripts": {
Expand Down Expand Up @@ -29,7 +29,7 @@
"release": "./scripts/publish.sh",
"start": "npm run webpack -- --progress --watch",
"test": "npm run format:check && npm run test:unit && npm run jest-ssr && npm run karma && npm run jest-screenshot",
"test:unit": "vitest run",
"test:unit": "vitest",
"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",
"typecheck": "npm run flow-typed && npm run flow",
"version": "./scripts/version.sh",
Expand Down Expand Up @@ -109,6 +109,7 @@
"@krakenjs/zoid": "^10.3.1",
"@paypal/common-components": "^1.0.35",
"@paypal/funding-components": "^1.0.31",
"@paypal/connect-loader-component": "^1.1.0",
"@paypal/sdk-client": "^4.0.176",
"@paypal/sdk-constants": "^1.0.133",
"@paypal/sdk-logos": "^2.2.6"
Expand Down
96 changes: 96 additions & 0 deletions src/connect/component.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/* @flow */
import { loadAxo } from "@paypal/connect-loader-component";
import {
getClientID,
getClientMetadataID,
getUserIDToken,
getLogger,
} from "@paypal/sdk-client/src";

const sendCountMetric = ({
dimensions,
event = "unused",
name,
value = 1,
}: {|
event?: string,
name: string,
value?: number,
dimensions: {
[string]: mixed,
},
// $FlowIssue return type
|}) =>
getLogger().metric({
dimensions,
metricEventName: event,
metricNamespace: name,
metricValue: value,
metricType: "counter",
});

// $FlowFixMe
export const getConnectComponent = async (merchantProps) => {
sendCountMetric({
name: "pp.app.paypal_sdk.connect.init.count",
dimensions: {},
});

const cmid = getClientMetadataID();
const clientID = getClientID();
const userIdToken = getUserIDToken();
const { metadata } = merchantProps;

let loadResult = {};
try {
loadResult = await loadAxo({
platform: "PPCP",
btSdkVersion: "3.97.3-connect-alpha.6.1",
minified: true,
metadata,
});
} catch (error) {
sendCountMetric({
name: "pp.app.paypal_sdk.connect.init.error.count",
event: "error",
dimensions: {
errorName: "connect_load_error",
},
});

throw new Error(error);
}

try {
const connect = await window.braintree.connect.create({
...loadResult.metadata, // returns a localeURL for assets
...merchantProps, // AXO specific props
platformOptions: {
platform: "PPCP",
userIdToken,
clientID,
clientMetadataId: cmid,
fraudnet: () => {
return "";
},
},
});

sendCountMetric({
name: "pp.app.paypal_sdk.connect.init.success.count",
event: "success",
dimensions: {},
});

return connect;
} catch (error) {
sendCountMetric({
name: "pp.app.paypal_sdk.connect.init.error.count",
event: "error",
dimensions: {
errorName: "connect_init_error",
},
});
throw new Error(error);
}
};
83 changes: 83 additions & 0 deletions src/connect/component.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/* @flow */

import {
getClientID,
getClientMetadataID,
getUserIDToken,
getLogger,
} from "@paypal/sdk-client/src";
import { loadAxo } from "@paypal/connect-loader-component";
import { describe, expect, test, vi } from "vitest";

import { getConnectComponent } from "./component";

vi.mock("@paypal/sdk-client/src", () => {
return {
getClientID: vi.fn(() => "mock-client-id"),
getClientMetadataID: vi.fn(() => "mock-cmid"),
getUserIDToken: vi.fn(() => "mock-uid"),
getLogger: vi.fn(() => ({ metric: vi.fn() })),
};
});

vi.mock("@paypal/connect-loader-component", () => {
return {
loadAxo: vi.fn(),
};
});

describe("getConnectComponent: returns ConnectComponent", () => {
const mockAxoMetadata = { someData: "data" };
const mockProps = { someProp: "value" };
beforeEach(() => {
vi.clearAllMocks();
window.braintree = {
connect: {
create: vi.fn(),
},
};

loadAxo.mockResolvedValue({ metadata: mockAxoMetadata });
});

test("loadAxo and window.braintree.connect.create are called with proper data", async () => {
await getConnectComponent(mockProps);

expect(getClientID).toHaveBeenCalled();
expect(getClientMetadataID).toHaveBeenCalled();
expect(getUserIDToken).toHaveBeenCalled();
expect(loadAxo).toHaveBeenCalled();

expect(window.braintree.connect.create).toHaveBeenCalledWith({
...mockAxoMetadata,
...mockProps,
platformOptions: {
platform: "PPCP",
clientID: "mock-client-id",
clientMetadataID: "mock-cmid",
userIdToken: "mock-uid",
},
});
expect(getLogger).toBeCalledTimes(2);
});

test("loadAxo failure is handled", async () => {
const errorMessage = "Something went wrong";
loadAxo.mockRejectedValue(errorMessage);

await expect(() => getConnectComponent(mockProps)).rejects.toThrow(
errorMessage
);
expect(getLogger).toHaveBeenCalledTimes(2);
});

test("connect create failure is handled", async () => {
const expectedError = "create failed";
window.braintree.connect.create.mockRejectedValue(expectedError);

await expect(() => getConnectComponent(mockProps)).rejects.toThrow(
expectedError
);
expect(getLogger).toBeCalledTimes(2);
});
});
16 changes: 16 additions & 0 deletions src/connect/interface.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/* eslint-disable flowtype/no-weak-types */
/* @flow */
// flow-disable

import { getConnectComponent } from "./component";

type ConnectComponent = (merchantProps: any) => ConnectComponent;
// $FlowFixMe
export const Connect: ConnectComponent = async (
merchantProps: any
): ConnectComponent => {
// $FlowFixMe
return await getConnectComponent(merchantProps);
};

/* eslint-enable flowtype/no-weak-types */
19 changes: 19 additions & 0 deletions src/connect/interface.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/* @flow */

import { describe, expect, vi } from "vitest";

import { getConnectComponent } from "./component";
import { Connect } from "./interface";

describe("interface.js", () => {
vi.mock("./component", () => {
return {
getConnectComponent: vi.fn(),
};
});
it("should call getConnectComponent with merchant props", async () => {
const merchantProps = { props: "someProps" };
await Connect(merchantProps);
expect(getConnectComponent).toBeCalledWith(merchantProps);
});
});
8 changes: 8 additions & 0 deletions src/ui/buttons/styles/color.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export const buttonColorStyle = `
@media (hover:hover) {
.${CLASS.BUTTON}.${CLASS.COLOR}-${BUTTON_COLOR.GOLD}:hover {
filter: brightness(0.95);
overflow: inherit;
}
}

Expand Down Expand Up @@ -156,6 +157,7 @@ export const buttonColorStyle = `
.${CLASS.BUTTON}[${ATTRIBUTE.FUNDING_SOURCE}=${FUNDING.PAIDY}].${CLASS.COLOR}-${BUTTON_COLOR.DEFAULT}:hover,
.${CLASS.BUTTON}[${ATTRIBUTE.FUNDING_SOURCE}=${FUNDING.WECHATPAY}].${CLASS.COLOR}-${BUTTON_COLOR.DEFAULT}:hover {
filter: brightness(1.2);
overflow: inherit;
}

/* APM button on focus actions */
Expand Down Expand Up @@ -214,6 +216,7 @@ export const buttonColorStyle = `
@media (hover:hover) {
.${CLASS.BUTTON}.${CLASS.COLOR}-${BUTTON_COLOR.BLUE}:hover {
filter: brightness(0.95);
overflow: inherit;
}
}

Expand Down Expand Up @@ -241,6 +244,7 @@ export const buttonColorStyle = `
@media (hover:hover) {
.${CLASS.BUTTON}.${CLASS.COLOR}-${BUTTON_COLOR.SILVER}:hover {
filter: brightness(0.95);
overflow: inherit;
}
}

Expand All @@ -267,6 +271,7 @@ export const buttonColorStyle = `

.${CLASS.BUTTON}.${CLASS.COLOR}-${BUTTON_COLOR.DARKBLUE}:hover {
filter: brightness(1.2);
overflow: inherit;
}

.${CLASS.BUTTON}.${CLASS.COLOR}-${BUTTON_COLOR.DARKBLUE}:focus {
Expand Down Expand Up @@ -294,6 +299,7 @@ export const buttonColorStyle = `

.${CLASS.BUTTON}.${CLASS.COLOR}-${BUTTON_COLOR.BLACK}:hover {
filter: brightness(1.2);
overflow: inherit;
}

.${CLASS.BUTTON}.${CLASS.COLOR}-${BUTTON_COLOR.BLACK}:focus {
Expand Down Expand Up @@ -321,6 +327,7 @@ export const buttonColorStyle = `
@media (hover:hover) {
.${CLASS.BUTTON}.${CLASS.COLOR}-${BUTTON_COLOR.WHITE}:hover {
filter: brightness(0.95);
overflow: inherit;
}
}

Expand Down Expand Up @@ -357,6 +364,7 @@ export const buttonColorStyle = `

.${CLASS.BUTTON} .${CLASS.CARD}:hover {
filter: brightness(1.2);
overflow: inherit;
}

.${CLASS.BUTTON} .${CLASS.CARD}:focus {
Expand Down
Loading