Code refactoring, simplifying the 'process_refund' method#157
Merged
Conversation
Contributor
Author
|
Here is a use case after this refactoring. By adding this line, it will enable payment methods to be able to create a refund on WooCommerce user interface. |
jonrandy
suggested changes
Mar 20, 2020
jonrandy
left a comment
There was a problem hiding this comment.
A couple of English things, and a function name
7cbc10f to
01ecf2a
Compare
jonrandy
suggested changes
Apr 2, 2020
Contributor
Author
jonrandy
approved these changes
Apr 3, 2020
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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_refundmethod 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_refundmethod out fromOmise_Payment_TruemoneyandOmise_Payment_Creditcardclasses (move to its parent class, Omise_Payment).Implementing the
process_refundmethod 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_refundcode 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_refundmethod.There will be 3 more PRs coming.
Make use of
$reasonvariable that is in the 3rd argument ofprocess_refund. (in WooCommerce, you can add a reason of refunding, which we can pass thatreasonto themetadataparameter when creating a new Refund object)Adding refund feature to
AlipayandInstallmentpayment 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.