Skip to content

Commit

Permalink
Merge pull request #140 from omise/tesco-bill-payment
Browse files Browse the repository at this point in the history
Tesco Lotus Payment Implementation
  • Loading branch information
jacstn authored Sep 28, 2018
2 parents 67ab7d1 + 6d050b6 commit 690d500
Show file tree
Hide file tree
Showing 13 changed files with 286 additions and 0 deletions.
50 changes: 50 additions & 0 deletions Block/Checkout/Onepage/Success/TescoAdditionalInformation.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php
namespace Omise\Payment\Block\Checkout\Onepage\Success;

class TescoAdditionalInformation extends \Magento\Framework\View\Element\Template
{
/**
* @var \Magento\Checkout\Model\Session
*/
protected $_checkoutSession;

/**
* @param \Magento\Framework\View\Element\Template\Context $context
* @param \Magento\Checkout\Model\Session $checkoutSession
* @param array $data
*/
public function __construct(
\Magento\Framework\View\Element\Template\Context $context,
\Magento\Checkout\Model\Session $checkoutSession,
array $data = []
) {
$this->_checkoutSession = $checkoutSession;
parent::__construct($context, $data);
}

/**
* Return HTML code with tesco lotus payment infromation
*
* @return string
*/
protected function _toHtml()
{
$paymentData = $this->_checkoutSession->getLastRealOrder()->getPayment()->getData();
if (!isset($paymentData['additional_information']['payment_type']) || $paymentData['additional_information']['payment_type'] !== 'bill_payment_tesco_lotus') {
return parent::_toHtml();
}
$tescoCodeImageUrl = $paymentData['additional_information']['barcode'];

if ($tescoCodeImageUrl) {
$orderCurrency = $this->_checkoutSession->getLastRealOrder()->getOrderCurrency()->getCurrencyCode();

$this->addData(
[
'tesco_code_url' => $tescoCodeImageUrl,
'order_amount' => number_format($paymentData['amount_ordered'], 2) .' '.$orderCurrency
]
);
}
return parent::_toHtml();
}
}
6 changes: 6 additions & 0 deletions Gateway/Request/APMBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Magento\Payment\Gateway\Helper\SubjectReader;
use Magento\Payment\Gateway\Request\BuilderInterface;
use Omise\Payment\Model\Config\Alipay;
use Omise\Payment\Model\Config\Tesco;
use Omise\Payment\Model\Config\Internetbanking;
use Omise\Payment\Observer\InternetbankingDataAssignObserver;

Expand Down Expand Up @@ -58,6 +59,11 @@ public function build(array $buildSubject)
self::SOURCE_TYPE => 'alipay'
];
break;
case Tesco::CODE:
$paymentInfo[self::SOURCE] = [
self::SOURCE_TYPE => 'bill_payment_tesco_lotus'
];
break;
case Internetbanking::CODE:
$paymentInfo[self::SOURCE] = [
self::SOURCE_TYPE => $method->getAdditionalInformation(InternetbankingDataAssignObserver::OFFSITE)
Expand Down
5 changes: 5 additions & 0 deletions Gateway/Response/PaymentDetailsHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,10 @@ public function handle(array $handlingSubject, array $response)

$payment->setAdditionalInformation('charge_id', $response['charge']->id);
$payment->setAdditionalInformation('charge_authorize_uri', $response['charge']->authorize_uri);
$payment->setAdditionalInformation('payment_type', $response['charge']->source['type']);

if ($response['charge']->source['type'] === 'bill_payment_tesco_lotus') {
$payment->setAdditionalInformation('barcode', $response['charge']->source['references']['barcode']);
}
}
}
12 changes: 12 additions & 0 deletions Model/Config/Tesco.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php
namespace Omise\Payment\Model\Config;

use Omise\Payment\Model\Config\Config;

