diff --git a/CHANGELOG.md b/CHANGELOG.md index d9bf6563..467856e0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ * Added ability to read and write custom invoice notes [115](https://github.com/recurly/recurly-client-php/pull/115) * Added vat_location_valid field to Account [127](https://github.com/recurly/recurly-client-php/pull/127) * Added updateNotes() and vat_reverse_charge to Subscription. Added vat_reverse_charge_notes to Invoice. [128](https://github.com/recurly/recurly-client-php/pull/128) +* Added `invoice_number_prefix` and `invoiceNumberWithPrefix()` to `Invoice`. This is to be used with the Country Invoice Sequencing feature. [130](https://github.com/recurly/recurly-client-php/pull/130) ## Version 2.3.1 (Sept 26th, 2014) diff --git a/Tests/Recurly/Invoice_Test.php b/Tests/Recurly/Invoice_Test.php index 96f38cf8..9c8c6c11 100644 --- a/Tests/Recurly/Invoice_Test.php +++ b/Tests/Recurly/Invoice_Test.php @@ -7,19 +7,20 @@ class Recurly_InvoiceTest extends Recurly_TestCase function defaultResponses() { return array( - array('GET', '/invoices/abcdef1234567890', 'invoices/show-200.xml'), + array('GET', '/invoices/1001', 'invoices/show-200.xml'), + array('GET', '/invoices/1002', 'invoices/show-with-prefix-200.xml'), ); } public function testGetInvoice() { - $invoice = Recurly_Invoice::get('abcdef1234567890', $this->client); + $invoice = Recurly_Invoice::get('1001', $this->client); $this->assertInstanceOf('Recurly_Invoice', $invoice); $this->assertInstanceOf('Recurly_Stub', $invoice->account); $this->assertInstanceOf('Recurly_Stub', $invoice->subscription); $this->assertEquals($invoice->state, 'collected'); $this->assertEquals($invoice->total_in_cents, 2995); - $this->assertEquals($invoice->getHref(),'https://api.recurly.com/v2/invoices/abcdef1234567890'); + $this->assertEquals($invoice->getHref(),'https://api.recurly.com/v2/invoices/1001'); $this->assertInstanceOf('Recurly_TransactionList', $invoice->transactions); $this->assertEquals($invoice->transactions->current()->uuid, '012345678901234567890123456789ab'); $this->assertEquals($invoice->transactions->count(), 1); @@ -27,6 +28,15 @@ public function testGetInvoice() { $this->assertEquals($invoice->terms_and_conditions, 'Some Terms and Conditions'); $this->assertEquals($invoice->customer_notes, 'Some Customer Notes'); $this->assertEquals($invoice->vat_reverse_charge_notes, 'Some VAT Notes'); + $this->assertEquals($invoice->invoice_number_prefix, ''); + $this->assertEquals($invoice->invoiceNumberWithPrefix(), '1001'); + } + + public function testGetInvoiceWithPrefix() { + $invoice = Recurly_Invoice::get('1002', $this->client); + $this->assertEquals($invoice->invoice_number, '1002'); + $this->assertEquals($invoice->invoice_number_prefix, 'GB'); + $this->assertEquals($invoice->invoiceNumberWithPrefix(), 'GB1002'); } public function testInvoicePendingCharges() { @@ -91,24 +101,24 @@ public function testMarkSuccessful() { // - Recurly_Resource::_save() passes the current XML into the PUT which // doesn't seem quite right but I don't want to change it without // understanding what side effects it would have. - $this->client->addResponse('PUT', 'https://api.recurly.com/v2/invoices/abcdef1234567890/mark_successful', 'invoices/mark_successful-200.xml'); + $this->client->addResponse('PUT', 'https://api.recurly.com/v2/invoices/1001/mark_successful', 'invoices/mark_successful-200.xml'); - $invoice = Recurly_Invoice::get('abcdef1234567890', $this->client); + $invoice = Recurly_Invoice::get('1001', $this->client); $invoice->markSuccessful(); $this->assertEquals($invoice->state, 'collected'); } public function testMarkFailed() { // See the notes in testMarkSuccessful(). - $this->client->addResponse('PUT', 'https://api.recurly.com/v2/invoices/abcdef1234567890/mark_failed', 'invoices/mark_failed-200.xml'); + $this->client->addResponse('PUT', 'https://api.recurly.com/v2/invoices/1001/mark_failed', 'invoices/mark_failed-200.xml'); - $invoice = Recurly_Invoice::get('abcdef1234567890', $this->client); + $invoice = Recurly_Invoice::get('1001', $this->client); $invoice->markFailed(); $this->assertEquals($invoice->state, 'failed'); } public function testGetInvoicePdf() { - $result = Recurly_Invoice::getInvoicePdf('abcdef1234567890', 'en-GB', $this->client); - $this->assertEquals(array('/invoices/abcdef1234567890', 'en-GB'), $result); + $result = Recurly_Invoice::getInvoicePdf('1001', 'en-GB', $this->client); + $this->assertEquals(array('/invoices/1001', 'en-GB'), $result); } } diff --git a/Tests/fixtures/invoices/create-201.xml b/Tests/fixtures/invoices/create-201.xml index a34ff31e..288a469e 100644 --- a/Tests/fixtures/invoices/create-201.xml +++ b/Tests/fixtures/invoices/create-201.xml @@ -8,6 +8,7 @@ Location: https://api.recurly.com/v2/invoices/created-invoice 012345678901234567890123456789ab open 1000 + USD 300 300 diff --git a/Tests/fixtures/invoices/mark_failed-200.xml b/Tests/fixtures/invoices/mark_failed-200.xml index 299ecd20..feb898aa 100644 --- a/Tests/fixtures/invoices/mark_failed-200.xml +++ b/Tests/fixtures/invoices/mark_failed-200.xml @@ -2,11 +2,12 @@ HTTP/1.1 200 OK Content-Type: application/xml; charset=utf-8 - + 012345678901234567890123456789aa failed - abcdef1234567890 + 1001 + 2995 @@ -17,7 +18,7 @@ Content-Type: application/xml; charset=utf-8 - + 012345678901234567890123456789ab invoiced Silver Plan diff --git a/Tests/fixtures/invoices/mark_successful-200.xml b/Tests/fixtures/invoices/mark_successful-200.xml index abe1c1f4..3385d5ad 100644 --- a/Tests/fixtures/invoices/mark_successful-200.xml +++ b/Tests/fixtures/invoices/mark_successful-200.xml @@ -2,11 +2,12 @@ HTTP/1.1 200 OK Content-Type: application/xml; charset=utf-8 - + 012345678901234567890123456789aa collected - abcdef1234567890 + 1001 + 2995 @@ -17,7 +18,7 @@ Content-Type: application/xml; charset=utf-8 - + 012345678901234567890123456789ab invoiced Silver Plan diff --git a/Tests/fixtures/invoices/preview-200.xml b/Tests/fixtures/invoices/preview-200.xml index a5c40605..71564a37 100644 --- a/Tests/fixtures/invoices/preview-200.xml +++ b/Tests/fixtures/invoices/preview-200.xml @@ -7,6 +7,7 @@ Content-Type: application/xml; charset=utf-8 012345678901234567890123456789ab open 1000 + USD 300 300 diff --git a/Tests/fixtures/invoices/show-200.xml b/Tests/fixtures/invoices/show-200.xml index 01269ecd..f492f99f 100644 --- a/Tests/fixtures/invoices/show-200.xml +++ b/Tests/fixtures/invoices/show-200.xml @@ -2,12 +2,13 @@ HTTP/1.1 200 OK Content-Type: application/xml; charset=utf-8 - + 012345678901234567890123456789aa collected - abcdef1234567890 + 1001 + 2995 @@ -25,7 +26,7 @@ Content-Type: application/xml; charset=utf-8 - + 012345678901234567890123456789ab invoiced @@ -48,7 +49,7 @@ Content-Type: application/xml; charset=utf-8 - + 012345678901234567890123456789ab purchase diff --git a/Tests/fixtures/invoices/show-with-prefix-200.xml b/Tests/fixtures/invoices/show-with-prefix-200.xml new file mode 100644 index 00000000..a0fd816c --- /dev/null +++ b/Tests/fixtures/invoices/show-with-prefix-200.xml @@ -0,0 +1,101 @@ +HTTP/1.1 200 OK +Content-Type: application/xml; charset=utf-8 + + + + + + 012345678901234567890123456789aa + collected + 1002 + GB + + + 2995 + 0 + 2995 + USD + 2012-05-28T17:44:13Z + 2012-05-28T17:44:13Z + 0 + automatic + usst + Some Terms and Conditions + Some Customer Notes + Some VAT Notes + + + + + + 012345678901234567890123456789ab + invoiced + Silver Plan + + + plan + 2995 + 1 + 0 + 0 + 2995 + USD + false + 2012-05-28T17:44:13Z + 2013-05-28T17:44:13Z + 2012-05-28T17:44:13Z + + + + + + + + 012345678901234567890123456789ab + purchase + 2995 + 0 + USD + success + credit_card + 12345 + subscription + false + true + true + true + Match + Street address and postal code match. + Y + Y + 2012-05-28T17:44:13Z +
+ + 1 + John + Doe + + john@example.com + + + + + + + + + + + + Visa + 2013 + 1 + 411111 + 1111 + + +
+ +
+
+
diff --git a/Tests/fixtures/subscriptions/preview-200-change.xml b/Tests/fixtures/subscriptions/preview-200-change.xml index 2c87d9f2..d920c8ba 100644 --- a/Tests/fixtures/subscriptions/preview-200-change.xml +++ b/Tests/fixtures/subscriptions/preview-200-change.xml @@ -31,6 +31,7 @@ Content-Type: application/xml; charset=utf-8 abcdefg123 open + 5000 diff --git a/lib/recurly/invoice.php b/lib/recurly/invoice.php index f2720a9d..ad4408ce 100644 --- a/lib/recurly/invoice.php +++ b/lib/recurly/invoice.php @@ -70,6 +70,10 @@ public function markFailed() { $this->_save(Recurly_Client::PUT, $this->uri() . '/mark_failed'); } + public function invoiceNumberWithPrefix() { + return $this->invoice_number_prefix . $this->invoice_number; + } + protected function getNodeName() { return 'invoice'; } @@ -80,10 +84,11 @@ protected function getRequiredAttributes() { return array(); } protected function uri() { + $invoiceNumberWithPrefix = $this->invoiceNumberWithPrefix(); if (!empty($this->_href)) return $this->getHref(); - else if (!empty($this->invoice_number)) - return Recurly_Invoice::uriForInvoice($this->invoice_number); + else if (!empty($invoiceNumberWithPrefix)) + return Recurly_Invoice::uriForInvoice($invoiceNumberWithPrefix); else throw new Recurly_Error("Invoice number not specified"); }