Closed guzzilar closed 4 years ago
Here is a use case after this refactoring. https://github.com/omise/omise-woocommerce/pull/158/files#diff-3f1dd1d765734b8bbc1ab3abf4d36ff6R12
By adding this line, it will enable payment methods to be able to create a refund on WooCommerce user interface.
@jonrandy thanks for pointing out 👍 Fixed here https://github.com/omise/omise-woocommerce/pull/157/commits/287dcb6e629deda65d0b38e4c4935ede0c198369
1. Objective
The main concept of this refactoring is about implementing the refund feature for Alipay and Installment. However, looking at the current code and found that the
process_refund
method has been implemented separately in Credit Card and TrueMoney Wallet payment methods.Therefore this pull request is submitted to reduce the duplicated code so we can easily implement the refund feature to those 2 payment methods without producing any more duplicated.
Related information: Related issue(s): T19965 (internal ticket)
2. Description of change
Removing
process_refund
method out fromOmise_Payment_Truemoney
andOmise_Payment_Creditcard
classes (move to its parent class, Omise_Payment).Implementing the
process_refund
method back to Omise_Payment class (so it can be shared between each payment method class that are supported for the refund feature.Tweaking messages that are related to the refund feature. Making it more lean, and less redundant, clearer message.
3. Quality assurance
🔧 Environments:
✏️ Details:
To make sure that this refactoring will not break any current feature, there are 3 main points we should cover. 1. Making sure we can make a refund using TrueMoney Wallet payment method. 1.1. After placed an order, at WooCommerce Order page, you can create a refund here.
1.2. If succeed, there will be a note that the order has been refunded.
1.3. Double check at Omise Dashboard to make sure that the refund has been done properly.
2. Making sure we can make a refund using Credit Card payment method.
3. Making sure we can make a refund using Credit Card payment method and the plugin can detect and add a proper note accordingly if that refund is being treated as voided.
Also, testing and making sure that the plugin can handle failure cases properly.
4. Making sure that the plugin will be raising a proper failure message in case if it cannot retrieve an order object from a given order ID.
By doing that, when you try to create a refund, the plugin will raise an error that, it cannot retrieve order from the given order ID.
5. You mat try modify another part of the
process_refund
code to see different cases of failure message. In this case, when the Omise Charge object cannot be retrieve. At the same file as the case [4], but adding a random string at the line 250.You will get an error message saying that charge cannot be retrieve.
6. Or, at the line 252 of the same file, you may add a random amount that make the refund failed.
By trying to create a refund with amount that is higher than its charge's amount, you will receive a message saying that refund failed.
7. Also, making sure that those orders that are placed using payment methods that don't support for the refund feature, won't be able to create a refund via Omise. Placing an order using Internet Banking payment method will not show "Refund via Omise" button at the order detail page.
4. Impact of the change
Nothing
5. Priority of change
Normal
6. Additional Notes
This PR is focusing on relocating the
process_refund
method. There will be 3 more PRs coming.Make use of
$reason
variable that is in the 3rd argument ofprocess_refund
. (in WooCommerce, you can add a reason of refunding, which we can pass thatreason
to themetadata
parameter when creating a new Refund object)Adding refund feature to
Alipay
andInstallment
payment methods.As from the internal ticket that WooCommerce cannot sync up refund status from Omise Dashboard. One more dedicated PR will be coming to handle this issue.