Skip to content

Commit

Permalink
PayPal
Browse files Browse the repository at this point in the history
  • Loading branch information
skeeks-semenov committed Apr 7, 2016
1 parent ee9b91b commit 376732c
Show file tree
Hide file tree
Showing 5 changed files with 162 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
Changelog
==============

1.0.0-alpha6.pre
-----------------
* PayPal

1.0.0-alpha5
-----------------
* Update admin products grids
Expand Down
16 changes: 15 additions & 1 deletion controllers/OrderController.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,24 @@ public function actionPay()
* @var $shopOrder ShopOrder
*/
$shopOrder = ShopOrder::findOne(\Yii::$app->request->get('id'));

//TODO: проверки

return $shopOrder->paySystem->paySystemHandler->paymentResponse($shopOrder);

}

public function actionPayPal()
{
return $this->render($this->action->id, [
'model' => ShopOrder::findOne(\Yii::$app->request->get('id'))
]);
}

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

}
88 changes: 88 additions & 0 deletions paySystems/PayPalPaySystem.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<?php
/**
* @author Semenov Alexander <[email protected]>
* @link http://skeeks.com/
* @copyright 2010 SkeekS (СкикС)
* @date 12.10.2015
*/
namespace skeeks\cms\shop\paySystems;
use skeeks\cms\shop\components\PaySystemHandlerComponent;
use skeeks\cms\shop\models\ShopOrder;
use yii\base\Component;
use yii\helpers\ArrayHelper;
use yii\widgets\ActiveForm;

/**
* Class PayPalPaySystem
* @package skeeks\cms\shop\paySystems
*/
class PayPalPaySystem extends PaySystemHandlerComponent
{
public $payNowButtonUrl = 'https://www.sandbox.paypal.com/cgi-bin/websc'; //https://auth.robokassa.ru/Merchant/Index.aspx
public $receiverEmail = '[email protected]';
public $sMerchantPass1 = '';
public $sMerchantPass2 = '';

/**
* Можно задать название и описание компонента
* @return array
*/
static public function descriptorConfig()
{
return array_merge(parent::descriptorConfig(), [
'name' => \skeeks\cms\shop\Module::t('app', 'PayPal'),
]);
}

public function rules()
{
return ArrayHelper::merge(parent::rules(), [
[['payNowButtonUrl'], 'string'],
[['payNowButtonUrl'], 'url'],
[['receiverEmail'], 'string'],
]);
}

public function attributeLabels()
{
return ArrayHelper::merge(parent::attributeLabels(), [
'payNowButtonUrl' => \skeeks\cms\shop\Module::t('app', 'Road to the api service paypal'),
'receiverEmail' => 'PayPal account email',
]);
}

/**
* @return \skeeks\cms\shop\paySystems\robokassa\Merchant
* @throws \yii\base\InvalidConfigException
*/
public function getMerchant()
{
/**
* @var \skeeks\cms\shop\paySystems\robokassa\Merchant $merchant
*/
$merchant = \Yii::createObject(ArrayHelper::merge($this->toArray(['baseUrl', 'sMerchantLogin', 'sMerchantPass1', 'sMerchantPass2']), [
'class' => '\skeeks\cms\shop\paySystems\robokassa\Merchant',
]));

return $merchant;
}

/**
* @param ShopOrder $shopOrder
* @return $this
*/
public function paymentResponse(ShopOrder $shopOrder)
{
return \Yii::$app->response->redirect(['shop/order/pay-pal', 'id' => $shopOrder->id]);

/*return \Yii::$app->view->render('@skeeks/cms/shop/views/pay-system/pay-pal', [
'model' => $shopOrder
], $this);*/
}

public function renderConfigForm(ActiveForm $activeForm)
{
echo $activeForm->field($this, 'payNowButtonUrl')->textInput();
echo $activeForm->field($this, 'receiverEmail')->textInput();
}
}
3 changes: 2 additions & 1 deletion views/admin-pay-system/_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
<?= $form->fieldSelect($model, 'component', [
\skeeks\cms\shop\Module::t('app', 'Basic payment systems') =>
[
\skeeks\cms\shop\paySystems\RobokassaPaySystem::className() => (new \skeeks\cms\shop\paySystems\RobokassaPaySystem())->descriptor->name
\skeeks\cms\shop\paySystems\RobokassaPaySystem::className() => (new \skeeks\cms\shop\paySystems\RobokassaPaySystem())->descriptor->name,
\skeeks\cms\shop\paySystems\PayPalPaySystem::className() => (new \skeeks\cms\shop\paySystems\PayPalPaySystem())->descriptor->name
],
], [
'allowDeselect' => true
Expand Down
53 changes: 53 additions & 0 deletions views/order/pay-pal.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?
/**
* @author Semenov Alexander <[email protected]>
* @link http://skeeks.com/
* @copyright 2010 SkeekS (СкикС)
* @date 07.04.2016
*/
/* @var $this yii\web\View */
/* @var $payPal skeeks\cms\shop\paySystems\PayPalPaySystem */
/* @var $model \skeeks\cms\shop\models\ShopOrder */

$payPal = $model->paySystem->paySystemHandler;

$returnUrl = \yii\helpers\Url::to(['/shop/order/view', 'id' => $model->id], true);
$notifyUrl = \yii\helpers\Url::to(['/shop/order/pay-pal-notify'], true);

$money = $model->money->convertToCurrency("RUB");

$customData = ['product_id' => $model->id];
$this->registerJs(<<<JS
$(function()
{
$('#payPal').submit();
});
JS
)
?>
<div style="text-align: center; margin: 100px; font-size: 20px;">
Wait, is redirected to the payment system...
</div>
<div style="display: none">
<form action="<?php echo $payPal->payNowButtonUrl; ?>" method="post" id="payPal">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="<?php echo $payPal->receiverEmail; ?>">
<input id="paypalItemName" type="hidden" name="item_name" value="Order #<?= $model->id; ?>">
<input id="paypalQuantity" type="hidden" name="quantity" value="1">
<input id="paypalAmmount" type="hidden" name="amount" value="<?= $money->getValue(); ?>">
<input type="hidden" name="no_shipping" value="1">
<input type="hidden" name="return" value="<?php echo $returnUrl; ?>">
<input type="hidden" name="cancel_return" value="<?php echo $returnUrl; ?>">
<input type="hidden" name="notify_url" value="<?php echo $notifyUrl; ?>">

<input type="hidden" name="custom" value="<?php echo json_encode($customData);?>">

<input type="hidden" name="currency_code" value="RUB">
<input type="hidden" name="lc" value="US">
<input type="hidden" name="bn" value="PP-BuyNowBF">

<button type="submit">
Pay Now
</button>
</form>
</div>

0 comments on commit 376732c

Please sign in to comment.