Exemplo n.º 1
0
 /**
  * Send current cart details back to X-Payments.   
  *
  * @return void
  */
 protected function doActionCheckCart()
 {
     $refId = \XLite\Core\Request::getInstance()->refId;
     $transaction = $this->detectTransaction();
     $xml = '';
     if ($transaction) {
         $cart = $transaction->getOrder();
         $response = array('status' => 'cart-changed', 'ref_id' => $refId);
         $clientXpayments = \XLite\Module\CDev\XPaymentsConnector\Core\XPaymentsClient::getInstance();
         if (method_exists($transaction, 'isAntiFraudApplied') && method_exists($transaction, 'checkBlockOrder') && $transaction->isAntiFraudApplied() && $transaction->checkBlockOrder(true)) {
             // ANTIFRAUD RELATED CHANGES
             // This makes a error top messsage at checkout
             $transaction->setDataCell('status', 'AF Error #1: Cannot process this order. Contact administrator', null, 'C');
         } else {
             // Prepare cart
             $preparedCart = $clientXpayments->prepareCart($cart, $transaction->getPaymentMethod(), $refId);
             if ($cart && $preparedCart) {
                 $response['cart'] = $preparedCart;
             }
         }
         try {
             // Convert array to XML and encrypt it
             $xml = $clientXpayments->encryptRequest($response);
         } catch (\XLite\Module\CDev\XPaymentsConnector\Core\XpcResponseException $exception) {
             // Doesn't matter, but al least we can send something
             $xml = $exception->getMessage();
         }
         print $xml;
         die(0);
     }
 }
Exemplo n.º 2
0
 /**
  * If we can proceed with checkout with current cart
  *
  * @return boolean
  */
 public function checkCart()
 {
     $result = parent::checkCart();
     if (\XLite\Module\CDev\XPaymentsConnector\Core\XPaymentsClient::getInstance()->isModuleConfigured() && !$result) {
         \XLite\Module\CDev\XPaymentsConnector\Core\XPaymentsClient::getInstance()->clearInitDataFromSession();
     }
     return $result;
 }
Exemplo n.º 3
0
 /**
  * Do Recharge the difference request.
  * Returns false on failure or redirects admin back to the order page
  * the necessary actions with the backend transaction are taken in the
  * Callback request processing
  *
  * @param \XLite\Model\Order $order Order which is recharged
  * @param \XLite\Model\Payment\Transaction $parentCardTransaction Trandaction with saved card
  * @param float $amount Amount to recharge
  *
  * @return boolean
  */
 public function doRecharge(\XLite\Model\Order $order, \XLite\Model\Payment\Transaction $parentCardTransaction, $amount)
 {
     $newTransaction = new \XLite\Model\Payment\Transaction();
     $newTransaction->setPaymentMethod($this->getSavedCardsPaymentMethod());
     $newTransaction->setStatus(\XLite\Model\Payment\Transaction::STATUS_INPROGRESS);
     $newTransaction->setDataCell('is_recharge', 'Y', null, 'C');
     $newTransaction->setValue($amount);
     $order->addPaymentTransactions($newTransaction);
     $newTransaction->setOrder($order);
     foreach ($this->paymentSettingsToSave as $field) {
         $key = 'xpc_can_do_' . $field;
         if ($parentCardTransaction->getDataCell($key) && $parentCardTransaction->getDataCell($key)->getValue()) {
             $newTransaction->setDataCell($key, $parentCardTransaction->getDataCell($key)->getValue(), null, 'C');
         }
     }
     $this->copyMaskedCard($parentCardTransaction, $newTransaction);
     $recharge = $this->client->requestPaymentRecharge($parentCardTransaction->getDataCell('xpc_txnid')->getValue(), $newTransaction);
     if ($recharge->isSuccess()) {
         $response = $recharge->getResponse();
         if (self::STATUS_AUTH == $response['status'] || self::STATUS_CHARGED == $response['status']) {
             \XLite\Core\TopMessage::getInstance()->addInfo($response['message'] ? $response['message'] : 'Operation successfull');
             if ($response['transaction_id']) {
                 $newTransaction->setDataCell('xpc_txnid', $response['transaction_id'], 'X-Payments transaction ID', 'C');
             }
         } else {
             \XLite\Core\TopMessage::getInstance()->addError($response['error'] ? $response['error'] : 'Operation failed');
             $newTransaction->setStatus(\XLite\Model\Payment\Transaction::STATUS_FAILED);
         }
     } else {
         $message = 'Operation failed';
         if ($recharge->getError()) {
             $message .= '. ' . $recharge->getError();
         }
         \XLite\Core\TopMessage::getInstance()->addError($message);
         $newTransaction->setStatus(\XLite\Model\Payment\Transaction::STATUS_FAILED);
     }
     \XLite\Core\Database::getEM()->flush();
 }
Exemplo n.º 4
0
 /**
  * Finalize X-Payments iframe
  *
  * @return void
  */
 public function finalize()
 {
     if ($this->getError()) {
         \XLite\Module\CDev\XPaymentsConnector\Core\XPaymentsClient::getInstance()->clearInitDataFromSession();
     }
     print $this->getHTML();
     \XLite\Core\Database::getEM()->flush();
     die(0);
 }
