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

fix(payment): Fix Adyen invoice payment #1689

Merged
merged 2 commits into from
Feb 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions app/services/invoices/payments/adyen_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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:,
Expand Down Expand Up @@ -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?

Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions app/services/payment_provider_customers/adyen_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down
8 changes: 5 additions & 3 deletions lib/lago/adyen/error_handlable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading