omise / omise-woocommerce

Omise WooCommerce Plugin
https://docs.opn.ooo/woocommerce-plugin
MIT License
47 stars 27 forks source link

Manual Sync, handling more cases: 'expired', 'refunded', 'reversed'. #183

Closed guzzilar closed 4 years ago

guzzilar commented 4 years ago

1. Objective

There are some cases that the manual-sync feature at the moment cannot handle (expired, refunded, reversed). This pull request is providing am improvement of this feature.

Related information: Related issue(s): T18954 (internal ticket), T22392 (internal ticket), T22486 (internal ticket)

2. Description of change

Note, the change has been accidentally rebased and merged to the master branch within the prior pull request: #182, "Cleaning up code style & indentation", commit: https://github.com/omise/omise-woocommerce/pull/182/commits/864eb4e2069e855f1ccd2fd219e12c49c7deb238

This pull request is to write a test to cover all possible cases, and to re-review (if possible) the change. (Please check the core-actual change from this commit: https://github.com/omise/omise-woocommerce/pull/182/commits/864eb4e2069e855f1ccd2fd219e12c49c7deb238)

3. Quality assurance

🔧 Environments:

✏️ Details:

From this change, the manual-sync feature will be supporting for 6 different cases as the following: successful, failed, pending, refunded, expired, reversed.

In this section, we will be testing all the 6 cases. To prepare for the test, you may make sure that the Webhook endpoint has not been set to Omise Account in order to test for the manual sync.

Pending

The pending case will happen only when the charge.status = pending. The plugin will "only" add an order note saying that payment is still in progress.

Reference: https://github.com/omise/omise-woocommerce/pull/182/commits/864eb4e2069e855f1ccd2fd219e12c49c7deb238#diff-b2a67ad6a97418df7dddcefcfc2a5319R352-R360

pending

Successful

If charge.status = successful and charge.funding_amount != charge.refunded_amount, then the plugin will add a new order note saying that the payment is successful. Also update the Order status to processing if it hasn't already.

Reference: https://github.com/omise/omise-woocommerce/pull/182/commits/864eb4e2069e855f1ccd2fd219e12c49c7deb238#diff-b2a67ad6a97418df7dddcefcfc2a5319R328-R338

successful

Manual Capture

Manual capture will give the same result as Successful case above.

capture

Failed

The plugin will add a new order note to inform that the payment is failed. As well, if not already then the plugin will update Order status to failed.

Reference: https://github.com/omise/omise-woocommerce/pull/182/commits/864eb4e2069e855f1ccd2fd219e12c49c7deb238#diff-b2a67ad6a97418df7dddcefcfc2a5319R340-R350

failed

Refunded

Reference: https://github.com/omise/omise-woocommerce/commit/864eb4e2069e855f1ccd2fd219e12c49c7deb238?branch=864eb4e2069e855f1ccd2fd219e12c49c7deb238&diff=split#diff-b2a67ad6a97418df7dddcefcfc2a5319R317-R326

refund refund-2

Reversed

In case of reversed-charge, the plugin will add a new order note to inform so, and if not already, then Order status will be marked as cancelled. Reference: https://github.com/omise/omise-woocommerce/pull/182/commits/864eb4e2069e855f1ccd2fd219e12c49c7deb238#diff-b2a67ad6a97418df7dddcefcfc2a5319R371-R378

reversed

Expired

To test expired transaction, you may modify the charge.status result at the core code to simulate the response from Omise Charge API. At includes/gateway/class-omise-payment.php::sync_payment() Line: 314. You may add the following code above the switch condition.

$charge['status'] = self::STATUS_EXPIRED;

The case of expired is similar to reversed. However, the order note's message is different. Reference: https://github.com/omise/omise-woocommerce/pull/182/commits/864eb4e2069e855f1ccd2fd219e12c49c7deb238#diff-b2a67ad6a97418df7dddcefcfc2a5319R362-R369

4. Impact of the change

None

5. Priority of change

Normal

6. Additional Notes

guzzilar commented 4 years ago

I have just pushed a new commit https://github.com/omise/omise-woocommerce/pull/183/commits/f8cbb504733ac8c3cb3f68daa622e53f5700a476

This is to re-locate the order-note message for a better understanding flow.

refunded-3