Skip to content
This repository has been archived by the owner on Apr 14, 2023. It is now read-only.

one to one relationship for gateway customer #212

Conversation

skukx
Copy link
Contributor

@skukx skukx commented Jan 30, 2019

Ensure that when creating braintree customers we create one per spree
user. To do this, first generate a token with the given customer id if
available. When a braintree customer already exists, rather than create
a new braintree customer, add the payment method to the existing
braintree customer.

Closes #206

Copy link

@ericsaupe ericsaupe left a comment

Choose a reason for hiding this comment

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

How does the braintree_customer_id get saved to a user?

@skukx
Copy link
Contributor Author

skukx commented Jan 30, 2019

Copy link
Member

@kennyadsl kennyadsl left a comment

Choose a reason for hiding this comment

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

Some notes other than review comments left:

  • a lot of cassettes changed, is that intentional?
  • git commits are a bit messed up, there's a merge commit and some can be squashed for sure, can we fix that?

app/models/solidus_paypal_braintree/gateway.rb Outdated Show resolved Hide resolved
spec/spec_helper.rb Show resolved Hide resolved
app/models/solidus_paypal_braintree/customer.rb Outdated Show resolved Hide resolved
solidus_paypal_braintree.gemspec Outdated Show resolved Hide resolved
@@ -375,5 +391,16 @@ def customer_profile_params(payment)

params
end

def payment_method_params(payment)
Copy link
Member

Choose a reason for hiding this comment

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

This method smells like it shouldn't be here, what about a separate class? Anyway I'd call this method payment_method_attributes_from(payment) at least or payment_to_braintree_payment_method_attributes(payment), not sure what's best, or worst? 🙂

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 agree with this, I followed suit with the customer_profile_params(payment) method for consistency.

@skukx
Copy link
Contributor Author

skukx commented Feb 4, 2019

@kennyadsl The reason all the VCR cassettes changed is because there is now a different api call that is made. When there is a braintree customer attached to a spree user then we Add a payment method. Otherwise we are Creating a new customer with the new payment method.

This is one of the reasons I'm not a fan of VCR (there are many). VCR is very quick and simple but can create issues over time. I would love to open a PR to remove VCR altogether and stub the service with sinatra.

As far as commits go, I'm probably going to squash all of this into 1 commit

@skukx skukx force-pushed the 206-one-to-one-relationship-for-gateway-customer branch 5 times, most recently from b683d3c to 084e5de Compare February 5, 2019 22:53
Ensure that when creating braintree customers we create one per spree
user. To do this, first generate a token with the given customer id if
available. When a braintree customer already exists, rather than create
a new braintree customer, add the payment method to the existing
braintree customer.
@skukx skukx force-pushed the 206-one-to-one-relationship-for-gateway-customer branch from 084e5de to 0f8e967 Compare February 12, 2019 16:55
end

def customer_id
return unless try_spree_current_user&.braintree_customer
Copy link
Contributor Author

Choose a reason for hiding this comment

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

There is a bug with the ClientTokensController. The controller generates the token for the current user. However if that endpoint is called from admin then it will attach the payment source to the administrating user rather than the user on the order

Copy link
Member

Choose a reason for hiding this comment

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

good catch!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Debating if the token should be generated when the view is rendered. Maybe as a hidden input

Copy link
Member

Choose a reason for hiding this comment

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

Not sure, what's the difference?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

See implementation 2 here: solidusio/solidus_braintree#79

The main difference is that the view no longer makes an api request to obtain the client token but rather just generates it when the view renders. The api request was only made if the new braintree payment method was selected (javascript events). This change generates a token even if the user may not be adding a new payment method. Therefore it could mean a slight increase in api requests sent to braintree. I think this should be negligible though

Copy link
Member

Choose a reason for hiding this comment

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

What about who is using this gem without a Rails frontend, eg on React or Vue.js? I think we still need this controller to work for them, right?

@seand7565
Copy link
Contributor

@skukx Hello again! Now that the other PR has been merged, would you mind rebasing this one as well? Thanks!

@skukx skukx closed this Sep 20, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

New Braintree Customer created for every payment method created
4 participants