From 205363a15a21deca5a521ae407873cea5c4d61e6 Mon Sep 17 00:00:00 2001 From: LovroColic Date: Mon, 12 Feb 2024 13:35:26 +0100 Subject: [PATCH] feat (payment-url): add support for invoice payment url (#172) --- lib/lago/api/resources/invoice.rb | 7 +++++++ spec/lago/api/resources/invoice_spec.rb | 22 ++++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/lib/lago/api/resources/invoice.rb b/lib/lago/api/resources/invoice.rb index b6d4f79..a307eab 100644 --- a/lib/lago/api/resources/invoice.rb +++ b/lib/lago/api/resources/invoice.rb @@ -49,6 +49,13 @@ def retry_payment(invoice_id) JSON.parse(response.to_json, object_class: OpenStruct) end + def payment_url(invoice_id) + path = "/api/v1/invoices/#{invoice_id}/payment_url" + response = connection.post({}, path)['invoice_payment_details'] + + JSON.parse(response.to_json, object_class: OpenStruct) + end + def whitelist_params(params) result = { payment_status: params[:payment_status], diff --git a/spec/lago/api/resources/invoice_spec.rb b/spec/lago/api/resources/invoice_spec.rb index 4fe1452..d92f9dd 100644 --- a/spec/lago/api/resources/invoice_spec.rb +++ b/spec/lago/api/resources/invoice_spec.rb @@ -261,4 +261,26 @@ expect(result).to eq(true) end end + + describe '#payment_url' do + let(:url_response) do + { + 'invoice_payment_details' => { + 'payment_url' => 'https://example.com', + } + }.to_json + end + + before do + stub_request(:post, "https://api.getlago.com/api/v1/invoices/#{invoice_id}/payment_url") + .with(body: {}) + .to_return(body: url_response, status: 200) + end + + it 'returns payment url' do + result = resource.payment_url(invoice_id) + + expect(result.payment_url).to eq('https://example.com') + end + end end