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

Fixed Updating customer billing address now correctly reflected to stripe #3696

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

nidhi-soni1104
Copy link
Contributor

@nidhi-soni1104 nidhi-soni1104 commented Feb 20, 2024

What this PR does / why we need it:

Changing customer billing address, in the developer portal, is updated to Stripe only when credit card details are changed. Just editing and saving billing address details creates problems, when customer details are not consistent between 3scale and Stripe. This can be forcefully fixed, when the customer updates their credit card information as well.

Expected behavior:

Editing just billing address details should update customer details on Stripe.

Which issue(s) this PR fixes
https://issues.redhat.com/browse/THREESCALE-9532

Verification steps
Mentioned in jira with snapshots

@nidhi-soni1104 nidhi-soni1104 self-assigned this Feb 20, 2024
@nidhi-soni1104 nidhi-soni1104 marked this pull request as draft February 20, 2024 08:21
@nidhi-soni1104 nidhi-soni1104 marked this pull request as ready for review March 4, 2024 13:54
@nidhi-soni1104 nidhi-soni1104 force-pushed the THREESCALE-9532-fix-stripe-billing-adress-update branch 2 times, most recently from a8ee671 to 5024303 Compare March 11, 2024 08:45
@github-actions github-actions bot added the Stale label May 11, 2024
@github-actions github-actions bot closed this May 26, 2024
@3scale 3scale deleted a comment from github-actions bot May 26, 2024
@akostadinov akostadinov removed the Stale label May 26, 2024
@akostadinov akostadinov reopened this May 26, 2024
@mayorova mayorova force-pushed the THREESCALE-9532-fix-stripe-billing-adress-update branch 5 times, most recently from 55fcccc to 2ef2719 Compare May 27, 2024 13:37
match 'hosted_success', via: [:get, :post], on: :member
end

resource :stripe, only: %i[show edit update] do
Copy link
Contributor

Choose a reason for hiding this comment

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

Adding update method for Stripe

@@ -8,7 +8,17 @@ def html_class_name
end

def path
admin_account_payment_details_path
if payment_gateway_type == :stripe
admin_account_stripe_path
Copy link
Contributor

Choose a reason for hiding this comment

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

This is in order for update method to be executed on StripeController, and not the generic PaymentDetailsBaseController, so that billing address is updated on the payment method.

nidhi-soni1104 and others added 2 commits May 27, 2024 15:53
…e Stripe

fixed code climate issues and failed test

fixed climate code

fixed failing cucumber

fixed first time adding billing address

fixed cuccumber faliures

fixed code climate issues

refactored code

added missing arguments

fixed failed uni test

fixed code climate

keep method in its own file

code refactored

refactored code

updated stripe error

fixed id faliure error
@mayorova mayorova force-pushed the THREESCALE-9532-fix-stripe-billing-adress-update branch from 2ef2719 to 0c78c4f Compare May 27, 2024 13:55
@mayorova mayorova force-pushed the THREESCALE-9532-fix-stripe-billing-adress-update branch from 2cc7132 to 17605be Compare May 28, 2024 13:15
josemigallas
josemigallas previously approved these changes Jun 3, 2024

customer
rescue Stripe::InvalidRequestError
create_customer
Copy link
Contributor

Choose a reason for hiding this comment

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

this changes logic. First of all I don't understand why do we rescue with create_customer with create_customer. Maybe retry? But then in the past, we only retried one of the options... just it is a little weird to read.

As I see it, first create customer in case we don't find an ID. We retrieve customer by ID and create it in case it's status is deleted. And we rescue when in case the retrieve call or the deleted? call raised. It will retry if create_customer failed though.

I mean, I'm not sure we need to change original unless we understand why it was written like that.

Copy link
Contributor

Choose a reason for hiding this comment

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

Just for reference: the original piece was added here: https://github.com/3scale/porta/pull/3351/files#diff-4c16dc8fb0816a60d4675d1987c5588b66341daf5edd80d0cb2fb1ececb5a9b6R47

This was to fix an issue where a reference was stored in our DB, but we couldn't find the Stripe::Customer by that ID anymore. So, previously the situation when the customer has been deleted was checked (and the fallback was to create a new customer). But the issue still occurred, when (if I remember correctly) switching the Stripe credentials - to point to a different Stripe instance. Obviously, in this case all old references become invalid.

I think in practical this changed code works almost the same way. The only caveat I see is that if customer_id.blank? and create_customer throws a Stripe::InvalidRequestError for some reason, then create_customer would be retried again (which was not happening originally, and it would just throw directly).

I can certainly revert this change to avoid confusion.

Copy link
Contributor

Choose a reason for hiding this comment

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

(I was wondering why this change was made in the first place, but it turns out to be the result of a refactor, and undoing of that refactor 😬 )

@@ -47,6 +68,7 @@ def find_or_create_customer
begin
customer = Stripe::Customer.retrieve(customer_id, api_key)
return create_customer if customer.deleted?

Copy link
Contributor

Choose a reason for hiding this comment

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

This is just to make RuboCop happy:

RuboCop: Add empty line after guard clause. [Layout/EmptyLineAfterGuardClause]

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