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 Bill Payment, Tesco Lotus (only available in Thailand) #122

Merged
merged 6 commits into from
Aug 7, 2019

Conversation

guzzilar
Copy link
Contributor

@guzzilar guzzilar commented Jul 27, 2019

1. Objective

As the statement Omise put at the releasing article:

Our focus is to help you boost sales by offering payment solutions that put customers choice and experience ahead. We’re super excited to let you know that starting today, Omise merchants in Thailand will be able to offer cash payments at Tesco Lotus as an option for customers to pay.

Increasingly we see consumers shifting over to online payments, however a large percentage still prefer to pay by cash over-the-counter. Tesco Lotus is currently the most preferred outlet by consumers, with more than 1800 locations across the country including 24-hour Lotus Express stores.

The objective of this pull request is to bring this feature to our lovely WooCommerce.

https://www.omise.co/now-supporting-over-the-counter-payments-at-tesco-lotus

2. Description of change

Adding all the needs in order to integrate Omise Bill Payment to WooCommerce.

  • Implementing all the foundation code to list the payment at WooCommerce payment setting page.
  • Displaying Bill Payment payment method at Omise setting page.
  • Integrating Bill Payment to WooCommerce checkout page
  • Display Bill Payment's barcode at the "order-received" page.

3. Quality assurance

🔧 Environments:

  • WordPress: v5.2.2 (latest)
  • WooCommerce: v3.6.5 (latest)
  • PHP version: v7.3.3

✏️ Details:

After installed this patch, you will be able to use Omise Bill Payment Tesco.
The below quality assurance steps is to make sure that all functions are properly work as expected.

  1. At Omise Payment Setting page (logged in to WordPress admin page first), there will be a new payment method, "Bill Payment: Tesco".
    billpayment-setting

  2. Once the payment is enabled, new payment method will be displayed at the checkout page.
    billpayment-checkout

  3. Bill Payment uses the "offline" flow, meaning that there is no redirect to any 3rd party page but create a new charge with authorize: pending, and paid: pending status then redirect buyer to the order-received page.

billpayment-completed

billpayment-charge

billpayment-log

  1. At WooCommerce Order Admin page, a new order will be created with pending payment status.

Screen Shot 2562-07-31 at 13 56 40

IMPORTANT

  1. If Webhook is set, Omise-WooCommerce will catch a charge.complete event and update a pending-payment order accordingly. If no, then merchants have to update an order status manually.

Successful case, order status get updated to processing.
billpayment-order-paid

Failure case, order status get updated to failed.
billpayment-order-failed

4. Impact of the change

Nothing

5. Priority of change

Normal

6. Additional Notes

There are 2 more PRs coming regarding to Omise Bill Payment, which are:

  1. Hook and display Bill Payment's barcode at the WC order confirmation email.
  2. Adding 'printing' button, buyer can print out the barcode after completed the purchase.

Also, according to the Quality assurance section, case [5].
There is one solution that I would like to provide in the future pull request (after the above 2 coming pull requests). Update order status when buyers open an order history page.

The flow is simple, when buyers open an order history page then, plugin will first, check if there is any pending-payment status remains. Then request to Omise Charge API to check for a new status and update those orders accordingly before display it on a screen.

@guzzilar guzzilar force-pushed the introduce-billpayment branch 3 times, most recently from c8402ca to 82ab13f Compare July 28, 2019 19:24
@guzzilar guzzilar requested review from jacstn and jonrandy July 31, 2019 13:25
@guzzilar guzzilar force-pushed the introduce-billpayment branch 2 times, most recently from 323a139 to 9324e69 Compare July 31, 2019 19:24
@guzzilar guzzilar force-pushed the introduce-billpayment branch from 9324e69 to 2367254 Compare August 1, 2019 08:04
@guzzilar
Copy link
Contributor Author

guzzilar commented Aug 5, 2019

