public function processResponse(PaymentTransaction $paymentTransaction, Response $response)
 {
     if ($response->isApproved()) {
         $paymentTransaction->setStatus(PaymentTransaction::STATUS_APPROVED);
     }
     return $response;
 }
 public function processCallback(PaymentTransaction $paymentTransaction, CallbackResponse $callback)
 {
     $paymentTransaction->setStatus(PaymentTransaction::STATUS_APPROVED);
     return $callback;
 }
 /**
  * Updates payment transaction by query response data
  * if payment transaction is not processing or approved
  *
  * @param       PaymentTransaction      $paymentTransaction     Payment transaction for updating
  * @param       Response                $response               Response for payment transaction updating
  */
 protected function updatePaymentTransactionOnError(PaymentTransaction $paymentTransaction, Response $response)
 {
     if ($response->isDeclined()) {
         $paymentTransaction->setStatus($response->getStatus());
     } else {
         $paymentTransaction->setStatus(PaymentTransaction::STATUS_ERROR);
     }
     $paymentTransaction->addError($response->getError());
     $this->setPaynetId($paymentTransaction, $response);
 }
 /**
  * Updates Payment transaction by Callback data
  *
  * @param       PaymentTransaction      $paymentTransaction     Payment transaction for updating
  * @param       CallbackResponse        $response               Callback for payment transaction updating
  */
 protected function updatePaymentTransaction(PaymentTransaction $paymentTransaction, CallbackResponse $callbackResponse)
 {
     $paymentTransaction->setStatus($callbackResponse->getStatus());
     $paymentTransaction->getPayment()->setPaynetId($callbackResponse->getPaymentPaynetId());
     if ($callbackResponse->isError() || $callbackResponse->isDeclined()) {
         $paymentTransaction->addError($callbackResponse->getError());
     }
 }
 /**
  * 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;
 }