Skip to content

Commit

Permalink
Merge pull request #75 from yoomoney/release/v2.2.2
Browse files Browse the repository at this point in the history
Release/2.2.2
  • Loading branch information
tonchik-tm authored Feb 15, 2022
2 parents 5a27aae + 00d0455 commit 27a21ec
Show file tree
Hide file tree
Showing 27 changed files with 895 additions and 185 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
### v2.2.2 от 14.02.2022
* Отключен способ оплаты Webmoney
* Обновлен SDK до версии 2.2.6
* Добавлена обработка уведомлений от ЮKassa следующих типов: payment.canceled, refund.succeeded, payout.canceled, payout.succeeded, deal.closed

### v2.2.1 от 02.12.2021
* Обновлен SDK до версии 2.2.2

Expand Down
Binary file removed api-prestashop-yoomoneymodule.zip
Binary file not shown.
23 changes: 22 additions & 1 deletion src/classes/Models/KassaModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
use YooKassa\Request\Payments\Payment\CreateCaptureRequestBuilder;
use YooKassa\Request\Payments\Payment\CreateCaptureRequestSerializer;
use YooKassa\Request\Refunds\CreateRefundRequest;
use YooKassa\Request\Refunds\RefundResponse;
use YooMoneyModule;

class KassaModel extends AbstractPaymentModel
Expand All @@ -50,6 +51,7 @@ class KassaModel extends AbstractPaymentModel
private static $disabledPaymentMethods = array(
PaymentMethodType::B2B_SBERBANK,
PaymentMethodType::WECHAT,
PaymentMethodType::WEBMONEY,
);

const PAYMENT_METHOD_WIDGET = 'widget';
Expand Down Expand Up @@ -456,7 +458,7 @@ public function getNpsBlock($isoCode)

$token = Tools::getAdminTokenLite(YooMoneyModule::ADMIN_CONTROLLER);

