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

Enable refunds through gateway #44

Merged
merged 5 commits into from
Oct 2, 2020
Merged

Conversation

websupporter
Copy link
Member

Fixes #30

@websupporter websupporter changed the title [WIP] Enable refunds through gateway Enable refunds through gateway Sep 28, 2020
@mattallan mattallan self-assigned this Sep 29, 2020
@mattallan
Copy link
Contributor

I'm not sure if this is worth mentioning but I accidentally started testing refunds where my Woo store set to AUD currency and my PayPal Account set to USD and I had my PP account set up so that I had to accept all payments in a different currency.

This means all AUD orders were appearing in PayPal as "Unclaimed".

When I tried to make a refund on orders that hadn't been "accepted" yet, this resulted in the following notice https://d.pr/i/xfBLou and when I tried making a partial refund I got:

WARNING [UNPROCESSABLE_ENTITY] The requested action could not be performed, semantically incorrect, or failed business validation. https://developer.paypal.com/docs/api/payments/v2/#error-PARTIAL_REFUND_NOT_ALLOWED

I just wanted to check if this is working as expected or whether we have accounted for this case?


I haven't done any code review yet, mostly functional testing. Here are some issues that I've found so far:

  • When I tried refund that hasn't been captured yet I get the fatal errors below. I'm not sure if we need to implement voiding a payment that haven't been captured instead of trying to refund it. After getting this fatal, when I refreshed the page it said the order was refunded, but it was still on-hold and I was still able to capture the payment: https://d.pr/i/cCuOXr
[29-Sep-2020 07:10:37 UTC] PHP Notice:  Undefined offset: 0 in /Users/matt/local/store/wp-content/plugins/paypal-for-woocommerce/modules/ppcp-wc-gateway/src/Processor/class-refundprocessor.php on line 71
[29-Sep-2020 07:10:37 UTC] PHP Fatal error:  Uncaught Error: Call to a member function invoice_id() on null in /Users/matt/local/store/wp-content/plugins/paypal-for-woocommerce/modules/ppcp-wc-gateway/src/Processor/class-refundprocessor.php:74
Stack trace:
#0 /Users/matt/local/store/wp-content/plugins/paypal-for-woocommerce/modules/ppcp-wc-gateway/src/Gateway/class-creditcardgateway.php(249): WooCommerce\PayPalCommerce\WcGateway\Processor\RefundProcessor->process(Object(Automattic\WooCommerce\Admin\Overrides\Order), 64.95, 'tetst')
#1 /Users/matt/local/store/wp-content/plugins/woocommerce/includes/wc-order-functions.php(666): WooCommerce\PayPalCommerce\WcGateway\Gateway\CreditCardGateway->process_refund(5920, '64.95', 'tetst')
#2 /Users/matt/local/store/wp-content/plugins/woocommerce/includes/wc-order-functions.php(595): wc_refund_payment(Object(Automattic\WooCommerce\Admin\Overrides\Order), '64.95', 'tetst')
#3 /Users/matt/local/store/wp-content/plugins/woocommerce/includes/class-wc-ajax.php(1905): wc_create_refund(Array)
#4 /Users/matt/local/store/wp- in /Users/matt/local/store/wp-content/plugins/paypal-for-woocommerce/modules/ppcp-wc-gateway/src/Processor/class-refundprocessor.php on line 74
  • Refunding without a reason results in:
[29-Sep-2020 07:17:20 UTC] PHP Notice:  Undefined property: stdClass::$status_details in /Users/matt/local/store/wp-content/plugins/paypal-for-woocommerce/modules/ppcp-api-client/src/Factory/class-capturefactory.php on line 48
[29-Sep-2020 07:17:20 UTC] PHP Notice:  Trying to get property 'reason' of non-object in /Users/matt/local/store/wp-content/plugins/paypal-for-woocommerce/modules/ppcp-api-client/src/Factory/class-capturefactory.php on line 48

I haven't finished testing everything yet but I wanted to share these things while I continue looking at this PR :)

@websupporter
Copy link
Member Author

websupporter commented Sep 29, 2020

The two commits address the notices and fatals thrown. (Codestyle will be ok in next commit again)

@mattallan
Copy link
Contributor

Thanks @websupporter I've confirmed those issues have been resolved.

This is very close now! From my testing, I found one issue:

  • ❌ Try refunding an order that is pending payment
[30-Sep-2020 03:21:57 UTC] PHP Fatal error:  Uncaught Error: Call to a member function captures() on null in /Users/matt/local/store/wp-content/plugins/paypal-for-woocommerce/modules/ppcp-wc-gateway/src/Processor/class-refundprocessor.php:76
Stack trace:
#0 /Users/matt/local/store/wp-content/plugins/paypal-for-woocommerce/modules/ppcp-wc-gateway/src/Gateway/class-paypalgateway.php(339): WooCommerce\PayPalCommerce\WcGateway\Processor\RefundProcessor->process(Object(Automattic\WooCommerce\Admin\Overrides\Order), 64.95, 'Refunding a pen...')
#1 /Users/matt/local/store/wp-content/plugins/woocommerce/includes/wc-order-functions.php(666): WooCommerce\PayPalCommerce\WcGateway\Gateway\PayPalGateway->process_refund(5948, '64.95', 'Refunding a pen...')
#2 /Users/matt/local/store/wp-content/plugins/woocommerce/includes/wc-order-functions.php(595): wc_refund_payment(Object(Automattic\WooCommerce\Admin\Overrides\Order), '64.95', 'Refunding a pen...')
#3 /Users/matt/local/store/wp-content/plugins/woocommerce/includes/class-wc-ajax.php(1905): wc_create_refund(Array)
# in /Users/matt/local/store/wp-content/plugins/paypal-for-woocommerce/modules/ppcp-wc-gateway/src/Processor/class-refundprocessor.php on line 76

To reproduce:

  1. Enable PayPal Checkout gateway
  2. Add a product to the cart
  3. Visit the checkout and click on the PayPal button (which will create an order with pending payment status)
  4. Close the PayPal pop-up
  5. Visit the Edit Order page for this new Pending Payment order
  6. Try refund

Codestyle will be ok in next commit again

Okay, no worries.

It looks like there's just a small PHPCS issue:

FILE: ...r-woocommerce/modules/ppcp-api-client/src/Factory/class-capturefactory.php
--------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
--------------------------------------------------------------------------------
 45 | ERROR | [x] Space before opening parenthesis of function call prohibited

@websupporter websupporter added this to the 1.0 milestone Sep 30, 2020
@mattallan
Copy link
Contributor

Thanks for fixing that final thing @websupporter. This looks good to be merged 👍 🚀

@mattallan mattallan merged commit 5fa0c29 into master Oct 2, 2020
@AlexP11223 AlexP11223 deleted the issue-30-support-refunds branch August 1, 2022 06:28
@wazhoare wazhoare mentioned this pull request Mar 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Missing support for refunds through the Edit Order page
2 participants