public function testSerializeAndUnserialize()
 {
     $payment = new Payment(array('customer' => new Customer(array('first_name' => 'Vasya', 'last_name' => 'Pupkin', 'email' => '*****@*****.**'))));
     $paymentTransaction = new PaymentTransaction(array('status' => PaymentTransaction::STATUS_APPROVED));
     $paymentTransaction->addError(new PaynetException('Test exception'));
     $payment->setStatus(Payment::STATUS_CAPTURE)->addPaymentTransaction($paymentTransaction)->addPaymentTransaction(new PaymentTransaction());
     $unserializedPayment = unserialize(serialize($payment));
     $paymentTransactions = $unserializedPayment->getPaymentTransactions();
     $unserializedTransaction = reset($paymentTransactions);
     $this->assertEquals(Payment::STATUS_CAPTURE, $unserializedPayment->getStatus());
     $this->assertEquals('*****@*****.**', $unserializedPayment->getCustomer()->getEmail());
     $this->assertCount(2, $paymentTransactions);
     $this->assertEquals(PaymentTransaction::STATUS_APPROVED, $unserializedTransaction->getStatus());
     $errors = $unserializedTransaction->getErrors();
     $this->assertTrue($unserializedTransaction->hasErrors());
     $this->assertEquals('Test exception', reset($errors)->getMessage());
 }
 /**
  * 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;
 }
 /**
  * Set payment transaction payment
  *
  * @param       Payment         $payment        Payment
  *
  * @return      self
  */
 public function setPayment(Payment $payment)
 {
     $this->payment = $payment;
     if (!$payment->hasPaymentTransaction($this)) {
         $payment->addPaymentTransaction($this);
     }
     return $this;
 }
 /**
  * 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;
 }