diff --git a/app/services/invoices/payments/adyen_service.rb b/app/services/invoices/payments/adyen_service.rb index 32385c4ac83..d82def5c27c 100644 --- a/app/services/invoices/payments/adyen_service.rb +++ b/app/services/invoices/payments/adyen_service.rb @@ -30,8 +30,8 @@ def create res = create_adyen_payment return result unless res - handle_adyen_response(res) - return result unless result.success? + adyen_success, _adyen_error = handle_adyen_response(res) + return result unless adyen_success payment = Payment.new( invoice:, @@ -77,7 +77,8 @@ def generate_payment_url return result unless should_process_payment? res = client.checkout.payment_links_api.payment_links(Lago::Adyen::Params.new(payment_url_params).to_h) - handle_adyen_response(res) + adyen_success, adyen_error = handle_adyen_response(res) + result.service_failure!(code: adyen_error.code, message: adyen_error.msg) unless adyen_success return result unless result.success? @@ -87,7 +88,7 @@ def generate_payment_url rescue Adyen::AdyenError => e deliver_error_webhook(e) - result.single_validation_failure!(error_code: 'payment_provider_error') + result.service_failure!(code: e.code, message: e.msg) end private @@ -154,8 +155,7 @@ def create_adyen_payment rescue Adyen::AdyenError => e deliver_error_webhook(e) update_invoice_payment_status(payment_status: :failed, deliver_webhook: false) - - raise + raise e end def payment_method_params diff --git a/app/services/payment_provider_customers/adyen_service.rb b/app/services/payment_provider_customers/adyen_service.rb index b84dcab93e3..cc9f8748a25 100644 --- a/app/services/payment_provider_customers/adyen_service.rb +++ b/app/services/payment_provider_customers/adyen_service.rb @@ -30,8 +30,8 @@ def generate_checkout_url(send_webhook: true) return result.not_found_failure!(resource: 'adyen_payment_provider') unless adyen_payment_provider res = client.checkout.payment_links_api.payment_links(Lago::Adyen::Params.new(payment_link_params).to_h) - handle_adyen_response(res) - + adyen_success, adyen_error = handle_adyen_response(res) + result.service_failure!(code: adyen_error.code, message: adyen_error.msg) unless adyen_success return result unless result.success? result.checkout_url = res.response['url'] diff --git a/lib/lago/adyen/error_handlable.rb b/lib/lago/adyen/error_handlable.rb index cf6e28ae484..bd849fcf3d3 100644 --- a/lib/lago/adyen/error_handlable.rb +++ b/lib/lago/adyen/error_handlable.rb @@ -4,13 +4,15 @@ module Lago module Adyen module ErrorHandlable def handle_adyen_response(res) - return if res.status < 400 + return [true, nil] if res.status < 400 code = res.response['errorType'] message = res.response['message'] - deliver_error_webhook(::Adyen::AdyenError.new(nil, nil, message, code)) - result.service_failure!(code:, message:) + error = ::Adyen::AdyenError.new(nil, nil, message, code) + deliver_error_webhook(error) + + [false, error] end end end