Skip to content

Commit

Permalink
misc(stripe): Improve error code handling (#3203)
Browse files Browse the repository at this point in the history
This PR improves #3200 by
relying on the error code rather than on the error message
  • Loading branch information
vincent-pochet authored Feb 18, 2025
1 parent 71d7238 commit c0e6050
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions app/services/credit_notes/refunds/stripe_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module Refunds
class StripeService < BaseService
include Customers::PaymentProviderFinder

INVALID_PAYMENT_METHOD_ERROR = "Refunds are not supported on this payment method."
INVALID_PAYMENT_METHOD_ERROR = "charge_not_refundable"

def initialize(credit_note = nil)
@credit_note = credit_note
Expand Down Expand Up @@ -39,7 +39,7 @@ def create
rescue ::Stripe::InvalidRequestError => e
deliver_error_webhook(message: e.message, code: e.code)
update_credit_note_status(:failed)
return result if e.message == INVALID_PAYMENT_METHOD_ERROR
return result if e.code == INVALID_PAYMENT_METHOD_ERROR

result.service_failure!(code: "stripe_error", message: e.message)
end
Expand Down
6 changes: 3 additions & 3 deletions spec/services/credit_notes/refunds/stripe_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@

before do
allow(Stripe::Refund).to receive(:create)
.and_raise(::Stripe::InvalidRequestError.new(error_message, {}))
.and_raise(::Stripe::InvalidRequestError.new(error_message, {}, code: error_message))
end

it "delivers an error webhook" do
Expand All @@ -107,7 +107,7 @@
provider_customer_id: stripe_customer.provider_customer_id,
provider_error: {
message: "error",
error_code: nil
error_code: "error"
}
)
end
Expand All @@ -130,7 +130,7 @@
provider_customer_id: stripe_customer.provider_customer_id,
provider_error: {
message: error_message,
error_code: nil
error_code: error_message
}
)
end
Expand Down

0 comments on commit c0e6050

Please sign in to comment.