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

Refactoring offsite payment methods (introducing abstract offsite class) #143

Merged
merged 3 commits into from
Nov 11, 2019

Conversation

guzzilar
Copy link
Contributor

@guzzilar guzzilar commented Nov 4, 2019

1. Objective

Those implemented offsite payment methods (Alipay, Installment, Internet Banking, and TrueMoney Wallet) have almost an identical function on result and callback methods.
Having to implement each of them separately increasing the risk of human-error and potential malfunctions as the code could be changed/enhanced overtime.

As you can see from the screenshot below

Screen_Shot_2562-11-01_at_04 35 25

These 2, "TrueMoney" on the left, and "Alipay" on the right, are doing exactly the same thing.
However this code introduces an inconsistency as the code on the left (TrueMoney) has been developed and improved overtime while the code on the right (Alipay) screen remains the same as original, and becomes obsolete.

It must be a risk or unnecessarily if this abstract offsite class was introduced at the very beginning, as fixing one place will effect to all methods, and that may not be what we wanted.

However, after repetitively implemented 4 offsite payment methods, we can now be sure that they are doing the exact same thing and it should be safe to group them now.

Bonus point.
This is to reduce the work on localization as well, as it will be easier to make sure that we don't miss any translation or having any typo here and there in each of payment classes as we can group them into one single file, Omise_Payment_Offsite class.

2. Description of change

  1. Grouping all repetitive offsite methods into one abstract Omise_Payment_Offsite class.

  2. Removing all redundant code from class-omise-payment-alipay.php, class-omise-payment-installment.php, class-omise-payment-internetbanking.php, class-omise-payment-truemoney.php.

  3. Generalizing all offsite-payment messages, making it more generic and can be used all across the offsite payment methods.
    Screen Shot 2562-11-05 at 07 19 27

3. Quality assurance

🔧 Environments:

  • WooCommerce: v3.7.1
  • WordPress: v5.3.2
  • PHP version: 7.3.3

✏️ Details:

The test will be conducted and categorized into 5 main topics.

Note, the information below might be overwhelmed, basically, it is focusing on making sure that all 4 offsite payment methods are working properly in cases of "successful", "failure", and "pending".

1. General tests
1.1.) All payment methods can be enabled properly.
Screen Shot 2562-11-05 at 09 26 53

2. Placing order using Alipay payment method
We will go through the normal WooCommerce checkout process and test mark a particular charge as "successful", "failed", and "pending".
Successful case
Screen Shot 2562-11-05 at 09 39 56
Screen Shot 2562-11-05 at 09 40 15

Failure case
Failure code and message can be shown properly as before.
Screen Shot 2562-11-05 at 09 27 55
Screen Shot 2562-11-05 at 09 31 05

Pending case
Screen Shot 2562-11-05 at 09 47 04
Screen Shot 2562-11-05 at 09 47 23

3. Placing order using Installment payment method
We will go through the normal WooCommerce checkout process and test mark a particular charge as "successful", "failed", and "pending".
Successful case
Screen Shot 2562-11-05 at 10 02 53
Screen Shot 2562-11-05 at 10 03 12

Failure case
Screen Shot 2562-11-05 at 10 00 03
Screen Shot 2562-11-05 at 10 00 36

Pending case
Screen Shot 2562-11-05 at 09 49 52
Screen Shot 2562-11-05 at 09 50 09

4. Placing order using Internet Banking payment method
We will go through the normal WooCommerce checkout process and test mark a particular charge as "successful", "failed", and "pending".
Successful case
Screen Shot 2562-11-05 at 10 06 52
Screen Shot 2562-11-05 at 10 07 46

Failure case
Screen Shot 2562-11-05 at 10 09 03
Screen Shot 2562-11-05 at 10 12 20

Pending case
Screen Shot 2562-11-05 at 10 10 16
Screen Shot 2562-11-05 at 10 10 33

5. Placing order using TrueMoney Wallet payment method
We will go through the normal WooCommerce checkout process and test mark a particular charge as "successful", "failed", and "pending".
Successful case
Screen Shot 2562-11-05 at 11 02 06
Screen Shot 2562-11-05 at 11 02 40

Failure case
Screen Shot 2562-11-05 at 11 04 21
Screen Shot 2562-11-05 at 11 04 29

Pending case
Screen Shot 2562-11-05 at 10 58 29
Screen Shot 2562-11-05 at 10 58 53

4. Impact of the change

