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
MAG1: Refactoring payment processor classes #92
Merged
Merged
Conversation
This file contains 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
… payment processor, move it to the parent class.
guzzilar
force-pushed
the
1-refactor-payment-processor
branch
2 times, most recently
from
October 25, 2017 10:04
53fc535
to
a3a26d7
Compare
Note that this commit is quite big because there are 3 parts in 1 commit. 1. Remove all 'strategy' patterns / classes. The main purpose of having 'strategy' class was to avoid 'authorize', 'capture' methods to take care lots of tasks, like, 'check if this payment requires 3-D Secure payment', 'build request params', 'create charge', 'validate result', 'handle if failed case', 'handle if successful case'. However, I've figured out that it would be more simple if just have another class, 'Model/Api/Charge' to taking care some of those validation part (and it makes totally sense that 'Charge object itself taking care on validation itself) and delegate 'common' logic that use to create charge into 'parent' method (please check Model/Payment::process() method for more detail). 2. Refactor payment processors (Model/Payment/Creditcard.php, Model/Payment/Offsiteinternetbanking.php). According to [1], once introduced 'Model/Api/Charge' and removed 'Model/Strategies/'. Now we can make those payment processors more simple, also more readable. 3. Clean up some unused properties / methods in those payment processor and parent classes.
…se) class to reduce duplicated code.
guzzilar
force-pushed
the
1-refactor-payment-processor
branch
from
October 25, 2017 10:27
a3a26d7
to
54eedc4
Compare
Since now we are using 'Model/Api/Charge' and 'Model/Api/Error' classes in the payment processor classes. This commit is to apply those approach to 'manual capture' action.
tested on Magento v1.9.3.6 |
👍 |
guzzilar
changed the title
[WIP] MAG1: Refactoring payment processor classes
MAG1: Refactoring payment processor classes
Oct 26, 2017
Merged
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
As for coming of the new payment method, Alipay payment, and Webhook feature.
Now we can see some of common logics that will be used again and again in another new payment method. Means, if we just continue implement those features right away with the previous approach, it will just make code more huge and hard to maintain.
So, this PR aims to clean up unnecessary/unused code, refactoring and preparing structure for those new coming features.
2. Description of change
There are 3 main parts that you should consider.
Get rid of duplicated code, locate methods to proper class / location.
Refactoring payment processor classes.
Remove all 'strategy' patterns / classes.
The main purpose of having 'strategy' class was to avoid
authorize
,capture
methods to take care too much of tasks. For example 'check if this payment requires 3-D Secure payment', 'build request params', 'create charge', 'validate result', 'handle if failed case', 'handle if successful case'.However, I've figured out that it would be more simple if just have another class, 'Model/Api/Charge' to taking care some of those validation part (and it makes totally sense that 'Charge object itself taking care on validation itself) and delegate 'common' logic that use to create charge into 'parent' method (please check Model/Payment::process() method for more detail).
Introduced 'Model/Api/Charge'.
According to [2.1], now we can make those payment processors more simple, also more readable by moving those validations back into
Model_Api_Charge
object (as mentioned in [1], it makes totally sense thatCharge object
itself taking care of its validation).It also allows us to write some methods inside to make code can be reusable.
Considering:
Here, those Credit Card, InternetBanking, Alipay can reuse this class without worrying about maintain repeatedly writing 'validation' code again and again.
Move some charge creation logics into parent class (
Model/Payment.php
).Refactoring offsite validation controllers (Credit Card 3-D Secure, Internet Banking), move some duplicated code into the parent class. This is a preparation to reduce duplicated code when Alipay and Webhook feature come.
3. Quality assurance
🔧 Environments:
v5.6.30
v1.9.2.4
,v1.9.3.6
✏️ Details:
Make sure that you can still make charge with Credit Card payment method.
Make sure that you can still make charge with Internet Banking payment method on both failed and successful cases.
Make sure that those payment methods can still handle
error
andfailed
case properly.4. Impact of the change
No
5. Priority of change
Normal
6. Additional Notes
No