Skip to content

Commit

Permalink
API v2.10 and Credit Memos
Browse files Browse the repository at this point in the history
  • Loading branch information
bhelx committed Mar 16, 2018
1 parent e39a28b commit 9902681
Show file tree
Hide file tree
Showing 29 changed files with 498 additions and 328 deletions.
15 changes: 15 additions & 0 deletions Tests/Recurly/CreditPaymentList_Test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

class Recurly_CreditPaymentListTest extends Recurly_TestCase
{
function defaultResponses() {
return array(
array('GET', '/credit_payments', 'credit_payments/index-200.xml')
);
}

function testCreditPaymentIndex() {
$credit_payments = Recurly_CreditPaymentList::get(null, $this->client);
$this->assertInstanceOf('Recurly_CreditPaymentList', $credit_payments);
}
}
14 changes: 14 additions & 0 deletions Tests/Recurly/Invoice_Collection_Test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

class Recurly_InvoiceCollectionTest extends Recurly_TestCase
{
public function testInvoiceCollectionDeserialization() {
$this->client->addResponse('GET', '/invoices/1001', 'invoices/show-200.xml');
$this->client->addResponse('PUT', 'https://api.recurly.com/v2/invoices/1001/mark_failed', 'invoices/mark_failed-200.xml');
$invoice = Recurly_Invoice::get('1001', $this->client);

$collection = $invoice->markFailed();
$this->assertInstanceOf('Recurly_Invoice', $collection->charge_invoice);
$this->assertInstanceOf('Recurly_Invoice', $collection->credit_invoices[0]);
}
}
12 changes: 6 additions & 6 deletions Tests/Recurly/Invoice_List_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,22 @@