class Tesco extends Config
{
/**
* @var string
*/
const CODE = 'omise_offline_tesco';
}
15 changes: 15 additions & 0 deletions etc/adminhtml/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,21 @@
<config_path>payment/omise_offsite_alipay/title</config_path>
</field>
</group>
<group id="omise_offline_tesco" translate="label" sortOrder="190" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Enable Tesco Bill Payment Solution</label>
<comment>Enable customers to pay for products in Tesco Lotus Stores.</comment>
<field id="active" translate="label comment" type="select" sortOrder="200" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Enable/Disable</label>
<comment>Enable Tesco Bill Payment Solution.</comment>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
<config_path>payment/omise_offline_tesco/active</config_path>
</field>
<field id="title" translate="label" type="text" sortOrder="210" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Title</label>
<comment>This controls the title which the user sees during checkout.</comment>
<config_path>payment/omise_offline_tesco/title</config_path>
</field>
</group>
</group>
</section>
</system>
Expand Down
12 changes: 12 additions & 0 deletions etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,18 @@
<can_review_payment>1</can_review_payment>
<payment_action>authorize_capture</payment_action>
</omise_offsite_alipay>

<omise_offline_tesco>
<active>0</active>
<title>Tesco Bill Payment</title>
<model>OmiseTescoAdapter</model>
<is_gateway>1</is_gateway>
<can_initialize>1</can_initialize>
<can_use_checkout>1</can_use_checkout>
<can_capture>0</can_capture>
<can_review_payment>1</can_review_payment>
<payment_action>order</payment_action>
</omise_offline_tesco>
</payment>
</default>
</config>
34 changes: 34 additions & 0 deletions etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,40 @@
</virtualType>
<!-- /Value Handler -->

<!-- Tesco payment solution-->
<virtualType name="OmiseTescoAdapter" type="Magento\Payment\Model\Method\Adapter">
<arguments>
<argument name="code" xsi:type="const">Omise\Payment\Model\Config\Tesco::CODE</argument>
<argument name="formBlockType" xsi:type="string">Magento\Payment\Block\Form</argument>
<argument name="infoBlockType" xsi:type="string">Magento\Payment\Block\Info</argument>
<argument name="valueHandlerPool" xsi:type="object">OmiseAPMTescoValueHandlerPool</argument>
<argument name="validatorPool" xsi:type="object">OmiseValidatorPool</argument>
<argument name="commandPool" xsi:type="object">OmiseAPMCommandPool</argument>
</arguments>
</virtualType>

<!-- Tesco :: Value Handler Pool -->
<virtualType name="OmiseAPMTescoValueHandlerPool" type="Magento\Payment\Gateway\Config\ValueHandlerPool">
<arguments>
<argument name="handlers" xsi:type="array">
<item name="default" xsi:type="string">OmiseAPMTescoConfigValueHandler</item>
</argument>
</arguments>
</virtualType>

<virtualType name="OmiseAPMTescoConfigValueHandler" type="Magento\Payment\Gateway\Config\ConfigValueHandler">
<arguments>
<argument name="configInterface" xsi:type="object">OmiseAPMTescoConfig</argument>
</arguments>
</virtualType>

<virtualType name="OmiseAPMTescoConfig" type="Magento\Payment\Gateway\Config\Config">
<arguments>
<argument name="methodCode" xsi:type="const">Omise\Payment\Model\Config\Tesco::CODE</argument>
</arguments>
</virtualType>
<!-- /Value Handler -->

<!-- Alipay payment solution-->
<virtualType name="OmiseAlipayAdapter" type="Magento\Payment\Model\Method\Adapter">
<arguments>
Expand Down
3 changes: 3 additions & 0 deletions view/frontend/layout/checkout_index_index.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
</item>
<item name="omise_offsite_alipay" xsi:type="array">
<item name="isBillingAddressRequired" xsi:type="boolean">true</item>
</item>
<item name="omise_offline_tesco" xsi:type="array">
<item name="isBillingAddressRequired" xsi:type="boolean">true</item>
</item>
</item>
</item>
Expand Down
15 changes: 15 additions & 0 deletions view/frontend/layout/checkout_onepage_success.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceContainer name="order.success.additional.info">
<block class="Omise\Payment\Block\Checkout\Onepage\Success\TescoAdditionalInformation" name="onepage.success.billing_agreement"
template="Omise_Payment::checkout/onepage/success/tesco_additional_info.phtml"/>
</referenceContainer>
</body>
</page>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

