From 360e224fb2019140accf63731eebe72d45302f5e Mon Sep 17 00:00:00 2001 From: Vincent Pochet Date: Thu, 14 Nov 2024 16:19:30 +0100 Subject: [PATCH] fix(adyen): Handle Adyen::AuthenticationError when creating the customer (#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 --- .../adyen_service.rb | 5 +++++ .../adyen_service_spec.rb | 21 +++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/app/services/payment_provider_customers/adyen_service.rb b/app/services/payment_provider_customers/adyen_service.rb index 48c43b95006..86aec0cb2a1 100644 --- a/app/services/payment_provider_customers/adyen_service.rb +++ b/app/services/payment_provider_customers/adyen_service.rb @@ -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 diff --git a/spec/services/payment_provider_customers/adyen_service_spec.rb b/spec/services/payment_provider_customers/adyen_service_spec.rb index f36548953b8..d9652883668 100644 --- a/spec/services/payment_provider_customers/adyen_service_spec.rb +++ b/spec/services/payment_provider_customers/adyen_service_spec.rb @@ -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