class Recurly_InvoiceListTest extends Recurly_TestCase
{
public function testGetOpen() {
public function testGetPending() {
$params = array('other' => 'pickles');
$url = '/invoices?other=pickles&state=open';
$url = '/invoices?other=pickles&state=pending';
$this->client->addResponse('GET', $url, 'invoices/index-200.xml');

$invoices = Recurly_InvoiceList::getOpen($params, $this->client);
$invoices = Recurly_InvoiceList::getPending($params, $this->client);
$this->assertInstanceOf('Recurly_InvoiceList', $invoices);
$this->assertEquals($url, $invoices->getHref());
}

public function testGetCollected() {
public function testGetPaid() {
$params = array('other' => 'pickles');
$url = '/invoices?other=pickles&state=collected';
$url = '/invoices?other=pickles&state=paid';
$this->client->addResponse('GET', $url, 'invoices/index-200.xml');

$invoices = Recurly_InvoiceList::getCollected($params, $this->client);
$invoices = Recurly_InvoiceList::getPaid($params, $this->client);
$this->assertInstanceOf('Recurly_InvoiceList', $invoices);
$this->assertEquals($url, $invoices->getHref());
}
Expand Down
10 changes: 5 additions & 5 deletions Tests/Recurly/Invoice_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public function testGetInvoice() {
$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->state, 'paid');
$this->assertEquals($invoice->total_in_cents, 2995);
$this->assertEquals($invoice->getHref(),'https://api.recurly.com/v2/invoices/1001');
$this->assertInstanceOf('Recurly_TransactionList', $invoice->transactions);
Expand Down Expand Up @@ -104,24 +104,24 @@ public function testMarkSuccessful() {

$invoice = Recurly_Invoice::get('1001', $this->client);
$invoice->markSuccessful();
$this->assertEquals($invoice->state, 'collected');
$this->assertEquals($invoice->state, 'paid');
}

public function testForceCollect() {
$this->client->addResponse('PUT', 'https://api.recurly.com/v2/invoices/1001/collect', 'invoices/force_collect-200.xml');

$invoice = Recurly_Invoice::get('1001', $this->client);
$invoice->forceCollect();
$this->assertEquals($invoice->state, 'collected');
$this->assertEquals($invoice->state, 'paid');
}

public function testMarkFailed() {
// See the notes in testMarkSuccessful().
$this->client->addResponse('PUT', 'https://api.recurly.com/v2/invoices/1001/mark_failed', 'invoices/mark_failed-200.xml');

$invoice = Recurly_Invoice::get('1001', $this->client);
$invoice->markFailed();
$this->assertEquals($invoice->state, 'failed');
$collection = $invoice->markFailed();
$this->assertEquals($collection->charge_invoice->state, 'failed');
}

public function testGetInvoicePdf() {
Expand Down
22 changes: 12 additions & 10 deletions Tests/Recurly/Purchase_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,31 +52,33 @@ public function testXml() {

public function testInvoicePurchase() {
$purchase = $this->mockPurchase();
$invoice = Recurly_Purchase::invoice($purchase, $this->client);
$collection = Recurly_Purchase::invoice($purchase, $this->client);

$this->assertInstanceOf('Recurly_Invoice', $invoice);
$this->assertEquals('3d8648fcf2be67ed304ff242d6bbb9d4', $invoice->uuid);
$this->assertInstanceOf('Recurly_InvoiceCollection', $collection);
$this->assertInstanceOf('Recurly_Invoice', $collection->charge_invoice);
$this->assertEquals('3d8648fcf2be67ed304ff242d6bbb9d4', $collection->charge_invoice->uuid);
}

public function testPreviewPurchase() {
$purchase = $this->mockPurchase();
$invoice = Recurly_Purchase::preview($purchase, $this->client);
$collection = Recurly_Purchase::preview($purchase, $this->client);

$this->assertInstanceOf('Recurly_Invoice', $invoice);
$this->assertNull($invoice->uuid);
$this->assertInstanceOf('Recurly_InvoiceCollection', $collection);
$this->assertInstanceOf('Recurly_Invoice', $collection->charge_invoice);
$this->assertNull($collection->charge_invoice->uuid);
}

public function testAuthorizePurchase() {
$purchase = $this->mockPurchase();
$purchase->account->email = 'benjamin.dumonde@example.com';
$purchase->account->billing_info->external_hpp_type = 'adyen';
$invoice = Recurly_Purchase::authorize($purchase, $this->client);
$collection = Recurly_Purchase::authorize($purchase, $this->client);

$this->assertInstanceOf('Recurly_Invoice', $invoice);
$this->assertNull($invoice->uuid);
$this->assertInstanceOf('Recurly_InvoiceCollection', $collection);
$this->assertInstanceOf('Recurly_Invoice', $collection->charge_invoice);
$this->assertNull($collection->charge_invoice->uuid);
}


public function testTransactionError() {
$this->client->addResponse('POST', '/purchases', 'purchases/create-422.xml');
$purchase = $this->mockPurchase();
Expand Down
15 changes: 15 additions & 0 deletions Tests/fixtures/credit_payments/index-200.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
HTTP/1.1 200 OK
Content-Type: application/xml; charset=utf-8

<?xml version="1.0" encoding="UTF-8"?>
<credit_payments>
<credit_payment href="https://api.recurly.com/v2/adjustments/abcdef1234567890">
<account href="https://api.recurly.com/v2/accounts/account"/>
<uuid>abcdef1234567890</uuid>
<amount_in_cents type="integer">1200</amount_in_cents>
<currency>USD</currency>
<created_at type="datetime">2018-08-31T03:30:00Z</created_at>
<updated_at type="datetime">2018-04-30T07:00:00Z</updated_at>
<voided_at type="datetime">2018-04-30T07:00:00Z</voided_at>
</credit_payment>
</credit_payments>
2 changes: 1 addition & 1 deletion Tests/fixtures/invoices/create-201.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Location: https://api.recurly.com/v2/invoices/created-invoice
<invoice href="https://api.recurly.com/v2/invoices/012345678901234567890123456789ab">
<account href="https://api.recurly.com/v2/accounts/abcdef1234567890"/>
<uuid>012345678901234567890123456789ab</uuid>
<state>open</state>
<state>pending</state>
<invoice_number type="integer">1000</invoice_number>
<invoice_number_prefix></invoice_number_prefix>
<currency>USD</currency>
Expand Down
2 changes: 1 addition & 1 deletion Tests/fixtures/invoices/force_collect-200.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Content-Type: application/xml; charset=utf-8
<invoice href="https://api.recurly.com/v2/invoices/1001">
<account href="https://api.recurly.com/v2/accounts/1"/>
<uuid>012345678901234567890123456789aa</uuid>
<state>collected</state>
<state>paid</state>
<invoice_number type="integer">1001</invoice_number>
<invoice_number_prefix></invoice_number_prefix>
<po_number nil="nil"></po_number>
Expand Down
6 changes: 3 additions & 3 deletions Tests/fixtures/invoices/index-200.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Content-Type: application/xml; charset=utf-8
</address>
<subscription href="https://api.recurly.com/v2/subscriptions/32558dd8a07eec471fbe6642d3a422f4"/>
<uuid>32558dd8acf30242475046443c8149ed</uuid>
<state>collected</state>
<state>paid</state>
<invoice_number_prefix></invoice_number_prefix>
<invoice_number type="integer">1002</invoice_number>
<po_number nil="nil"></po_number>
Expand Down Expand Up @@ -70,7 +70,7 @@ Content-Type: application/xml; charset=utf-8
</address>
<subscription href="https://api.recurly.com/v2/subscriptions/313928798e08cf7d2403b34ed1954801"/>
<uuid>31392879f497d0230dd39640b786b223</uuid>
<state>collected</state>
<state>paid</state>
<invoice_number_prefix></invoice_number_prefix>
<invoice_number type="integer">1000</invoice_number>
<po_number nil="nil"></po_number>
Expand Down Expand Up @@ -281,7 +281,7 @@ Content-Type: application/xml; charset=utf-8
</address>
<subscription href="https://api.recurly.com/v2/subscriptions/30fb3db268a0ddbf62753a4cce8bfa7e"/>
<uuid>30fb3db2766a00f1f6cc2043f59bd43a</uuid>
<state>collected</state>
<state>paid</state>
<invoice_number_prefix></invoice_number_prefix>
<invoice_number type="integer">1001</invoice_number>
<po_number nil="nil"></po_number>
Expand Down
105 changes: 73 additions & 32 deletions Tests/fixtures/invoices/mark_failed-200.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,40 +2,81 @@ HTTP/1.1 200 OK
Content-Type: application/xml; charset=utf-8

<?xml version="1.0" encoding="UTF-8"?>
<invoice href="https://api.recurly.com/v2/invoices/1001">
<account href="https://api.recurly.com/v2/accounts/1"/>
<uuid>012345678901234567890123456789aa</uuid>
<state>failed</state>
<invoice_number type="integer">1001</invoice_number>
<invoice_number_prefix></invoice_number_prefix>
<po_number nil="nil"></po_number>
<vat_number nil="nil"></vat_number>
<subtotal_in_cents type="integer">2995</subtotal_in_cents>
<tax_in_cents type="integer">0</tax_in_cents>
<total_in_cents type="integer">2995</total_in_cents>
<currency>USD</currency>
<created_at type="datetime">2012-05-28T17:44:13Z</created_at>
<line_items type="array">
<adjustment href="https://api.recurly.com/v2/adjustments/190357944dad4d461272774dd184a17e" type="charge">
<invoice_collection>
<charge_invoice>
<account href="https://api.recurly.com/v2/accounts/1"/>
<uuid>012345678901234567890123456789aa</uuid>
<state>failed</state>
<invoice_number type="integer">1001</invoice_number>
<invoice_number_prefix></invoice_number_prefix>
<po_number nil="nil"></po_number>
<vat_number nil="nil"></vat_number>
<subtotal_in_cents type="integer">2995</subtotal_in_cents>
<tax_in_cents type="integer">0</tax_in_cents>
<total_in_cents type="integer">2995</total_in_cents>
<currency>USD</currency>
<created_at type="datetime">2012-05-28T17:44:13Z</created_at>
<line_items type="array">
<adjustment href="https://api.recurly.com/v2/adjustments/190357944dad4d461272774dd184a17e" type="charge">
<account href="https://api.recurly.com/v2/accounts/1"/>
<invoice href="https://api.recurly.com/v2/invoices/1001"/>
<uuid>012345678901234567890123456789ab</uuid>
<state>invoiced</state>
<description>Silver Plan</description>
<accounting_code></accounting_code>
<origin>plan</origin>
<unit_amount_in_cents type="integer">2995</unit_amount_in_cents>
<quantity type="integer">1</quantity>
<discount_in_cents type="integer">0</discount_in_cents>
<tax_in_cents type="integer">0</tax_in_cents>
<total_in_cents type="integer">2995</total_in_cents>
<currency>USD</currency>
<taxable type="boolean">false</taxable>
<start_date type="datetime">2012-05-28T17:44:13Z</start_date>
<end_date type="datetime">2013-05-28T17:44:13Z</end_date>
<created_at type="datetime">2012-05-28T17:44:13Z</created_at>
</adjustment>
</line_items>
<transactions type="array">
</transactions>
</charge_invoice>
<credit_invoices type="array">
<invoice>
<account href="https://api.recurly.com/v2/accounts/1"/>
<invoice href="https://api.recurly.com/v2/invoices/1001"/>
<uuid>012345678901234567890123456789ab</uuid>
<state>invoiced</state>
<description>Silver Plan</description>
<accounting_code></accounting_code>
<origin>plan</origin>
<unit_amount_in_cents type="integer">2995</unit_amount_in_cents>
<quantity type="integer">1</quantity>
<discount_in_cents type="integer">0</discount_in_cents>
<uuid>012345678901234567890123456789aa</uuid>
<state>failed</state>
<invoice_number type="integer">1001</invoice_number>
<invoice_number_prefix></invoice_number_prefix>
<po_number nil="nil"></po_number>
<vat_number nil="nil"></vat_number>
<subtotal_in_cents type="integer">2995</subtotal_in_cents>
<tax_in_cents type="integer">0</tax_in_cents>
<total_in_cents type="integer">2995</total_in_cents>
<currency>USD</currency>
<taxable type="boolean">false</taxable>
<start_date type="datetime">2012-05-28T17:44:13Z</start_date>
<end_date type="datetime">2013-05-28T17:44:13Z</end_date>
<created_at type="datetime">2012-05-28T17:44:13Z</created_at>
</adjustment>
</line_items>
<transactions type="array">
</transactions>
</invoice>
<line_items type="array">
<adjustment href="https://api.recurly.com/v2/adjustments/190357944dad4d461272774dd184a17e" type="charge">
<account href="https://api.recurly.com/v2/accounts/1"/>
<invoice href="https://api.recurly.com/v2/invoices/1001"/>
<uuid>012345678901234567890123456789ab</uuid>
<state>invoiced</state>
<description>Silver Plan</description>
<accounting_code></accounting_code>
<origin>plan</origin>
<unit_amount_in_cents type="integer">2995</unit_amount_in_cents>
<quantity type="integer">1</quantity>
<discount_in_cents type="integer">0</discount_in_cents>
<tax_in_cents type="integer">0</tax_in_cents>
<total_in_cents type="integer">2995</total_in_cents>
<currency>USD</currency>
<taxable type="boolean">false</taxable>
<start_date type="datetime">2012-05-28T17:44:13Z</start_date>
<end_date type="datetime">2013-05-28T17:44:13Z</end_date>
<created_at type="datetime">2012-05-28T17:44:13Z</created_at>
</adjustment>
</line_items>
<transactions type="array">
</transactions>
</invoice>
</credit_invoices>
</invoice_collection>
2 changes: 1 addition & 1 deletion Tests/fixtures/invoices/mark_successful-200.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Content-Type: application/xml; charset=utf-8
<invoice href="https://api.recurly.com/v2/invoices/1001">
<account href="https://api.recurly.com/v2/accounts/1"/>
<uuid>012345678901234567890123456789aa</uuid>
<state>collected</state>
<state>paid</state>
<invoice_number type="integer">1001</invoice_number>
<invoice_number_prefix></invoice_number_prefix>
<po_number nil="nil"></po_number>
Expand Down
2 changes: 1 addition & 1 deletion Tests/fixtures/invoices/preview-200.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Content-Type: application/xml; charset=utf-8
<invoice href="">
<account href="https://api.recurly.com/v2/accounts/abcdef1234567890"/>
<uuid>012345678901234567890123456789ab</uuid>
<state>open</state>
<state>pending</state>
<invoice_number type="integer">1000</invoice_number>
<invoice_number_prefix></invoice_number_prefix>
<currency>USD</currency>
Expand Down
4 changes: 2 additions & 2 deletions Tests/fixtures/invoices/refund-201.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ HTTP/1.1 201 Created
Content-Type: application/xml; charset=utf-8
Location: https://api.recurly.com/v2/invoices/created-invoice

<invoice href="https://api.recurly.com/v2/invoices/1001">
<invoice>
<account href="https://api.recurly.com/v2/accounts/1"/>
<subscription href="https://api.recurly.com/v2/subscriptions/1234567890abcdef"/>
<uuid>012345678901234567890123456789aa</uuid>
<state>collected</state>
<state>paid</state>
<invoice_number type="integer">abcdef1234567890</invoice_number>
<po_number></po_number>
<vat_number></vat_number>
Expand Down
2 changes: 1 addition & 1 deletion Tests/fixtures/invoices/show-200.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Content-Type: application/xml; charset=utf-8
<account href="https://api.recurly.com/v2/accounts/1"/>
<subscription href="https://api.recurly.com/v2/subscriptions/1234567890abcdef"/>
<uuid>012345678901234567890123456789aa</uuid>
<state>collected</state>
<state>paid</state>
<invoice_number type="integer">1001</invoice_number>
<invoice_number_prefix></invoice_number_prefix>
<po_number></po_number>
Expand Down
Loading

0 comments on commit 9902681

Please sign in to comment.