<commit_before><?php
namespace Omise\Payment\Observer;

use Magento\Framework\Event\ObserverInterface;
use Magento\Framework\Event\Observer;

class OfflinePaymentObserver implements ObserverInterface
{
    /**
    * @var \Magento\Framework\App\Config\ScopeConfigInterface
    */
    private $_scopeConfig;    
    
    /**
    * @var  \Magento\Framework\Mail\Template\TransportBuilder
    */
    private $_transportBuilder;
    
    /**
    * @var  \Omise\Payment\Helper
    */
    private $_helper;

    /**
     * @var \Omise\Payment\Model\Api\Charge
     */
    protected $charge;
    /**
     * @var \Magento\Framework\View\Asset\Repository
     */
    protected $_assetRepo;

    /**
     * @param \Omise\Payment\Helper\OmiseHelper $helper
     * @param \Magento\Framework\Mail\Template\TransportBuilder $transportBuilder
     * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
     * @param \Magento\Framework\View\Asset\Repository $assetRepo
     * @param \Omise\Payment\Model\Api\Charge $charge
     */
    public function __construct(
        \Omise\Payment\Helper\OmiseHelper $helper,
        \Magento\Framework\Mail\Template\TransportBuilder $transportBuilder,
        \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
        \Magento\Framework\View\Asset\Repository $assetRepo,
        \Omise\Payment\Model\Api\Charge  $charge
    ) {
        $this->_scopeConfig      = $scopeConfig;
        $this->_helper           = $helper;
        $this->_transportBuilder = $transportBuilder;
        $this->_assetRepo = $assetRepo;
        $this->charge  = $charge;
    }

    /**
     * @param \Magento\Framework\Event\Observer $observer
     * @return $this
     */
    public function execute(Observer $observer)
    {
        $order   = $observer->getEvent()->getOrder();
        $payment = $order->getPayment();
        $emailData     = new \Magento\Framework\DataObject();
        $charge_id = $payment->getAdditionalInformation('charge_id');
        $charge = $this->charge->find($charge_id);
        switch($payment->getAdditionalInformation('payment_type')) {
            case 'bill_payment_tesco_lotus':
                // make sure timezone is Thailand.
                date_default_timezone_set("Asia/Bangkok");
                $barcodeHtml   = $this->_helper->convertTescoSVGCodeToHTML($payment->getAdditionalInformation('barcode'));
                $emailTemplate = 'send_email_tesco_template';
                $validUntil    = date("d-m-Y H:i:s" , strtotime($charge->expires_at));
                break;
            case 'paynow':
                // make sure timezone is Singapore.
                date_default_timezone_set("Asia/Singapore");
                $barcodeHtml   = "<img src= '".$charge->source['scannable_code']['image']['download_uri']."'/>";
                $emailTemplate = 'send_email_paynow_template';
                $emailData->setData(['banksUrl' => $this->_assetRepo->getUrl('Omise_Payment::images/paynow_supportedbanks.png')]);
                $validUntil    = date("d-m-Y H:i:s" , strtotime($charge->expires_at));
                break;
            case 'promptpay':
                // make sure timezone is Thailand.
                date_default_timezone_set("Asia/Bangkok");
                $barcodeHtml   = "<img src= '".$charge->source['scannable_code']['image']['download_uri']."'/>";
                $emailTemplate = 'send_email_promptpay_template';
                $validUntil    = date("d-m-Y H:i:s" , strtotime($charge->expires_at));
                break;
            default:
                return $this;
        }<commit_msg>Hardcoding charge expiry time for Paynow and Promptpay methods<commit_after><?php
namespace Omise\Payment\Observer;

use Magento\Framework\Event\ObserverInterface;
use Magento\Framework\Event\Observer;

class OfflinePaymentObserver implements ObserverInterface
{
    /**
    * @var \Magento\Framework\App\Config\ScopeConfigInterface
    */
    private $_scopeConfig;    
    
    /**
    * @var  \Magento\Framework\Mail\Template\TransportBuilder
    */
    private $_transportBuilder;
    
    /**
    * @var  \Omise\Payment\Helper
    */
    private $_helper;

    /**
     * @var \Omise\Payment\Model\Api\Charge
     */
    protected $charge;
    /**
     * @var \Magento\Framework\View\Asset\Repository
     */
    protected $_assetRepo;

    /**
     * @param \Omise\Payment\Helper\OmiseHelper $helper
     * @param \Magento\Framework\Mail\Template\TransportBuilder $transportBuilder
     * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
     * @param \Magento\Framework\View\Asset\Repository $assetRepo
     * @param \Omise\Payment\Model\Api\Charge $charge
     */
    public function __construct(
        \Omise\Payment\Helper\OmiseHelper $helper,
        \Magento\Framework\Mail\Template\TransportBuilder $transportBuilder,
        \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
        \Magento\Framework\View\Asset\Repository $assetRepo,
        \Omise\Payment\Model\Api\Charge  $charge
    ) {
        $this->_scopeConfig      = $scopeConfig;
        $this->_helper           = $helper;
        $this->_transportBuilder = $transportBuilder;
        $this->_assetRepo = $assetRepo;
        $this->charge  = $charge;
    }

    /**
     * @param \Magento\Framework\Event\Observer $observer
     * @return $this
     */
    public function execute(Observer $observer)
    {
        $order   = $observer->getEvent()->getOrder();
        $payment = $order->getPayment();
        $emailData     = new \Magento\Framework\DataObject();
        $charge_id = $payment->getAdditionalInformation('charge_id');
        $charge = $this->charge->find($charge_id);
        switch($payment->getAdditionalInformation('payment_type')) {
            case 'bill_payment_tesco_lotus':
                // make sure timezone is Thailand.
                date_default_timezone_set("Asia/Bangkok");
                $barcodeHtml   = $this->_helper->convertTescoSVGCodeToHTML($payment->getAdditionalInformation('barcode'));
                $emailTemplate = 'send_email_tesco_template';
                $validUntil    = date("d-m-Y H:i:s" , strtotime($charge->expires_at));
                break;
            case 'paynow':
                // make sure timezone is Singapore.
                date_default_timezone_set("Asia/Singapore");
                $barcodeHtml   = "<img src= '".$charge->source['scannable_code']['image']['download_uri']."'/>";
                $emailTemplate = 'send_email_paynow_template';
                $emailData->setData(['banksUrl' => $this->_assetRepo->getUrl('Omise_Payment::images/paynow_supportedbanks.png')]);
                $validUntil    = date("d-m-Y H:i:s" , strtotime(date("Y-m-d 23:59:59")));
                break;
            case 'promptpay':
                // make sure timezone is Thailand.
                date_default_timezone_set("Asia/Bangkok");
                $barcodeHtml   = "<img src= '".$charge->source['scannable_code']['image']['download_uri']."'/>";
                $emailTemplate = 'send_email_promptpay_template';
                $validUntil    = date("d-m-Y H:i:s" , strtotime('+1 day'));
                break;
            default:
                return $this;
        }
{'fraction_non_alphanumeric': 0.13402061855670103, 'fraction_numerical': 0.0009621993127147767, 'mean_word_length': 2.360739030023095, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 53, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2958203', 'n_tokens_mistral': 2139, 'n_tokens_neox': 2088, 'n_words': 310}