Should be none.

5. Priority of change

Normal

6. Additional Notes

The translation will be corrected and done in another different time, when we start working on Konbini payment.
This pull request is focusing only for refactoring the offsite payment classes.

@guzzilar guzzilar force-pushed the refactoring-offsite-methods branch 3 times, most recently from 6a3d161 to 3c3a55c Compare November 5, 2019 01:59
@guzzilar guzzilar force-pushed the refactoring-offsite-methods branch from 3c3a55c to dc877d7 Compare November 5, 2019 02:46
@guzzilar guzzilar requested review from jacstn and jonrandy November 5, 2019 04:05
@guzzilar guzzilar changed the title [WIP] Refactoring offsite payment methods (introducing abstract offsite class) Refactoring offsite payment methods (introducing abstract offsite class) Nov 5, 2019
@jonrandy
Copy link

jonrandy commented Nov 5, 2019

"The translation will be corrected and done in another different time, when we start working on Konbini payment."

Am I missing something? There don't appear to be any translations in the PR. Some of the English needs fixing though - is that something I should do in this review?

@guzzilar
Copy link
Contributor Author

guzzilar commented Nov 5, 2019

Am I missing something? There don't appear to be any translations in the PR. Some of the English needs fixing though - is that something I should do in this review?

@jonrandy This pull request is tweaking some messages here and there.
i.e.
before

We cannot validate your payment result:
Note that your payment might already has been processed. Please contact our support team if you have any questions.

after

We cannot validate your payment result:
Note that your payment might already has been processed.
Please contact our support team if you have any questions.

and these affects to the localisation as its translation is paired and matched with the previous 'before' version.

However, for English fixing, yeah, help me (in this PR) 🆘
Thanks :D

…extended from its abstract parent class. Removing abstract 'charge' method out from 'Omise_Payment_Offsite'.
@guzzilar
Copy link
Contributor Author

guzzilar commented Nov 5, 2019

For the recent commit (bfed4a4)
Thanks to @jacstn, we have found that; PHP prior 7.2 can’t override-declare an abstract method inside an extended abstract class from an original (parent) abstract class

This won’t work on PHP prior 7.2

abstract class class1 {
  abstract public function someFunc();
}
abstract class class2 extends class1 {
  abstract public function someFunc();
}

ref:
https://www.php.net/manual/en/language.oop5.abstract.php#78388
https://github.com/php/php-src/blob/php-7.2.0alpha1/UPGRADING (section, “2. New Features > Core”)


By removing the abstract charge() method out from Omise_Payment_Offsite, it should work as designed now. I've tested on PHP v5.6.40, worked as well.

if ( ! $order ) {
$message = __(
'<strong>We cannot validate your payment result:</strong><br/>
Note that your payment might already has been processed.<br/>
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Note that your payment may have already been processed."


if ( self::STATUS_PENDING === $charge['status'] && ! $charge['paid'] ) {
$message = __(
'Omise: The payment has been processing.<br/>
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Omise: The payment is being processed."

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jonrandy just wonder what is the nuance that these 2 sentences are giving. Not similar, if not the same?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"The payment has been processing" implies that it was being processed, but now has stopped for some reason - which I don't think is what you wanted to say

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ic. Thanks 👍

if ( self::STATUS_PENDING === $charge['status'] && ! $charge['paid'] ) {
$message = __(
'Omise: The payment has been processing.<br/>
Due to the payment provider, this may take some time to process.<br/>
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Depending on the payment provider, this may take some time to process."

$message = __(
'Omise: The payment has been processing.<br/>
Due to the payment provider, this may take some time to process.<br/>
Please do a manual \'Sync Payment Status\' action from the <strong>Order Actions</strong> panel or check the payment status directly at Omise dashboard again later.',
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Please do a manual 'Sync Payment Status' action from the Order Actions panel, or check the payment status directly at the Omise dashboard later."

}

$message = __(
'Note that your payment might already has been processed.<br/>
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Note that your payment may have already been processed."

Copy link

@jonrandy jonrandy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

English fixes needed (see notes)

@guzzilar
Copy link
Contributor Author

guzzilar commented Nov 6, 2019

@jonrandy Hi, I just pushed a new commit. Can you help review c5546e3 ?
Thanks : )

@guzzilar guzzilar merged commit faf544a into master Nov 11, 2019
@guzzilar guzzilar deleted the refactoring-offsite-methods branch November 11, 2019 07:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants