/** * handleRequest * * @return void */ public function handleRequest() { if ($this->getModuleID() && 'CDev\\AmazonS3Images' == $this->getModule()->getActualName() && \XLite\Core\Request::getInstance()->isGet() && !\XLite\Core\TopMessage::getInstance()->getPreviousMessages()) { $this->checkAmazonS3Settings(); } parent::handleRequest(); }
/** * Validate return from Canada Post merchant registration process * * @return void */ protected function capostValidateMerchant() { $token = \XLite\Core\Request::getInstance()->{'token-id'}; $status = \XLite\Core\Request::getInstance()->{'registration-status'}; if (\XLite\Module\XC\CanadaPost\Core\Service\Platforms::REG_STATUS_SUCCESS === $status) { // Registration is complete // Send request to Canada Post server to retrieve merchant details $data = \XLite\Module\XC\CanadaPost\Core\Service\Platforms::getInstance()->callGetMerchantRegistrationInfoByToken($token); if (isset($data->merchantInfo)) { // Update Canada Post settings $this->updateCapostMerchantSettings($data->merchantInfo); // Disable wizard $this->disableCapostWizard(); \XLite\Core\TopMessage::getInstance()->addInfo('Registration process has been completed successfully.'); } else { foreach ($data->errors as $err) { \XLite\Core\TopMessage::getInstance()->addError('ERROR: [' . $err->code . '] ' . $err->description); } } } else { // An error occurred if (\XLite\Module\XC\CanadaPost\Core\Service\Platforms::REG_STATUS_CANCELLED === $status) { \XLite\Core\TopMessage::getInstance()->addError('Registration process has been canceled.'); } else { \XLite\Core\TopMessage::getInstance()->addError('Failure to finish registration process.'); } } // Remove token from the session \XLite\Core\Session::getInstance()->capost_token_id = null; \XLite\Core\Session::getInstance()->capost_token_ts = null; // Redirect back to the Canada Post settings page $this->setReturnURL($this->buildURL('capost')); }
/** * X-Cart Wrapper for BitPay Library * @param \XLite\Model\Payment\Method $method */ public function __construct($method) { $this->method = $method; // Load up the BitPay library $autoloader = LC_DIR_MODULES . 'BitPay' . LC_DS . 'BitPay' . LC_DS . 'lib' . LC_DS . 'Bitpay' . LC_DS . 'xcartAutoloader.php'; if (true === file_exists($autoloader) && true === is_readable($autoloader)) { require_once $autoloader; \Bitpay\xcartAutoloader::register(); } else { \XLite\Core\TopMessage::getInstance()->addError('[Error] Unable to load BitPay library'); } }
public function doActionUpdate() { $request = \XLite\Core\Request::getInstance(); $result = false; if ($request->delete_token) { try { $condition = array('id' => $request->delete_token); $repo = $this->getModelRepo(); $token = $repo->findOneBy($condition); $this->getEM()->remove($token); $this->getEM()->flush(); $result = true; } catch (Exception $e) { } } if ($result) { \XLite\Core\TopMessage::getInstance()->addInfo('Operation successfull'); } }
/** * Get Canada Post merchant registration token * * @return string */ public function getTokenId() { $token = null; if (!$this->isTokenValid()) { // Send request to Canada Post server to retrieve token $data = \XLite\Module\XC\CanadaPost\Core\Service\Platforms::getInstance()->callGetMerchantRegistrationToken(); if (isset($data->token)) { $token = $data->token->tokenId; \XLite\Core\Session::getInstance()->capost_token_id = $token; \XLite\Core\Session::getInstance()->capost_token_ts = \XLite\Core\Converter::time(); \XLite\Core\Session::getInstance()->capost_developer_mode = \XLite\Core\Config::getInstance()->XC->CanadaPost->developer_mode; } else { // TODO: print real error message returned by the request \XLite\Core\TopMessage::getInstance()->addError('Failure to get token ID.'); } } else { // Get token from the session $token = \XLite\Core\Session::getInstance()->capost_token_id; } return $token; }
/** * isWrongLocation * * @return boolean */ protected function isWrongLocation() { $result = false; // Counter of checkings $counter = isset(\XLite\Core\Config::getInstance()->Internal->check_location) ? intval(\XLite\Core\Config::getInstance()->Internal->check_location) : 1; // Check location each 10 visits of the admin dashboard page if (0 < $counter) { // Prepare new value for counter $newCounterValue = 10 == $counter ? 1 : $counter + 1; if (1 === $counter) { // Check directory location $result = preg_match('/modules\\/lc_connector/', __DIR__); if ($result) { // Generate top message \XLite\Core\TopMessage::getInstance()->addWarning('Warning: LiteCommerce is installed within the "LC Connector" module directory. It is strongly recommended to move LiteCommerce directory from that location to avoid the problem, described <a href="http://www.facebook.com/litecommerce/posts/440928792599823">here</a>. You can find the instructions on how to do it <a href="https://github.com/litecommerce/core/wiki/Moving-LiteCommerce-subdirectory-to-the-Drupal-directory" target="new">here</a>. If you find it difficult to follow the instruction yourself, please contact <a href="mailto:xlite@litecommerce.com">xlite@litecommerce.com</a> or create a ticket at <a href="http://bt.litecommerce.com/">Bugtracker</a>.'); } else { $newCounterValue = 0; } } // Create/Update option with new counter value \XLite\Core\Database::getRepo('XLite\\Model\\Config')->createOption(array('name' => 'check_location', 'category' => 'Internal', 'value' => $newCounterValue)); } return $result; }
/** * 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(); }
/** * Prepare and validate inline widget * * @param \XLite\View\FormField\Inline\AInline $widget Widget * * @return boolean */ protected function prepareInlineWidget(\XLite\View\FormField\Inline\AInline $widget) { $widget->setValueFromRequest(); list($flag, $message) = $widget->validate(); if (!$flag) { \XLite\Core\TopMessage::getInstance()->addError($message); } return $flag; }
/** * Add diagnostic messages after importing is finished * * @return void */ protected function postprocessImport() { $this->importCell['old'] = \XLite\Core\Database::getRepo('XLite\\Model\\Product')->countLastUpdated($this->importCell['start']); $this->importCell['old'] -= $this->importCell['new']; $this->importCell['old'] = max(0, $this->importCell['old']); $label = null; if ($this->importCell['new'] && $this->importCell['old']) { $label = 'Occurred X add product events and Y update product events'; } elseif ($this->importCell['new']) { $label = 'Occurred X add product events'; } elseif ($this->importCell['old']) { $label = 'Occurred Y update product events'; } if ($label) { \XLite\Core\TopMessage::getInstance()->add($label, array('new' => $this->importCell['new'], 'old' => $this->importCell['old']), null, \XLite\Core\TopMessage::INFO, false, false); } if (0 < $this->importCell['warning_count']) { \XLite\Core\TopMessage::getInstance()->add('During the import was recorded X errors. You can get them by downloading the log files.', array('count' => $this->importCell['warning_count'], 'url' => \XLite\Logger::getInstance()->getCustomLogURL('import')), null, \XLite\Core\TopMessage::WARNING, false, false); \XLite\Core\TopMessage::getInstance()->add('Some products could have been imported incorrectly', array(), null, \XLite\Core\TopMessage::WARNING, false, false); } }
/** * Perform some actions on error * * @return void */ protected function postprocessErrorAction() { \XLite\Core\TopMessage::getInstance()->addBatch($this->getErrorMessages(), \XLite\Core\TopMessage::ERROR); $method = __FUNCTION__ . ucfirst($this->currentAction); if (method_exists($this, $method)) { // Run corresponded function $this->{$method}(); } $this->setActionError(); }
/** * Get top messages * * @return array */ protected function getTopMessages() { if (!isset($this->messages)) { $this->messages = \XLite\Core\TopMessage::getInstance()->unloadPreviousMessages(); } return $this->messages; }
/** * Process * * @return void */ public function process() { if ($this->preValidateAction()) { parent::process(); $items = \XLite\Core\Database::getRepo('XLite\\Model\\OrderItem')->search($this->getSearchCondition()); foreach ($items as $item) { $item->calculate(); } } else { \XLite\Core\TopMessage::getInstance()->addError(static::t('All items cannot be removed from the order.')); $this->setActionError(); } }
/** * Process DoCapture response * * @param \XLite\Model\Payment\BackendTransaction $transaction Transaction * @param string $responseData Response data OPTIONAL * * @return boolean */ protected function processRefundTransactionResponse(\XLite\Model\Payment\BackendTransaction $transaction, $responseData = null) { $result = false; if (!empty($responseData)) { $status = \XLite\Model\Payment\Transaction::STATUS_FAILED; if ('Success' === $responseData['ACK']) { $result = true; $status = \XLite\Model\Payment\Transaction::STATUS_SUCCESS; $transaction->getPaymentTransaction()->getOrder()->setPaymentStatus(\XLite\Model\Order\Status\Payment::STATUS_REFUNDED); // save transaction id for IPN $transaction->setDataCell('PPREF', $responseData['REFUNDTRANSACTIONID'], 'Unique PayPal transaction ID (REFUNDTRANSACTIONID)'); \XLite\Core\TopMessage::getInstance()->addInfo('Payment has bes refunded successfully'); } else { \XLite\Core\TopMessage::getInstance()->addError('Transaction failure. PayPal response: ' . $responseData['L_LONGMESSAGE0']); } $transaction->setStatus($status); $transaction->update(); } return $result; }
/** * Populate model object properties by the passed data * * @param array $data Data to set * * @return void */ protected function setModelProperties(array $data) { if (isset($data['enabled']) && !$data['enabled']) { $data = array('enabled' => '0'); } foreach ($data as $name => $value) { switch ($name) { case 'agreement': $value = !empty($value); break; case 'email': $publisherId = $this->getModelObject()->getSetting('publisherId'); $email = $this->getModelObject()->getSetting('email'); if (empty($publisherId) || $email !== $value) { $publisherId = Paypal\Core\PaypalCredit::getInstance()->getPublisherId($value); if (empty($publisherId)) { \XLite\Core\TopMessage::getInstance()->addWarning('Unable to retrieve Publisher ID for specified PayPal account. Banners are now disabled.'); } $this->getModelObject()->setSetting('publisherId', $publisherId); } break; default: break; } $this->getModelObject()->setSetting($name, $value); } }
/** * Process errors * * @return void */ protected function processUpdateWarnings() { $warnings = $this->getWarningMessages(); if ($warnings) { \XLite\Core\TopMessage::getInstance()->addBatch($warnings, \XLite\Core\TopMessage::WARNING); } }
/** * doExpressCheckoutReturn * * @return void */ protected function doActionExpressCheckoutReturn() { $request = \XLite\Core\Request::getInstance(); $cart = $this->getCart(); \XLite\Module\CDev\Paypal\Main::addLog('doExpressCheckoutReturn()', $request->getData()); if (isset($request->cancel)) { \XLite\Core\Session::getInstance()->ec_token = null; \XLite\Core\Session::getInstance()->ec_date = null; \XLite\Core\Session::getInstance()->ec_payer_id = null; \XLite\Core\Session::getInstance()->ec_type = null; $cart->unsetPaymentMethod(); \XLite\Core\TopMessage::getInstance()->addWarning('Express Checkout process stopped.'); } elseif (!isset($request->token) || $request->token != \XLite\Core\Session::getInstance()->ec_token) { \XLite\Core\TopMessage::getInstance()->addError('Wrong token of Express Checkout.'); } elseif (!isset($request->PayerID)) { \XLite\Core\TopMessage::getInstance()->addError('PayerID value was not returned by PayPal.'); } else { // Express Checkout shortcut flow processing \XLite\Core\Session::getInstance()->ec_type = \XLite\Module\CDev\Paypal\Model\Payment\Processor\ExpressCheckout::EC_TYPE_SHORTCUT; \XLite\Core\Session::getInstance()->ec_payer_id = $request->PayerID; $paymentMethod = $this->getExpressCheckoutPaymentMethod(); $buyerData = $paymentMethod->getProcessor()->doGetExpressCheckoutDetails($paymentMethod, $request->token); if (empty($buyerData)) { \XLite\Core\TopMessage::getInstance()->addError('Your address data was not received from PayPal.'); } else { // Fill the cart with data received from Paypal $this->requestData = $this->prepareBuyerData($buyerData); $this->updateProfile(); $this->requestData['billingAddress'] = $this->requestData['shippingAddress']; $this->requestData['same_address'] = true; $this->updateShippingAddress(); $this->updateBillingAddress(); } } }
/** * Validate secret word * * @return void */ protected function doActionValidateSecretWord() { $secretWord = trim(\XLite\Core\Request::getInstance()->secret_word); $secret = md5(md5($secretWord) . md5(\XLite\Module\CDev\Moneybookers\Model\Payment\Processor\Moneybookers::getPlatformSecretWord())); $platformId = \XLite\Module\CDev\Moneybookers\Model\Payment\Processor\Moneybookers::getPlatformCustomerID(); $request = new \XLite\Core\HTTP\Request('https://www.skrill.com/app/secret_word_check.pl' . '?secret=' . $secret . '&email=' . urlencode(\XLite\Core\Config::getInstance()->CDev->Moneybookers->email) . '&cust_id=' . $platformId); $response = $request->sendRequest(); if (200 == $response->code && 'OK' == $response->body) { \XLite\Core\Database::getRepo('\\XLite\\Model\\Config')->createOption(array('category' => 'CDev\\Moneybookers', 'name' => 'secret_word', 'value' => $secretWord)); \XLite\Core\TopMessage::getInstance()->add('Secret word is valid'); } elseif ('VELOCITY_CHECK_EXCEEDED' == $response->body) { \XLite\Core\TopMessage::getInstance()->add('Maximum number of checks for a particular user has been reached' . ' (currently set to 3 per user per hour)', array(), null, \XLite\Core\TopMessage::ERROR); } elseif ('REQUESTER_NOT_AUTHORISED' == $response->body) { \XLite\Core\TopMessage::getInstance()->add('Requestor\'s account not authorised to run the secret word check', array(), null, \XLite\Core\TopMessage::ERROR); } else { \XLite\Core\TopMessage::getInstance()->add('Secret word is not valid', array(), null, \XLite\Core\TopMessage::ERROR); } }
/** * Renew settings allowed values * * @return void */ protected function doActionRenewSettings() { $aupost = $this->getProcessor(); $errors = $aupost->updateServiceData(true); if (!empty($errors)) { foreach ($errors as $key => $msg) { \XLite\Core\TopMessage::getInstance()->addWarning(sprintf('Request "%s" has been failed: %s. Please retry later.', $key, $msg)); } } else { \XLite\Core\TopMessage::getInstance()->addInfo(static::t('Option values has been successfully updated.')); } $this->setReturnURL(\XLite\Core\Converter::buildURL($this->getTarget())); }
/** * Get a specific path * * @return string */ protected function getPath() { return \XLite\Core\TopMessage::getInstance()->getPath(); }
/** * Set Drupal messages using LC top messages data * * @return void */ protected function setPreviousTopMessages() { foreach (\XLite\Core\TopMessage::getInstance()->unloadPreviousMessages() as $message) { drupal_set_message($message['text'], isset($this->messageTypes[$message['type']]) ? $this->messageTypes[$message['type']] : 'status'); } }
/** * doExpressCheckoutReturn * * @return void */ protected function doActionExpressCheckoutReturn() { $request = \XLite\Core\Request::getInstance(); $cart = $this->getCart(); Paypal\Main::addLog('doExpressCheckoutReturn()', $request->getData()); $checkoutAction = false; if (isset($request->cancel)) { \XLite\Core\Session::getInstance()->ec_token = null; \XLite\Core\Session::getInstance()->ec_date = null; \XLite\Core\Session::getInstance()->ec_payer_id = null; \XLite\Core\Session::getInstance()->ec_type = null; $cart->unsetPaymentMethod(); \XLite\Core\TopMessage::getInstance()->addWarning('Express Checkout process stopped.'); } elseif (!isset($request->token) || $request->token != \XLite\Core\Session::getInstance()->ec_token) { \XLite\Core\TopMessage::getInstance()->addError('Wrong token of Express Checkout.'); } elseif (!isset($request->PayerID)) { \XLite\Core\TopMessage::getInstance()->addError('PayerID value was not returned by PayPal.'); } else { // Express Checkout shortcut flow processing \XLite\Core\Session::getInstance()->ec_type = Paypal\Model\Payment\Processor\ExpressCheckout::EC_TYPE_SHORTCUT; \XLite\Core\Session::getInstance()->ec_payer_id = $request->PayerID; $paymentMethod = $this->getExpressCheckoutPaymentMethod(); $processor = $paymentMethod->getProcessor(); $buyerData = $processor->doGetExpressCheckoutDetails($paymentMethod, $request->token); if (empty($buyerData)) { \XLite\Core\TopMessage::getInstance()->addError('Your address data was not received from PayPal.'); } else { // Fill the cart with data received from Paypal $this->requestData = $this->prepareBuyerData($processor, $buyerData); if (!\XLite\Core\Auth::getInstance()->isLogged()) { $this->updateProfile(); } $modifier = $cart->getModifier(\XLite\Model\Base\Surcharge::TYPE_SHIPPING, 'SHIPPING'); if ($modifier && $modifier->canApply()) { $this->requestData['billingAddress'] = $this->requestData['shippingAddress']; $this->requestData['same_address'] = true; $this->updateShippingAddress(); $this->updateBillingAddress(); } $this->setCheckoutAvailable(); $this->updateCart(); $this->doActionCheckout(); $checkoutAction = true; } } if (!$checkoutAction) { $this->setReturnURL(\XLite\Core\Request::getInstance()->cancelUrl ?: $this->buildURL('checkout')); } }
/** * Process return * * @return void */ protected function doActionReturn() { $txn = null; $txnIdName = \XLite\Model\Payment\Base\Online::RETURN_TXN_ID; if (isset(\XLite\Core\Request::getInstance()->txn_id_name)) { /** * some of gateways can't accept return url on run-time and * use the one set in merchant account, so we can't pass * 'order_id' in run-time, instead pass the order id parameter name */ $txnIdName = \XLite\Core\Request::getInstance()->txn_id_name; } if (isset(\XLite\Core\Request::getInstance()->{$txnIdName})) { $txn = \XLite\Core\Database::getRepo('XLite\\Model\\Payment\\Transaction')->find(\XLite\Core\Request::getInstance()->{$txnIdName}); } if (!$txn) { $methods = \XLite\Core\Database::getRepo('XLite\\Model\\Payment\\Method')->findAllActive(); foreach ($methods as $method) { if (method_exists($method->getProcessor(), 'getReturnOwnerTransaction')) { $txn = $method->getProcessor()->getReturnOwnerTransaction(); if ($txn) { break; } } } } if ($txn) { $txn->getPaymentMethod()->getProcessor()->processReturn($txn); $txn->registerTransactionInOrderHistory('web'); if ($txn->getNote()) { \XLite\Core\TopMessage::getInstance()->add($txn->getNote(), array(), null, $txn->isFailed() ? \XLite\Core\TopMessage::ERROR : \XLite\Core\TopMessage::INFO, true); } if ($txn->isFailed()) { $txn->getOrder()->setStatus(\XLite\Model\Order::STATUS_FAILED); } \XLite\Core\Database::getEM()->flush(); $url = $this->getShopURL($this->buildURL('checkout', 'return', array('order_id' => $txn->getOrder()->getOrderId())), \XLite\Core\Config::getInstance()->Security->customer_security); switch ($txn->getPaymentMethod()->getProcessor()->getReturnType()) { case \XLite\Model\Payment\Base\WebBased::RETURN_TYPE_HTML_REDIRECT: $this->doHTMLRedirect($url); break; case \XLite\Model\Payment\Base\WebBased::RETURN_TYPE_HTML_REDIRECT_WITH_IFRAME_DESTROYING: $this->doHTMLRedirectWithIframeDestroying($url); break; case \XLite\Model\Payment\Base\WebBased::RETURN_TYPE_CUSTOM: $txn->getPaymentMethod()->getProcessor()->doCustomReturnRedirect(); break; default: $this->setReturnURL($url); } } else { // TODO - add error logging $this->setReturnURL($this->buildURL('checkout')); } }
/** * Refund * * @param \XLite\Model\Payment\BackendTransaction $transaction Backend transaction * * @return boolean */ protected function doRefund(\XLite\Model\Payment\BackendTransaction $transaction) { $this->includeVelocityLibrary(); $backendTransactionStatus = $transaction::STATUS_FAILED; $errorData = ''; if ($this->getSetting('mode') == 'test') { $isTestAccount = true; } else { $isTestAccount = false; } try { $velocityProcessor = new \VelocityProcessor(self::$applicationprofileid, self::$merchantprofileid, self::$workflowid, $isTestAccount, self::$identitytoken); } catch (Exception $e) { $transaction->setDataCell('error_message', $e->getMessage(), 'Velocity error message'); $errorData .= $e->getMessage(); } $refund_amount = $transaction->getValue(); $txnid = $transaction->getPaymentTransaction()->getDataCell('velocity_payment_id')->getValue(); try { // request for refund $response = $velocityProcessor->returnById(array('amount' => $refund_amount, 'TransactionId' => $txnid)); $xml = \VelocityXmlCreator::returnByIdXML($refund_amount, $txnid); // got ReturnById xml object. $req = $xml->saveXML(); $obj_req = serialize($req); if (is_array($response) && !empty($response) && isset($response['Status']) && $response['Status'] == 'Successful') { $backendTransactionStatus = $transaction::STATUS_SUCCESS; $transaction->setDataCell('velocity_refund_id', $response['TransactionId'], 'Velocity Refund ID'); $transaction->setDataCell('approval_code', $response['ApprovalCode'], 'Velocity Approval Code'); $transaction->setDataCell('request_refund_object', $obj_req, 'Velocity Request Refund Object'); $transaction->setDataCell('response_refund_object', serialize($response), 'Velocity Response Refund Object'); $transaction->setDataCell('refund_status', $response['TransactionState'], 'Refund Transaction Status'); $transaction->setStatus($backendTransactionStatus); \XLite\Core\Database::getEM()->flush(); } else { if (is_array($response) && !empty($response)) { $transaction->setDataCell('error_message', $response['StatusMessage'], 'Velocity error message'); $errorData .= $response['StatusMessage']; } else { if (is_string($response)) { $transaction->setDataCell('error_message', $response, 'Velocity error message'); $errorData .= $response; } else { $transaction->setDataCell('error_message', 'Unknown Error please contact the site admin', 'Velocity error message'); $errorData .= 'Unknown Error please contact the site admin'; } } } } catch (Exception $e) { $transaction->setDataCell('error_message', $e->getMessage(), 'Velocity error message'); $errorData .= $e->getMessage(); } if (\XLite\Model\Payment\BackendTransaction::STATUS_SUCCESS == $backendTransactionStatus) { $order = $transaction->getPaymentTransaction()->getOrder(); $paymentTransactionSums = $order->getRawPaymentTransactionSums(); $refunded = $paymentTransactionSums['refunded']; $status = $refunded < $transaction->getPaymentTransaction()->getValue() ? \XLite\Model\Order\Status\Payment::STATUS_PART_PAID : \XLite\Model\Order\Status\Payment::STATUS_REFUNDED; $order->setPaymentStatus($status); \XLite\Core\TopMessage::getInstance()->addInfo('Payment has been refunded successfully'); } else { $msg = 'Transaction failure'; if (!empty($errorData)) { $msg .= '-' . $errorData; } \XLite\Core\TopMessage::getInstance()->addError($msg); } return \XLite\Model\Payment\BackendTransaction::STATUS_SUCCESS == $backendTransactionStatus; }
/** * Return from payment gateway * * :TODO: to revise * :FIXME: decompose * * @return void */ protected function doActionReturn() { // some of gateways can't accept return url on run-time and // use the one set in merchant account, so we can't pass // 'order_id' in run-time, instead pass the order id parameter name $orderId = \XLite\Core\Request::getInstance()->order_id; $cart = \XLite\Core\Database::getRepo('XLite\\Model\\Order')->find($orderId); if ($cart) { \XLite\Model\Cart::setObject($cart); } if (!$cart) { \XLite\Core\Session::getInstance()->order_id = null; \XLite\Core\TopMessage::addError('Order not found'); $this->setReturnURL($this->buildURL('cart')); } elseif (0 < $cart->getOpenTotal() && !in_array($cart->getStatus(), array(\XLite\Model\Order::STATUS_FAILED, \XLite\Model\Order::STATUS_DECLINED))) { \XLite\Core\TopMessage::addWarning('Payment was not finished', array('url' => $this->buildURL('cart', 'add_order', array('order_id' => $cart->getOrderId())))); $this->setReturnURL($this->buildURL(\XLite\Core\Auth::getInstance()->isLogged() ? 'order_list' : '')); } else { if ($cart->isPayed()) { $status = \XLite\Model\Order::STATUS_PROCESSED; $hasIncompletePayment = 0 < $cart->getOpenTotal(); $hasAuthorizedPayment = false; foreach ($cart->getPaymentTransactions() as $t) { $hasAuthorizedPayment = $hasAuthorizedPayment || $t->isAuthorized(); } if ($hasIncompletePayment) { $status = \XLite\Model\Order::STATUS_QUEUED; } elseif ($hasAuthorizedPayment) { $status = \XLite\Model\Order::STATUS_AUTHORIZED; } } else { $status = \XLite\Model\Order::STATUS_QUEUED; $transactions = $cart->getPaymentTransactions(); if (!empty($transactions)) { $lastTransaction = $transactions[count($transactions) - 1]; if ($lastTransaction->isFailed()) { $status = \XLite\Model\Order::STATUS_FAILED; } } } $cart->setStatus($status); $this->processSucceed(); \XLite\Core\TopMessage::getInstance()->clearTopMessages(); $this->setReturnURL($this->buildURL(\XLite\Model\Order::STATUS_FAILED == $status ? 'checkoutFailed' : 'checkoutSuccess', '', array('order_id' => $orderId))); } }
/** * Process errors * * @return void */ protected function processUpdateErrors() { \XLite\Core\TopMessage::getInstance()->addBatch($this->getErrorMessages(), \XLite\Core\TopMessage::ERROR); // Run controller's method $this->setActionError(); }
/** * Action to send test email notification * * @return void */ protected function doActionTestEmail() { $request = \XLite\Core\Request::getInstance(); $error = \XLite\Core\Mailer::sendTestEmail($request->test_from_email_address, $request->test_to_email_address, $request->test_email_body); if ($error) { \XLite\Core\Session::getInstance()->test_email_error = $error; \XLite\Core\TopMessage::getInstance()->addError('Error of test e-mail sending: ' . $error); } else { \XLite\Core\TopMessage::getInstance()->add('Test e-mail have been successfully sent'); } $this->setReturnURL($this->buildURL('settings', '', array('page' => static::EMAIL_PAGE))); }
/** * Do 'CREDIT' request. * Returns true on success or false on failure * * @param \XLite\Model\Payment\BackendTransaction $transaction Transaction * * @return boolean */ protected function doRefund(\XLite\Model\Payment\BackendTransaction $transaction) { $result = false; $responseData = $this->doRequest('Credit', $transaction); if (!empty($responseData)) { $status = \XLite\Model\Payment\Transaction::STATUS_FAILED; if ('0' == $responseData['RESULT']) { $result = true; $status = \XLite\Model\Payment\Transaction::STATUS_SUCCESS; \XLite\Core\TopMessage::getInstance()->addInfo('Payment has been refunded successfully'); } else { \XLite\Core\TopMessage::getInstance()->addError('Transaction failure. PayPal response: ' . $responseData['RESPMSG']); } $transaction->setStatus($status); $transaction->update(); } return $result; }
/** * Return from payment gateway * * :TODO: to revise * :FIXME: decompose * * @return void */ protected function doActionReturn() { // some of gateways can't accept return url on run-time and // use the one set in merchant account, so we can't pass // 'order_id' in run-time, instead pass the order id parameter name $orderId = \XLite\Core\Request::getInstance()->order_id; /** @var \XLite\Model\Order $cart */ $cart = \XLite\Core\Database::getRepo('XLite\\Model\\Cart')->find($orderId) ?: \XLite\Core\Database::getRepo('XLite\\Model\\Order')->find($orderId); if ($cart) { \XLite\Model\Cart::setObject($cart); } if (!$cart) { // Cart not found unset(\XLite\Core\Session::getInstance()->order_id); \XLite\Core\TopMessage::addError('Order not found'); $this->setReturnURL($this->buildURL('cart')); } elseif ($cart->getOpenTotal() > 0) { // Order still not payed $this->assignTransactionMessage(); $this->setReturnURL($this->buildURL('checkout')); } else { // Order payed or pending if ($cart instanceof \XLite\Model\Cart) { $cart->tryClose(); \XLite\Core\Database::getEM()->flush(); } \XLite\Core\Session::getInstance()->last_order_id = $orderId; \XLite\Core\TopMessage::getInstance()->clearTopMessages(); $this->setReturnURL($this->buildURL($this->getStatusTarget($cart->getPaymentStatusCode()), '', $cart->getOrderNumber() ? array('order_number' => $cart->getOrderNumber()) : array('order_id' => $orderId))); } }
/** * Translate top messages to HTTP headers (AJAX) * * @return void */ protected function translateTopMessagesToHTTPHeaders() { foreach (\XLite\Core\TopMessage::getInstance()->getAJAXMessages() as $message) { $encodedMessage = json_encode(array('type' => $message[\XLite\Core\TopMessage::FIELD_TYPE], 'message' => $message[\XLite\Core\TopMessage::FIELD_TEXT])); header('event-message: ' . $encodedMessage); } \XLite\Core\TopMessage::getInstance()->clearAJAX(); }
/** * 'add' action * * @return void */ protected function doActionAdd() { parent::doActionAdd(); // check for valid ProductOptions if ($this->optionInvalid) { // Save wrong options set $request = \XLite\Core\Request::getInstance(); \XLite\Core\Session::getInstance()->saved_invalid_options = array($request->product_id => $request->product_options); \XLite\Core\TopMessage::getInstance()->clear(); \XLite\Core\TopMessage::addError('The product options you have selected are not valid or fall into an exception.' . ' Please select other product options and add the product to cart once again.'); $this->setReturnURL($this->buildURL('product', '', array('product_id' => \XLite\Core\Request::getInstance()->product_id))); } else { \XLite\Core\Session::getInstance()->saved_invalid_options = null; } }