Skip to content

Event "charge.complete", making sure that event's charge id is identical with order transaction id.#131

Merged
guzzilar merged 1 commit intomasterfrom
handle-webhook-charge-timeout
Sep 12, 2019
Merged

Event "charge.complete", making sure that event's charge id is identical with order transaction id.#131
guzzilar merged 1 commit intomasterfrom
handle-webhook-charge-timeout

Conversation

@guzzilar
Copy link
Copy Markdown
Contributor

@guzzilar guzzilar commented Aug 26, 2019

1. Objective

There is one edge case where multiple Omise Charge ID could be assigned to a one single WooCommerce Order object.

As a report from merchant of this behaviour that has happened with Internet Banking and Credit Card payment methods where their buyer places order with Internet Banking then leave the bank page and complete the payment with another, Credit Card payment method late on.

The problem of the above case is that, Omise Webhook will be triggered 2 times for these 2 charges to the particular WooCommerce Order object and the WooCommerce order status may be set incorrectly. i.e. Credit Card charge.complete event may comes first with status: successful status then, Internet Banking charge.complete event comes after with status: failure, time_out status.

Related information:
Related issue(s): #100, #103

2. Description of change

Add a condition block to check if order's transaction id is the same as charge object in the event's payload.

3. Quality assurance

🔧 Environments:

  • WooCommerce: v3.7.0.
  • WordPress: v5.2.2.
  • PHP: v5.6.40, v7.3.3.

✏️ Details:

To test this case, you will need to have Webhook setup for your store.

There are 2 possible ways to test this pull request.

  1. Place order with Internet Banking then leave the bank page and place the order again with Credit Card payment method, then wait for Internet Banking time out Webhook.

  2. At this line https://github.com/omise/omise-woocommerce/pull/131/files#diff-5d50c8e849d8c8ff8c4b6c55f50cd317R56
    Modify code to make sure that Omise-WooCommerce will not process any further if WooCommerce Order's transaction id is not the same as Webhook Charge.Complete event's payload.

You may add some random string to make this if ( $order->get_transaction_id() !== $data->id ) { ... } condition to be false.

i.e.

if ( $order->get_transaction_id() . '_blah' !== $data->id ) {
    return;
}

4. Impact of the change

No

5. Priority of change

High

6. Additional Notes

No

Comment thread includes/events/class-omise-event-charge-complete.php
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.

2 participants