Skip to content

Reduce duplicated code from offline payment methods to a dedicated class#168

Merged
guzzilar merged 2 commits intomasterfrom
refactoring-offline-methods
Jun 17, 2020
Merged

Reduce duplicated code from offline payment methods to a dedicated class#168
guzzilar merged 2 commits intomasterfrom
refactoring-offline-methods

Conversation

@guzzilar
Copy link
Copy Markdown
Contributor

@guzzilar guzzilar commented May 11, 2020

1. Objective

This pull request is aiming to reduce duplicated code that was discovered during the implementation of API Localization #156

To reduce a place where we have to apply the L10n for those API response messages.

Related information:
Related issue(s): T21114 (internal ticket)

2. Description of change

• Implementing a dedicated class Omise_Payment_Offline for those offline payment methods to reduce duplicated code.

3. Quality assurance

🔧 Environments:

  • WooCommerce: v4.0.1
  • WordPress: v5.4.1
  • PHP version: 7.3.3.

✏️ Details:

As we're refactoring the charge and result methods, we should be making sure that those 2 offline payment methods can be created properly.

  1. Making sure that users can place an order using Bill Payment Tesco payment method.
    1.1. Charge can be created properly.

bill-successful

1.2. All the params are assigned properly (price, description, metadata)

bill-successful-dashboard

  1. Making sure that users can place an order using PayNow payment method.
    2.1. Charge can be created properly.

paynow-successful

2.2. All the params are assigned properly (price, description, metadata)

paynow-successful-dashboard

4. Impact of the change

No

5. Priority of change

Normal

6. Additional Notes

This Omise_Payment_Offline class may get modified again once we switch back to work on #149 Konbini payment (as Konbini requires more parameters to be passed when creating a new charge)

@guzzilar guzzilar force-pushed the refactoring-offline-methods branch 4 times, most recently from e1db86b to f9f2a50 Compare May 12, 2020 06:40
@guzzilar guzzilar requested review from jonrandy and mayurkathale May 12, 2020 06:59
@guzzilar guzzilar force-pushed the refactoring-offline-methods branch from f9f2a50 to 06f9708 Compare May 12, 2020 07:00
'description' => apply_filters( 'omise_charge_params_description', 'WooCommerce Order id ' . $order_id, $order ),
'source' => array( 'type' => $this->source_type ),
'metadata' => $metadata
) );
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Note that return_uri has been removed. It is because Offline payment methods don't require for the return_uri parameter.

abstract class Omise_Payment_Offline extends Omise_Payment {
/**
* A string of Omise Source's type
* (expecting for either 'paynow' or 'bill_payment_tesco_lotus').
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Comment should probably go as no doubt more offline payment methods will be added

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@jonrandy any suggestion? (can't think of other message than adding a word at the moment).

/**
 * A string of Omise Source's type
 * 'bill_payment_tesco_lotus', 'paynow' (at the moment).
 */

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Just remove that line of the comment, the rest is fine

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If we must have an example, we can say:

(e.g. paynow or bill_payment_tesco_lotus)

Then we're not limited when we inevitably add more source types

abstract class Omise_Payment_Offline extends Omise_Payment {
/**
* A string of Omise Source's type
* (expecting for either 'paynow' or 'bill_payment_tesco_lotus').
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If we must have an example, we can say:

(e.g. paynow or bill_payment_tesco_lotus)

Then we're not limited when we inevitably add more source types

@bigomise
Copy link
Copy Markdown

@guzzilar not sure that this PR will fix issue what if the merchant would like to use live mode, but the setting is automatically changed to test mode?

@guzzilar
Copy link
Copy Markdown
Contributor Author

@bigomise Can I have more detail about that case? Never heard that issue before.

@guzzilar guzzilar force-pushed the refactoring-offline-methods branch from b1abb19 to 1bb2c5e Compare June 16, 2020 09:28
);

return OmiseCharge::create( array(
'amount' => Omise_Money::to_subunit( $total, $currency ),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

In the future, we may want to consider passing custom expires_at params

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Noted 👍

@guzzilar guzzilar merged commit e9e8a50 into master Jun 17, 2020
@guzzilar guzzilar deleted the refactoring-offline-methods branch June 17, 2020 06:31
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.

4 participants