-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #140 from omise/tesco-bill-payment
Tesco Lotus Payment Implementation
- Loading branch information
Showing
13 changed files
with
286 additions
and
0 deletions.
There are no files selected for viewing
50 changes: 50 additions & 0 deletions
50
Block/Checkout/Onepage/Success/TescoAdditionalInformation.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
4 changes: 4 additions & 0 deletions
4
view/frontend/templates/checkout/onepage/success/tesco_additional_info.phtml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
82 changes: 82 additions & 0 deletions
82
view/frontend/web/js/view/payment/method-renderer/omise-offline-tesco-method.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
}); | ||
} | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
view/frontend/web/template/payment/offline-tesco-form.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |