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

Refactor payments-stripe to only use getStripeInstanceForShop #4951

Conversation

rattrayalex-stripe
Copy link
Contributor

Resolves #4942 (review)
Impact: minor
Type: refactor

Issue

This is a followup to #4942

  1. There was a string constant ("reaction-stripe") being duplicated in many places.
  2. Some code referenced paymentMethod.paymentPluginName, but should have instead referenced the above constant.
  3. Use of connectAuth.access_token should probably be deprecated from payments-stripe, as it should only be set in the marketplace plugin.
  4. We were instantiating stripe in several places, potentially in inconsistent ways.

Solution

  1. Make a constants file with STRIPE_PACKAGE_NAME.
  2. Get rid of getStripeApiKey, move its connectAuth functionality into getStripeInstanceForShop with a warning log.
  3. Separate out getStripePackageForShop since I thought it would be needed elsewhere, but I'm not sure this is the case.

I have a few questions for the reviewer (presumably @aldeed ):

  1. getStripeInstance and getStripePackage are now only called from one file. Should they be moved into that file?
  2. Is the constant in the right place, and does the name seem good?
  3. Is Packages.findOne() actually asynchronous? If not, I can remove await from calls to instantiate Stripe, which would be nice.

Breaking changes

Previously, certain calls to instantiate stripe would throw an error if you did not have an api_key set. Now, those same calls will succeed, but use connectAuth.access_token if it is set. This is a breaking change, though my intuition is that no users would have relied on this behavior while also having connectAuth.access_token set 🤞.

Testing

I ran the unit tests locally.

Copy link
Contributor

@aldeed aldeed left a comment

Choose a reason for hiding this comment

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

@rattrayalex-stripe Thanks! Can you merge latest develop branch into this branch? It will delete the checkout client files that you modified because they were for the old checkout UI, which is gone in the next release. The recommendation now is to build your own or start with the example storefront.

To answer your questions:

  • getStripeInstance and getStripePackage may at some point be needed in other files (we plan to add a stored card method, for example). So I'd keep them separated.
  • Constant name and location is fine
  • Yes Packages.findOne() returns a Promise.

@rattrayalex-stripe rattrayalex-stripe force-pushed the refactor-57-rattrayalex-stripe-refactor-payments-stripe branch from bc5bb2c to 8347d01 Compare February 7, 2019 01:41
@rattrayalex-stripe
Copy link
Contributor Author

Interesting! Will that use the new checkout (currently in beta)? Should make things much easier for users.

In any case, rebased!

@aldeed
Copy link
Contributor

aldeed commented Feb 8, 2019

@rattrayalex-stripe There is a test failing on CI: https://circleci.com/gh/reactioncommerce/reaction/37940?utm_campaign=vcs-integration-link&utm_medium=referral&utm_source=github-checks-link

Looks like one of the import paths for the constant needs to be fixed.

I wasn't aware of the new full-page checkout and the example storefront does not currently use it, but we may want to implement that as an alternative example. Reaction will not be shipping with a storefront anymore, but there will be example storefronts and docs with storefront development instructions. So it is up to individual installations whether they want to migrate to the new checkout page, but we can ensure that it works on the server API side.

…d pull out a STRIPE_PACKAGE_NAME constant

Signed-off-by: Alex Rattray <rattrayalex@stripe.com>
@rattrayalex-stripe rattrayalex-stripe force-pushed the refactor-57-rattrayalex-stripe-refactor-payments-stripe branch from 8347d01 to 461832f Compare February 8, 2019 16:54
@rattrayalex-stripe
Copy link
Contributor Author

Oops, thanks for catching that - maybe caused by the rebase.

Should be good now!

And interesting re; storefronts... Let me know if you need help adding checkout compatibility!

@rattrayalex-stripe
Copy link
Contributor Author

Whoops, just noticed this is still open 😅 ping @aldeed
I'm actually interested in making one or two deeper contributions involving some new API's we're launching. Any chance you'd be up to discuss real quick over email/phone? my email is github_username.replace('-', '@') + '.com'

@aldeed
Copy link
Contributor

aldeed commented Apr 2, 2019

@rattrayalex-stripe Thanks. Last thing I remember was pulling this down to test but I'm not sure I ever completed that testing before getting busy with other things. I'll prioritize for this week. And I'll send you an email.

@rattrayalex-stripe
Copy link
Contributor Author

Awesome, thanks!

Signed-off-by: Eric Dobbertin <eric@dairystatedesigns.com>
@aldeed aldeed merged commit 7c2a0ef into reactioncommerce:develop Aug 6, 2019
@aldeed
Copy link
Contributor

aldeed commented Aug 6, 2019

Finally got this tested and merged! Thanks @rattrayalex-stripe

@rattrayalex-stripe rattrayalex-stripe deleted the refactor-57-rattrayalex-stripe-refactor-payments-stripe branch August 6, 2019 16:10
@kieckhafer kieckhafer mentioned this pull request Aug 28, 2019
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.

None yet

2 participants