omise / omise-woocommerce

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

Adding ability to sync payment status to Bill Payment and TrueMoney Payment. #140

Closed guzzilar closed 5 years ago

guzzilar commented 5 years ago

1. Objective

In a case of offsite payment, there is a chance that a payment transaction will not be resolved immediately after users have completed their payment at the 3rd-party payment page (i.e. Internet Banking). Omise Charge status will stay as pending and as so, WooCommerce order status.

With the above case, unless the Webhook feature is properly set. Merchant will need to go to Omise Dashboard to check a final status later on, then manually update his/her order status accordingly.

This pull request is to add a functionality where merchants can pull a latest status of a particular Omise Charge transaction and automatically update WooCommerce Order's status accordingly right at the WooCommerce Order page.

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

2. Description of change

This feature has been implemented to the rest payment methods. However, there are 2 missing payment methods, which are, Bill Payment, and TrueMoney Wallet.

3. Quality assurance

🔧 Environments:

WooCommerce: v3.7.0

✏️ Details:

As we cannot test the pending case with Omise test account. This test requires a little modification on Omise-WooCommerce's code.

Preparation

  1. At directory includes/gateway, you will see bunch of classes that are representing of each payment method. Open includes/gateway/class-omise-payment-truemoney.php file with your text editor.

  2. Find the method callback() and search for the following line

    $charge = OmiseCharge::retrieve( $order->get_transaction_id() );

Then add this code after.

$charge['paid']   = false;
$charge['status'] = 'pending';

Output

/**
 * @return void
 */
public function callback() {

    ...

    try {
        $charge = OmiseCharge::retrieve( $order->get_transaction_id() );
        $charge['paid']   = false; // add the code right here
        $charge['status'] = 'pending'; // add the code right here

        ...
}
  1. Save the file, then back to WooCommerce store. Place an order with Omise TrueMoney Wallet payment method. WooCommerce Order will be created with TrueMoney Wallet payment, with on-hold status.

Screen Shot 2562-10-25 at 14 18 47

Note, there will be 2 double notes and that is a normal-expected behaviour.

Test for TrueMoney Wallet payment

  1. At the right-top of WooCommerce Order page, Order actions section. Choose: Omise: Manual sync payment status. 2Screen_Shot_2562-10-07_at_15 32 25_copy

  2. Click "Update" button. Screen_Shot_2562-10-07_at_16 18 22_copy

  3. In case of "successful" payment (charge.status = successful)

    • An order status will be changed to processing.
    • A note will be added with the following message
      Omise: Payment successful.
      An amount {amount} {currency} has been paid (manual sync).

      Screen Shot 2562-10-25 at 15 56 57 copy

  4. In case of "failed" payment (charge.status = failed)

    • An order status will be changed to failed.
    • A note will be added with the following message
      Omise: Payment failed.
      {failure_message} (code: {failure_code}) (manual sync).
      Screen Shot 2562-10-25 at 16 52 52 copy
  5. In case of "pending" payment (charge.status = pending) There may be a chance where a particular charge has not yet been processed even after a while.

    • An order status stays as on-hold
    • A note will be added with the following message
      Omise: Payment is still in progress.
      You might wait for a moment before click sync the status again or contact Omise support team at support@omise.co if you have any questions (manual sync).
      Screen Shot 2562-10-25 at 16 57 38 copy

Test for Bill Payment

Bill Payment case is similar to TrueMoney Wallet payment, except that you don't need to alter the plugin code at callback method (because Bill Payment payment method is an offline method, there is no redirection after finished the purchase).

  1. Place an order with Bill Payment method, then go to Omise Dashboard to mark a charge to be either "successful" or "failed"

    Screen Shot 2562-10-25 at 17 33 51 copy
  2. In a case of either "successful" or "failed", the result will be identically the same as TrueMoney Wallet payment (and the same as the rest of other payment methods).

Pending > Successful

Screen Shot 2562-10-25 at 17 25 27 copy

Failed

Screen Shot 2562-10-25 at 17 51 36 copy

4. Impact of the change

None

5. Priority of change

Normal

6. Additional Notes

Please note that at the moment, a pending status of Bill Payment is shown as pending payment which will be corrected in the coming Pull Request. (it should be set to on-hold instead)