Hook and display Bill Payment's barcode at the WC order confirmation email.

Done at PR #125

<small class="omise-billpayment-tesco-reference-number">|&nbsp;&nbsp;&nbsp; <?php echo $tax_id; ?> &nbsp;&nbsp;&nbsp; 00 &nbsp;&nbsp;&nbsp; <?php echo $ref_1; ?> &nbsp;&nbsp;&nbsp; <?php echo $ref_2; ?> &nbsp;&nbsp;&nbsp; <?php echo $amount; ?></small>
</div>
<?php
}
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, as this code is worked as normal as for the basic need to display barcode at the Thank-You page, this method has also been modified at #125 to support for displaying barcode at WC Order Confirmation email.
https://github.com/omise/omise-woocommerce/pull/125/files#diff-b100586f82e3090b17f2369adb8d9235R111

@guzzilar
Copy link
Contributor Author

guzzilar commented Aug 5, 2019

Adding 'printing' button, buyer can print out the barcode after completed the purchase.

Done at #126

@jacstn
Copy link
Contributor

jacstn commented Aug 6, 2019

tested, everything works as expected.

'title' => array(
'title' => __( 'Title', 'omise' ),
'type' => 'text',
'description' => __( 'This controls the title which the user sees during checkout.', 'omise' ),
Copy link

Choose a reason for hiding this comment

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

This controls the title the user sees during checkout.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jonrandy 👍 you've mentioned that for Installment once, I forgot 😂
Thanks!

'description' => array(
'title' => __( 'Description', 'omise' ),
'type' => 'textarea',
'description' => __( 'This controls the description which the user sees during checkout.', 'omise' )
Copy link

Choose a reason for hiding this comment

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

This controls the description the user sees during checkout.


return OmiseCharge::create( array(
'amount' => Omise_Money::to_subunit( $order->get_total(), $order->get_order_currency() ),
'currency' => $order->get_order_currency(),
Copy link

Choose a reason for hiding this comment

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

Seems a bit wasteful to call get_order_currency twice

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jonrandy thanks for pointing out. I was going to say I don't see much different and I will leave it as it is, but after dig a bit into WC's get_order_currency() method and with some researches, the code with variable is sparking more joy to me.
Updating.

'currency' => $order->get_order_currency(),
'description' => apply_filters( 'omise_charge_params_description', 'WooCommerce Order id ' . $order_id, $order ),
'source' => array( 'type' => 'bill_payment_tesco_lotus' ),
'return_uri' => add_query_arg( 'order_id', $order_id, site_url() . "?wc-api=omise_billpayment_tesco_callback" ),
Copy link

Choose a reason for hiding this comment

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

Is it correct to add one query argument using a function and another directly in a string?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jonrandy Good catch! Definitely not correct. It has been fixed in another payment classes and this one is a legacy that comes before the fixed PR. 👍

$ref_2 = $charge['source']['references']['reference_number_2'];
?>

<div class="omise omise-billpayment-tesco-details">
Copy link

Choose a reason for hiding this comment

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

Is this a recommended way to output HTML in WooCommerce?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jonrandy yup (we've discussed this topic already in some PR in the past) – It is a common way in WordPress.

}

if ( 'pending' == $charge['status'] ) {
return [
Copy link

Choose a reason for hiding this comment

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

Which array creation style should we be using? Is there a standard in WooCommerce?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jonrandy good catch again, array() it is.

@guzzilar
Copy link
Contributor Author

guzzilar commented Aug 6, 2019

@jonrandy @jacstn I have addressed all the feedbacks above and retested.
Can you help me review it again? Thank a lot : D

Copy link

@jonrandy jonrandy left a comment

Choose a reason for hiding this comment

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

LGTM

@guzzilar guzzilar merged commit 2a0a842 into master Aug 7, 2019
@guzzilar guzzilar deleted the introduce-billpayment branch August 7, 2019 07:15
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