/** * @param Payment $payment * @param CHttpRequest $request * @return bool */ public function processCheckout(Payment $payment, CHttpRequest $request) { $amount = $request->getParam('OutSum'); $orderId = (int) $request->getParam('InvId'); $crc = strtoupper($request->getParam('SignatureValue')); $order = Order::model()->findByPk($orderId); if (null === $order) { Yii::log(Yii::t('RobokassaModule.robokassa', 'Order with id = {id} not found!', ['{id}' => $orderId]), CLogger::LEVEL_ERROR, self::LOG_CATEGORY); return false; } if ($order->isPaid()) { Yii::log(Yii::t('RobokassaModule.robokassa', 'Order with id = {id} already payed!', ['{id}' => $orderId]), CLogger::LEVEL_ERROR, self::LOG_CATEGORY); return false; } $settings = $payment->getPaymentSystemSettings(); $myCrc = strtoupper(md5("{$amount}:{$orderId}:" . $settings['password2'])); if ($myCrc !== $crc) { Yii::log(Yii::t('RobokassaModule.robokassa', 'Error pay order with id = {id}! Bad crc!', ['{id}' => $orderId]), CLogger::LEVEL_ERROR, self::LOG_CATEGORY); return false; } if ($amount != Yii::app()->money->convert($order->total_price, $payment->currency_id)) { Yii::log(Yii::t('RobokassaModule.robokassa', 'Error pay order with id = {id}! Incorrect price!', ['{id}' => $orderId]), CLogger::LEVEL_ERROR, self::LOG_CATEGORY); return false; } if ($order->pay($payment)) { Yii::log(Yii::t('RobokassaModule.robokassa', 'Success pay order with id = {id}!', ['{id}' => $orderId]), CLogger::LEVEL_INFO, self::LOG_CATEGORY); return true; } else { Yii::log(Yii::t('RobokassaModule.robokassa', 'Error pay order with id = {id}! Error change status!', ['{id}' => $orderId]), CLogger::LEVEL_ERROR, self::LOG_CATEGORY); return false; } }
/** * @param Payment $payment * @param CHttpRequest $request */ public function processCheckout(Payment $payment, CHttpRequest $request) { $settings = $payment->getPaymentSystemSettings(); $params = ['action' => $request->getParam('action'), 'orderSumAmount' => $request->getParam('orderSumAmount'), 'orderSumCurrencyPaycash' => $request->getParam('orderSumCurrencyPaycash'), 'orderSumBankPaycash' => $request->getParam('orderSumBankPaycash'), 'shopId' => $settings['shopid'], 'invoiceId' => $request->getParam('invoiceId'), 'customerNumber' => $request->getParam('customerNumber'), 'password' => $settings['password']]; /* @var $order Order */ $order = Order::model()->findByPk($request->getParam('orderNumber')); if ($order === null) { $message = Yii::t('YandexMoneyModule.ymoney', 'The order doesn\'t exist.'); Yii::log($message, CLogger::LEVEL_ERROR); $this->showResponse($params, $message, 200); } if ($order->isPaid()) { $message = Yii::t('YandexMoneyModule.ymoney', 'The order #{n} is already payed.', $order->getPrimaryKey()); Yii::log($message, CLogger::LEVEL_ERROR); $this->showResponse($params, $message, 200); } if ($this->getOrderCheckSum($params) !== $request->getParam('md5')) { $message = Yii::t('YandexMoneyModule.ymoney', 'Wrong checksum'); Yii::log($message, CLogger::LEVEL_ERROR); $this->showResponse($params, $message, 200); } if ((double) $order->getTotalPriceWithDelivery() !== (double) $params['orderSumAmount']) { $message = Yii::t('YandexMoneyModule.ymoney', 'Wrong payment amount'); Yii::log($message, CLogger::LEVEL_ERROR); $this->showResponse($params, $message, 200); } if ($params['action'] === 'checkOrder') { $this->showResponse($params); } if ($params['action'] === 'paymentAviso' && $order->pay($payment)) { Yii::log(Yii::t('YandexMoneyModule.ymoney', 'The order #{n} has been payed successfully.', $order->getPrimaryKey()), CLogger::LEVEL_INFO); $this->showResponse($params); } }
protected function checkSign() { $keys = $this->application->app_keys; // If there's no config app keys, we ignore the sign . if (empty($keys)) { return; } $clientAppId = $this->request->getParam('app_id'); foreach ($keys as $app_key) { if ($app_key['app_id'] == $clientAppId) { $clientAppSecret = $app_key['app_secret']; } } if (!$this->request->getParam('timestamp')) { throw new CAPIException(500, 'Sorry, the timestamp param is required', self::STATUS_TIMESTAMP_REQUIRED); } if (empty($clientAppSecret)) { throw new CAPIException(500, "Sorry, the app id {$clientAppId} is missed or not found", self::STATUS_APPID_NOT_FOUND); } if ($this->request->isPostRequest || $this->request->isPutRequest) { $params = $_POST; } else { $params = $_GET; } $clientSign = $this->request->getParam('sign'); if (empty($clientSign)) { throw new CAPIException(500, 'Sorry, the sign is required', self::STATUS_SIGN_REQUIRED); } if ($clientSign != $this->makeSign($clientAppSecret, $params)) { throw new CAPIException(500, 'Sorry, the sign is not matched. ', self::STATUS_SIGN_NOT_MATCH); } }
/** * Gets the status of the current payment * * @param CHttpRequest $request * @return string|bool */ public function getPaymentStatus(CHttpRequest $request) { $data = ['key' => $this->key, 'order_id' => $request->getParam('order_id')]; $response = $this->sendRequest($data, 'GetStatus'); if (!isset($response['status'])) { return false; } return $response['status']; }
public function processCheckout(CHttpRequest $request) { $amount = $request->getParam('OutSum'); $orderId = (int) $request->getParam('InvId'); $crc = strtoupper($request->getParam('SignatureValue')); $subscription = Subscription::model()->findByPk($orderId); if (null === $subscription) { //echo Yii::t('site', 'Subscription with id = {id} not found!', array('{id}' => $orderId)); Yii::log(Yii::t('site', 'Subscription with id = {id} not found!', array('{id}' => $orderId)), CLogger::LEVEL_ERROR, self::LOG_CATEGORY); return false; } if ($subscription->type != Subscription::TYPE_FULL) { //echo Yii::t('site', 'Subscription with id = {id} is trial!', array('{id}' => $orderId)); Yii::log(Yii::t('site', 'Subscription with id = {id} is trial!', array('{id}' => $orderId)), CLogger::LEVEL_ERROR, self::LOG_CATEGORY); return false; } if ($subscription->isPaid()) { //echo Yii::t('site', 'Subscription with id = {id} already payed!', array('{id}' => $orderId)); Yii::log(Yii::t('site', 'Subscription with id = {id} already payed!', array('{id}' => $orderId)), CLogger::LEVEL_ERROR, self::LOG_CATEGORY); return false; } $settings = $this->_getSettings(); $myCrc = strtoupper(md5("{$amount}:{$orderId}:" . $settings['password2'])); if ($myCrc !== $crc) { //echo Yii::t('site', 'Error pay subscription with id = {id}! Bad crc!', array('{id}' => $orderId)); Yii::log(Yii::t('site', 'Error pay subscription with id = {id}! Bad crc!', array('{id}' => $orderId)), CLogger::LEVEL_ERROR, self::LOG_CATEGORY); return false; } if ($amount != $subscription->getTotalCost()) { //echo Yii::t('site', 'Error pay subscription with id = {id}! Incorrect price!', array('{id}' => $orderId)); Yii::log(Yii::t('site', 'Error pay subscription with id = {id}! Incorrect price!', array('{id}' => $orderId)), CLogger::LEVEL_ERROR, self::LOG_CATEGORY); return false; } if ($subscription->pay()) { echo "OK{$orderId}\n"; Yii::log(Yii::t('site', 'Success pay subscription with id = {id}!', array('{id}' => $orderId)), CLogger::LEVEL_INFO, self::LOG_CATEGORY); return true; } else { //echo Yii::t('site', 'Error pay subscription with id = {id}! Error change status!', array('{id}' => $orderId)); Yii::log(Yii::t('site', 'Error pay subscription with id = {id}! Error change status!', array('{id}' => $orderId)), CLogger::LEVEL_ERROR, self::LOG_CATEGORY); return false; } }
protected function dealParam($isMobileRequest = null) { //获取全部标签 $mc_tag_tree1 = md5('mc_tag_tree_key1'); $mc_tag_tree2 = md5('mc_tag_tree_key2'); $mc_tag_tree3 = md5('mc_tag_tree_key3'); $typeId = $this->request->getParam('typeId'); if (empty($typeId)) { $productType = Yii::app()->db->createCommand('select * from ff_product_type order by type_sort limit 1')->queryAll(); $typeId = $productType[0]['id']; } $proTypes = $this->getProductType(); $type_val = $proTypes[$typeId]['type_val']; if ($type_val == 1) { $tree = Yii::app()->cache->get($mc_tag_tree1); } elseif ($type_val == 2) { $tree = Yii::app()->cache->get($mc_tag_tree2); } elseif ($type_val == 3) { $tree = Yii::app()->cache->get($mc_tag_tree3); } if (!$tree) { $tree = new FTree(Yii::app()->db->createCommand("select * from ff_tag where type_val = {$type_val} order by tag_sort")->queryAll()); $key = "mc_tag_tree_key" . $type_val; Yii::app()->cache->set(md5($key), $tree, 600); } $param = array('cate' => trim($this->request->getParam('cate')), 'tags' => $tree->getArray(), 'seo_year' => date("Y"), 'parameters' => '', 'basePath' => ''); $param['typeId'] = $typeId; if ($isMobileRequest) { $_url_prefix = ''; //FF_DOMAIN . "/w/index/caseList/" } else { //生成标签展示URL $_url_prefix = FF_DOMAIN . "/s/{$typeId}/"; } //获取参数相关配置文件 $p_config = FConfig::item("tags.param.{$type_val}"); $rs = $param['cate'] ? $this->dealCate($param['cate']) : ''; foreach ($p_config as $k => $v) { //设置参数 $param[$v['short']] = isset($rs[$v['short']]) && in_array($rs[$v['short']], array_keys($tree->get_child($v['id']))) ? $rs[$v['short']] : 0; //SEO title,keyword,desc拼接 $seo_show_tmp = $param[$v['short']] > 0 ? $param['tags'][$param[$v['short']]]['name'] : ''; if ($v['short'] == 'a') { $a = $seo_show_tmp; $a1 = isset($rs['a']) ? 'a' . $rs['a'] : ''; } if ($v['short'] == 'b') { $b = $seo_show_tmp; $b1 = isset($rs['b']) ? 'b' . $rs['b'] : ''; } if ($v['short'] == 'c') { $c = $seo_show_tmp; $c1 = isset($rs['c']) ? 'c' . $rs['c'] : ''; } if ($v['short'] == 'd') { $d = $seo_show_tmp; $d1 = isset($rs['d']) ? 'd' . $rs['d'] : ''; } if ($v['short'] == 'e') { $e = $seo_show_tmp; $e1 = isset($rs['e']) ? 'e' . $rs['e'] : ''; } if ($v['short'] == 'f') { $f = $seo_show_tmp; $f1 = isset($rs['f']) ? 'f' . $rs['f'] : ''; } } //搜索参数拼接 $param['parameters'] = $a1 . $b1 . $c1 . $d1 . $e1 . $f1; $param['pname'] = $a . $b . $c . $d . $e . $f; foreach ($param['tags'] as $k => &$v) { $v['url'] = $_url_prefix; foreach ($p_config as $pc_k => $pc_v) { if ($pc_v['id'] == $v['id']) { $v['url'] .= ''; } elseif ($pc_v['id'] == $v['parent_id']) { $v['url'] .= $pc_v['short'] . $v['id']; } else { //组合查询打开 if ($param[$pc_v['short']] > 0) { $v['url'] .= $pc_v['short'] . $param[$pc_v['short']]; $param['tags'][$param[$pc_v['short']]]['class'] = 'current'; } else { //$param['tags'][$v['parent_id']]['class'] = 'current'; $param['tags'][$pc_v['id']]['class'] = 'current'; } } } if (substr($v['url'], strlen($v['url']) - 1) !== '/') { $v['url'] .= '/'; } } $param['basePath'] = FF_DOMAIN . "/s/"; return $param; }