Skip to content

Commit

Permalink
fix(adyen-checkout-url): Fix generating adyen checkout url when psp i…
Browse files Browse the repository at this point in the history
…s not present (#1406)
  • Loading branch information
ivannovosad authored Oct 20, 2023
1 parent e919f5e commit 7904cef
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 7 deletions.
2 changes: 2 additions & 0 deletions app/services/payment_provider_customers/adyen_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ def create
end

def generate_checkout_url
return result.not_found_failure!(resource: 'adyen_payment_provider') unless adyen_payment_provider

res = client.checkout.payment_links_api.payment_links(payment_link_params)
checkout_url = res.response['url']

Expand Down
48 changes: 41 additions & 7 deletions spec/services/payment_provider_customers/adyen_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@
create(:adyen_customer, customer:, provider_customer_id: nil)
end

before do
allow(Adyen::Client).to receive(:new).and_return(adyen_client)
allow(adyen_client).to receive(:checkout).and_return(checkout)
allow(checkout).to receive(:payment_links_api).and_return(payment_links_api)
allow(payment_links_api).to receive(:payment_links).and_return(payment_links_response)
end

describe '#create' do
subject(:adyen_service_create) { adyen_service.create }

before do
allow(Adyen::Client).to receive(:new).and_return(adyen_client)
allow(adyen_client).to receive(:checkout).and_return(checkout)
allow(checkout).to receive(:payment_links_api).and_return(payment_links_api)
allow(payment_links_api).to receive(:payment_links).and_return(payment_links_response)
end

context 'when customer does not have an adyen customer id yet' do
it 'calls adyen api client payment links' do
adyen_service_create
Expand Down Expand Up @@ -79,4 +79,38 @@
end
end
end

describe '#generate_checkout_url' do
context 'when adyen payment provider is nil' do
before { adyen_provider.destroy! }

it 'returns a not found error' do
result = adyen_service.generate_checkout_url

aggregate_failures do
expect(result).not_to be_success
expect(result.error).to be_a(BaseService::NotFoundFailure)
expect(result.error.message).to eq('adyen_payment_provider_not_found')
end
end
end

context 'when adyen payment provider is present' do
subject(:generate_checkout_url) { adyen_service.generate_checkout_url }

it 'generates a checkout url' do
expect(generate_checkout_url).to be_success
end

it 'delivers a success webhook' do
expect { generate_checkout_url }.to enqueue_job(SendWebhookJob)
.with(
'customer.checkout_url_generated',
customer,
checkout_url: 'https://test.adyen.link/test',
)
.on_queue(:webhook)
end
end
end
end

0 comments on commit 7904cef

Please sign in to comment.