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

Support open amount and line item refunds #133

Merged
merged 1 commit into from
Feb 6, 2015
Merged

Conversation

bhelx
Copy link
Contributor

@bhelx bhelx commented Jan 13, 2015

This pull request is to support both open amount and line item refunds on Invoice.

Approvers: @drewish

Testing

Open Amount:

$invoice = Recurly_Invoice::get('1002');  // get some invoice
$ref = $invoice->refundAmount(100);      // refund some amount in cents
var_dump($ref); // verify the returned refund invoice is correct

Line Item [WIP]:

// get some invoice, preferably with multiple line items
$invoice = Recurly_Invoice::get('1002');

// grab out which ever ones you want to refund
$line_items = $invoice->line_items;

// You probably want to build new adjustment objects
// rather than modifying your existing line items
// and passing those in
$adjustment_map = function($line_item) {
  return $line_item->toRefundAttributes();
};
$refunds = array_map($adjustment_map, $line_items);

$ref = $invoice->refund($refunds); // create a refund invoice from refund attributes
var_dump($ref);   // verify the returned refund invoice is correct

@bhelx bhelx changed the title [WIP] Support open amount refunds Support open amount refunds Jan 14, 2015
@bhelx bhelx force-pushed the open_amount_refund branch 2 times, most recently from 129ec0c to 537e5dc Compare January 19, 2015 18:20
public function refundAmount($amount_in_cents) {
$uri = $this->uri() . '/refund';

$invoice = new self();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any objection to naming this $refund or $refund_invoice?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, sounds good. That's what I am doing in other branch. Will change.

@bhelx bhelx changed the title Support open amount refunds Support open amount and line item refunds Jan 29, 2015
return new DOMDocument("1.0");
}

public function renderXML($doc) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this whole refactoring.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@bhelx bhelx force-pushed the open_amount_refund branch 2 times, most recently from 5c56093 to cce6048 Compare February 5, 2015 19:52
@drewish
Copy link

drewish commented Feb 5, 2015

I think we need to ensure that the adjustment has an invoice. If you try to refund an un-invoiced charge:

Recurly_Adjustment::get('2cca2c8255f0d5582af2aa4eed9c26a9')->refund(2, true);
Fatal error: Call to a member function get() on a non-object in /Users/andrew/projects/recurly-client-php/lib/recurly/adjustment.php on line 38

@bhelx
Copy link
Contributor Author

bhelx commented Feb 5, 2015

Good point

drewish added a commit that referenced this pull request Feb 6, 2015
Support open amount and line item refunds
@drewish drewish merged commit 3625632 into master Feb 6, 2015
@drewish
Copy link

drewish commented Feb 6, 2015

+1

@drewish drewish deleted the open_amount_refund branch February 6, 2015 21:58
@bhelx bhelx mentioned this pull request Feb 9, 2015
@bhelx bhelx added the V2 V2 Client label Mar 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
V2 V2 Client
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants