public function informCustomer(\Magento\Sales\Model\Order $order, $amount, $currency) { try { if (!($order_increment_id = $order->getRealOrderId()) or !($method_config = $this->_s2pModel->getFullConfigArray())) { return false; } $siteUrl = $order->getStore()->getBaseUrl(); $siteName = $this->_helper->getStoreName(); $supportEmail = $this->_helper->getStoreConfig('trans_email/ident_support/email'); $supportName = $this->_helper->getStoreConfig('trans_email/ident_support/name'); $payment_details_arr['site_url'] = $siteUrl; $payment_details_arr['order_increment_id'] = $order_increment_id; $payment_details_arr['site_name'] = $siteName; $payment_details_arr['customer_name'] = $order->getCustomerName(); $payment_details_arr['order_date'] = $order->getCreatedAtFormatted(\IntlDateFormatter::LONG); $payment_details_arr['support_email'] = $supportEmail; $payment_details_arr['total_paid'] = number_format($amount / 100, 2); $payment_details_arr['currency'] = $currency; $transport = $this->_transportBuilder->setTemplateIdentifier($method_config['smart2pay_email_payment_confirmation'])->setTemplateOptions(['area' => \Magento\Framework\App\Area::AREA_ADMINHTML, 'store' => $order->getStore()->getId()])->setTemplateVars($payment_details_arr)->setFrom(['name' => $supportName, 'email' => $supportEmail])->addTo($order->getCustomerEmail())->getTransport(); $transport->sendMessage(); } catch (\Magento\Framework\Exception\MailException $e) { $this->_s2pLogger->write('Error sending customer informational email to [' . $order->getCustomerEmail() . ']', 'email_template'); $this->_s2pLogger->write($e->getMessage(), 'email_exception'); } catch (\Exception $e) { $this->_s2pLogger->write($e->getMessage(), 'exception'); } return true; }
/** * Prepares block data * * @return void */ protected function prepareBlockData() { $order_is_ok = true; $order_error_message = ''; if (!($order = $this->_checkoutSession->getLastRealOrder())) { $order_error_message = __('Couldn\'t extract order information.'); } elseif ($order->getState() != Order::STATE_NEW) { $order_error_message = __('Order was already processed or session information expired.'); } elseif (!($additional_info = $order->getPayment()->getAdditionalInformation()) or !is_array($additional_info) or empty($additional_info['sp_method']) or empty($additional_info['sp_transaction'])) { $order_error_message = __('Couldn\'t extract payment information from order.'); } if (!empty($order_error_message)) { $order_is_ok = false; } $smart2pay_config = $this->_s2pModel->getFullConfigArray(); $merchant_transaction_id = $order->getRealOrderId(); // assume live environment if we don't get something valid from config if (empty($smart2pay_config['environment']) or !($environment = Environment::validEnvironment($smart2pay_config['environment']))) { $environment = Environment::ENV_LIVE; } if ($environment == Environment::ENV_DEMO) { $merchant_transaction_id = $this->_helper->convert_to_demo_merchant_transaction_id($merchant_transaction_id); } $form_data = $smart2pay_config; if ($order_is_ok) { $form_data['environment'] = $environment; $form_data['method_id'] = !empty($additional_info['sp_method']) ? intval($additional_info['sp_method']) : 0; $form_data['order_id'] = $merchant_transaction_id; $form_data['currency'] = $order->getOrderCurrency()->getCurrencyCode(); $form_data['amount'] = number_format($order->getGrandTotal(), 2, '.', '') * 100; //anonymous user, get the info from billing details if ($order->getCustomerId() === null) { $form_data['customer_last_name'] = $this->_helper->s2p_mb_substr($order->getBillingAddress()->getLastname(), 0, 30); $form_data['customer_first_name'] = $this->_helper->s2p_mb_substr($order->getBillingAddress()->getFirstname(), 0, 30); $form_data['customer_name'] = $this->_helper->s2p_mb_substr($form_data['customer_first_name'] . ' ' . $form_data['customer_last_name'], 0, 30); } else { $form_data['customer_name'] = $this->_helper->s2p_mb_substr($order->getCustomerName(), 0, 30); $form_data['customer_last_name'] = $this->_helper->s2p_mb_substr($order->getCustomerLastname(), 0, 30); $form_data['customer_first_name'] = $this->_helper->s2p_mb_substr($order->getCustomerFirstname(), 0, 30); } $form_data['customer_email'] = trim($order->getCustomerEmail()); $form_data['country'] = $order->getBillingAddress()->getCountryId(); $messageToHash = 'MerchantID' . $form_data['mid'] . 'MerchantTransactionID' . $form_data['order_id'] . 'Amount' . $form_data['amount'] . 'Currency' . $form_data['currency'] . 'ReturnURL' . $form_data['return_url']; if ($form_data['site_id']) { $messageToHash .= 'SiteID' . $form_data['site_id']; } $messageToHash .= 'CustomerName' . $form_data['customer_name']; $messageToHash .= 'CustomerLastName' . $form_data['customer_last_name']; $messageToHash .= 'CustomerFirstName' . $form_data['customer_first_name']; $messageToHash .= 'CustomerEmail' . $form_data['customer_email']; $messageToHash .= 'Country' . $form_data['country']; $messageToHash .= 'MethodID' . $form_data['method_id']; $form_data['order_description'] = 'Ref. no.: ' . $form_data['order_id']; if (empty($form_data['product_description_ref'])) { $form_data['order_description'] = $form_data['product_description_custom']; } $messageToHash .= 'Description' . $form_data['order_description']; $form_data['skip_hpp'] = 0; if ($form_data['skip_payment_page'] and (!in_array($form_data['method_id'], [Smart2Pay::PAYMENT_METHOD_BT, Smart2Pay::PAYMENT_METHOD_SIBS]) or $form_data['notify_payment_instructions'])) { $form_data['skip_hpp'] = 1; $messageToHash .= 'SkipHpp1'; } if ($form_data['redirect_in_iframe']) { $messageToHash .= 'RedirectInIframe1'; } if ($form_data['skin_id']) { $messageToHash .= 'SkinID' . $form_data['skin_id']; } $messageToHash .= $form_data['signature']; $form_data['message_to_hash'] = $this->_helper->s2p_mb_strtolower($messageToHash); $form_data['hash'] = $this->_helper->computeSHA256Hash($messageToHash); $this->_s2pLogger->write('Form hash: [' . $messageToHash . ']', 'info'); $s2p_transaction = $this->_s2pTransaction->create(); $s2p_transaction->setID($additional_info['sp_transaction'])->setMethodID($form_data['method_id'])->setMerchantTransactionID($form_data['order_id'])->setSiteID($form_data['site_id'])->setEnvironment($form_data['environment']); $s2p_transaction->save(); $order->addStatusHistoryComment('Smart2Pay :: redirecting to payment page with MethodID: ' . $form_data['method_id']); $order->save(); } $this->addData(['order_ok' => $order_is_ok, 'error_message' => $order_error_message, 'order_id' => $order->getIncrementId(), 'form_data' => $form_data]); }