Skip to content

Commit

Permalink
Update purchase endpoint with new properties
Browse files Browse the repository at this point in the history
  • Loading branch information
bhelx committed Jul 13, 2017
1 parent 1bf0ae9 commit 10fd024
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 15 deletions.
8 changes: 1 addition & 7 deletions lib/recurly/adjustment.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ protected function createUriForAccount() {
}

protected function populateXmlDoc(&$doc, &$node, &$obj, $nested = false) {
if ($this->isEmbedded($node)) {
if ($this->isEmbedded($node, 'adjustments')) {
$adjustmentNode = $node->appendChild($doc->createElement($this->getNodeName()));
parent::populateXmlDoc($doc, $adjustmentNode, $obj);
} else {
Expand All @@ -99,10 +99,4 @@ protected function getWriteableAttributes() {
'revenue_schedule_type', 'origin', 'product_code'
);
}

private function isEmbedded($node) {
$path = explode('/', $node->getNodePath());
$last = $path[count($path)-1];
return $last == 'adjustments';
}
}
5 changes: 4 additions & 1 deletion lib/recurly/purchase.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
* @property string $currency The currency to use in this invoice
* @property string $po_number The po number for the invoice
* @property integer $net_terms The net terms of the invoice
* @property string[] $coupon_codes An array of coupon codes to apply to the purchase
* @property Recurly_Subscription[] $subscriptions An array of subscriptions to apply to the purchase
* @property Recurly_GiftCard $gift_card A gift card to apply to the purchase
*/
class Recurly_Purchase extends Recurly_Resource
{
Expand Down Expand Up @@ -42,7 +45,7 @@ protected function getNodeName() {
protected function getWriteableAttributes() {
return array(
'account', 'adjustments', 'collection_method', 'currency', 'po_number',
'net_terms'
'net_terms', 'subscriptions', 'gift_card', 'coupon_codes'
);
}
}
6 changes: 6 additions & 0 deletions lib/recurly/resource.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,12 @@ public function renderXML($doc) {
return $doc->saveXML(null, LIBXML_NOEMPTYTAG);
}

protected function isEmbedded($node, $xmlKey) {
$path = explode('/', $node->getNodePath());
$last = $path[count($path)-1];
return $last == $xmlKey;
}

protected function populateXmlDoc(&$doc, &$node, &$obj, $nested = false)
{
$attributes = $obj->getChangedAttributes($nested);
Expand Down
8 changes: 1 addition & 7 deletions lib/recurly/shipping_address.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,11 @@ protected function getWriteableAttributes() {
);
}
protected function populateXmlDoc(&$doc, &$node, &$obj, $nested = false) {
if ($this->isEmbedded($node)) {
if ($this->isEmbedded($node, 'shipping_addresses')) {
$shippingAddressNode = $node->appendChild($doc->createElement($this->getNodeName()));
parent::populateXmlDoc($doc, $shippingAddressNode, $obj);
} else {
parent::populateXmlDoc($doc, $node, $obj);
}
}

private function isEmbedded($node) {
$path = explode('/', $node->getNodePath());
$last = $path[count($path)-1];
return $last == 'shipping_addresses';
}
}
8 changes: 8 additions & 0 deletions lib/recurly/subscription.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,14 @@ protected static function uriForSubscription($uuid) {
return Recurly_Client::PATH_SUBSCRIPTIONS . '/' . rawurlencode($uuid);
}

protected function populateXmlDoc(&$doc, &$node, &$obj, $nested = false) {
if ($this->isEmbedded($node, 'subscriptions')) {
$subscriptionNode = $node->appendChild($doc->createElement($this->getNodeName()));
parent::populateXmlDoc($doc, $subscriptionNode, $obj);
} else {
parent::populateXmlDoc($doc, $node, $obj);
}
}
protected function getNodeName() {
return 'subscription';
}
Expand Down

0 comments on commit 10fd024

Please sign in to comment.