<commit_before><?php

/*
 * This file is part of the LolautruchePaylineBundle package.
 *
 * (c) <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Lolautruche\PaylineBundle\Payline;

use Lolautruche\PaylineBundle\Event\PaylineEvents;
use Lolautruche\PaylineBundle\Event\ResultEvent;
use Lolautruche\PaylineBundle\Event\WebTransactionEvent;
use Payline\PaylineSDK;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;

/**
 * Main Payline implementation, abstracting PaylineSDK.
 */
class Payline implements WebGatewayInterface
{
    /**
     * @var PaylineSDK
     */
    private $paylineSDK;

    /**
     * @var EventDispatcherInterface
     */
    private $eventDispatcher;

    /**
     * Default currency code.
     *
     * @var int
     */
    private $defaultCurrency;

    /**
     * Default contract number, reprenting payment mediums available.
     *
     * @var string
     */
    private $defaultContractNumber;

    public function __construct(PaylineSDK $paylineSDK, EventDispatcherInterface $eventDispatcher, $defaultCurrency, $defaultContractNumber = null)
    {
        $this->paylineSDK = $paylineSDK;
        $this->eventDispatcher = $eventDispatcher;
        $this->defaultCurrency = $defaultCurrency;
        $this->defaultContractNumber = (string)$defaultContractNumber;
    }

    /**
     * @return PaylineSDK
     */
    public function getPaylineSDK()
    {
        return $this->paylineSDK;
    }

    /**
     * {@inheritdoc}
     */
    public function initiateWebTransaction(WebTransaction $transaction)
    {
        $this->eventDispatcher->dispatch(
            PaylineEvents::BEFORE_WEB_TRANSACTION_INITIATE,
            new WebTransactionEvent($transaction)
        );

        $payment = [
            'amount' => $transaction->getAmount(),
            'currency' => $transaction->getCurrency() ?: $this->defaultCurrency,
            'action' => $transaction->getAction(),
            'mode' => $transaction->getMode(),
            'contractNumber' => (string)$transaction->getContractNumber() ?: $this->defaultContractNumber,
        ];

        $order = [
            'ref' => $transaction->getOrderRef(),
            'amount' => $transaction->getOrderAmount() ?: $transaction->getAmount(),
            'currency' => $transaction->getOrderCurrency() ?: $transaction->getCurrency(),
            'date' => $transaction->getOrderDate(),
        ];
        if ($orderTaxes = $transaction->getOrderTaxes()) {
            $order['taxes'] = $orderTaxes;
        }
        if ($orderCountry = $transaction->getOrderCountry()) {
            $order['country'] = $orderCountry;
        }

        $params = array_merge_recursive([
            'payment' => $payment,
            'order' => $order,
        ], $transaction->getExtraOptions());

        $paylineResult = new PaylineResult($this->paylineSDK->doWebPayment($params));
        $this->eventDispatcher->dispatch(
            PaylineEvents::AFTER_WEB_TRANSACTION_INITIATE,
            new ResultEvent($paylineResult)
        );

        return $paylineResult;
    }

    /**
     * {@inheritdoc}
     */
    public function verifyWebTransaction($paymentToken)
    {<commit_msg>Fixed order date format<commit_after><?php

/*
 * This file is part of the LolautruchePaylineBundle package.
 *
 * (c) <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Lolautruche\PaylineBundle\Payline;

use Lolautruche\PaylineBundle\Event\PaylineEvents;
use Lolautruche\PaylineBundle\Event\ResultEvent;
use Lolautruche\PaylineBundle\Event\WebTransactionEvent;
use Payline\PaylineSDK;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;

/**
 * Main Payline implementation, abstracting PaylineSDK.
 */
class Payline implements WebGatewayInterface
{
    /**
     * @var PaylineSDK
     */
    private $paylineSDK;

    /**
     * @var EventDispatcherInterface
     */
    private $eventDispatcher;

    /**
     * Default currency code.
     *
     * @var int
     */
    private $defaultCurrency;

    /**
     * Default contract number, reprenting payment mediums available.
     *
     * @var string
     */
    private $defaultContractNumber;

    public function __construct(PaylineSDK $paylineSDK, EventDispatcherInterface $eventDispatcher, $defaultCurrency, $defaultContractNumber = null)
    {
        $this->paylineSDK = $paylineSDK;
        $this->eventDispatcher = $eventDispatcher;
        $this->defaultCurrency = $defaultCurrency;
        $this->defaultContractNumber = (string)$defaultContractNumber;
    }

    /**
     * @return PaylineSDK
     */
    public function getPaylineSDK()
    {
        return $this->paylineSDK;
    }

    /**
     * {@inheritdoc}
     */
    public function initiateWebTransaction(WebTransaction $transaction)
    {
        $this->eventDispatcher->dispatch(
            PaylineEvents::BEFORE_WEB_TRANSACTION_INITIATE,
            new WebTransactionEvent($transaction)
        );

        $payment = [
            'amount' => $transaction->getAmount(),
            'currency' => $transaction->getCurrency() ?: $this->defaultCurrency,
            'action' => $transaction->getAction(),
            'mode' => $transaction->getMode(),
            'contractNumber' => (string)$transaction->getContractNumber() ?: $this->defaultContractNumber,
        ];

        $order = [
            'ref' => $transaction->getOrderRef(),
            'amount' => $transaction->getOrderAmount() ?: $transaction->getAmount(),
            'currency' => $transaction->getOrderCurrency() ?: $transaction->getCurrency(),
            'date' => $transaction->getOrderDate()->format('d/m/Y H:i'),
        ];
        if ($orderTaxes = $transaction->getOrderTaxes()) {
            $order['taxes'] = $orderTaxes;
        }
        if ($orderCountry = $transaction->getOrderCountry()) {
            $order['country'] = $orderCountry;
        }

        $params = array_merge_recursive([
            'payment' => $payment,
            'order' => $order,
        ], $transaction->getExtraOptions());

        $paylineResult = new PaylineResult($this->paylineSDK->doWebPayment($params));
        $this->eventDispatcher->dispatch(
            PaylineEvents::AFTER_WEB_TRANSACTION_INITIATE,
            new ResultEvent($paylineResult)
        );

        return $paylineResult;
    }

    /**
     * {@inheritdoc}
     */
    public function verifyWebTransaction($paymentToken)
    {
{'fraction_non_alphanumeric': 0.1258900166641418, 'fraction_numerical': 0.0, 'mean_word_length': 2.7048260381593714, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 86, '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': '1956971', 'n_tokens_mistral': 1843, 'n_tokens_neox': 1800, 'n_words': 334}