示例#1
0
 public function testInitialize()
 {
     $state = 'pending_payment';
     $this->scopeConfig->expects($this->at(0))->method('getValue')->willReturn($state);
     $stateObject = new \Magento\Framework\Object();
     $this->model->initialize('action', $stateObject);
     $this->assertEquals($state, $stateObject->getState());
     $this->assertEquals($state, $stateObject->getStatus());
     $this->assertFalse($stateObject->getIsNotified());
 }
示例#2
0
 /**
  * Prepares block data
  *
  * @return void
  */
 protected function prepareBlockData()
 {
     $s2p_transaction = $this->_s2pTransaction->create();
     $order = $this->_orderFactory->create();
     $module_settings = $this->_s2pModel->getFullConfigArray();
     $transaction_obj = false;
     $error_message = '';
     $merchant_transaction_id = 0;
     if (($status_code = $this->_helper->getParam('data', null)) === null) {
         $error_message = __('Transaction status not provided.');
     } elseif (!($merchant_transaction_id = $this->_helper->getParam('MerchantTransactionID', '')) or !($merchant_transaction_id = $this->_helper->convert_from_demo_merchant_transaction_id($merchant_transaction_id))) {
         $error_message = __('Couldn\'t extract transaction information.');
     } elseif (!$s2p_transaction->loadByMerchantTransactionId($merchant_transaction_id) or !$s2p_transaction->getID()) {
         $error_message = __('Transaction not found in database.');
     } elseif (!$order->loadByIncrementId($merchant_transaction_id) or !$order->getEntityId()) {
         $error_message = __('Order not found in database.');
     }
     $status_code = intval($status_code);
     if (empty($status_code)) {
         $status_code = Smart2Pay::S2P_STATUS_FAILED;
     }
     $transaction_extra_data = [];
     $transaction_details_titles = [];
     if (in_array($s2p_transaction->getMethodId(), [\Smart2Pay\GlobalPay\Model\Smart2Pay::PAYMENT_METHOD_BT, \Smart2Pay\GlobalPay\Model\Smart2Pay::PAYMENT_METHOD_SIBS])) {
         if ($transaction_details_titles = \Smart2Pay\GlobalPay\Helper\Smart2Pay::transaction_logger_params_to_title() and is_array($transaction_details_titles)) {
             if (!($all_params = $this->_helper->getParams())) {
                 $all_params = [];
             }
             foreach ($transaction_details_titles as $key => $title) {
                 if (!array_key_exists($key, $all_params)) {
                     continue;
                 }
                 $transaction_extra_data[$key] = $all_params[$key];
             }
         }
     }
     $result_message = __('Transaction status is unknown.');
     if (empty($error_message)) {
         //map all statuses to known Magento statuses (message_data_2, message_data_4, message_data_3 and message_data_7)
         $status_id_to_string = array(Smart2Pay::S2P_STATUS_OPEN => Smart2Pay::S2P_STATUS_PENDING_PROVIDER, Smart2Pay::S2P_STATUS_SUCCESS => Smart2Pay::S2P_STATUS_SUCCESS, Smart2Pay::S2P_STATUS_CANCELLED => Smart2Pay::S2P_STATUS_CANCELLED, Smart2Pay::S2P_STATUS_FAILED => Smart2Pay::S2P_STATUS_FAILED, Smart2Pay::S2P_STATUS_EXPIRED => Smart2Pay::S2P_STATUS_FAILED, Smart2Pay::S2P_STATUS_PENDING_CUSTOMER => Smart2Pay::S2P_STATUS_PENDING_PROVIDER, Smart2Pay::S2P_STATUS_PENDING_PROVIDER => Smart2Pay::S2P_STATUS_PENDING_PROVIDER, Smart2Pay::S2P_STATUS_SUBMITTED => Smart2Pay::S2P_STATUS_PENDING_PROVIDER, Smart2Pay::S2P_STATUS_PROCESSING => Smart2Pay::S2P_STATUS_PENDING_PROVIDER, Smart2Pay::S2P_STATUS_AUTHORIZED => Smart2Pay::S2P_STATUS_PENDING_PROVIDER, Smart2Pay::S2P_STATUS_APPROVED => Smart2Pay::S2P_STATUS_PENDING_PROVIDER, Smart2Pay::S2P_STATUS_CAPTURED => Smart2Pay::S2P_STATUS_PENDING_PROVIDER, Smart2Pay::S2P_STATUS_REJECTED => Smart2Pay::S2P_STATUS_FAILED, Smart2Pay::S2P_STATUS_PENDING_CAPTURE => Smart2Pay::S2P_STATUS_PENDING_PROVIDER, Smart2Pay::S2P_STATUS_EXCEPTION => Smart2Pay::S2P_STATUS_PENDING_PROVIDER, Smart2Pay::S2P_STATUS_PENDING_CANCEL => Smart2Pay::S2P_STATUS_PENDING_PROVIDER, Smart2Pay::S2P_STATUS_REVERSED => Smart2Pay::S2P_STATUS_PENDING_PROVIDER, Smart2Pay::S2P_STATUS_COMPLETED => Smart2Pay::S2P_STATUS_SUCCESS, Smart2Pay::S2P_STATUS_PROCESSING => Smart2Pay::S2P_STATUS_PENDING_PROVIDER, Smart2Pay::S2P_STATUS_DISPUTED => Smart2Pay::S2P_STATUS_PENDING_PROVIDER, Smart2Pay::S2P_STATUS_CHARGEBACK => Smart2Pay::S2P_STATUS_PENDING_PROVIDER);
         if (isset($module_settings['message_data_' . $status_code])) {
             $result_message = $module_settings['message_data_' . $status_code];
         } elseif (!empty($status_id_to_string[$status_code]) and isset($module_settings['message_data_' . $status_id_to_string[$status_code]])) {
             $result_message = $module_settings['message_data_' . $status_id_to_string[$status_code]];
         }
     }
     $this->addData(['error_message' => $error_message, 'result_message' => $result_message, 'transaction_data' => $s2p_transaction->getData(), 'transaction_extra_data' => $transaction_extra_data, 'transaction_details_title' => $transaction_details_titles, 'is_order_visible' => $this->isVisible($order), 'view_order_url' => $this->getUrl('sales/order/view/', ['order_id' => $order->getEntityId()]), 'can_view_order' => $this->canViewOrder($order), 'order_id' => $order->getIncrementId()]);
 }
示例#3
0
 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;
 }
示例#4
0
 /**
  * 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]);
 }