Here's a patch that adds the ability to process refunds on the original stripe transaction through the commerce orders payment tab.

Note that this patch uses $charge->refund( ) because the $charge->refunds->create() method mentioned in the documentation was not available in the Stripe PHP (version 1.18.0).

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

pnigro’s picture

Thank you for the patch andyg5000. The refund is successfully applied to the original transaction on Stripe. However, the refund amount is $0 on the commerce order payment tab. The following errors are displayed after a refund is processed as shown in the picture.

Notice: Trying to get property of non-object in commerce_stripe_refund_form_submit() (line 115 of C:\xampp\htdocs\local\sites\all\modules\commerce_stripe\includes\commerce_stripe.admin.inc).

Notice: Trying to get property of non-object in commerce_stripe_refund_form_submit() (line 130 of C:\xampp\htdocs\local\sites\all\modules\commerce_stripe\includes\commerce_stripe.admin.inc).

Notice: Trying to get property of non-object in commerce_stripe_refund_form_submit() (line 131 of C:\xampp\htdocs\local\sites\all\modules\commerce_stripe\includes\commerce_stripe.admin.inc).

Patch was tested with:
Commerce Stripe version = "7.x-1.0-rc7+13-dev" - 2015-Jan-21
Stripe PHP version = 1.18.0 and 1.17.5

Thank you,
Paul

andyg5000’s picture

Status: Needs review » Needs work

Hey Paul,

It looks like you're not getting the same response from stripe API that I was when I wrote the patch. I'll investigate with the info you provided and update the patch.

Thanks!

andyg5000’s picture

Hey Paul,

I noticed that my dblog had the following error, which may be related to your issue:

Notice: Indirect modification of overloaded property Stripe_Charge::$refunds has no effect in commerce_stripe_refund_form_submit() (line 108 of .../commerce_stripe/includes/commerce_stripe.admin.inc).

Can you try this patch and let me know if it solves the problem?

If not, can you do a var_dump/print_r of the response object (around line 105 of commerce_stripe.admin.inc) and send me the results? Strip out any sensitive information beforehand.

Thanks for testing!

andyg5000’s picture

Status: Needs work » Needs review
pnigro’s picture

Hello andyg5000,

I tried patch #2 and the same errors are present. Attached are the response objects you requested. One is with Stripe PHP 1.17.5 and the other is with 1.18.0. Thank you for a great feature. If you need any more help testing please let me know.

Thanks
Paul

andyg5000’s picture

Status: Needs review » Needs work

I'm using the exact same libraries, but receiving a different response from Stripe somehow.

Stripe module = 7.x-1.x-dev
Stripe PHP library = 1.18.0 2015-01-21

In yours, the refunds are
[refunds] => Stripe_List Object

In mine, the refunds are
[refunds] => Array

Also, the documentation for refunds https://stripe.com/docs/api?lang=php#create_refund doesn't work on my end. I'm wondering if it would for you.

I'll let you know what I figure out

andyg5000’s picture

Ah ha! I didn't realize you specify the API version in your stripe account as well. Can you tell me which version your running (stripe.com > account > api keys > version listed at top).

andyg5000’s picture

Status: Needs work » Needs review
FileSize
8.67 KB

Alright Paul. I think we got this all figured out :) Thanks for your feedback and testing!

I also made the following improvements:

Load the charge object from stripe to show the user how much they can actually refund
Use the actual charge object balance for form validation
Use the new Stripe API method for creating a refund
Create our own payload object to prevent saving the api keys in the payment transaction data

Note this patch requires that you set the API version of your account on stripe.com's website to 2015-01-26 ( under API settings )

pnigro’s picture

Hey Andy,

Ah, that makes sense! It's always the little things. I tested patch #8 with API Version 2014-12-17 and 2015-01-26 and it works perfectly.
Thank you so much for this feature.

Paul

aviindub’s picture

hi guys, thanks for the patch. this is a great feature.

unfortunately, we are not accepting new features in the 1.0 branch. i will definitely get this patched in the 2.0 branch as soon as the remaining blockers to 1.0 are cleared. if you want to help with that, take a look here https://www.drupal.org/node/2329471#comment-9621457

aviindub’s picture

Version: 7.x-1.x-dev » 7.x-2.x-dev
torgosPizza’s picture

Version: 7.x-2.x-dev » 7.x-1.x-dev

Bumping this and moving back to 7.x-1.x.. I will test on our environment as well.

torgosPizza’s picture

Status: Needs review » Reviewed & tested by the community

Tested and working perfectly in latest API version, even worked on a partial refund. Awesome work! Setting RTBC.

mxwitkowski’s picture

Hi - I applied patch #8 and noticed that the new file created 'commerce_stripe.admin.inc' was created in the module directory - however the code in the patch indicates that is should have been created in a new 'includes' subdirectory? Something looks incorrect with my applicaiton of the patch.

torgosPizza’s picture

How did you apply the patch? I found it works best if you go into /commerce_stripe/ and issue the command:

patch -p1 < commerce_stripe-add_ability_to_process_refunds-2418701-7.patch

It worked for me and did create /includes with the admin.inc file in it, but I did notice that the current patch has a /dev/null in it. Could be related.

Here's a re-roll which should work better for you. Make sure you revert the previous patch first, and delete the erroneous admin.inc file.

mxwitkowski’s picture

@torgosPizza - thanks for the update. I was able to apply the patch and tested successfully. By the way, I decided to my Stripe API version to: 2015-04-07 and all looks to be working well for charges, full refunds, and partial refunds.

All is looking good for this patch from my point of view and testing. YEAH!

torgosPizza’s picture

Glad to hear it! Hopefully @aviindub can review it and push a commit soon.

  • aviindub committed efab64b on 7.x-1.x authored by andyg5000
    Issue #2418701 by andyg5000: Add ability to process refunds from the...

  • aviindub committed 44e48c3 on 7.x-1.x
    Revert "Issue #2418701 by andyg5000: Add ability to process refunds from...
  • aviindub committed fdcf203 on 7.x-1.x authored by andyg5000
    Issue #2418701 by andyg5000: Add ability to process refunds from the...
aviindub’s picture

Status: Reviewed & tested by the community » Fixed

ignore that first one, i screwed something up there. should be good to go.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.