<p><?= __('To finish payment, print the code below and bring it to make payment in any Tesco Lotus Store. Code is valid for the next <b>24 hours only</b>. After that time your order will be canceled.'); ?></p>
<p style="margin:.5rem 0"><?= $block->escapeHtml(__('Amount to pay'))?>: <strong><?= $block->getOrderAmount();?></b></strong>
<p><img src="<?= $block->escapeUrl($block->getTescoCodeUrl()) ?>" /></p>
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
define(
[
'ko',
'Magento_Checkout/js/view/payment/default',
'Magento_Checkout/js/model/full-screen-loader',
'Magento_Checkout/js/action/redirect-on-success',
'Magento_Checkout/js/model/quote',
'Magento_Checkout/js/model/error-processor'
],
function (
ko,
Component,
fullScreenLoader,
redirectOnSuccessAction,
quote,
errorProcessor
) {
'use strict';

return Component.extend({
defaults: {
template: 'Omise_Payment/payment/offline-tesco-form'
},

isPlaceOrderActionAllowed: ko.observable(quote.billingAddress() != null),

/**
* Get payment method code
*
* @return {string}
*/
getCode: function() {
return 'omise_offline_tesco';
},

/**
* Is method available to display
*
* @return {boolean}
*/
isActive: function() {
return true;
},

/**
* Handle payment error
*/
handlePaymentError: function(response) {
errorProcessor.process(response, self.messageContainer);
fullScreenLoader.stopLoader();
self.isPlaceOrderActionAllowed(true);
},

/**
* Hook the placeOrder function.
* Original source: placeOrder(data, event); @ module-checkout/view/frontend/web/js/view/payment/default.js
*
* @return {boolean}
*/
placeOrder: function(data, event) {
var self = this;

if (event) {
event.preventDefault();
}

self.getPlaceOrderDeferredObject()
.fail(
function(response) {
self.handlePaymentError(response);
}
).done(
function() {
redirectOnSuccessAction.execute();
}
);

return true;
}
});
}
);
7 changes: 7 additions & 0 deletions view/frontend/web/js/view/payment/omise.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ define(
}
);

rendererList.push(
{
type: 'omise_offline_tesco',
component: 'Omise_Payment/js/view/payment/method-renderer/omise-offline-tesco-method'
}
);

return Component.extend({});
}
);
41 changes: 41 additions & 0 deletions view/frontend/web/template/payment/offline-tesco-form.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<div class="payment-method"
data-bind="css: {'_active': (getCode() == isChecked())}">
<div class="payment-method-title field choice">
<input type="radio" name="payment[method]" class="radio"
data-bind="attr: {
'id': getCode()
},
value: getCode(),
checked: isChecked,
click: selectPaymentMethod,
visible: isRadioButtonVisible()" />
<label data-bind="attr: {'for': getCode()}" class="label">
<span data-bind="text: getTitle()"></span>
</label>
</div>
<div class="payment-method-content">
<!-- ko foreach: getRegion('messages') -->
<!-- ko template: getTemplate() -->
<!-- /ko -->
<!--/ko-->
<div class="payment-method-billing-address">
<!-- ko foreach: $parent.getRegion(getBillingAddressFormName()) -->
<!-- ko template: getTemplate() -->
<!-- /ko -->
<!--/ko-->
</div>
<div class="actions-toolbar">
<div class="primary">
<button class="action primary checkout" type="submit"
disabled="disabled"
data-bind="
click: placeOrder,
attr: {title: $t('Place Order')},
css: {disabled: !isPlaceOrderActionAllowed()},
enable: (getCode() == isChecked())">
<span data-bind="i18n: 'Place Order'"></span>
</button>
</div>
</div>
</div>
</div>

0 comments on commit 690d500

Please sign in to comment.