コード例 #1
0
ファイル: Smart2Pay.php プロジェクト: smart2pay/magento20
 /**
  * Prepare information specific to current payment method
  *
  * @param null|\Magento\Framework\DataObject|array $transport
  * @return \Magento\Framework\DataObject
  */
 protected function _prepareSpecificInformation($transport = null)
 {
     if (null !== $this->_paymentSpecificInformation) {
         return $this->_paymentSpecificInformation;
     }
     $transport = parent::_prepareSpecificInformation($transport);
     $module_name = $this->getRequest()->getModuleName();
     $action_name = $this->getRequest()->getActionName();
     if ($details_arr = $this->getInfo()->getAdditionalInformation() and !empty($details_arr['sp_method']) and $method_obj = $this->_s2pMethod->create()->load($details_arr['sp_method'])) {
         if (!empty($details_arr['sp_transaction']) and $transaction_obj = $this->_s2pTransaction->create()->load($details_arr['sp_transaction'])) {
             if (!($payment_id = $transaction_obj->getPaymentId())) {
                 $payment_id = __('N/A')->render();
             }
             $this->_paymentSpecificInformation->setData(__('Method')->render(), $method_obj->getDisplayName());
             $this->_paymentSpecificInformation->setData(__('Environment')->render(), $transaction_obj->getEnvironment());
             $this->_paymentSpecificInformation->setData(__('Payment ID')->render(), $payment_id);
             if ($transaction_extra_arr = $transaction_obj->getExtraDataArray() and $details_titles_arr = $this->_helper->transaction_logger_params_to_title()) {
                 foreach ($transaction_extra_arr as $title_key => $val) {
                     if (empty($details_titles_arr[$title_key])) {
                         continue;
                     }
                     $this->_paymentSpecificInformation->setData($details_titles_arr[$title_key], $val);
                 }
             }
         }
     }
     $this->_paymentSpecificInformation->setData('Test', 'Test value');
     return $this->_paymentSpecificInformation;
 }
コード例 #2
0
ファイル: Finish.php プロジェクト: smart2pay/magento20
 /**
  * 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
ファイル: Notification.php プロジェクト: smart2pay/magento20
 /**
  * Send email with payment details to customer
  *
  * @param Order $order Order
  * @param array $payment_details_arr Payment details
  */
 public function sendPaymentDetails(\Magento\Sales\Model\Order $order, $payment_details_arr)
 {
     $payment_details_arr = self::validatePaymentDetailsParams($payment_details_arr);
     try {
         if (!($order_increment_id = $order->getRealOrderId()) or !($method_config = $this->_s2pModel->getFullConfigArray()) or !($transaction_data = $this->_s2pTransaction->create()->loadByMerchantTransactionId($order_increment_id)->getData()) or !is_array($transaction_data) or empty($transaction_data['id']) or empty($transaction_data['method_id']) or !in_array($transaction_data['method_id'], [\Smart2Pay\GlobalPay\Model\Smart2Pay::PAYMENT_METHOD_BT, \Smart2Pay\GlobalPay\Model\Smart2Pay::PAYMENT_METHOD_SIBS])) {
             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');
         if ($transaction_data['method_id'] == \Smart2Pay\GlobalPay\Model\Smart2Pay::PAYMENT_METHOD_SIBS) {
             $templateId = $method_config['smart2pay_email_payment_instructions_sibs'];
         } else {
             $templateId = $method_config['smart2pay_email_payment_instructions_bt'];
         }
         $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;
         $transport = $this->_transportBuilder->setTemplateIdentifier($templateId)->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 payment instructions 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
ファイル: Smart2Pay.php プロジェクト: smart2pay/magento20
 /**
  * Assign corresponding data
  *
  * @param \Magento\Framework\DataObject|mixed $data
  * @return $this
  * @throws LocalizedException
  */
 public function assignData(\Magento\Framework\DataObject $data)
 {
     parent::assignData($data);
     $infoInstance = $this->getInfoInstance();
     if (($s2p_method = $data->getSpMethod()) === null) {
         $s2p_method = $data->getAdditionalData('sp_method');
     }
     if (($country_code = $data->getSelectedCountry()) === null) {
         $country_code = $data->getAdditionalData('selected_country');
     }
     if (!empty($country_code)) {
         $country_code = strtoupper(trim($country_code));
     }
     $configured_methods_instance = $this->_configuredMethods->create();
     if (!$s2p_method or empty($country_code) or !($method_details = $configured_methods_instance->getConfiguredMethodDetails($s2p_method, ['country_code' => $country_code, 'only_active' => true]))) {
         // ob_start();
         // var_dump( $data->getSpMethod() );
         // var_dump( $data->getAdditionalData( 'sp_method' ) );
         // var_dump( $s2p_method );
         // var_dump( $country_code );
         // if( isset( $method_details ) )
         //     var_dump( $method_details );
         // $buf = ob_get_clean();
         throw new LocalizedException(__('Please select a valid Smart2Pay method first.'));
     }
     $details_arr = array();
     if (!empty($method_details[$country_code])) {
         $details_arr = $method_details[$country_code];
     } elseif (!empty($method_details[Country::INTERNATIONAL_CODE])) {
         $details_arr = $method_details[Country::INTERNATIONAL_CODE];
     }
     if (empty($details_arr) or !is_array($details_arr)) {
         throw new LocalizedException(__('Couldn\'t obtain Smart2Pay payment method details. Please retry.'));
     }
     $s2p_transaction = $this->_s2pTransaction->create();
     $s2p_transaction->setMethodID($s2p_method)->setMerchantTransactionID('NOTSETYET_' . microtime(true));
     $s2p_transaction->save();
     $infoInstance->setAdditionalInformation('sp_method', $s2p_method);
     $infoInstance->setAdditionalInformation('sp_surcharge', isset($details_arr['surcharge']) ? $details_arr['surcharge'] : 0);
     $infoInstance->setAdditionalInformation('sp_fixed_amount', isset($details_arr['fixed_amount']) ? $details_arr['fixed_amount'] : 0);
     $infoInstance->setAdditionalInformation('sp_transaction', $s2p_transaction->getID());
     return $this;
 }
コード例 #5
0
ファイル: Send.php プロジェクト: smart2pay/magento20
 /**
  * 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]);
 }