<commit_before><?php
/**
 * Created by PhpStorm.
 * User: boshurik
 * Date: 15.02.16
 * Time: 17:54
 */

namespace BoShurik\Payum\YandexMoney\Action;

use Payum\Core\Action\GatewayAwareAction;
use Payum\Core\ApiAwareInterface;
use Payum\Core\Storage\StorageInterface;
use Payum\Core\Bridge\Spl\ArrayObject;
use Payum\Core\Exception\RequestNotSupportedException;
use Payum\Core\Reply\HttpResponse;
use Payum\Core\Request\GetHttpRequest;
use Payum\Core\Request\Notify;
use BoShurik\Payum\YandexMoney\Api;

/**
 * NotifyAction
 */
class NotifyAction extends GatewayAwareAction implements ApiAwareInterface
{
    /**
     * Implements ApiAwareInterface
     */
    use ApiAwareTrait;

    /**
     * @var StorageInterface
     */
    protected $tokenStorage;

    /**
     * @param StorageInterface $tokenStorage
     */
    public function __construct(StorageInterface $tokenStorage)
    {
        $this->tokenStorage = $tokenStorage;
    }

    /**
     * {@inheritDoc}
     *
     * @param Notify $request
     */
    public function execute($request)
    {
        RequestNotSupportedException::assertSupports($this, $request);

        $model = ArrayObject::ensureArrayObject($request->getModel());

        $this->gateway->execute($httpRequest = new GetHttpRequest());

        if (false == $this->api->verifyRequest($httpRequest->request)) {
            throw new HttpResponse('The notification is invalid. [2]', 400);
        }

        if ($model['amount'] != $httpRequest->request['withdraw_amount']) {
            throw new HttpResponse('The notification is invalid. [3]', 400);
        }

        if ('true' === $httpRequest->request['unaccepted']) {
            throw new HttpResponse('The notification is invalid. [4]', 400);
        }

        $model->replace(array(
            Api::FIELD_STATUS => Api::STATUS_CAPTURED,
        ));

        $this->tokenStorage->delete($request->getToken());
<commit_msg>Fix yandex notify amount check<commit_after><?php
/**
 * Created by PhpStorm.
 * User: boshurik
 * Date: 15.02.16
 * Time: 17:54
 */

namespace BoShurik\Payum\YandexMoney\Action;

use Payum\Core\Action\GatewayAwareAction;
use Payum\Core\ApiAwareInterface;
use Payum\Core\Storage\StorageInterface;
use Payum\Core\Bridge\Spl\ArrayObject;
use Payum\Core\Exception\RequestNotSupportedException;
use Payum\Core\Reply\HttpResponse;
use Payum\Core\Request\GetHttpRequest;
use Payum\Core\Request\Notify;
use BoShurik\Payum\YandexMoney\Api;

/**
 * NotifyAction
 */
class NotifyAction extends GatewayAwareAction implements ApiAwareInterface
{
    /**
     * Implements ApiAwareInterface
     */
    use ApiAwareTrait;

    /**
     * @var StorageInterface
     */
    protected $tokenStorage;

    /**
     * @param StorageInterface $tokenStorage
     */
    public function __construct(StorageInterface $tokenStorage)
    {
        $this->tokenStorage = $tokenStorage;
    }

    /**
     * {@inheritDoc}
     *
     * @param Notify $request
     */
    public function execute($request)
    {
        RequestNotSupportedException::assertSupports($this, $request);

        $model = ArrayObject::ensureArrayObject($request->getModel());

        $this->gateway->execute($httpRequest = new GetHttpRequest());

        if (false == $this->api->verifyRequest($httpRequest->request)) {
            throw new HttpResponse('The notification is invalid. [2]', 400);
        }

        if ($model['amount'] != $httpRequest->request['withdraw_amount'] &&
            $model['amount'] != $httpRequest->request['amount']) {
            throw new HttpResponse('The notification is invalid. [3]', 400);
        }

        if ('true' === $httpRequest->request['unaccepted']) {
            throw new HttpResponse('The notification is invalid. [4]', 400);
        }

        $model->replace(array(
            Api::FIELD_STATUS => Api::STATUS_CAPTURED,
        ));

        $this->tokenStorage->delete($request->getToken());

{'fraction_non_alphanumeric': 0.13527309851965288, 'fraction_numerical': 0.011230219499744768, 'mean_word_length': 3.0485537190082646, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 32, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7623098', 'n_tokens_mistral': 1198, 'n_tokens_neox': 1147, 'n_words': 216}