Skip to content
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

Introducing PromptPay payment method (Thailand) #170

Merged
merged 2 commits into from
Aug 20, 2020
Merged

Introducing PromptPay payment method (Thailand) #170

merged 2 commits into from
Aug 20, 2020

Conversation

guzzilar
Copy link
Contributor

@guzzilar guzzilar commented Jun 17, 2020

1. Objective

This pull request is introducing PromptPay payment method to Omise-WooCommerce plugin.

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

2. Description of change

  • Displaying PromptPay payment method at the checkout page.

promptpay-04

  • Displaying PromptPay QR code at the Thank-you page.
    Alongs with the QR code expiry date.

Screen Shot 2563-08-17 at 13 23 20

  • Displaying successful payment message if the payment has been successfully paid.

promptpay-01

  • Displaying failed payment message if the payment has failed.

promptpay-02

  • After 10 minutes, if a particular order status still stay as on-hold then the plugin will stop Ajax-polling request to save the computer resource and display a 'refresh' button to allow buyer to fetch a payment status manually instead.

Screen Shot 2563-08-17 at 12 20 04

  • Displaying a link to PromptPay QR code at the order-confirmation email.

Screen Shot 2563-08-17 at 12 53 51

3. Quality assurance

🔧 Environments:

  • WooCommerce: v4.3
  • WordPress: v5.4.2
  • PHP version: 7.3.3.

✏️ Details:

There are 2 aspects that we want to test for this pull request, "merchant's perspective" and "buyer's perspective".
All the tests in this section will be separated into 2 situations as mentioned.

Setting up:

  1. Once installed this PR, at the admin page, from sidebar menu Omise > Settings. You will see the PromptPay payment method is listed at the Available Payment Methods table. Click config

Screen Shot 2563-08-17 at 13 49 04

  1. You may rename or add a payment description at the payment configuration page. Then, check the Enable Omise PromptPay Payment and click Save changes

Screen Shot 2563-08-17 at 13 49 11

  1. To be able to use the full feature of plugin, you may set the Webhook endpoint to your Omise Account as well.

Note: As Webhook endpoint requires for HTTPS server. For localhost test, you can use https://ngrok.com tool to simulate for https protocol.

Screen Shot 2563-08-17 at 13 49 04

  1. Once done, the PromptPay payment method will be listed at the checkout page.

Screen Shot 2563-08-17 at 14 07 44

Placing Order:

As a buyer:

Once the payment method has been set and enabled. Buyers will be able to placing order using PromptPay payment method at the checkout page.
Screen Shot 2563-08-17 at 14 07 44

After selecting PromptPay as a payment method, PromptPay QR code will be displayed at the WooCommerce Order-Confirmation page (thank-you page), along with the QR code expiry date.
Screen Shot 2563-08-17 at 14 31 28

Important: at this step, there will be AJAX polling request running behind to keep fetch order status every 10 seconds for 10 minutes to check if the payment has been paid (to update the screen accordingly). After 10 minutes, the AJAX will be terminated and displaying "refresh status" on the screen instead.

As well, there will be an email sent to buyer's billing email.
Screen Shot 2563-08-17 at 14 53 52

At this point, user may scan the QR code to pay.

As a merchant:

Once buyers make placed an order using PromptPay payment method, a new order with on-hold status will be created on WooCommerce.

Screen Shot 2563-08-17 at 14 47 38

Complete the payment

As a buyer:

Once the buyer paid for the payment, if payment is successful, there will be a successful payment message appear on the screen.
Screen Shot 2563-08-17 at 15 04 23

Once the buyer paid for the payment, if payment is failed, there will be a failure payment message appear on the screen.
Screen Shot 2563-08-17 at 15 06 08

In case if buyer didn't complete the transaction within 10 minutes, there will be a button refresh status appeared on the screen (this means that the AJAX polling has been terminated. Buyer can click this button to reactivate the AJAX script).
Screen Shot 2563-08-17 at 15 03 11

As a merchant:

In case of payment successful, the order status will be updated to processing.

Screen Shot 2563-08-17 at 15 09 42

In case of payment successful, the order status will be updated to failed.

Screen Shot 2563-08-17 at 15 09 48

4. Impact of the change

None

5. Priority of change

Normal

6. Additional Notes

Nothing.

<?php echo __( 'Scan the QR code to pay', 'omise' ); ?>
</p>
<div class="omise omise-promptpay-qrcode">
<img src="<?php echo $qrcode; ?>" alt="Omise QR code ID: <?php echo $charge['source']['scannable_code']['image']['id']; ?>">
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need to make accommodations for SVG QRs in, say, Gmail?

Copy link
Contributor

Choose a reason for hiding this comment

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

@mayurkathale will work on a SVG->PNG converter. I'm not sure if the PHP library requirements (e.g. ImageMagick/GD) for WooCommerce are similar enough?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm actually trying to go with file-attachment instead. (or in a worse case, just put a link there and let buyer click the link to open the QR code)

