From 1ba770b3ab38aa34c6abab6f9f832eb294b6a7d3 Mon Sep 17 00:00:00 2001 From: Ivan Novosad Date: Thu, 11 Apr 2024 14:53:19 +0200 Subject: [PATCH] feat(disputes): Add invoice lose dispute (#182) --- Gemfile.lock | 6 ++++-- lib/lago/api/resources/invoice.rb | 7 +++++++ spec/fixtures/api/invoice.json | 1 + spec/lago/api/resources/invoice_spec.rb | 18 ++++++++++++++++++ 4 files changed, 30 insertions(+), 2 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 6d41fce..be395f3 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - lago-ruby-client (1.0.0) + lago-ruby-client (1.1.0) jwt openssl @@ -16,6 +16,7 @@ GEM addressable (2.8.1) public_suffix (>= 2.0.2, < 6.0) ast (2.4.2) + base64 (0.2.0) concurrent-ruby (1.2.2) crack (0.4.5) rexml @@ -31,7 +32,8 @@ GEM io-console (0.6.0) irb (1.6.3) reline (>= 0.3.0) - jwt (2.7.1) + jwt (2.8.1) + base64 minitest (5.19.0) openssl (3.2.0) parallel (1.22.1) diff --git a/lib/lago/api/resources/invoice.rb b/lib/lago/api/resources/invoice.rb index a307eab..6b41072 100644 --- a/lib/lago/api/resources/invoice.rb +++ b/lib/lago/api/resources/invoice.rb @@ -42,6 +42,13 @@ def finalize(invoice_id) JSON.parse(response.to_json, object_class: OpenStruct).invoice end + def lose_dispute(invoice_id) + path = "/api/v1/invoices/#{invoice_id}/lose_dispute" + response = connection.put(path, identifier: nil, body: {}) + + JSON.parse(response.to_json, object_class: OpenStruct).invoice + end + def retry_payment(invoice_id) path = "/api/v1/invoices/#{invoice_id}/retry_payment" response = connection.post({}, path) diff --git a/spec/fixtures/api/invoice.json b/spec/fixtures/api/invoice.json index af942f6..bb69411 100644 --- a/spec/fixtures/api/invoice.json +++ b/spec/fixtures/api/invoice.json @@ -4,6 +4,7 @@ "sequential_id": 15, "number": "LAG-1234-001-002", "issuing_date": "2022-06-02", + "payment_dispute_lost_at": "2022-04-29T08:59:51Z", "payment_due_date": "2022-06-02", "invoice_type": "one_off", "version_number": 2, diff --git a/spec/lago/api/resources/invoice_spec.rb b/spec/lago/api/resources/invoice_spec.rb index d92f9dd..f87d280 100644 --- a/spec/lago/api/resources/invoice_spec.rb +++ b/spec/lago/api/resources/invoice_spec.rb @@ -248,6 +248,24 @@ end end + describe '#lose_dispute' do + let(:response_body) do + { 'invoice' => factory_invoice.to_h } + end + + before do + stub_request(:put, "https://api.getlago.com/api/v1/invoices/#{invoice_id}/lose_dispute") + .with(body: {}).to_return(body: invoice_response, status: 200) + end + + it 'returns invoice' do + invoice = resource.lose_dispute(invoice_id) + + expect(invoice.lago_id).to eq(invoice_id) + expect(invoice.payment_dispute_lost_at).to eq('2022-04-29T08:59:51Z') + end + end + describe '#retry_payment' do before do stub_request(:post, "https://api.getlago.com/api/v1/invoices/#{invoice_id}/retry_payment")