Exemplo n.º 5
0
 /**
  * Import payment methods from X-Payments and return error or warning message (if any)
  *
  * @return void
  */
 public function importPaymentMethods()
 {
     $list = \XLite\Module\CDev\XPaymentsConnector\Core\XPaymentsClient::getInstance()->requestPaymentMethods();
     if (is_array($list) && !empty($list)) {
         foreach ($this->getPaymentMethods() as $pm) {
             if (!$this->checkMethodInImportedList($pm, $list)) {
                 \XLite\Core\Database::getEM()->remove($pm);
             }
         }
         foreach ($list as $settings) {
             if (!isset($settings['paymentMethodId'])) {
                 // Create new payment method
                 $pm = new \XLite\Model\Payment\Method();
                 \XLite\Core\Database::getEM()->persist($pm);
                 $xpModuleClass = $this->detectModuleClass($settings);
                 $pm->setClass('Module\\CDev\\XPaymentsConnector\\Model\\Payment\\Processor\\XPayments');
                 $pm->setServiceName('XPayments.' . $xpModuleClass);
                 $pm->setName($settings['moduleName']);
                 $pm->setType(\XLite\Model\Payment\Method::TYPE_CC_GATEWAY);
                 $pm->setOrderby(static::getPaymentMethodOrderby('XPayments.' . $xpModuleClass));
                 $pm->setAdded(true);
                 // Tokenization is disabled by default
                 $pm->setSetting('saveCards', 'N');
             } else {
                 // Use existsting payment method
                 $pm = \XLite\Core\Database::getRepo('XLite\\Model\\Payment\\Method')->find($settings['paymentMethodId']);
             }
             $this->setPaymentMethodSettings($pm, $settings);
         }
         \XLite\Core\Database::getEM()->flush();
         \XLite\Core\TopMessage::addInfo('Payment methods have been imported successfully');
     } elseif (is_array($list)) {
         \XLite\Core\TopMessage::addWarning('There are no payment configurations for this store.');
     } else {
         \XLite\Core\TopMessage::addError('Error had occured during the requesting of payment methods from X-Payments. See log files for details.');
     }
 }
Exemplo n.º 6
0
 /**
  * Check response for errors 
  *
  * @param array $response Formatted response from X-Payments
  *
  * @return void 
  */
 protected function checkError($response)
 {
     $message = $code = '';
     if (!empty($response['error_message'])) {
         $message = $response['error_message'];
     }
     if (!empty($response['error'])) {
         $code = $response['error'];
     }
     if ($code || $message) {
         $error = \XLite\Module\CDev\XPaymentsConnector\Core\XPaymentsClient::getInstance()->composeErrorMessage($code, $message);
         self::throwError($error);
     }
 }
Exemplo n.º 7
0
 /**
  * Get X-Payments connector transactions
  *
  * @return boolean
  */
 public function getXpcTransactionsAddInfo()
 {
     $transaction = \XLite\Core\Database::getRepo('XLite\\Model\\Payment\\Transaction')->find(\XLite\Core\Request::getInstance()->transaction_id);
     $result = false;
     if ($transaction && $transaction->isXpc(true) && $transaction->getDataCell('xpc_txnid')) {
         $client = \XLite\Module\CDev\XPaymentsConnector\Core\XPaymentsClient::getInstance();
         $info = $client->requestPaymentAdditionalInfo($transaction->getDataCell('xpc_txnid')->getValue());
         if ($info->isSuccess()) {
             $response = $info->getResponse();
             if (!empty($response['transactions']) && is_array($response['transactions'])) {
                 $result = $response['transactions'];
             }
         }
     }
     return $result;
 }
Exemplo n.º 8
0
 /**
  * Clear init data from session and redirrcet back to checkout
  *
  * @return void
  */
 protected function doActionClearInitData()
 {
     \XLite\Module\CDev\XPaymentsConnector\Core\XPaymentsClient::getInstance()->clearInitDataFromSession();
     $this->setHardRedirect();
     $this->setReturnURL($this->buildURL('cart', 'checkout'));
     $this->doRedirect();
 }
Exemplo n.º 9
0
 /**
  * Display connection steps or not 
  *
  * @return boolean
  */
 public function isDisplaySteps()
 {
     return !\XLite\Module\CDev\XPaymentsConnector\Core\XPaymentsClient::getInstance()->isModuleConfigured();
 }
Exemplo n.º 10
0
 /**
  * Check if this is error for unaccepted changes of templates in X-Payments
  *
  * @param string $message Message
  *
  * @return array
  */
 public function isUnacceptedTemplateError($message)
 {
     list($code, $message) = \XLite\Module\CDev\XPaymentsConnector\Core\XPaymentsClient::getInstance()->parseErrorMessage($message);
     return '505' == $code;
 }
Exemplo n.º 11
0
 /**
  * Get X-Payments client 
  *
  * @return object
  */
 protected static function getClient()
 {
     return \XLite\Module\CDev\XPaymentsConnector\Core\XPaymentsClient::getInstance();
 }
Exemplo n.º 12
0
 /**
  * Check if widget is visible
  *
  * @return boolean
  */
 protected function isVisible()
 {
     return parent::isVisible() && \XLite\Module\CDev\XPaymentsConnector\Core\XPaymentsClient::getInstance()->isModuleConfigured();
 }