New refund method in EDD_Payment

Last week we released version 2.5.7 of Easy Digital Downloads. In case you missed it, it was a pretty significant bug fix release with 24 fixes, a few tweaks, and 3 new enhancements. One of the major enhancements was the addition of a refund() method within the EDD_Payment class added in version 2.5. Today I want to give you a detailed look at using this method and what happens when running it for a payment.

General Usage

At the end of the day, the purpose of EDD_Payment is abstracting all the work of interacting with payments, to make it as easy as possible for developers to integrate with EDD as a platform. With that in mind, refunding a payment is as simple as:

$payment = new EDD_Payment( 123 );
$payment->refund();

And that’s all there is to it. The supplied method handles all the status updates and runs all the necessary changes to earnings and sales stats. Which is what leads us to why this becomes more powerful for developers.

Note: When processing a refund in EDD the refund request may not be sent to the payment gateway. This is gateway dependent and needs to be supported by the gateway extension.

Filtering the refund process

In previous versions of Easy Digital Downloads, the task of refunding a payment was reserved only for payments moving from Completed or Revoked. Outside of those two statuses, EDD would not process the necessary actions other than updating the status. We’ve added some filters in place to allow developers to allow their custom payment statuses to also run as refunds, and handle earnings and sales stats accordingly.

https://gist.github.com/cklosowski/a36607655301c2af9b64

Still Final

Since we’re still finalizing all of the details of using EDD_Payment, we’re going to be keeping the Final keyword on the class for a little longer. The addition of these types of methods allows us to get closer to having a fully abstracted interaction with payments. As always if you have feedback leave it in the comments or hop on over to GitHub and let us know how we can improve this development feature.

Leave a Reply

Your email address will not be published. Required fields are marked *