Skip to content

Commit

Permalink
feat(disputes): Add invoice lose dispute (#182)
Browse files Browse the repository at this point in the history
  • Loading branch information
ivannovosad authored Apr 11, 2024
1 parent 1561dd2 commit 1ba770b
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 2 deletions.
6 changes: 4 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
lago-ruby-client (1.0.0)
lago-ruby-client (1.1.0)
jwt
openssl

Expand All @@ -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
Expand All @@ -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)
Expand Down
7 changes: 7 additions & 0 deletions lib/lago/api/resources/invoice.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions spec/fixtures/api/invoice.json
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
18 changes: 18 additions & 0 deletions spec/lago/api/resources/invoice_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 1ba770b

Please sign in to comment.