Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update notes path and vat_reverse_charge_notes #128

Merged
merged 1 commit into from
Jan 8, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
* Added invoice previews: `Recurly_Invoice::previewPendingCharges('<accountCode>');` [112](https://github.com/recurly/recurly-client-php/pull/112)
* 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)

## Version 2.3.1 (Sept 26th, 2014)

Expand Down
7 changes: 5 additions & 2 deletions Tests/Recurly/Invoice_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public function testGetInvoice() {
$this->assertEquals($invoice->tax_type, 'usst');
$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');
}

public function testInvoicePendingCharges() {
Expand All @@ -41,6 +42,7 @@ public function testInvoicePendingCharges() {
$this->assertEquals($invoice->getHref(),'https://api.recurly.com/v2/invoices/012345678901234567890123456789ab');
$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');
}

public function testFailedInvoicePendingCharges() {
Expand All @@ -66,8 +68,9 @@ public function testPreviewPendingCharges() {
$this->assertEquals($invoice->currency, 'USD');
$this->assertEquals($invoice->total_in_cents, 300);
$this->assertEquals($invoice->getHref(), Null);
$this->assertEquals($invoice->terms_and_conditions, "New Terms");
$this->assertEquals($invoice->customer_notes, "New Notes");
$this->assertEquals($invoice->terms_and_conditions, 'New Terms');
$this->assertEquals($invoice->customer_notes, 'New Notes');
$this->assertEquals($invoice->vat_reverse_charge_notes, 'New VAT Notes');
}

public function testFailedPreviewPendingCharges() {
Expand Down
16 changes: 16 additions & 0 deletions Tests/Recurly/Subscription_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public function testGetSubscription() {
$this->assertEquals('usst', $subscription->tax_type);
$this->assertEquals('Some Terms and Conditions', $subscription->terms_and_conditions);
$this->assertEquals('Some Customer Notes', $subscription->customer_notes);
$this->assertEquals('Some VAT Notes', $subscription->vat_reverse_charge_notes);

# TODO: Should test the rest of the parsing.
}
Expand Down Expand Up @@ -175,4 +176,19 @@ public function testPreviewChangeSubscription() {
$this->assertEquals('5000', $subscription->cost_in_cents);
$this->assertEquals('gold', $subscription->plan_code);
}

public function testUpdateNotes() {
$this->client->addResponse('GET', '/subscriptions/012345678901234567890123456789ab', 'subscriptions/show-200.xml');
$this->client->addResponse('PUT', 'https://api.recurly.com/v2/subscriptions/012345678901234567890123456789ab/notes', 'subscriptions/show-200-changed-notes.xml');

$subscription = Recurly_Subscription::get('012345678901234567890123456789ab', $this->client);

$notes = array("customer_notes" => "New Customer Notes", "terms_and_condititions" => "New Terms", "vat_reverse_charge_notes" => "New VAT Notes");

$subscription->updateNotes($notes);

foreach($notes as $key => $value) {
$this->assertEquals($subscription->$key, $value);
}
}
}
1 change: 1 addition & 0 deletions Tests/fixtures/invoices/create-201.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ Location: https://api.recurly.com/v2/invoices/created-invoice
<subtotal_in_cents type="integer">300</subtotal_in_cents>
<terms_and_conditions>Some Terms and Conditions</terms_and_conditions>
<customer_notes>Some Customer Notes</customer_notes>
<vat_reverse_charge_notes>Some VAT Notes</vat_reverse_charge_notes>
</invoice>
1 change: 1 addition & 0 deletions Tests/fixtures/invoices/preview-200.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ Content-Type: application/xml; charset=utf-8
<subtotal_in_cents type="integer">300</subtotal_in_cents>
<terms_and_conditions>New Terms</terms_and_conditions>
<customer_notes>New Notes</customer_notes>
<vat_reverse_charge_notes>New VAT Notes</vat_reverse_charge_notes>
</invoice>
1 change: 1 addition & 0 deletions Tests/fixtures/invoices/show-200.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Content-Type: application/xml; charset=utf-8
<tax_type>usst</tax_type>
<terms_and_conditions>Some Terms and Conditions</terms_and_conditions>
<customer_notes>Some Customer Notes</customer_notes>
<vat_reverse_charge_notes>Some VAT Notes</vat_reverse_charge_notes>
<line_items type="array">
<adjustment href="https://api.recurly.com/v2/adjustments/012345678901234567890123456789ab" type="charge">
<account href="https://api.recurly.com/v2/accounts/1"/>
Expand Down
40 changes: 40 additions & 0 deletions Tests/fixtures/subscriptions/show-200-changed-notes.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
HTTP/1.1 200 OK
Content-Type: application/xml; charset=utf-8

<?xml version="1.0" encoding="UTF-8"?>
<subscription href="https://api.recurly.com/v2/subscriptions/012345678901234567890123456789ab">
<account href="https://api.recurly.com/v2/accounts/verena"/>
<plan href="https://api.recurly.com/v2/plans/silver">
<plan_code>silver</plan_code>
<name>Silver Plan</name>
</plan>
<uuid>012345678901234567890123456789ab</uuid>
<state>active</state>
<net_terms type="integer">10</net_terms>
<collection_method>manual</collection_method>
<po_number>1000</po_number>
<quantity type="integer">1</quantity>
<total_amount_in_cents type="integer">1000</total_amount_in_cents>
<activated_at type="datetime">2011-04-30T07:00:00Z</activated_at>
<canceled_at nil="nil"></canceled_at>
<expires_at nil="nil"></expires_at>
<current_period_started_at type="datetime">2011-04-01T07:00:00Z</current_period_started_at>
<current_period_ends_at type="datetime">2011-05-01T06:59:59Z</current_period_ends_at>
<trial_started_at nil="nil"></trial_started_at>
<trial_ends_at nil="nil"></trial_ends_at>
<tax_in_cents type="integer">0</tax_in_cents>
<tax_type>usst</tax_type>
<terms_and_conditions>New Terms</terms_and_conditions>
<customer_notes>New Customer Notes</customer_notes>
<vat_reverse_charge_notes>New VAT Notes</vat_reverse_charge_notes>
<subscription_add_ons type="array">
<subscription_add_on>
<name>IP Addresses</name>
<add_on_code>ipaddresses</add_on_code>
<unit_amount_in_cents type="integer">200</unit_amount_in_cents>
<quantity type="integer">2</quantity>
</subscription_add_on>
</subscription_add_ons>
<a name="cancel" href="https://api.recurly.com/v2/subscriptions/012345678901234567890123456789ab/cancel" method="put"/>
<a name="terminate" href="https://api.recurly.com/v2/subscriptions/012345678901234567890123456789ab/terminate" method="put"/>
</subscription>
1 change: 1 addition & 0 deletions Tests/fixtures/subscriptions/show-200.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Content-Type: application/xml; charset=utf-8
<tax_type>usst</tax_type>
<terms_and_conditions>Some Terms and Conditions</terms_and_conditions>
<customer_notes>Some Customer Notes</customer_notes>
<vat_reverse_charge_notes>Some VAT Notes</vat_reverse_charge_notes>
<subscription_add_ons type="array">
<subscription_add_on>
<name>IP Addresses</name>
Expand Down
12 changes: 3 additions & 9 deletions lib/recurly/invoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class Recurly_Invoice extends Recurly_Resource

public static function init()
{
Recurly_Invoice::$_writeableAttributes = array('terms_and_conditions', 'customer_notes');
Recurly_Invoice::$_writeableAttributes = array('terms_and_conditions', 'customer_notes', 'vat_reverse_charge_notes');
Recurly_Invoice::$_nestedAttributes = array('account','line_items','transactions');
}

Expand Down Expand Up @@ -48,10 +48,7 @@ public static function getInvoicePdf($invoiceNumber, $locale = null, $client = n
public static function invoicePendingCharges($accountCode, $attributes = array(), $client = null) {
$uri = Recurly_Client::PATH_ACCOUNTS . '/' . rawurlencode($accountCode) . Recurly_Client::PATH_INVOICES;
$invoice = new self();
foreach($attributes as $key => $value) {
$invoice->$key = $value;
}
return self::_post($uri, $invoice->xml(), $client);
return self::_post($uri, $invoice->setValues($attributes)->xml(), $client);
}

/**
Expand All @@ -63,10 +60,7 @@ public static function invoicePendingCharges($accountCode, $attributes = array()
public static function previewPendingCharges($accountCode, $attributes = array(), $client = null) {
$uri = Recurly_Client::PATH_ACCOUNTS . '/' . rawurlencode($accountCode) . Recurly_Client::PATH_INVOICES . '/preview';
$invoice = new self();
foreach($attributes as $key => $value) {
$invoice->$key = $value;
}
return self::_post($uri, $invoice->xml(), $client);
return self::_post($uri, $invoice->setValues($attributes)->xml(), $client);
}

public function markSuccessful() {
Expand Down
13 changes: 12 additions & 1 deletion lib/recurly/resource.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,18 @@ public function getErrors() {
return $this->_errors;
}


/**
* Does a mass assignment on this resource's values
*
* @parameter array
* The array of values to set on the resource.
*/
public function setValues($values) {
foreach($values as $key => $value) {
$this->$key = $value;
}
return $this;
}

protected function _save($method, $uri)
{
Expand Down
12 changes: 11 additions & 1 deletion lib/recurly/subscription.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ public static function init()
'account','plan_code','coupon_code','unit_amount_in_cents','quantity',
'currency','starts_at','trial_ends_at','total_billing_cycles', 'first_renewal_date',
'timeframe', 'subscription_add_ons', 'net_terms', 'po_number', 'collection_method',
'cost_in_cents', 'remaining_billing_cycles', 'bulk', 'terms_and_conditions', 'customer_notes'
'cost_in_cents', 'remaining_billing_cycles', 'bulk', 'terms_and_conditions', 'customer_notes',
'vat_reverse_charge_notes'
);
Recurly_Subscription::$_nestedAttributes = array('account', 'subscription_add_ons');
}
Expand Down Expand Up @@ -100,6 +101,15 @@ public function postpone($nextRenewalDate, $bulk = false) {
$this->_save(Recurly_Client::PUT, $this->uri() . '/postpone?next_renewal_date=' . $nextRenewalDate . '&bulk=' . ((bool) $bulk));
}

/**
* Updates the notes fields of the subscription without generating a SubscriptionChange.
*
* @parameter array of notes, allowed keys: (customer_notes, terms_and_conditions, vat_reverse_charge_notes)
**/
public function updateNotes($notes) {
$this->setValues($notes)->_save(Recurly_Client::PUT, $this->uri() . '/notes');
}

protected function uri() {
if (!empty($this->_href))
return $this->getHref();
Expand Down