-
Notifications
You must be signed in to change notification settings - Fork 74
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
THREESCALE-11383: Ignore errors on payment gateway initialization when destroying buyer #3900
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
module Account::Gateway | ||
extend ActiveSupport::Concern | ||
|
||
class InvalidSettingsError < StandardError; end | ||
|
||
included do | ||
has_many :payment_transactions | ||
has_one :payment_gateway_setting, dependent: :destroy, inverse_of: :account | ||
|
@@ -18,6 +20,8 @@ def payment_gateway(**options) | |
return if payment_gateway_type.blank? | ||
|
||
PaymentGateway.implementation(payment_gateway_type, **options).new(payment_gateway_options || {}) | ||
rescue ArgumentError => exception | ||
raise InvalidSettingsError, exception.message | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My question is whether we should raise here? Or should we return something like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well, I'm not sure to be honest whether it's "easy" to misconfigure it... I'm not sure in fact how it is possible 😬 (and how that "bad" configuration got there in the first place) Looks like the current implementation returns To me throwing an exception seems to be more logical and straightforward than returning a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @akostadinov So, what do you think? I am a bit concerned that we may throw this exception in production. But on the other hand, currently an exception would also be thrown, so the current behavior actually wouldn't change 😅 It would just give us more useful info about the error in BugSnag. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I still believe that we should not throw but return an object. Still this fixes a real issue and is a net improvement in behavior so I'm approving. Thank you. |
||
end | ||
|
||
def payment_gateway_configured? | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this line can be removed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, I trusted you and removed the line, but then I realized that this
end
in line:104
doesn't actually end the method, so I think we can't get rid ofbegin
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
my bad, I overlooked that, thought you added by mistake
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Although then there is a check
return if payment_detail.destroyed?
which idk how it is supposed to work. Maybe we should make the rescue global for the method.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think these are need to be executed in any case:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wouldn't care about these other values. If things work in real life as they are now, then I'm fine with it. I was just worried that by invalid configuration
payment_detail
may raise. But I think your test ensures it wouldn't.