Skip to content

Commit

Permalink
Added payPal
Browse files Browse the repository at this point in the history
  • Loading branch information
skeeks-semenov committed Apr 8, 2016
1 parent 376732c commit dee4f6a
Show file tree
Hide file tree
Showing 9 changed files with 335 additions and 30 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ Changelog

1.0.0-alpha6.pre
-----------------
* PayPal
* Rewrite robokassa
* Added payPal

1.0.0-alpha5
-----------------
Expand Down
10 changes: 10 additions & 0 deletions components/PaySystemHandlerComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,14 @@ class PaySystemHandlerComponent extends Model implements ConfigFormInterface

public function renderConfigForm(ActiveForm $activeForm)
{}

static public function logError($message, $group = "")
{
\Yii::error($message, static::className() . "::" . $group);
}

static public function logInfo($message, $group = "")
{
\Yii::info($message, static::className() . "::" . $group);
}
}
17 changes: 10 additions & 7 deletions controllers/OrderController.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,16 @@ public function behaviors()
]);
}

public function beforeAction($action)
{
if ($action->id == 'view')
{
$this->enableCsrfValidation = false;
}

return parent::beforeAction($action);
}

/**
* @return string
*/
Expand Down Expand Up @@ -122,11 +132,4 @@ public function actionPayPal()
]);
}

public function actionPayPalNotify()
{
\Yii::error(serialize(\Yii::$app->request->get()), 'paypal');
\Yii::error(serialize(\Yii::$app->request->post()), 'paypal');
return "";
}

}
97 changes: 97 additions & 0 deletions controllers/PayPalController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
<?php
/**
* @author Semenov Alexander <[email protected]>
* @link http://skeeks.com/
* @copyright 2010 SkeekS (СкикС)
* @date 21.09.2015
*/
namespace skeeks\cms\shop\controllers;

use skeeks\cms\base\Controller;
use skeeks\cms\components\Cms;
use skeeks\cms\filters\CmsAccessControl;
use skeeks\cms\helpers\RequestResponse;
use skeeks\cms\shop\models\ShopBasket;
use skeeks\cms\shop\models\ShopBuyer;
use skeeks\cms\shop\models\ShopFuser;
use skeeks\cms\shop\models\ShopOrder;
use skeeks\cms\shop\models\ShopPersonType;
use skeeks\cms\shop\models\ShopPersonTypeProperty;
use skeeks\cms\shop\models\ShopProduct;
use skeeks\cms\shop\paySystems\PayPalPaySystem;
use skeeks\cms\shop\paySystems\robokassa\Merchant;
use skeeks\cms\shop\paySystems\RobokassaPaySystem;
use yii\base\Exception;
use yii\filters\AccessControl;
use yii\filters\VerbFilter;
use yii\helpers\ArrayHelper;
use yii\helpers\Json;
use yii\helpers\Url;
use yii\web\BadRequestHttpException;

/**
* Class RobocassaController
* @package skeeks\cms\shop\controllers
*/
class PayPalController extends Controller
{
/**
* @inheritdoc
*/
public $enableCsrfValidation = false;

public function actionIpn()
{
$custom = (int) \Yii::$app->request->post('custom');
\Yii::info('Ipn post data: ' . serialize(\Yii::$app->request->post()), 'paypal');
\Yii::info('Ipn custom: ' . $custom, 'paypal');

/*if (!$custom)
{
$custom = (int) \Yii::$app->request->get('custom');
}*/

if (!$custom)
{
\Yii::error('Order id not found', 'paypal');
return false;
}

$shopOrder = ShopOrder::findOne($custom);
\Yii::info('Ordder id: ' . $shopOrder->id);

if (!$shopOrder)
{
\Yii::error('Ordder not found: ' . $custom, 'paypal');
}

/**
* @var $payPal PayPalPaySystem
* @var $shopOrder ShopOrder
*/
$payPal = $shopOrder->paySystem->paySystemHandler;
if (!$payPal instanceof PayPalPaySystem)
{
\Yii::error('Order handler not paypal: ', 'paypal');
}

if ($payPal->initIpn())
{
if ($shopOrder->payed != "Y")
{
\Yii::info('Order processNotePayment', 'paypal');
$shopOrder->processNotePayment();
}

$shopOrder->ps_status = "STATUS_SUCCESS";
$shopOrder->payed = "Y";
$shopOrder->save();

} else
{
\Yii::error('Ipn false: ', 'paypal');
}

return "";
}
}
17 changes: 14 additions & 3 deletions controllers/RobokassaController.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,32 +55,37 @@ class RobokassaController extends Controller

public function actionSuccess()
{
RobokassaPaySystem::logInfo('success request');

if (!isset($_REQUEST['OutSum'], $_REQUEST['InvId'], $_REQUEST['SignatureValue']))
{
RobokassaPaySystem::logError('Not found params');
throw new BadRequestHttpException('Not found params');
}

$order = $this->loadModel($_REQUEST['InvId']);
$merchant = $this->getMerchant($order);
$shp = $this->getShp();


if ($merchant->checkSignature($_REQUEST['SignatureValue'], $_REQUEST['OutSum'], $_REQUEST['InvId'], $merchant->sMerchantPass1, $shp)) {

$order->ps_status = "STATUS_ACCEPTED";
$order->save();
return $this->redirect(Url::to(['/shop/order/view', 'id' => $order->id]));
}

RobokassaPaySystem::logError('bad signature');
throw new BadRequestHttpException('bad signature');
}


public function actionResult()
{
RobokassaPaySystem::logInfo('result request');

if (!isset($_REQUEST['OutSum'], $_REQUEST['InvId'], $_REQUEST['SignatureValue']))
{
RobokassaPaySystem::logError('Not found params');
throw new BadRequestHttpException('Not found params');
}

Expand All @@ -90,8 +95,7 @@ public function actionResult()

if ($merchant->checkSignature($_REQUEST['SignatureValue'], $_REQUEST['OutSum'], $_REQUEST['InvId'], $merchant->sMerchantPass2, $shp)) {



RobokassaPaySystem::logInfo('result signature OK');
if ($order->payed != "Y")
{
$order->processNotePayment();
Expand All @@ -104,13 +108,18 @@ public function actionResult()
return 'Ok';
}

RobokassaPaySystem::logError('bad signature');

throw new BadRequestHttpException;
}

public function actionFail()
{
RobokassaPaySystem::logInfo('fail request');

if (!isset($_REQUEST['OutSum'], $_REQUEST['InvId']))
{
RobokassaPaySystem::logError('Not found params');
throw new BadRequestHttpException;
}

Expand Down Expand Up @@ -190,13 +199,15 @@ protected function getMerchant(ShopOrder $order)
$paySystemHandler = $order->paySystem->paySystemHandler;
if (!$paySystemHandler || !$paySystemHandler instanceof RobokassaPaySystem)
{
RobokassaPaySystem::logError('Not found pay system');
throw new BadRequestHttpException('Not found pay system');
}

$merchant = $paySystemHandler->getMerchant();

if (!$merchant instanceof Merchant)
{
RobokassaPaySystem::logError('Not found merchant');
throw new BadRequestHttpException('Not found merchant');
}

Expand Down
Loading

0 comments on commit dee4f6a

Please sign in to comment.