/**
  * Transform OsCommerce order to PaynetEasy order
  *
  * @param       order           $oscommerce_order       OsCommerce order
  * @param       string          $redirect_url           Url for final payment processing
  *
  * @return      PaymentTransaction                      PaynetEasy transaction
  */
 protected function get_paynet_transaction(OsCommerceOrder $oscommerce_order, $redirect_url = null)
 {
     $oscommerce_customer = $oscommerce_order->customer;
     $paynet_transaction = new PaymentTransaction();
     $paynet_address = new BillingAddress();
     $paynet_payment = new Payment();
     $paynet_customer = new Customer();
     $query_config = new QueryConfig();
     $state_code = tep_get_zone_code($oscommerce_customer['country']['id'], $oscommerce_customer['zone_id'], $oscommerce_customer['state']);
     $paynet_address->setCountry($oscommerce_customer['country']['iso_code_2'])->setState($state_code)->setCity($oscommerce_customer['city'])->setFirstLine($oscommerce_customer['street_address'])->setZipCode($oscommerce_customer['postcode'])->setPhone($oscommerce_customer['telephone']);
     $paynet_customer->setEmail($oscommerce_customer['email_address'])->setFirstName($oscommerce_customer['firstname'])->setLastName($oscommerce_customer['lastname'])->setIpAddress(tep_get_ip_address());
     $paynet_payment->setClientId($oscommerce_order->info['order_id'])->setDescription($this->get_paynet_order_description($oscommerce_order))->setAmount($oscommerce_order->info['total'])->setCurrency($oscommerce_order->info['currency'])->setCustomer($paynet_customer)->setBillingAddress($paynet_address);
     if (isset($oscommerce_order->info['paynet_order_id'])) {
         $paynet_payment->setPaynetId($oscommerce_order->info['paynet_order_id']);
     }
     $query_config->setEndPoint((int) MODULE_PAYMENT_PAYNETEASYFORM_END_POINT)->setLogin(MODULE_PAYMENT_PAYNETEASYFORM_LOGIN)->setSigningKey(MODULE_PAYMENT_PAYNETEASYFORM_SIGNING_KEY)->setGatewayMode(MODULE_PAYMENT_PAYNETEASYFORM_GATEWAY_MODE)->setGatewayUrlSandbox(MODULE_PAYMENT_PAYNETEASYFORM_SANDBOX_GATEWAY)->setGatewayUrlProduction(MODULE_PAYMENT_PAYNETEASYFORM_PRODUCTION_GATEWAY);
     if (Validator::validateByRule($redirect_url, Validator::URL, false)) {
         $query_config->setRedirectUrl($redirect_url)->setCallbackUrl($redirect_url);
     }
     $paynet_transaction->setPayment($paynet_payment)->setQueryConfig($query_config);
     return $paynet_transaction;
 }
 /**
  * Get PaynetEasy payment transaction object by OpenCart order data array
  *
  * @param       MageOrder       $mageOrder          Magento order
  * @param       string          $redirectUrl        Url for final payment processing
  *
  * @return      PaynetTransaction                   PaynetEasy payment transaction
  */
 protected function getPaynetTransaction(array $opencart_order, $redirect_url = null)
 {
     $query_config = new QueryConfig();
     $paynet_address = new BillingAddress();
     $paynet_transaction = new PaymentTransaction();
     $paynet_payment = new Payment();
     $paynet_customer = new Customer();
     $paynet_address->setCountry($opencart_order['payment_iso_code_2'])->setCity($opencart_order['payment_city'])->setFirstLine($opencart_order['payment_address_1'])->setZipCode($opencart_order['payment_postcode'])->setPhone($opencart_order['telephone'])->setState($opencart_order['payment_zone_code']);
     $paynet_customer->setEmail($opencart_order['email'])->setFirstName($opencart_order['firstname'])->setLastName($opencart_order['lastname'])->setIpAddress($opencart_order['ip']);
     $paynet_payment->setClientId($opencart_order['order_id'])->setDescription($this->getPaynetPaymentDescription($opencart_order))->setAmount($opencart_order['total'])->setCurrency($opencart_order['currency_code'])->setCustomer($paynet_customer)->setBillingAddress($paynet_address);
     $query_config->setEndPoint($this->getModuleConfigValue('end_point'))->setLogin($this->getModuleConfigValue('login'))->setSigningKey($this->getModuleConfigValue('signing_key'))->setGatewayMode($this->getModuleConfigValue('gateway_mode'))->setGatewayUrlSandbox($this->getModuleConfigValue('sandbox_gateway'))->setGatewayUrlProduction($this->getModuleConfigValue('production_gateway'));
     if (Validator::validateByRule($redirect_url, Validator::URL, false)) {
         $query_config->setRedirectUrl($redirect_url)->setCallbackUrl($redirect_url);
     }
     $paynet_transaction->setPayment($paynet_payment)->setQueryConfig($query_config);
     return $paynet_transaction;
 }
 /**
  * Add query config data to PaynetEasy payment transaction
  *
  * @param       PaynetTransaction       $paynetTransaction      PaynetEasy payment transaction
  * @param       string                  $redirectUrl            Url for final payment processing
  *
  * @return      PaynetTransaction                               PaynetEasy payment transaction
  */
 protected function addQueryConfigData(PaynetTransaction $paynetTransaction, $redirectUrl = null)
 {
     $paynetTransaction->getQueryConfig()->setEndPoint($this->getConfigData('endpoint_id'))->setLogin($this->getConfigData('merchant_login'))->setSigningKey($this->getConfigData('merchant_key'))->setGatewayMode($this->getConfigData('gateway_mode'))->setGatewayUrlSandbox($this->getConfigData('sandbox_api_url'))->setGatewayUrlProduction($this->getConfigData('production_api_url'));
     if (Validator::validateByRule($redirectUrl, Validator::URL, false)) {
         $paynetTransaction->getQueryConfig()->setRedirectUrl($redirectUrl)->setCallbackUrl($redirectUrl);
     }
 }
 /**
  * Transform joomla order to PaynetEasy order
  *
  * @param       stdClass        $joomlaAddress      Joomla address
  * @param       string          $redirectUrl        Url for final payment processing
  *
  * @return      PaymentTransaction                  PaynetEasy order
  */
 protected function getPaynetTransaction(stdClass $joomlaAddress, $redirectUrl = null)
 {
     $queryConfig = new QueryConfig();
     $paynetAddress = new BillingAddress();
     $paynetTransaction = new PaymentTransaction();
     $paynetPayment = new Payment();
     $paynetCustomer = new Customer();
     $countryCode = ShopFunctions::getCountryByID($joomlaAddress->virtuemart_country_id, 'country_2_code');
     $currencyCode = ShopFunctions::getCurrencyByID($joomlaAddress->order_currency, 'currency_code_3');
     $paynetAddress->setCountry($countryCode)->setCity($joomlaAddress->city)->setFirstLine($joomlaAddress->address_1)->setZipCode($joomlaAddress->zip)->setPhone($joomlaAddress->phone_1 ?: '(000) 00-00-00');
     if (isset($joomlaAddress->virtuemart_state_id)) {
         $stateCode = ShopFunctions::getStateByID($joomlaAddress->virtuemart_state_id, 'state_2_code');
         $paynetAddress->setState($stateCode);
     }
     $paynetCustomer->setEmail($joomlaAddress->email)->setFirstName($joomlaAddress->first_name)->setLastName($joomlaAddress->last_name)->setIpAddress($joomlaAddress->ip_address);
     $paynetPayment->setClientId($joomlaAddress->order_number)->setDescription($this->getPaynetOrderDescription($joomlaAddress))->setAmount($joomlaAddress->order_total)->setCurrency($currencyCode)->setCustomer($paynetCustomer)->setBillingAddress($paynetAddress);
     if (isset($joomlaAddress->paynet_order_id)) {
         $paynetPayment->setPaynetId($joomlaAddress->paynet_order_id);
     }
     if (isset($joomlaAddress->payment_status)) {
         $paynetPayment->setStatus($joomlaAddress->payment_status);
     }
     $queryConfig->setEndPoint($this->getConfig('end_point'))->setLogin($this->getConfig('login'))->setSigningKey($this->getConfig('signing_key'))->setGatewayMode($this->getConfig('gateway_mode'))->setGatewayUrlSandbox($this->getConfig('sandbox_gateway'))->setGatewayUrlProduction($this->getConfig('production_gateway'));
     if (Validator::validateByRule($redirectUrl, Validator::URL, false)) {
         $queryConfig->setRedirectUrl($redirectUrl)->setCallbackUrl($redirectUrl);
     }
     $paynetTransaction->setPayment($paynetPayment)->setQueryConfig($queryConfig);
     if (isset($joomlaAddress->transaction_status)) {
         $paynetTransaction->setStatus($joomlaAddress->transaction_status);
     }
     return $paynetTransaction;
 }