From 064bfcddf70ecdb76c67a6c75a991894fbc2192e Mon Sep 17 00:00:00 2001 From: jomz Date: Wed, 4 Dec 2019 03:43:59 +0100 Subject: [PATCH 1/3] Avoid returning the same InvoiceID (a.o.) for all payments from get_payments --- lib/xero_gateway/payment.rb | 6 +++--- test/integration/get_payments_test.rb | 7 +++++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/xero_gateway/payment.rb b/lib/xero_gateway/payment.rb index b49f9ac5..b03968fb 100644 --- a/lib/xero_gateway/payment.rb +++ b/lib/xero_gateway/payment.rb @@ -30,10 +30,10 @@ def self.from_xml(payment_element) when 'Reference' then payment.reference = element.text when 'CurrencyRate' then payment.currency_rate = BigDecimal(element.text) when 'Invoice' - payment.invoice_id = element.elements["//InvoiceID"].text - payment.invoice_number = element.elements["//InvoiceNumber"].text + payment.invoice_id = element.elements["InvoiceID"].text + payment.invoice_number = element.elements["InvoiceNumber"].text when 'IsReconciled' then payment.reconciled = (element.text == "true") - when 'Account' then payment.account_id = element.elements["//AccountID"].text + when 'Account' then payment.account_id = element.elements["AccountID"].text end end payment diff --git a/test/integration/get_payments_test.rb b/test/integration/get_payments_test.rb index 1c5296b0..27cd65e1 100644 --- a/test/integration/get_payments_test.rb +++ b/test/integration/get_payments_test.rb @@ -27,6 +27,13 @@ def test_get_payments assert_kind_of(XeroGateway::Payment, payment.first) end + def test_get_payments_gets_actual_invoice_ids + result = @gateway.get_payments + assert_not_equal result.payments[0].invoice_id, result.payments[1].invoice_id + # assert_equal result.payments[0].invoice_id, 'b0875d8b-ff26-4ce8-8aea-6955492ead48' + # assert_equal result.payments[1].invoice_id, '33c8d757-2db0-48a2-8daa-f54768fabeb1' + end + def test_get_payments_modified_since_date # Create a test payment @gateway.create_payment(create_test_payment) From 7a62bdaf8e8d718512728f811b1836ecd2b1865d Mon Sep 17 00:00:00 2001 From: Benny Degezelle Date: Mon, 23 Dec 2019 18:52:17 +0100 Subject: [PATCH 2/3] Add a Payment w/o InvoiceNumber to payments stub This breaks all payments tests as get_payment assumed Invoice.InvoiceNumber to not be nil... --- test/stub_responses/payments.xml | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/test/stub_responses/payments.xml b/test/stub_responses/payments.xml index c3684dd5..0ff25894 100644 --- a/test/stub_responses/payments.xml +++ b/test/stub_responses/payments.xml @@ -52,5 +52,27 @@ RPT469-1 + + d3b72ed1-4269-40a4-b0de-4be6fb3586c5 + 2019-12-29T00:00:00 + 142.00 + 1.000000 + ACCPAYPAYMENT + AUTHORISED + 2019-12-02T10:48:51.15 + + ac993f75-035b-433c-82e0-7b7a2d40802c + 090 + + + + 16b4cdc2-b36a-4b25-b9c8-7a50c17b10ba + Truxton Property Management + + NZD + ACCPAY + c475f4c3-2b8b-4d44-b4fc-cbe7ee6fa9dd + + From bb5a510a1d8eb5d59b9834bf3d43b44a7f6730d7 Mon Sep 17 00:00:00 2001 From: Benny Degezelle Date: Mon, 23 Dec 2019 18:56:29 +0100 Subject: [PATCH 3/3] Do not assume that all results from get_payments have a Invoice.InvoiceNumber --- lib/xero_gateway/payment.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/xero_gateway/payment.rb b/lib/xero_gateway/payment.rb index b03968fb..a5620c65 100644 --- a/lib/xero_gateway/payment.rb +++ b/lib/xero_gateway/payment.rb @@ -31,7 +31,7 @@ def self.from_xml(payment_element) when 'CurrencyRate' then payment.currency_rate = BigDecimal(element.text) when 'Invoice' payment.invoice_id = element.elements["InvoiceID"].text - payment.invoice_number = element.elements["InvoiceNumber"].text + payment.invoice_number = element.elements["InvoiceNumber"].try(:text) when 'IsReconciled' then payment.reconciled = (element.text == "true") when 'Account' then payment.account_id = element.elements["AccountID"].text end