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

NCPS v2 πŸ‘Ύ #2389

Merged
merged 22 commits into from
May 21, 2024
Merged

NCPS v2 πŸ‘Ύ #2389

merged 22 commits into from
May 21, 2024

Conversation

spencersablan
Copy link
Contributor

@spencersablan spencersablan commented May 9, 2024

Description

Note

Very sorry this PR became a bit larger than originally expected. I'll try to leave some comments around to point out some of the main parts.

  • 🀝 Support for NCP form fields API v2 - Support for v2 without losing support for v1.
  • πŸ“ Extensive testing - Added / adjusted a ton of unit tests to account for the new API.
  • πŸ™…β€β™‚οΈ Removal for .setAttribute() - We had merchants concerned with .setAttribute() as it violates some CSP's.
  • πŸ¦† **Updated some syntax in utils.js to make it slightly more consistent ** - I noticed sometimes we were using function name() {} and sometimes we were using const name = () => {}... TBH, I'd rather use function, but it seems like we use const more, so I went with that. Would love some opinions here πŸ˜„

Why are we making these changes? Include references to any related Jira tasks or GitHub Issues

JIRA: DTPPCPSDK-2228 & DTPPCPSDK-2229

Reproduction Steps (if applicable)

Setup
  • Pull this branch to local
  • In clientsdknodeweb's package.json, under `proxy`, change `/ncp` to `"https://www.te-ncp-js-sdk.qa.paypal.com"` (this will give you the v2 NCP Form Fields API)
  • Run CSNW & SCNW using `npm run debug`.
Creating a local no-code integration
  • Navigate to https://www.msmaster.qa.paypal.com/buttons/smart
  • Sign in using an msmaster developer account
  • Build any integration you'd like and copy the code
  • Add that code to an html file and launch it in your browser.
  • Screenshots (if applicable)

    Important

    The styles are a bit off in these screenshots since the NCP team has not included finalized styles in their API response. So ignore the lack of margin between our buttons & their "checkout" button. πŸ˜„

    Click through to see the different cases:

    Prefers only PayPal button
    preferences: {  
        button_preferences: [ "paypal" ], 
        eligible_funding_methods: ["paypal",  "paylater" ]
    }
    
    image
    Prefers PayPal & Venmo, both are eligible.
    preferences: {  
        button_preferences: [ "paypal", "venmo" ], 
        eligible_funding_methods: ["paypal", "venmo", "paylater" ]
    }
    
    image
    Prefers PayPal & PayLater, both are eligible.
    preferences: {  
        button_preferences: [ "paypal", "paylater" ], 
        eligible_funding_methods: ["paypal", "venmo", "paylater" ]
    }
    
    image
    Prefers PayPal & Venmo, Venmo not eligible. (Shows only PayPal)
    preferences: {  
        button_preferences: [ "paypal", "venmo" ], 
        eligible_funding_methods: ["paypal",  "paylater" ]
    }
    
    image
    Prefers PayPal & default second button.
    preferences: {  
        button_preferences: [ "paypal", "venmo" ], 
        eligible_funding_methods: ["paypal",  "venmo", "paylater" ]
    }
    
    image
    Prefers PayPal & default second button, but all second buttons fail Buttons().isEligible() check. (Shows only PayPal)
    preferences: {  
        button_preferences: [ "paypal", "default" ], 
        eligible_funding_methods: ["paypal",  "paylater" ]
    }
    ... 
    

    Buttons({ fundingSource: "paylater" }).isEligible() -> false 😱


    image

    Horizontal layout example (S/O @nikrom17 )
    preferences: {  
        button_preferences: [ "paypal", "venmo" ], 
        eligible_funding_methods: ["paypal",  "venmo", "paylater" ]
    }
    
    image

    ❀️ Thank you!

    @spencersablan spencersablan marked this pull request as ready for review May 9, 2024 22:58
    @spencersablan spencersablan requested a review from a team as a code owner May 9, 2024 22:58
    Copy link
    Contributor Author

    @spencersablan spencersablan left a comment

    Choose a reason for hiding this comment

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

    Here's a couple of helpful notes as you review this PR πŸ˜„ ⬇️

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

    @nikrom17 nikrom17 left a comment

    Choose a reason for hiding this comment

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

    This is looking pretty good so far πŸ™Œ

    src/hosted-buttons/utils.js Outdated Show resolved Hide resolved
    src/hosted-buttons/index.js Outdated Show resolved Hide resolved
    src/hosted-buttons/utils.js Show resolved Hide resolved
    src/hosted-buttons/utils.js Show resolved Hide resolved
    src/hosted-buttons/utils.js Show resolved Hide resolved
    src/hosted-buttons/utils.js Outdated Show resolved Hide resolved
    src/hosted-buttons/utils.js Outdated Show resolved Hide resolved
    src/hosted-buttons/utils.js Outdated Show resolved Hide resolved
    src/hosted-buttons/utils.js Outdated Show resolved Hide resolved
    @@ -63,30 +68,25 @@ export const getHostedButtonsComponent = (): HostedButtonsComponent => {
    style,
    };

    if (shouldRenderSDKButtons(fundingSources)) {
    if (version === "2") {
    Copy link
    Contributor

    Choose a reason for hiding this comment

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

    Do we anticipate additional major API versions frequently needing to maintain backwards compatibility like this?

    Copy link
    Member

    Choose a reason for hiding this comment

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

    from what we've been told, this is an evergreen experience so any major changes would be a change in the sdk itself.

    This version check is more like a feature-flag so we don't break the current experience while we work on the new one.

    Copy link
    Contributor Author

    Choose a reason for hiding this comment

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

    Good question! I think once v2 is completely rolled out, we can remove this check and all the v1 handling. I should totally add a comment for this.

    Copy link
    Contributor

    Choose a reason for hiding this comment

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

    sounds good! my concern was maintaining this version-based model of backwards compatibility with future versions, but doesn't sound like an issue here πŸš€

    src/hosted-buttons/utils.js Outdated Show resolved Hide resolved
    @@ -602,4 +588,234 @@ test("getElementFromSelector", () => {
    expect(mockQuerySelector).toHaveBeenCalledWith(containerId);
    });

    describe("getButtonPreferences", () => {
    Copy link
    Contributor

    Choose a reason for hiding this comment

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

    nice test coverage

    Copy link
    Contributor

    @nikrom17 nikrom17 left a comment

    Choose a reason for hiding this comment

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

    Looks great!

    @spencersablan spencersablan merged commit c849191 into main May 21, 2024
    4 checks passed
    @spencersablan spencersablan deleted the feature/ncps-preferences branch May 21, 2024 21:37
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    None yet
    Projects
    None yet
    4 participants