return $this->module->displayConfirmation('Помогите нам улучшить модуль ЮKassa — ответьте на
return $this->module->displayConfirmation('Помогите нам улучшить модуль ЮKassa — ответьте на
<a href="#" onclick="return false;" class="yoomoney_nps_link"
data-controller="'.YooMoneyModule::ADMIN_CONTROLLER.'"
data-token="'.$token.'">один вопрос</a>');
Expand Down Expand Up @@ -722,6 +724,25 @@ public function getPayment($paymentId)
return $payment;
}

/**
* Получает по API Юkassa объект возврата по переданному id
*
* @param string $refundId
*
* @return RefundResponse|null
*/
public function fetchRefund($refundId)
{
$refund = null;
try {
$refund = $this->getApiClient()->getRefundInfo($refundId);
} catch (\Exception $e) {
$this->module->log('error', 'Failed to fetch refund information from API: '.$e->getMessage());
}

return $refund;
}

/**
* @param Payment $payment
*
Expand Down
151 changes: 114 additions & 37 deletions src/controllers/front/notifycapture.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
<?php
/**
* @author YooMoney <[email protected]>
* @copyright © 2020 "YooMoney", NBСO LLC
* @copyright © 2022 "YooMoney", NBСO LLC
* @license https://yoomoney.ru/doc.xml?id=527052
*/
use YooKassa\Model\Notification\NotificationSucceeded;
use YooKassa\Model\Notification\NotificationWaitingForCapture;
use YooKassa\Model\NotificationEventType;
use YooKassa\Model\Payment;
use YooKassa\Model\PaymentStatus;
use YooKassa\Model\Notification\NotificationFactory;
use YooKassa\Model\RefundStatus;

/**
* Class YooMoneyModulePaymentKassaModuleFrontController
Expand All @@ -17,6 +16,13 @@
*/
class YooMoneyModuleNotifyCaptureModuleFrontController extends ModuleFrontController
{
const REFUND_STATUS_ID = 7;

/**
* Обработка входящих уведомлений от Юkassa
*
* @return bool|void
*/
public function postProcess()
{
if ($_SERVER['REQUEST_METHOD'] == 'GET') {
Expand All @@ -37,8 +43,8 @@ public function postProcess()

return;
}
$json = json_decode($source, true);
if (empty($json)) {
$data = json_decode($source, true);
if (empty($data)) {
if (json_last_error() === JSON_ERROR_NONE) {
$message = 'empty object in body';
} else {
Expand All @@ -49,47 +55,118 @@ public function postProcess()

return;
}

$kassa = $this->module->getKassaModel();

try {
if ($json['event'] == NotificationEventType::PAYMENT_WAITING_FOR_CAPTURE) {
$notification = new NotificationWaitingForCapture($json);
$factory = new NotificationFactory();
$notificationObject = $factory->factory($data);

$paymentId = $notificationObject->getObject()->getId();

if ($notificationObject->getEvent() === NotificationEventType::REFUND_SUCCEEDED) {
$refundNotifyObj = $notificationObject->getObject();
$refundKassaObj = $kassa->fetchRefund($refundNotifyObj->getId());
$paymentId = $refundKassaObj->getPaymentId();
}

$paymentModel = $kassa->getPayment($paymentId);

$result = false;
if (
$notificationObject->getEvent() === NotificationEventType::PAYMENT_SUCCEEDED
&& $paymentModel->getStatus() === PaymentStatus::SUCCEEDED
) {
$kassa->updatePaymentStatus($paymentModel);
$orderId = $kassa->getOrderIdByPayment($paymentModel);
$orderStatusId = $kassa->getSuccessStatusId();
$history = new OrderHistory();
$history->id_order = $orderId;
$history->changeIdOrderState($orderStatusId, $orderId);
$history->addWithemail(true);
// обновляем номер транзакции, привязанной к заказу
$kassa->updateOrderPaymentId($orderId, $paymentModel);
$result = true;
}

if (
$notificationObject->getEvent() === NotificationEventType::PAYMENT_WAITING_FOR_CAPTURE
&& $paymentModel->getStatus() === PaymentStatus::WAITING_FOR_CAPTURE
) {
$this->module->log('info', 'Notification waiting for capture init.');
$result = $this->module->captureOrHoldPayment($notification->getObject()->getId());
} else {
$webhookObject = new NotificationSucceeded($json);
$this->module->log('info', 'Notification succeeded init.');
$paymentData = $webhookObject->getObject();
$kassa = $this->module->getKassaModel();
$paymentModel = $kassa->getPayment($paymentData->getId());
if ($paymentModel->status === PaymentStatus::SUCCEEDED) {
$kassa->updatePaymentStatus($paymentModel);
$orderId = $kassa->getOrderIdByPayment($paymentModel);
$orderStatusId = $kassa->getSuccessStatusId();
$history = new OrderHistory();
$history->id_order = $orderId;
$history->changeIdOrderState($orderStatusId, $orderId);
$history->addWithemail(true);
// обновляем номер транзакции, привязанной к заказу
$this->module->getKassaModel()->updateOrderPaymentId($orderId, $paymentData);
echo json_encode(array('success' => true));
exit();
} else {
$result = false;
}

$kassa->updatePaymentStatus($paymentModel);
$orderId = $kassa->getOrderIdByPayment($paymentModel);

$history = new OrderHistory();
$history->id_order = $orderId;
$history->changeIdOrderState($kassa->getOnHoldStatusId(), $orderId);
$history->addWithemail(true);
$kassa->updateOrderPaymentId($orderId, $paymentModel);
$result = true;
}

if (
$notificationObject->getEvent() === NotificationEventType::PAYMENT_CANCELED
&& $paymentModel->getStatus() === PaymentStatus::CANCELED
) {
$this->module->log('info', 'Notification payment canceled init.');

$kassa->updatePaymentStatus($paymentModel);
$orderId = $kassa->getOrderIdByPayment($paymentModel);
$history = new OrderHistory();
$history->id_order = $orderId;
$history->changeIdOrderState($kassa->getCancelStatusId(), $orderId);
$history->addWithemail(true);
$kassa->updateOrderPaymentId($orderId, $paymentModel);

$result = true;
}

if (
$notificationObject->getEvent() === NotificationEventType::REFUND_SUCCEEDED
&& $refundKassaObj->getStatus() === RefundStatus::SUCCEEDED
&& $paymentModel->getStatus() === PaymentStatus::SUCCEEDED
) {
$this->module->log('info', 'Notification payment refund init.');

$kassa->updatePaymentStatus($paymentModel);
$orderId = $kassa->getOrderIdByPayment($paymentModel);
$history = new OrderHistory();
$history->id_order = $orderId;
$history->changeIdOrderState(self::REFUND_STATUS_ID, $orderId);
$history->addWithemail(true);
$kassa->updateOrderPaymentId($orderId, $paymentModel);

$result = true;
}

if (
$notificationObject->getEvent() === NotificationEventType::DEAL_CLOSED
|| $notificationObject->getEvent() === NotificationEventType::PAYOUT_CANCELED
|| $notificationObject->getEvent() === NotificationEventType::PAYOUT_SUCCEEDED
) {
$this->module->log(
'info',
'Notification ' . $notificationObject->getEvent() . ' received.'
);

return true;
}

if (!$result) {
header('HTTP/1.1 500 Server error 1');
exit();
}

echo json_encode(array('success' => true));
exit();

} catch (\Exception $e) {
$this->module->log('error', 'Invalid notification object - '.$e->getMessage());
header('HTTP/1.1 500 Server error: '.$e->getMessage());

return;
}

if (!$result) {
header('HTTP/1.1 500 Server error 1');
exit();
}
echo json_encode(array('success' => $result));
exit();
}
}
16 changes: 8 additions & 8 deletions src/lib/vendor/composer/installed.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,32 +52,32 @@
},
{
"name": "yoomoney/yookassa-sdk-php",
"version": "2.2.2",
"version_normalized": "2.2.2.0",
"version": "2.2.6",
"version_normalized": "2.2.6.0",
"source": {
"type": "git",
"url": "https://github.com/yoomoney/yookassa-sdk-php.git",
"reference": "cc9cddb807d93e4549af7f298f9780a3ebd3561a"
"reference": "0bbd87d76310b3239b6e6de6534c9fab9e7db847"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/yoomoney/yookassa-sdk-php/zipball/cc9cddb807d93e4549af7f298f9780a3ebd3561a",
"reference": "cc9cddb807d93e4549af7f298f9780a3ebd3561a",
"url": "https://api.github.com/repos/yoomoney/yookassa-sdk-php/zipball/0bbd87d76310b3239b6e6de6534c9fab9e7db847",
"reference": "0bbd87d76310b3239b6e6de6534c9fab9e7db847",
"shasum": ""
},
"require": {
"ext-curl": "*",
"ext-json": "*",
"ext-mbstring": "*",
"php": ">=5.3.0",
"psr/log": "^1.0 || ^2.0 || ^3.0"
"psr/log": "^1.0"
},
"require-dev": {
"ext-xml": "*",
"mockery/mockery": "^0.9.9",
"phpunit/phpunit": "^4.8.35 || ^5.7"
},
"time": "2021-11-16T11:21:19+00:00",
"time": "2022-01-21T13:31:53+00:00",
"type": "library",
"installation-source": "dist",
"autoload": {
Expand Down Expand Up @@ -106,7 +106,7 @@
],
"support": {
"issues": "https://github.com/yoomoney/yookassa-sdk-php/issues",
"source": "https://github.com/yoomoney/yookassa-sdk-php/tree/2.2.2"
"source": "https://github.com/yoomoney/yookassa-sdk-php/tree/2.2.6"
},
"install-path": "../yoomoney/yookassa-sdk-php"
}
Expand Down
10 changes: 5 additions & 5 deletions src/lib/vendor/composer/installed.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
'type' => 'library',
'install_path' => __DIR__ . '/../../',
'aliases' => array(),
'reference' => '08cae3b00fbbbb6e5d9cf9b76da9ba4414839872',
'reference' => 'fd1a980669146c6be4bfe4f2e607a3af372d94a8',
'name' => '__root__',
'dev' => true,
),
Expand All @@ -16,7 +16,7 @@
'type' => 'library',
'install_path' => __DIR__ . '/../../',
'aliases' => array(),
'reference' => '08cae3b00fbbbb6e5d9cf9b76da9ba4414839872',
'reference' => 'fd1a980669146c6be4bfe4f2e607a3af372d94a8',
'dev_requirement' => false,
),
'psr/log' => array(
Expand All @@ -29,12 +29,12 @@
'dev_requirement' => false,
),
'yoomoney/yookassa-sdk-php' => array(
'pretty_version' => '2.2.2',
'version' => '2.2.2.0',
'pretty_version' => '2.2.6',
'version' => '2.2.6.0',
'type' => 'library',
'install_path' => __DIR__ . '/../yoomoney/yookassa-sdk-php',
'aliases' => array(),
'reference' => 'cc9cddb807d93e4549af7f298f9780a3ebd3561a',
'reference' => '0bbd87d76310b3239b6e6de6534c9fab9e7db847',
'dev_requirement' => false,
),
),
Expand Down
4 changes: 2 additions & 2 deletions src/lib/vendor/yoomoney/yookassa-sdk-php/.travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ matrix:
include:
- php: 5.5
dist: trusty
# - php: 5.4
# dist: precise
- php: 5.4
dist: trusty
# - php: 5.3
# dist: precise

Expand Down
17 changes: 17 additions & 0 deletions src/lib/vendor/yoomoney/yookassa-sdk-php/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
### v2.2.6 от 21.01.2022
* Откат поддержки psr/log версий 2 и 3

### v2.2.5 от 28.12.2021
* Добавлен метод проверки IP адреса уведомления от Юkassa среди известных адресов Юkassa
* Добавлены тесты
* Добавлен пример в документацию

### v2.2.4 от 09.12.2021
* Фикс метода jsonSerialize() для ReceiptResponseItem
* Добавлена проверка на параметр platform_fee_amount при создании запроса для двухстадийного платежа
* Обновлены тесты
* Обновлен readme

### v2.2.3 от 07.12.2021
* Добавлена обработка параметра authorization_details.three_d_secure.applied в объекте платежа

### v2.2.2 от 16.11.2021
* Добавлены уведомления по Сделкам и Выплатам

Expand Down
Loading

0 comments on commit 27a21ec

Please sign in to comment.