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

[ncp] handle create order errors #2320

Merged
merged 2 commits into from
Jan 31, 2024
Merged

[ncp] handle create order errors #2320

merged 2 commits into from
Jan 31, 2024

Conversation

jshawl
Copy link
Contributor

@jshawl jshawl commented Jan 24, 2024

Description

This PR shows a helpful error message to the buyer when create order responds without an order id. It also removes the custom popup for inline guest.

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

If a merchant accidentally changes the client id or hosted button id, buyers will not be able to complete a checkout, and no error message is shown. This PR shows the error message above the buttons.

Reproduction Steps (if applicable)

Not yet applicable in a production/sandbox environment, but let me know if you want to try it out locally and I can share the details

❤️ Thank you!

Copy link

codecov bot commented Jan 24, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (18cd546) 51.30% compared to head (08aa534) 51.32%.
Report is 7 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2320      +/-   ##
==========================================
+ Coverage   51.30%   51.32%   +0.02%     
==========================================
  Files         104      104              
  Lines        2037     2038       +1     
  Branches      604      604              
==========================================
+ Hits         1045     1046       +1     
  Misses        889      889              
  Partials      103      103              
Flag Coverage Δ
jest 31.99% <ø> (ø)
karma 50.06% <ø> (+0.02%) ⬆️

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 handle-ncp-errors branch from c1fa20a to fc488aa Compare January 25, 2024 19:10
container?.appendChild(div);
}
};
};
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 not sure I like this implementation. I did it so that I didn't have to pass popupFallback and selector down into onApprove. e.g. the alternative to this would be:

onApprove: buildHostedButtonOnApprove({
  merchantId,
  hostedButtonId,
  selector,
  popupFallback
})

and then inside of buildHostedButtonOnApprove would be the contents of this function. I did it this way so that I could easily unit-test it without managing passing around props but now that I'm looking at it in the GitHub diff it looks a little confusing. wdyt?

Copy link
Contributor

Choose a reason for hiding this comment

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

Ease of testing is a good reason in my book for going this route. Thanks for explaining this!

@@ -149,19 +174,14 @@ export const buildHostedButtonOnApprove = ({
context_id: data.orderID,
}),
}).then((response) => {
// remove the popup fallback message, if present
document.querySelector(`.${popupFallbackClassName}`)?.remove();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is another weird thing in this PR. I was really hoping to have all the dom manipulation contained within the popup handling code, but we need this here to handle a specific use case:

  1. buyer uses inline guest to checkout, has popup blocked, error message is rendered in the dom
  2. buyer uses a different payment method ("paypal") and when they click on the button, there should no longer be an error message.

@jshawl jshawl marked this pull request as ready for review January 25, 2024 19:30
@jshawl jshawl requested a review from a team as a code owner January 25, 2024 19:30
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! 💯

container?.appendChild(div);
}
};
};
Copy link
Contributor

Choose a reason for hiding this comment

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

Ease of testing is a good reason in my book for going this route. Thanks for explaining this!

@jshawl jshawl merged commit 20c9729 into main Jan 31, 2024
3 checks passed
@jshawl jshawl deleted the handle-ncp-errors branch January 31, 2024 20:57
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.

3 participants