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

Hosted buttons component #2276

Merged
merged 6 commits into from
Jan 18, 2024
Merged

Hosted buttons component #2276

merged 6 commits into from
Jan 18, 2024

Conversation

jshawl
Copy link
Contributor

@jshawl jshawl commented Nov 16, 2023

Description

This PR implements a new paypal.HostedButtons() component. Example usage:

<div id="paypal-hosted-buttons"></div>
<script src="https://www.paypal.com/sdk/js?client-id=test&currency=USD&components=hosted-buttons"></script>
<script>
  paypal.HostedButtons({
    hostedButtonId: "B1234567890"
  }).render("#paypal-hosted-buttons")
</script>

Why are we making these changes?

This new component will allow merchants to configure styles, prices, and quantities through a hosted UI. These changes then fetch the details of that hosted button and render them using v5 of the JS SDK.

Reproduction Steps

N/A - the Hosted Buttons UI is not publicly available

❤️ Thank you!

Copy link

codecov bot commented Nov 16, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (10689f9) 51.30% compared to head (8559586) 51.30%.
Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2276   +/-   ##
=======================================
  Coverage   51.30%   51.30%           
=======================================
  Files         104      104           
  Lines        2037     2037           
  Branches      604      604           
=======================================
  Hits         1045     1045           
  Misses        889      889           
  Partials      103      103           
Flag Coverage Δ
jest 31.99% <ø> (ø)
karma 50.03% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@jshawl jshawl force-pushed the hosted-buttons-component branch 2 times, most recently from fe860b2 to 4fb5d3e Compare November 17, 2023 22:10
@jshawl jshawl force-pushed the hosted-buttons-component branch 4 times, most recently from 4fcdeed to ce7a68a Compare December 1, 2023 20:50
Copy link
Contributor

@nbierdeman nbierdeman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Niiiiiice! 💯

src/hosted-buttons/index.js Outdated Show resolved Hide resolved
src/hosted-buttons/index.js Outdated Show resolved Hide resolved
src/hosted-buttons/index.js Outdated Show resolved Hide resolved
src/hosted-buttons/index.js Outdated Show resolved Hide resolved
src/hosted-buttons/index.js Outdated Show resolved Hide resolved
src/hosted-buttons/index.js Outdated Show resolved Hide resolved
src/hosted-buttons/index.js Outdated Show resolved Hide resolved
@jshawl jshawl force-pushed the hosted-buttons-component branch from 0e9bb77 to 2364799 Compare December 21, 2023 16:21
@jshawl jshawl force-pushed the hosted-buttons-component branch 2 times, most recently from 1407d26 to 174fd15 Compare January 16, 2024 18:53
@jshawl jshawl marked this pull request as ready for review January 16, 2024 19:06
@jshawl jshawl requested a review from a team as a code owner January 16, 2024 19:06
@jshawl jshawl requested a review from ravishekhar January 16, 2024 19:06
src/interface/hosted-buttons.js Show resolved Hide resolved
src/zoid/checkout/component.jsx Outdated Show resolved Hide resolved
src/hosted-buttons/index.js Outdated Show resolved Hide resolved
Copy link
Contributor

@ravishekhar ravishekhar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Left a few suggestions.

src/hosted-buttons/index.js Outdated Show resolved Hide resolved
src/hosted-buttons/utils.js Outdated Show resolved Hide resolved
Copy link
Contributor

@nbierdeman nbierdeman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work, @jshawl! It's looking good! Just a couple minor questions/comments for you.

variables?.find((variable) => variable.name === key)?.value ?? "";

const getFundingSource = (paymentSource) => {
if (paymentSource === "credit") {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we could import these values from FUNDING in @paypal/sdk-constants/src instead of hardcoding "credit" and 'CARD'?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes! I like it 72e75b0

if (elm) {
elm.innerHTML = html + htmlScript;
const newScriptEl = document.createElement("script");
const oldScriptEl = elm.querySelector("script");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will there only ever be one script per element? I'm assuming so, but thought I'd doublecheck.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

entry_point: entryPoint,
funding_source: getFundingSource(data.paymentSource),
merchant_id: merchantId,
...userInputs,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a possible vector for malicious JS that needs to be guarded against?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm having trouble thinking of an attack vector here but only because the user input is never put back into the DOM; it will be sent to the hosted buttons API though. I think we're good here but lmk if you had a sanitization strategy in mind and/or if you have an idea for how to exploit.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't think of anything either, unless the API executes a request body value (which seems unlikely).

Copy link
Contributor

@nbierdeman nbierdeman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚢

@jshawl jshawl force-pushed the hosted-buttons-component branch from b005bc1 to 8559586 Compare January 17, 2024 22:52
Copy link
Member

@wsbrunson wsbrunson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ship it

Copy link
Contributor

@ravishekhar ravishekhar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀

@ravishekhar ravishekhar merged commit 5bb0cef into main Jan 18, 2024
4 checks passed
@ravishekhar ravishekhar deleted the hosted-buttons-component branch January 18, 2024 15:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants