/** * Process return * * @param \XLite\Model\Payment\Transaction $transaction Return-owner transaction * * @return void */ public function processReturn(\XLite\Model\Payment\Transaction $transaction) { parent::processReturn($transaction); \XLite\Module\XC\IdealPayments\Main::addLog('processReturn', \XLite\Core\Request::getInstance()->getData()); $message = ''; $data = array(); if (\XLite\Core\Request::getInstance()->ec && \XLite\Core\Request::getInstance()->trxid) { // iDEAL must redirect customer to URL with parameters ec and trxid $status = $transaction::STATUS_FAILED; // Perform request for transaction status to iDEAL server $statusRequest = $this->getIdealRequest('status'); $statusRequest->setTransactionId(\XLite\Core\Request::getInstance()->trxid); $transactionStatus = $statusRequest->doRequest(); if ($statusRequest->hasErrors()) { // Response contains errors foreach ($statusRequest->getErrors() as $errorEntry) { $message .= $errorEntry['desc'] . PHP_EOL; } } elseif (!empty($transactionStatus)) { // Transaction status successfully received if ($statusRequest->getAccountName()) { $data['accountName'] = utf8_encode($statusRequest->getAccountName()); } if ($statusRequest->getAccountNumber()) { $data['accountNum'] = utf8_encode($statusRequest->getAccountNumber()); } if (strcmp($transactionStatus, 'SUCCESS') === 0) { // Transaction is successful $status = $transaction::STATUS_SUCCESS; } elseif (strcmp($transactionStatus, 'CANCELLED') === 0) { // Transaction is canceled by customer $this->setDetail('status', 'Customer has canceled checkout before completing their payments', 'Status'); $this->transaction->setNote('Customer has canceled checkout before completing their payments'); $status = $transaction::STATUS_CANCELED; } else { // Transaction is failed by iDEAL payment gateway foreach ($statusRequest->getErrors() as $errorEntry) { $message .= $errorEntry['desc'] . PHP_EOL; } } } else { $message = static::t('Unexpected result was received from iDEAL (transaction status is not set)'); } } else { $message = static::t('Payment return page requested without expected parameters'); } // Save data in order history if ($message) { $data['message'] = $message; } if (!empty($data)) { $this->saveFilteredData($data); } // Set transaction status $this->transaction->setStatus($status); }
/** * Send GET/POST data through sockets * * @param string $url * @param string $data * @param integer $timeout * * @return string */ protected function postToHost($url, $data) { $request = new \XLite\Core\HTTP\Request($url); $request->body = $data; $response = $request->sendRequest(); // Log request/response \XLite\Module\XC\IdealPayments\Main::addLog('Post request and response', array('request' => array('url' => $url, 'data' => $data), 'response' => '200' == $response->code ? $response->body : $response)); $result = ''; if ($response->code != '200') { $this->setError('Error while connecting to ' . $url, false, __FILE__, __LINE__); } else { $result = $response->body; } return $result; }