Skip to content

Commit

Permalink
fix(adyen): Handle Adyen::AuthenticationError when creating the custo…
Browse files Browse the repository at this point in the history
…mer (#2820)

## Description

This Pull Request adds the handling of `Adyen::AuthenticationError` in
the `PaymentProviderCustomers::AdyenService#create` method.
It will keep delivering an error webhook, but will not raise the
authentication error anymore as nothing can be handled at Lago's level.

NOTE: In a future, the related `PaymentProvider` should marked as
failed/disconnected/invalid and the error logged to make it visible in
the web application and in the API
  • Loading branch information
vincent-pochet authored Nov 14, 2024
1 parent 3b851d9 commit 360e224
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
5 changes: 5 additions & 0 deletions app/services/payment_provider_customers/adyen_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ def create

result.checkout_url = checkout_url_result.checkout_url
result
rescue Adyen::AuthenticationError
# NOTE: Authentication errors will be sent to the account owner with a webhook.
# Since nothing can be done on Lago's side, we should not raise the error.
# TODO: Flag the error on the PaymentProvider instance.
result
end

def update
Expand Down
21 changes: 21 additions & 0 deletions spec/services/payment_provider_customers/adyen_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,27 @@
)
end
end

context 'with authentication error' do
before do
allow(payment_links_api)
.to receive(:payment_links).and_raise(Adyen::AuthenticationError.new('error', nil))
end

it 'delivers an error webhook' do
expect(adyen_service.create).to be_success

expect(SendWebhookJob).to have_been_enqueued
.with(
'customer.payment_provider_error',
customer,
provider_error: {
message: 'error',
error_code: 401
}
)
end
end
end

describe '#update' do
Expand Down

0 comments on commit 360e224

Please sign in to comment.