-
Notifications
You must be signed in to change notification settings - Fork 23
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 #158 from omise/tesco-email-code
Send Tesco barcode to customer's email
- Loading branch information
Showing
9 changed files
with
214 additions
and
23 deletions.
There are no files selected for viewing
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,88 @@ | ||
<?php | ||
namespace Omise\Payment\Observer; | ||
|
||
use Magento\Framework\Event\ObserverInterface; | ||
use Magento\Framework\Event\Observer; | ||
|
||
class TescoPaymentObserver implements ObserverInterface | ||
{ | ||
/** | ||
* @var \Magento\Framework\App\Config\ScopeConfigInterface | ||
*/ | ||
private $_scopeConfig; | ||
|
||
/** | ||
* @var \Magento\Framework\Mail\Template\TransportBuilder | ||
*/ | ||
private $_transportBuilder; | ||
|
||
/** | ||
* @var \Omise\Payment\Helper | ||
*/ | ||
private $_helper; | ||
|
||
public function __construct( | ||
\Omise\Payment\Helper\OmiseHelper $helper, | ||
\Magento\Framework\Mail\Template\TransportBuilder $transportBuilder, | ||
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig | ||
) { | ||
$this->_scopeConfig = $scopeConfig; | ||
$this->_helper = $helper; | ||
$this->_transportBuilder = $transportBuilder; | ||
} | ||
|
||
/** | ||
* @param \Magento\Framework\Event\Observer $observer | ||
* @return $this | ||
*/ | ||
public function execute(Observer $observer) | ||
{ | ||
$order = $observer->getEvent()->getOrder(); | ||
$payment = $order->getPayment(); | ||
|
||
if (!$payment) { | ||
return $this; | ||
} | ||
|
||
$paymentData = $payment->getData(); | ||
|
||
if ($paymentData['additional_information']['payment_type'] !== 'bill_payment_tesco_lotus') { | ||
return $this; | ||
} | ||
|
||
$amount = number_format($paymentData['amount_ordered'], 2) . ' ' . $order->getOrderCurrency()->getCurrencyCode(); | ||
$barcodeHtml = $this->_helper->convertTescoSVGCodeToHTML($paymentData['additional_information']['barcode']); | ||
$storeName = $this->_scopeConfig->getValue('trans_email/ident_sales/name', \Magento\Store\Model\ScopeInterface::SCOPE_STORE); | ||
$storeEmail = $this->_scopeConfig->getValue('trans_email/ident_sales/email', \Magento\Store\Model\ScopeInterface::SCOPE_STORE); | ||
$customerEmail = $order->getCustomerEmail(); | ||
$orderId = $order->getIncrementId(); | ||
|
||
// make sure timezone is Thailand. | ||
date_default_timezone_set("Asia/Bangkok"); | ||
|
||
// get DateTime deadline that is in next 24 hours. | ||
$validUntil = date("d-m-Y H:i:s" , time() + 24 * 60 * 60) . ' ICT'; | ||
|
||
$emailData = new \Magento\Framework\DataObject(); | ||
$emailData->setData(['barcode' => $barcodeHtml, 'amount' => $amount, 'storename' => $storeName, 'orderId' => $orderId, 'valid' => $validUntil]); | ||
|
||
// build and send email | ||
$transport = $this->_transportBuilder | ||
->setTemplateIdentifier('send_email_tesco_template') | ||
->setTemplateOptions([ | ||
'area' => \Magento\Framework\App\Area::AREA_FRONTEND, | ||
'store' => \Magento\Store\Model\Store::DEFAULT_STORE_ID, | ||
]) | ||
->setTemplateVars(['data' => $emailData]) | ||
->setFrom([ | ||
'name' => $storeName, | ||
'email' => $storeEmail, | ||
]) | ||
->addTo(['email' => $customerEmail], \Magento\Store\Model\ScopeInterface::SCOPE_STORE) | ||
->getTransport(); | ||
|
||
$transport->sendMessage(); | ||
|
||
return $this; | ||
} | ||
} |
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,5 @@ | ||
<?xml version="1.0"?> | ||
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../Email/etc/email_templates.xsd"> | ||
<template id="send_email_tesco_template" label="Email Form" file="tesco_template.html" type="html" | ||
module="Omise_Payment" area="frontend"/> | ||
</config> |
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,19 @@ | ||
<!--@subject {{trans "Tesco Lotus Payment"}} @--> | ||
{{template config_path="design/email/header_template"}} | ||
<div> | ||
<p> | ||
{{trans "%thankyou" thankyou="Thank you for your order."}}</p> | ||
{{trans "%message" message="This is your Tesco Lotus payment code. Please print it and bring it to any Tesco | ||
Lotus store within the next 24 hours to finalise payment. After that time your order will be automatically | ||
cancelled."}}<br/> | ||
{{trans "%orderid" orderid="Order ID:"}} <strong>{{var data.orderId|raw}}</strong><br/> | ||
{{trans "%valid" valid="Valid until:"}} <strong>{{var data.valid|raw}}</strong><br/> | ||
{{trans "%amounttopay" amounttopay="Amount to pay:"}} <strong>{{var data.amount|raw}}</strong><br/> | ||
<i>{{trans "%extrafees" extrafees="Extra fees may apply for the payment."}}</i> | ||
</p> | ||
<p style="margin: 50px auto; min-width: 600px; display: block;"> | ||
<div>{{var data.barcode|raw}}</div> | ||
</p> | ||
<p style="margin-top: 50px"><i>{{var data.storename|raw}}</i></p> | ||
</div> | ||
{{template config_path="design/email/footer_template"}} |
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