/** * Process return * * @param \XLite\Model\Payment\Transaction $transaction Return-owner transaction * * @return void */ public function processReturn(\XLite\Model\Payment\Transaction $transaction) { $txnId = \XLite\Core\Request::getInstance()->txnId; $info = $this->client->requestPaymentInfo($txnId); $transactionStatus = $transaction::STATUS_FAILED; $this->client->clearInitDataFromSession(); if ($info->isSuccess()) { $response = $info->getResponse(); $transaction->setDataCell('xpc_message', $response['message'], 'X-Payments response'); if ($response['isFraudStatus']) { $transaction->setDataCell('xpc_fmf', 'blocked', 'Fraud status'); } $errorDescription = false; if (abs($response['amount'] - $transaction->getValue()) > 0.01) { // Total wrong $errorDescription = 'Total amount doesn\'t match. ' . 'Transaction total: ' . $transaction->getValue() . ', ' . 'X-Payments amount: ' . $response['amount']; } if (!$transaction->getCurrency()) { // Adjust currency if it's not set $currency = $this->client->getCurrencyForPaymentMethod($transaction->getPaymentMethod()); $transaction->setCurrency($currency); } if ($response['currency'] != $transaction->getCurrency()->getCode()) { // Currency wrong $errorDescription = 'Currence doesn\'t match. ' . 'Transaction currency: ' . $transaction->getCurrency()->getCode() . ', ' . 'X-Payments currency: ' . $response['currency']; } if ($errorDescription) { // Set error details, status remails Failed $transaction->setDataCell('error', 'Hacking attempt!', 'Error'); $transaction->setDataCell('errorDescription', $errorDescription, 'Hacking attempt details'); } else { // Set the transaction status $transactionStatus = $this->getTransactionStatus($response, $transaction); } } if ($transactionStatus) { $transaction->setStatus($transactionStatus); } // AntiFraud check block by AVS if (method_exists($transaction, 'checkAvsDataValid') && $transaction->checkAvsDataValid()) { $result = $transaction->getAntiFraudResult(); if ($transaction->checkBlockAvs()) { $result->setDataCell('blocked_by_avs', '1'); $result->setScore($result::MAX_SCORE); } else { $result->setDataCell('blocked_by_avs', '0'); } } $this->transaction = $transaction; }
/** * {@inheritDoc} */ public function setCurrency(\XLite\Model\Currency $currency = NULL) { $this->__initializer__ && $this->__initializer__->__invoke($this, 'setCurrency', array($currency)); return parent::setCurrency($currency); }