Skip to content

Commit

Permalink
tesco_offline instead of tesco_offsite and other refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
jacstn committed Sep 28, 2018
1 parent 44b84f9 commit 6d050b6
Show file tree
Hide file tree
Showing 11 changed files with 110 additions and 173 deletions.
25 changes: 11 additions & 14 deletions Block/Checkout/Onepage/Success/TescoAdditionalInformation.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,24 +30,21 @@ public function __construct(
protected function _toHtml()
{
$paymentData = $this->_checkoutSession->getLastRealOrder()->getPayment()->getData();
if ($paymentData['additional_information']['payment_type'] !== 'bill_payment_tesco_lotus') {
return '';
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) {
return '';
}

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

$this->addData(
[
'tesco_code_url' => $tescoCodeImageUrl,
'order_amount' => number_format($paymentData['amount_ordered'], 2) .' '.$orderCurrency
]
);
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();
}
}
2 changes: 1 addition & 1 deletion Model/Config/Tesco.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ class Tesco extends Config
/**
* @var string
*/
const CODE = 'omise_offsite_tesco';
const CODE = 'omise_offline_tesco';
}
14 changes: 7 additions & 7 deletions etc/adminhtml/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -95,19 +95,19 @@
<config_path>payment/omise_offsite_alipay/title</config_path>
</field>
</group>
<group id="omise_offsite_tesco" translate="label" sortOrder="130" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Enable Tesco Solution</label>
<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="140" showInDefault="1" showInWebsite="1" showInStore="1">
<field id="active" translate="label comment" type="select" sortOrder="200" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Enable/Disable</label>
<comment>Enable Omise Tesco Solution.</comment>
<comment>Enable Tesco Bill Payment Solution.</comment>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
<config_path>payment/omise_offsite_tesco/active</config_path>
<config_path>payment/omise_offline_tesco/active</config_path>
</field>
<field id="title" translate="label" type="text" sortOrder="150" showInDefault="1" showInWebsite="1" showInStore="1">
<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_offsite_tesco/title</config_path>
<config_path>payment/omise_offline_tesco/title</config_path>
</field>
</group>
</group>
Expand Down
6 changes: 2 additions & 4 deletions etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
<payment_action>authorize_capture</payment_action>
</omise_offsite_alipay>

<omise_offsite_tesco>
<omise_offline_tesco>
<active>0</active>
<title>Tesco Bill Payment</title>
<model>OmiseTescoAdapter</model>
Expand All @@ -53,9 +53,7 @@
<can_capture>0</can_capture>
<can_review_payment>1</can_review_payment>
<payment_action>order</payment_action>
<allowspecific>1</allowspecific>
<specificcountry>FR</specificcountry>
</omise_offsite_tesco>
</omise_offline_tesco>
</payment>
</default>
</config>
2 changes: 1 addition & 1 deletion etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
</virtualType>
<!-- /Value Handler -->

<!-- Tesco payment solution-->
<!-- 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>
Expand Down
2 changes: 1 addition & 1 deletion view/frontend/layout/checkout_index_index.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
<item name="omise_offsite_alipay" xsi:type="array">
<item name="isBillingAddressRequired" xsi:type="boolean">true</item>
</item>
<item name="omise_offsite_tesco" xsi:type="array">
<item name="omise_offline_tesco" xsi:type="array">
<item name="isBillingAddressRequired" xsi:type="boolean">true</item>
</item>
</item>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +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'))?>: <b><?= $block->getOrderAmount();?></b></p>
<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;
}
});
}
);

This file was deleted.

4 changes: 2 additions & 2 deletions view/frontend/web/js/view/payment/omise.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ define(

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@
</div>
</div>
</div>
</div>
</div>

0 comments on commit 6d050b6

Please sign in to comment.