Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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).
Comment | File | Size | Author |
---|---|---|---|
#15 | commerce_stripe-process-refunds-2418701-15.patch | 8.7 KB | torgosPizza |
#5 | drupal_debug_v_1_18_0.txt | 59.11 KB | pnigro |
#5 | drupal_debug_v_1_17_5.txt | 27.67 KB | pnigro |
Comments
Comment #1
pnigro CreditAttribution: pnigro commentedThank 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
Comment #2
andyg5000Hey 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!
Comment #3
andyg5000Hey 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!
Comment #4
andyg5000Comment #5
pnigro CreditAttribution: pnigro commentedHello 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
Comment #6
andyg5000I'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
Comment #7
andyg5000Ah 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).
Comment #8
andyg5000Alright 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 )
Comment #9
pnigro CreditAttribution: pnigro commentedHey 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
Comment #10
aviindub CreditAttribution: aviindub commentedhi 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
Comment #11
aviindub CreditAttribution: aviindub commentedComment #12
torgosPizzaBumping this and moving back to 7.x-1.x.. I will test on our environment as well.
Comment #13
torgosPizzaTested and working perfectly in latest API version, even worked on a partial refund. Awesome work! Setting RTBC.
Comment #14
mxwitkowski CreditAttribution: mxwitkowski commentedHi - 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.
Comment #15
torgosPizzaHow 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.
Comment #16
mxwitkowski CreditAttribution: mxwitkowski commented@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!
Comment #17
torgosPizzaGlad to hear it! Hopefully @aviindub can review it and push a commit soon.
Comment #20
aviindub CreditAttribution: aviindub commentedignore that first one, i screwed something up there. should be good to go.