-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #317 from recurly/api_version_2_6
API Version 2.6
- Loading branch information
Showing
43 changed files
with
532 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
<?php | ||
|
||
class Recurly_PurchaseTest extends Recurly_TestCase | ||
{ | ||
function defaultResponses() { | ||
return array( | ||
array('POST', '/purchases', 'purchases/create-201.xml'), | ||
array('POST', '/purchases/preview', 'purchases/preview-200.xml'), | ||
); | ||
} | ||
|
||
public function mockPurchase() { | ||
$purchase = new Recurly_Purchase(); | ||
$purchase->currency = 'USD'; | ||
$purchase->collection_method = 'automatic'; | ||
$purchase->account = new Recurly_Account(); | ||
$purchase->account->account_code = 'aba9209a-aa61-4790-8e61-0a2692435fee'; | ||
$purchase->account->address->phone = "555-555-5555"; | ||
$purchase->account->address->email = "[email protected]"; | ||
$purchase->account->address->address1 = "123 Main St."; | ||
$purchase->account->address->city = "San Francisco"; | ||
$purchase->account->address->state = "CA"; | ||
$purchase->account->address->zip = "94110"; | ||
$purchase->account->address->country = "US"; | ||
|
||
$adjustment = new Recurly_Adjustment(); | ||
$adjustment->product_code = "abcd123"; | ||
$adjustment->unit_amount_in_cents = 1000; | ||
$adjustment->currency = 'USD'; | ||
$adjustment->quantity = 1; | ||
$adjustment->revenue_schedule_type = 'at_invoice'; | ||
|
||
$purchase->adjustments[] = $adjustment; | ||
|
||
return $purchase; | ||
} | ||
|
||
public function testXml() { | ||
$purchase = $this->mockPurchase(); | ||
|
||
$this->assertEquals( | ||
"<?xml version=\"1.0\"?>\n<purchase><account><account_code>aba9209a-aa61-4790-8e61-0a2692435fee</account_code><address><address1>123 Main St.</address1><city>San Francisco</city><state>CA</state><zip>94110</zip><country>US</country><phone>555-555-5555</phone></address></account><adjustments><adjustment><currency>USD</currency><unit_amount_in_cents>1000</unit_amount_in_cents><quantity>1</quantity><revenue_schedule_type>at_invoice</revenue_schedule_type><product_code>abcd123</product_code></adjustment></adjustments><collection_method>automatic</collection_method><currency>USD</currency></purchase>\n", | ||
$purchase->xml() | ||
); | ||
} | ||
|
||
public function testInvoicePurchase() { | ||
$purchase = $this->mockPurchase(); | ||
$invoice = Recurly_Purchase::invoice($purchase, $this->client); | ||
|
||
$this->assertInstanceOf('Recurly_Invoice', $invoice); | ||
$this->assertEquals('3d8648fcf2be67ed304ff242d6bbb9d4', $invoice->uuid); | ||
} | ||
|
||
public function testPreviewPurchase() { | ||
$purchase = $this->mockPurchase(); | ||
$invoice = Recurly_Purchase::preview($purchase, $this->client); | ||
|
||
$this->assertInstanceOf('Recurly_Invoice', $invoice); | ||
$this->assertNull($invoice->uuid); | ||
} | ||
|
||
public function testTransactionError() { | ||
$this->client->addResponse('POST', '/purchases', 'purchases/create-422.xml'); | ||
$purchase = $this->mockPurchase(); | ||
|
||
try { | ||
$invoice = Recurly_Purchase::invoice($purchase, $this->client); | ||
$this->fail('Purchase should throw transaction exception but it threw no exception'); | ||
} catch (Recurly_ValidationError $e) { | ||
$this->assertEquals($e->getMessage(), 'Credit card number is not valid.'); | ||
$this->assertInstanceOf('Recurly_TransactionError', $e->errors->transaction_error); | ||
$this->assertInstanceOf('Recurly_Transaction', $e->errors->transaction); | ||
} catch (Exception $e) { | ||
print $e->getMessage(); | ||
$this->fail('Purchase should have thrown transaction exception'); | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
<?php | ||
|
||
|
||
class Recurly_ShippingAddressTest extends Recurly_TestCase | ||
{ | ||
function defaultResponses() { | ||
|
@@ -9,12 +8,9 @@ function defaultResponses() { | |
); | ||
} | ||
|
||
public function testCreateShippingAddressOnExistingAccount() { | ||
$account = Recurly_Account::get('abcdef1234567890', $this->client); | ||
$this->client->addResponse('POST', 'https://api.recurly.com/v2/accounts/abcdef1234567890/shipping_addresses', 'shipping_addresses/create-201.xml'); | ||
|
||
protected function mockShippingAddress() { | ||
$shad = new Recurly_ShippingAddress(); | ||
$shad->nickname = "Home"; | ||
$shad->nickname = "Work"; | ||
$shad->first_name = "Verena"; | ||
$shad->last_name = "Example"; | ||
$shad->phone = "555-555-5555"; | ||
|
@@ -24,6 +20,25 @@ public function testCreateShippingAddressOnExistingAccount() { | |
$shad->state = "CA"; | ||
$shad->zip = "94110"; | ||
$shad->country = "US"; | ||
$shad->company = "Recurly Inc."; | ||
|
||
return $shad; | ||
} | ||
|
||
public function testXml() { | ||
$shad = $this->mockShippingAddress(); | ||
|
||
$this->assertEquals( | ||
"<?xml version=\"1.0\"?>\n<shipping_address><address1>123 Dolores St.</address1><city>San Francisco</city><state>CA</state><zip>94110</zip><country>US</country><phone>555-555-5555</phone><email>[email protected]</email><nickname>Work</nickname><first_name>Verena</first_name><last_name>Example</last_name><company>Recurly Inc.</company></shipping_address>\n", | ||
$shad->xml() | ||
); | ||
} | ||
|
||
public function testCreateShippingAddressOnExistingAccount() { | ||
$account = Recurly_Account::get('abcdef1234567890', $this->client); | ||
$this->client->addResponse('POST', 'https://api.recurly.com/v2/accounts/abcdef1234567890/shipping_addresses', 'shipping_addresses/create-201.xml'); | ||
|
||
$shad = $this->mockShippingAddress(); | ||
|
||
$account->createShippingAddress($shad, $this->client); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.