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

Handle an Omise event, charge.complete #45

Merged
merged 5 commits into from Nov 20, 2017

Conversation

Projects
None yet
1 participant
@nimid
Contributor

nimid commented Nov 20, 2017

1. Objective

Correctly update a status of PrestaShop order when checkout with Omise internet banking payment.

Note:
To complete the checkout with Omise internet banking payment, the payer need to be redirected off the PrestaShop website to the bank website. After the payer completed their payment on bank website, bank will,

  1. Redirect the payer back to PrestaShop website.
  2. Send the notification of payment result to Omise.

Sometimes the notification is delayed or slower than the redirection. This situation causes the Omise can not sure the result of payment.

This problem can be solved by using Omise webhooks. Whenever bank sent the notification of payment result to Omise, Omise will send the notification to the PrestaShop website.

Related information:

  • Related issue: -
  • Related ticket: -

2. Description of change

  • Add a logger class, OmiseLogger, to write log message to PrestaShop database.
  • Develop the mechanism to handle an Omise event, charge.complete.

3. Quality assurance

Environments:

  • Platform: PrestaShop 1.7.2.4
  • Omise plugin: Omise PrestaShop 1.3
  • PHP: 5.6.31

Details:

It has 2 test cases.

  1. The event is charge.complete, status of charge is successful. Expect the status PrestaShop order has been updated to be Payment accepted (success).

  2. The event is charge.complete, status of charge is failed. Expect the status PrestaShop order has been updated to be Canceled.

Steps before test.

  1. Configure the Omise Webhooks. By copy the URL from Webhooks endpoint that appeared in PrestaShop back office, Omise setting page, and paste it in Omise dashboard, Webhooks Endpoint.

  2. Go to PrestaShop front office and process checkout, at the payment step, select any bank from Omise internet banking payment.

The screenshot below shows the configuration for Omise Webhooks endpoint.

prestashop-1 7 2 4-configure-omise-webhooks-on-omise-dashboard

Test case 1:

The screenshot below shows Omise dashboard, webhooks detail. In the red boxes, there are show the event is charge.complete and charge status is successful.

omise-dashboard-webhooks-detail-charge complete-and-charge-status-is-successful

The screenshot below shows PrestaShop back office, order detail. In the red box, it shows order status is payment accepted.

prestashop-1 7 2 4-order-detail-order-status-is-payment-accepted

The screenshot below shows PrestaShop back office, logs page. In the red box, it shows log message that the module, Omise PrestaShop, has caught Omise webhooks event and updated PrestaShop order status to be payment accepted.

prestashop-1 7 2 4-logs-charge complete-event-update-order-status-to-be-payment-accepted

Test case 2:

The screenshot below shows Omise dashboard, webhooks detail. In the red boxes, they show the event is charge.complete and charge status is failed.

omise-dashboard-webhooks-detail-charge complete-and-charge-status-is-failed

The screenshot below shows PrestaShop back office, order detail. In the red box, it shows order status is canceled.

prestashop-1 7 2 4-order-detail-order-status-is-canceled

The screenshot below shows PrestaShop back office, logs page. In the red box, it shows log message that the module, Omise PrestaShop, has caught Omise webhooks event and updated PrestaShop order status to be canceled.

prestashop-1 7 2 4-logs-charge complete-event-update-order-status-to-be-canceled

4. Impact of the change

-

5. Priority of change

Normal

6. Additional notes

  • List of Omise events.

  • The HTML comments appeared in response body, Omise dashboard, webhooks detail, if PrestaShop is run on debug mode.

presashop-debug-mode-html-comments-appeard-on-response-body-omise-dashboard-webhooks-detail

nimid added some commits Nov 19, 2017

Develop a new class, OmiseLogger, for write log
This class wrapped the PrestaShop logger class, Logger. The Logger class
requires some parameters which they are not required or compatibled with
module such as $object_id or $object_type. The data type of $object_id is
int but the data type of Omise object id is string or $object_type is
the internal PrestaShop object, etc.

So, the wrapper class, OmiseLogger, has reduced the parameters that it is
not used by provides the necessary parameters, $message and $severity.
And $severity is optional the default value of $severify is info log
level.

The same log message can be added to database because OmiseLogger has
set a parameter, $allow_duplicate, to be true. It has the intent that
the same log message but differnt time can be added to database.
Add constants of Omise charge, failed & successful
Theses constants will be used for webhooks in the step of checking the
status of charge.
Add a function to get PS order ID from transaction
Add a function OmiseTransactionModel.getIdOrder(), to retrieve a
PrestaShop order ID from omise transaction table.

This function is search by using Omise charge ID.
Add a unit test for OmiseEventHandler
The unit test in this commit has only one test case because in actual
class, OmiseEventHandler, in has a static class attribute dependency,
OmiseEventChargeComplete::KEY, and a hard dependency (new Keyword),
new OmiseEventChargeComplete(), with the same class. This situation is
hard to create mock for unit testing.

So, a unit test case in this commit that test class, OmiseEventHandler,
is the test case that across the dependency that hard to mock.

@nimid nimid merged commit 314cc4d into webhooks Nov 20, 2017

@nimid nimid deleted the handle-charge-complete-event branch Nov 20, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment