/**
  * 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;
 }
 /**
  * Load PaynetEasy payment paynet_id from database.
  *
  * @param       Payment         $payment        PaynetEasy payment
  *
  * @throws      RuntimeException                Can not found paynet_id for payment client_id
  */
 protected function loadPaymentIds(Payment $payment)
 {
     $client_id = $payment->getClientId();
     $result = $this->db->query("\n            SELECT `paynet_id`\n            FROM `" . DB_PREFIX . "payneteasy_form_payment`\n            WHERE `client_id` = '{$this->db->escape($client_id)}'\n        ");
     if (empty($result->row)) {
         throw new RuntimeException("Can not find 'paynet_id' for Payment with 'client_id' = {$client_id}");
     }
     $payment->setPaynetId($result->row['paynet_id']);
 }
 /**
  * Get PaynetEasy payment object by Prestashop cart object.
  *
  * @param       Cart        $prestashop_cart        Prestashop cart.
  *
  * @return      Payment     PaynetEasy payment transaction
  */
 protected function getPaynetPayment(Cart $prestashop_cart)
 {
     $paynet_payment = new Payment();
     if (Tools::getIsset('orderid')) {
         $paynet_payment->setPaynetId(Tools::getValue('orderid'));
     }
     $paynet_payment->setClientId($prestashop_cart->id)->setDescription($this->getPaynetOrderDescription($prestashop_cart))->setAmount($prestashop_cart->getOrderTotal())->setCurrency(Currency::getCurrencyInstance($prestashop_cart->id_currency)->iso_code)->setCustomer($this->getPaynetCustomer($prestashop_cart))->setBillingAddress($this->getPaynetAddress($prestashop_cart));
     return $paynet_payment;
 }
 /**
  * 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;
 }