<commit_before><?php
namespace Gontran\SyliusPayboxBundle\Action;

use Payum\Core\Action\ActionInterface;
use Payum\Core\Request\GetStatusInterface;
use Payum\Core\Request\GetToken;
use Payum\Core\Bridge\Spl\ArrayObject;
use Payum\Core\Exception\RequestNotSupportedException;
use Payum\Core\GatewayAwareTrait;
use Payum\Core\GatewayAwareInterface;
use Sylius\Bundle\PayumBundle\Request\GetStatus;
use Sylius\Component\Payment\Model\PaymentInterface;

class StatusAction implements ActionInterface, GatewayAwareInterface
{
    use GatewayAwareTrait;

    const RESPONSE_SUCCESS = "00000";
    const RESPONSE_FAILED_MIN = "00100";
    const RESPONSE_FAILED_MAX = "00199";
    //TODO: handle other response codes


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

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


        if (null === $model['error_code']) {
            $request->markNew();
            return;
        }

        // Rely only on NotifyAction to update payment
        if (isset($model['notification_pending'])) {

            if (self::RESPONSE_SUCCESS === $model['error_code']) {
                $request->markCaptured();
            }
            else if (self::RESPONSE_FAILED_MIN <= $model['error_code'] && self::RESPONSE_FAILED_MAX >= $model['error_code']) {
                $request->markFailed();
            }
            else {
                $request->markCanceled();
            }
            unset($model['notification_pending']);
        }
        else {
            // To make Sylius display a correct message (PayumController:afterCaptureAction)
            // And because request is in state unknown
            // Let's mark the request with the state of the payment
            // Because IPN notification will always be handled by the server before user action<commit_msg>Update payment logic : if a payment have been previously canceled or has previously failed, allow it to be completed<commit_after><?php
namespace Gontran\SyliusPayboxBundle\Action;

use Payum\Core\Action\ActionInterface;
use Payum\Core\Request\GetStatusInterface;
use Payum\Core\Request\GetToken;
use Payum\Core\Bridge\Spl\ArrayObject;
use Payum\Core\Exception\RequestNotSupportedException;
use Payum\Core\GatewayAwareTrait;
use Payum\Core\GatewayAwareInterface;
use Sylius\Bundle\PayumBundle\Request\GetStatus;
use Sylius\Component\Payment\Model\PaymentInterface;

class StatusAction implements ActionInterface, GatewayAwareInterface
{
    use GatewayAwareTrait;

    const RESPONSE_SUCCESS = "00000";
    const RESPONSE_FAILED_MIN = "00100";
    const RESPONSE_FAILED_MAX = "00199";
    //TODO: handle other response codes


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

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


        if (null === $model['error_code']) {
            $request->markNew();
            return;
        }

        // Rely only on NotifyAction to update payment
        if (isset($model['notification_pending'])) {
            $request->setModel($request->getFirstModel());

            if (self::RESPONSE_SUCCESS === $model['error_code']) {
                $request->getModel()->setState(PaymentInterface::STATE_COMPLETED);
                $request->markCaptured();
            }
            else if (self::RESPONSE_FAILED_MIN <= $model['error_code'] && self::RESPONSE_FAILED_MAX >= $model['error_code']) {
                $request->getModel()->setState(PaymentInterface::STATE_FAILED);
                $request->markFailed();
            }
            else {
                $request->getModel()->setState(PaymentInterface::STATE_CANCELLED);
                $request->markCanceled();
            }
            unset($model['notification_pending']);
        }
        else {
            // To make Sylius display a correct message (PayumController:afterCaptureAction)
            // And because request is in state unknown
            // Let's mark the request with the state of the payment
            // Because IPN notification will always be handled by the server before user action
{'fraction_non_alphanumeric': 0.10768175582990398, 'fraction_numerical': 0.006858710562414266, 'mean_word_length': 2.7977430555555554, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 23, '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': '1434298', 'n_tokens_mistral': 1213, 'n_tokens_neox': 1179, 'n_words': 261}