From e5cc193b1ee7428fc771f2a0d2644736909c15a2 Mon Sep 17 00:00:00 2001 From: Petr Kopac Date: Tue, 2 May 2017 17:36:27 +0200 Subject: [PATCH] Adding List Invoices endpoint with spec (#39) * Adding List Invoices endpoint with spec * version 1.1.1 * Customer_uuid now on invoice in this case --- ...all_invoices_through_list_all_endpoint.yml | 46 +++++++++++++++++++ lib/chartmogul/invoice.rb | 16 +++++++ lib/chartmogul/version.rb | 2 +- spec/chartmogul/invoice_spec.rb | 10 ++++ 4 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 fixtures/vcr_cassettes/ChartMogul_Invoice/API_Interactions/returns_all_invoices_through_list_all_endpoint.yml diff --git a/fixtures/vcr_cassettes/ChartMogul_Invoice/API_Interactions/returns_all_invoices_through_list_all_endpoint.yml b/fixtures/vcr_cassettes/ChartMogul_Invoice/API_Interactions/returns_all_invoices_through_list_all_endpoint.yml new file mode 100644 index 0000000..b4f5b7f --- /dev/null +++ b/fixtures/vcr_cassettes/ChartMogul_Invoice/API_Interactions/returns_all_invoices_through_list_all_endpoint.yml @@ -0,0 +1,46 @@ +--- +http_interactions: +- request: + method: get + uri: https://api.chartmogul.com/v1/invoices?external_id=invoice_eid&per_page=10 + body: + encoding: US-ASCII + string: '' + headers: + User-Agent: + - Faraday v0.9.2 + Content-Type: + - application/json + Authorization: + - Basic MDFiNzI2YzI0ZjNiYjhlOTc0MmEwNGZiMDhhZmE3NzQ6NzJlNGMxYTdlZTFiYzlkNGZjMDBlZWUwNWIyN2QzMGY= + response: + status: + code: 200 + message: + headers: + server: + - nginx/1.9.10 + date: + - Wed, 29 Jun 2016 12:45:27 GMT + content-type: + - application/json + content-length: + - '1297' + connection: + - close + vary: + - Accept-Encoding + status: + - 200 OK + access-control-allow-credentials: + - 'true' + body: + encoding: UTF-8 + string: '{"invoices":[{"date":"2016-01-01 12:00:00 +0000","currency":"USD","line_items":[{"type":"subscription","subscription_external_id":"test_cus_sub_ext_id","plan_uuid":"pl_209e4674-1258-4a35-8378-9b15c4086965","service_period_start":"2016-01-01 + 12:00:00 +0000","service_period_end":"2016-02-01 12:00:00 +0000","amount_in_cents":1000,"cancelled_at":"2016-01-15 + 12:00:00 +0000","prorated":false,"quantity":5,"discount_amount_in_cents":1200,"discount_code":"DISCCODE","tax_amount_in_cents":200,"external_id":"test_cus_li_ext_id"}],"transactions":[{"type":"payment","date":"2016-01-01 + 12:00:00 +0000","result":"successful","external_id":"test_cus_tr_ext_id"}],"external_id":"invoice_eid","due_date":"2016-01-07 + 12:00:00 +0000","customer_uuid":"customer_uuid"}]}' + http_version: + recorded_at: Wed, 29 Jun 2016 12:45:27 GMT +recorded_with: VCR 3.0.3 diff --git a/lib/chartmogul/invoice.rb b/lib/chartmogul/invoice.rb index f329687..7c66484 100644 --- a/lib/chartmogul/invoice.rb +++ b/lib/chartmogul/invoice.rb @@ -1,6 +1,7 @@ module ChartMogul class Invoice < ChartMogul::Object readonly_attr :uuid + readonly_attr :customer_uuid writeable_attr :date, type: :time writeable_attr :currency @@ -58,5 +59,20 @@ def transaction_class(type) when 'refund' then ChartMogul::Transactions::Refund end end + + def self.all(options = {}) + Invoices.all(options) + end + end + class Invoices < APIResource + set_resource_name 'Invoices' + set_resource_path '/v1/invoices' + + set_resource_root_key :invoices + + include Concerns::Entries + include Concerns::Pageable2 + + set_entry_class Invoice end end diff --git a/lib/chartmogul/version.rb b/lib/chartmogul/version.rb index f48c0f0..e07b70a 100644 --- a/lib/chartmogul/version.rb +++ b/lib/chartmogul/version.rb @@ -1,3 +1,3 @@ module ChartMogul - VERSION = "1.1.0" + VERSION = "1.1.1" end diff --git a/spec/chartmogul/invoice_spec.rb b/spec/chartmogul/invoice_spec.rb index 9b57c8a..32753a2 100644 --- a/spec/chartmogul/invoice_spec.rb +++ b/spec/chartmogul/invoice_spec.rb @@ -225,4 +225,14 @@ ) end end + describe 'API Interactions', vcr: true do + it 'returns all invoices through list all endpoint', uses_api: true do + invoices = described_class.all(per_page: 10, external_id: "invoice_eid") + expect(invoices.instance_of? ChartMogul::Invoices).to be true + expect(invoices.size).to eq 1 + expect(invoices[0].instance_of? described_class).to be true + expect(invoices[0].external_id).to eq "invoice_eid" + expect(invoices[0].customer_uuid).to eq "customer_uuid" + end + end end