Copy link
Contributor

Choose a reason for hiding this comment

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

Cool. Can you coordinate with @mayurkathale on the ideal approach?

@guzzilar guzzilar force-pushed the promptpay branch 2 times, most recently from 3a0e5f9 to dbabbb9 Compare July 23, 2020 16:00
<?php echo __( 'Scan the QR code to pay', 'omise' ); ?>
</p>
<div class="omise omise-promptpay-qrcode">
<img src="<?php echo $qrcode; ?>" alt="Omise QR code ID: <?php echo $charge['source']['scannable_code']['image']['id']; ?>">
Copy link
Contributor

Choose a reason for hiding this comment

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

@mayurkathale will work on a SVG->PNG converter. I'm not sure if the PHP library requirements (e.g. ImageMagick/GD) for WooCommerce are similar enough?

includes/gateway/class-omise-payment-promptpay.php Outdated Show resolved Hide resolved
@guzzilar guzzilar force-pushed the promptpay branch 7 times, most recently from 2d8c305 to ecca2d1 Compare August 10, 2020 06:51
@guzzilar guzzilar changed the title [wip] Introducing PromptPay payment method (Thailand) Introducing PromptPay payment method (Thailand) Aug 17, 2020
$qrcode = $charge['source']['scannable_code']['image']['download_uri'];

$expires_datetime = new WC_DateTime( $charge['expires_at'], new DateTimeZone( 'UTC' ) );
$expires_datetime->set_utc_offset( wc_timezone_offset() );
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note: there is a timezone-offset configuration in WordPress itself. This part is to make sure that the plugin will set the time according to the WordPress configuration instead of server time/timezone.

<div id="omise-offline-additional-details" class="omise omise-additional-payment-details-box omise-promptpay-details" <?php echo 'email' === $context ? 'style="margin-bottom: 4em; text-align:center;"' : ''; ?>>
<p><?php echo __( 'Scan the QR code to pay', 'omise' ); ?></p>
<div class="omise omise-promptpay-qrcode">
<img style="margin: 0 auto;" src="<?php echo $qrcode; ?>" alt="Omise QR code ID: <?php echo $charge['source']['scannable_code']['image']['id']; ?>">
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note: Test-mode and Live-mode will give a different format of QR code picture (png and svg). However, there should be no problem to display in img element.


<div id="omise-offline-payment-result" class="omise-additional-payment-details-box" style="display: none;"></div>

<script>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note: this Javascript might need to be relocated to another file in the future once the same solution gets applied to PayNow payment method (or it may not possible, still testing the idea – however, it will be out of scope from PromptPay so I skip it)

public function register_ajax_actions() {
add_action('wp_ajax_nopriv_fetch_order_status', 'Omise_Ajax_Actions::fetch_order_status' );
add_action('wp_ajax_fetch_order_status', 'Omise_Ajax_Actions::fetch_order_status' );
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

https://developer.wordpress.org/reference/hooks/wp_ajax_nopriv__requestaction/
According to WordPress documents, wp_ajax_nopriv_* is needed for those non-authenticated Ajax actions for logged-out users. We need to hook 2 actions here to be able to implement the Ajax polling to keep tracking order-status at the Thank-you page.

<p><a href="<?php echo $qrcode; ?>"><?php echo __( 'Click this link to display the QR code', 'omise' ); ?></a></p>
<?php endif;
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not strong at Javascript. If there is any suggestion to improve or to make the code more effective, please feel free to let me know 🙇

@guzzilar guzzilar force-pushed the promptpay branch 2 times, most recently from dac1b67 to a9aa879 Compare August 17, 2020 08:20
$expires_datetime = new WC_DateTime( $charge['expires_at'], new DateTimeZone( 'UTC' ) );
$expires_datetime->set_utc_offset( wc_timezone_offset() );

if ( 'view' === $context ) : ?>
Copy link
Contributor

Choose a reason for hiding this comment

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

All of the inline CSS in the If block can be moved to omise-css.css file.

Copy link
Contributor Author

@guzzilar guzzilar Aug 19, 2020

Choose a reason for hiding this comment

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

Can I move this one to another PR?
I have a plan to revise the CSS classes to make all the shared-styles to be more in generic name but it will require to touch multiple files that out of scope from PromptPay implementation (planning to group those styles that are currently using with Offline additional information).

});
})(jQuery);
</script>
<?php elseif ( 'email' === $context ) : ?>
Copy link
Contributor

Choose a reason for hiding this comment

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

This part should be excluded in "Order failed" emails which usually gets send after failed charge creation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This part of the code will be triggered only when the charge is successfully created and user redirects to the thank-you page (or did you get another different result?)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed
Screen Shot 2563-08-20 at 01 18 36

Thank a lot! I totally missed this point 👍

Copy link
Contributor

@mayurkathale mayurkathale left a comment

Choose a reason for hiding this comment

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

Few changes above

@guzzilar
Copy link
Contributor Author

Thanks! @mayurkathale

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.

3 participants