Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions lib/killbill_client/models/account.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,17 @@ def paginated_bundles(account_id, offset = 0, limit = 100, audit = "NONE", optio
Bundle
end

def paginated_invoices(account_id, offset = 0, limit = 100, audit = "NONE", options = {})
# By default, invoices in a page are shallow (no items), i.e. amount, balance, etc. are 0.
# Set include_invoice_components to load the components of the invoices of the requested page only.
def paginated_invoices(account_id, offset = 0, limit = 100, audit = "NONE", options = {}, include_invoice_components = false)
params = {
:offset => offset,
:limit => limit,
:audit => audit
}
params[:includeInvoiceComponents] = true if include_invoice_components
get "#{KILLBILL_API_ACCOUNTS_PREFIX}/#{account_id}/invoices/pagination",
{
:offset => offset,
:limit => limit,
:audit => audit
},
params,
options,
Invoice
end
Expand Down
37 changes: 37 additions & 0 deletions spec/killbill_client/account_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
require 'spec_helper'

describe KillBillClient::Model::Account do

def json_response(body)
response = Net::HTTPOK.new('1.1', '200', 'OK')
response['Content-Type'] = 'application/json'
response.instance_variable_set(:@read, true)
response.instance_variable_set(:@body, body)
response
end

describe '.paginated_invoices' do
let(:account_id) { 'e6f0d4ab-0d2b-4a8f-9a5c-0a8f5b1c2d3e' }
let(:uri) { "/1.0/kb/accounts/#{account_id}/invoices/pagination" }

it 'does not request invoice components by default' do
expect(KillBillClient::API).to receive(:get)
.with(uri, {:offset => 0, :limit => 100, :audit => 'NONE'}, {:api_key => 'key'})
.and_return(json_response('[]'))

described_class.paginated_invoices(account_id, 0, 100, 'NONE', {:api_key => 'key'})
end

it 'requests invoice components when asked to' do
expect(KillBillClient::API).to receive(:get)
.with(uri, {:offset => 10, :limit => 50, :audit => 'NONE', :includeInvoiceComponents => true}, {:api_key => 'key'})
.and_return(json_response('[{"invoiceId":"abc","amount":12.5,"balance":2.5}]'))

invoices = described_class.paginated_invoices(account_id, 10, 50, 'NONE', {:api_key => 'key'}, true)

expect(invoices.size).to eq(1)
expect(invoices.first.amount).to eq(12.5)
expect(invoices.first.balance).to eq(2.5)
end
end
end
Loading