/** * Process PayPal Instant Payment Notifications (IPN) * * @param IsotopeProductCollection */ public function processPostsale(IsotopeProductCollection $objOrder) { if (!$this->validateUrlParams($objOrder)) { \System::log('ExperCash: data rejected' . print_r($_POST, true), __METHOD__, TL_GENERAL); } if (!$objOrder->checkout()) { \System::log('Postsale checkout for Order ID "' . $objOrder->id . '" failed', __METHOD__, TL_ERROR); return; } $objOrder->date_paid = time(); $objOrder->updateOrderStatus($this->new_order_status); $objOrder->save(); // 200 OK $objResponse = new Response(); $objResponse->send(); }
/** * Process PayPal Instant Payment Notifications (IPN) * * @param IsotopeProductCollection|Order $objOrder */ public function processPostsale(IsotopeProductCollection $objOrder) { if (\Input::post('payment_status') != 'Completed') { \System::log('PayPal IPN: payment status "' . \Input::post('payment_status') . '" not implemented', __METHOD__, TL_GENERAL); return; } $objRequest = new \Request(); $objRequest->send('https://www.' . ($this->debug ? 'sandbox.' : '') . 'paypal.com/cgi-bin/webscr?cmd=_notify-validate', file_get_contents("php://input"), 'post'); if ($objRequest->hasError()) { \System::log('PayPal IPN: Request Error (' . $objRequest->error . ')', __METHOD__, TL_ERROR); $response = new Response('', 500); $response->send(); } if ($objRequest->response != 'VERIFIED') { \System::log('PayPal IPN: data rejected (' . $objRequest->response . ')', __METHOD__, TL_ERROR); return; } if (\Input::post('receiver_email', true) != $this->paypal_account && !$this->debug) { \System::log('PayPal IPN: Account email does not match (got ' . \Input::post('receiver_email', true) . ', expected ' . $this->paypal_account . ')', __METHOD__, TL_ERROR); return; } // Validate payment data (see #2221) if ($objOrder->currency != \Input::post('mc_currency') || $objOrder->getTotal() != \Input::post('mc_gross')) { \System::log('PayPal IPN: manipulation in payment from "' . \Input::post('payer_email') . '" !', __METHOD__, TL_ERROR); return; } if (!$objOrder->checkout()) { \System::log('PayPal IPN: checkout for Order ID "' . \Input::post('invoice') . '" failed', __METHOD__, TL_ERROR); return; } // Store request data in order for future references $arrPayment = deserialize($objOrder->payment_data, true); $arrPayment['POSTSALE'][] = $_POST; $objOrder->payment_data = $arrPayment; $objOrder->date_paid = time(); $objOrder->updateOrderStatus($this->new_order_status); $objOrder->save(); \System::log('PayPal IPN: data accepted', __METHOD__, TL_GENERAL); }
/** * Process PayPal Instant Payment Notifications (IPN) * @param IsotopeProductCollection */ public function processPostsale(IsotopeProductCollection $objOrder) { $objRequest = new \Request(); $objRequest->send('https://www.' . ($this->debug ? 'sandbox.' : '') . 'paypal.com/cgi-bin/webscr?cmd=_notify-validate', file_get_contents("php://input"), 'post'); if ($objRequest->hasError()) { \System::log('Request Error: ' . $objRequest->error, __METHOD__, TL_ERROR); exit; } elseif ($objRequest->response == 'VERIFIED' && (\Input::post('receiver_email', true) == $this->paypal_account || $this->debug)) { // Validate payment data (see #2221) if ($objOrder->currency != \Input::post('mc_currency') || $objOrder->getTotal() != \Input::post('mc_gross')) { \System::log('IPN manipulation in payment from "' . \Input::post('payer_email') . '" !', __METHOD__, TL_ERROR); return; } if (!$objOrder->checkout()) { \System::log('IPN checkout for Order ID "' . \Input::post('invoice') . '" failed', __METHOD__, TL_ERROR); return; } // Store request data in order for future references $arrPayment = deserialize($objOrder->payment_data, true); $arrPayment['POSTSALE'][] = $_POST; $objOrder->payment_data = $arrPayment; $objOrder->save(); // @see https://www.paypalobjects.com/webstatic/en_US/developer/docs/pdf/ipnguide.pdf switch (\Input::post('payment_status')) { case 'Completed': $objOrder->date_paid = time(); $objOrder->updateOrderStatus($this->new_order_status); break; case 'Canceled_Reversal': case 'Denied': case 'Expired': case 'Failed': case 'Voided': // PayPal will also send this notification if the order has not been placed. // What do we do here? // $objOrder->date_paid = ''; // $objOrder->updateOrderStatus(Isotope::getConfig()->orderstatus_error); break; case 'In-Progress': case 'Partially_Refunded': case 'Pending': case 'Processed': case 'Refunded': case 'Reversed': break; } $objOrder->payment_data = $arrPayment; $objOrder->save(); \System::log('PayPal IPN: data accepted', __METHOD__, TL_GENERAL); } else { \System::log('PayPal IPN: data rejected (' . $objRequest->response . ')', __METHOD__, TL_ERROR); } // 200 OK $objResponse = new Response(); $objResponse->send(); }
/** * Redirect the Sparkasse server to our error page * @param array */ private function redirectError($arrData) { $strUrl = Checkout::generateUrlForStep('failed', null, \PageModel::findWithDetails((int) $arrData['sessionid'])); // 200 OK $objResponse = new Response('redirecturlf=' . \Environment::get('base') . $strUrl . '?reason=' . $arrData['directPosErrorMessage']); $objResponse->send(); }
/** * @expectedException InvalidArgumentException */ public function testSetStatusCodeException() { $objResponse = new Response('Foobar', 200); $objResponse->setStatusCode(7000); }
/** * Export with template. * * @param $config * @param ArrayReader $reader * @param Row $row * @param $format */ protected function exportWithTemplate($config, ArrayReader $reader, Row $row, $format) { // Fetch the template and make a copy of it $template = \FilesModel::findByPk($config->template); if (null === $template) { $objResponse = new Response('Could not find template.', 500); $objResponse->send(); } $tmpPath = 'system/tmp/' . File::getName($config); \Files::getInstance()->copy($template->path, $tmpPath); $excelReader = PHPExcel_IOFactory::createReader($format); $excel = $excelReader->load(TL_ROOT . '/' . $tmpPath); $excel->setActiveSheetIndex((int) $config->sheetIndex); $sheet = $excel->getActiveSheet(); $currentRow = (int) $config->startIndex ?: 1; $currentColumn = 0; foreach ($reader as $readerRow) { $compiledRow = $row->compile($readerRow); foreach ($compiledRow as $k => $value) { // Support explicit target column if ('tokens' === $config->export && isset($config->tokenFields[$k]['targetColumn'])) { $column = $config->tokenFields[$k]['targetColumn']; if (!is_numeric($column)) { $column = PHPExcel_Cell::columnIndexFromString($column) - 1; } } else { // Use next column, ignoring explicit target columns in the counter $column = $currentColumn++; } $sheet->setCellValueExplicitByColumnAndRow($column, $currentRow, (string) $value, \PHPExcel_Cell_DataType::TYPE_STRING2); } $currentColumn = 0; $currentRow++; } $excelWriter = \PHPExcel_IOFactory::createWriter($excel, $format); $excelWriter->save(TL_ROOT . '/' . $tmpPath); $this->updateLastRun($config); $tmpFile = new \File($tmpPath); $tmpFile->sendToBrowser(); }
/** * Run the controller */ public function run() { $objMethod = null; try { $strMod = $this->getModule(); $intId = $this->getModuleId(); if ($strMod == '' || $intId == 0) { \System::log('Invalid post-sale request (param error): ' . \Environment::get('request'), __METHOD__, TL_ERROR); $objResponse = new Response('Bad Request', 400); $objResponse->send(); } switch (strtolower($strMod)) { case 'pay': $objMethod = Payment::findByPk($intId); break; case 'ship': $objMethod = Shipping::findByPk($intId); break; } if (null === $objMethod) { \System::log('Invalid post-sale request (model not found): ' . \Environment::get('request'), __METHOD__, TL_ERROR); $objResponse = new Response('Not Found', 404); $objResponse->send(); } \System::log('New post-sale request: ' . \Environment::get('request'), __METHOD__, TL_ACCESS); if (!$objMethod instanceof IsotopePostsale) { \System::log('Invalid post-sale request (interface not implemented): ' . \Environment::get('request'), __METHOD__, TL_ERROR); $objResponse = new Response('Not Implemented', 501); $objResponse->send(); } $objOrder = $objMethod->getPostsaleOrder(); if (null === $objOrder || !$objOrder instanceof IsotopeProductCollection) { \System::log(get_class($objMethod) . ' did not return a valid order', __METHOD__, TL_ERROR); $objResponse = new Response('Failed Dependency', 424); $objResponse->send(); } global $objPage; // Load page configuration if (!is_object($objPage) && $objOrder->pageId > 0) { $objPage = \PageModel::findWithDetails($objOrder->pageId); $objPage = \Isotope\Frontend::loadPageConfig($objPage); } // Set the current system to the language when the user placed the order. // This will result in correct e-mails and payment description. if ($GLOBALS['TL_LANGUAGE'] != $objOrder->language) { $GLOBALS['TL_LANGUAGE'] = $objOrder->language; \System::loadLanguageFile('default', $objOrder->language, true); } Isotope::setConfig($objOrder->getRelated('config_id')); if (($objCart = $objOrder->getRelated('source_collection_id')) !== null && $objCart instanceof Cart) { Isotope::setCart($objCart); } $objMethod->processPostsale($objOrder); $objResponse = new Response(); $objResponse->send(); } catch (\Exception $e) { \System::log(sprintf('Exception in post-sale request in file "%s" on line "%s" with message "%s".', $e->getFile(), $e->getLine(), $e->getMessage()), __METHOD__, TL_ERROR); $objResponse = new Response('Internal Server Error', 500); $objResponse->send(); } }
/** * Run the controller */ public function run() { $this->logRequest(); $objMethod = null; try { $strMod = $this->getModule(); $intId = $this->getModuleId(); if ($strMod == '' || $intId == 0) { \System::log('Invalid post-sale request (param error): ' . \Environment::get('request'), __METHOD__, TL_ERROR); $objResponse = new Response('Bad Request', 400); $objResponse->send(); } switch (strtolower($strMod)) { case 'pay': $objMethod = Payment::findByPk($intId); break; case 'ship': $objMethod = Shipping::findByPk($intId); break; } if (null === $objMethod) { \System::log('Invalid post-sale request (model not found): ' . \Environment::get('request'), __METHOD__, TL_ERROR); $objResponse = new Response('Not Found', 404); $objResponse->send(); } \System::log('New post-sale request: ' . \Environment::get('request'), __METHOD__, TL_ACCESS); if (!$objMethod instanceof IsotopePostsale) { \System::log('Invalid post-sale request (interface not implemented): ' . \Environment::get('request'), __METHOD__, TL_ERROR); $objResponse = new Response('Not Implemented', 501); $objResponse->send(); } /** @type Order $objOrder */ $objOrder = $objMethod->getPostsaleOrder(); if (null === $objOrder || !$objOrder instanceof IsotopeProductCollection) { \System::log(get_class($objMethod) . ' did not return a valid order', __METHOD__, TL_ERROR); $objResponse = new Response('Failed Dependency', 424); $objResponse->send(); } Frontend::loadOrderEnvironment($objOrder); $objMethod->processPostsale($objOrder); $objResponse = new Response(); $objResponse->send(); } catch (\Exception $e) { \System::log(sprintf('Exception in post-sale request. See system/logs/isotope_postsale.log for details.', $e->getFile(), $e->getLine(), $e->getMessage()), __METHOD__, TL_ERROR); log_message(sprintf("Exception in post-sale request\n%s\n\n", $e->getTraceAsString()), 'isotope_postsale.log'); $objResponse = new Response('Internal Server Error', 500); $objResponse->send(); } }