<commit_before><?php
/**
 * @author @jayS-de <<EMAIL>>
 */


namespace Commercetools\Core\Payment;

use Commercetools\Core\ApiTestCase;
use Commercetools\Core\Model\Common\LocalizedString;
use Commercetools\Core\Model\Common\Money;
use Commercetools\Core\Model\Payment\PaymentDraft;
use Commercetools\Core\Model\Payment\PaymentMethodInfo;
use Commercetools\Core\Model\Payment\Transaction;
use Commercetools\Core\Model\Payment\TransactionState;
use Commercetools\Core\Model\State\State;
use Commercetools\Core\Request\Payments\Command\PaymentAddInterfaceInteractionAction;
use Commercetools\Core\Request\Payments\Command\PaymentAddTransactionAction;
use Commercetools\Core\Request\Payments\Command\PaymentChangeAmountPlannedAction;
use Commercetools\Core\Request\Payments\Command\PaymentChangeTransactionInteractionIdAction;
use Commercetools\Core\Request\Payments\Command\PaymentChangeTransactionStateAction;
use Commercetools\Core\Request\Payments\Command\PaymentChangeTransactionTimestampAction;
use Commercetools\Core\Request\Payments\Command\PaymentSetAmountPaidAction;
use Commercetools\Core\Request\Payments\Command\PaymentSetAmountRefundedAction;
use Commercetools\Core\Request\Payments\Command\PaymentSetAuthorizationAction;
use Commercetools\Core\Request\Payments\Command\PaymentSetCustomerAction;
use Commercetools\Core\Request\Payments\Command\PaymentSetCustomFieldAction;
use Commercetools\Core\Request\Payments\Command\PaymentSetCustomTypeAction;
use Commercetools\Core\Request\Payments\Command\PaymentSetExternalIdAction;
use Commercetools\Core\Request\Payments\Command\PaymentSetInterfaceIdAction;
use Commercetools\Core\Request\Payments\Command\PaymentSetMethodInfoInterfaceAction;
use Commercetools\Core\Request\Payments\Command\PaymentSetMethodInfoMethodAction;
use Commercetools\Core\Request\Payments\Command\PaymentSetMethodInfoNameAction;
use Commercetools\Core\Request\Payments\Command\PaymentSetStatusInterfaceCodeAction;
use Commercetools\Core\Request\Payments\Command\PaymentSetStatusInterfaceTextAction;
use Commercetools\Core\Request\Payments\Command\PaymentTransitionStateAction;
use Commercetools\Core\Request\Payments\PaymentCreateRequest;
use Commercetools\Core\Request\Payments\PaymentDeleteRequest;
use Commercetools\Core\Request\Payments\PaymentUpdateRequest;

class PaymentUpdateRequestTest extends ApiTestCase
{
    /**
     * @return PaymentDraft
     */
    protected function getDraft()
    {
        $draft = PaymentDraft::of()
            ->setExternalId('test-' . $this->getTestRun() . '-payment')
            ->setAmountPlanned(Money::ofCurrencyAndAmount('EUR', 100))
            ->setPaymentMethodInfo(
                PaymentMethodInfo::of()
                    ->setPaymentInterface('Test')
                    ->setMethod('CreditCard')
            )
        ;
        return $draft;
    }

    protected function createPayment(PaymentDraft $draft)
    {
        $request = PaymentCreateRequest::ofDraft($draft);
        $response = $request->executeWithClient($this->getClient());
        $payment = $request->mapResponse($response);

        $this->cleanupRequests[] = $this->deleteRequest = PaymentDeleteRequest::ofIdAndVersion(
            $payment->getId(),
            $payment->getVersion()
        );

        return $payment;
    }

    public function testPaymentPlanned()
    {
        $draft = $this->getDraft();
        $payment = $this->createPayment($draft);

        $amount = 200;
        $request = PaymentUpdateRequest::ofIdAndVersion($payment->getId(), $payment->getVersion())
            ->addAction(
                PaymentChangeAmountPlannedAction::of()->setAmount(Money::ofCurrencyAndAmount('EUR', $amount))
            )
        ;
        $response = $request->executeWithClient($this->getClient());
        $result = $request->mapResponse($response);
        $this->deleteRequest->setVersion($result->getVersion());

        $this->assertInstanceOf('\Commercetools\Core\Model\Payment\Payment', $result);
        $this->assertSame($amount, $result->getAmountPlanned()->getCentAmount());
        $this->assertNotSame($payment->getVersion(), $result->getVersion());
    }

    public function testSetCustomer()
    {
        $draft = $this->getDraft();
        $payment = $this->createPayment($draft);

        $customer = $this->getCustomer();
        $request = PaymentUpdateRequest::ofIdAndVersion($payment->getId(), $payment->getVersion())
            ->addAction(
                PaymentSetCustomerAction::of()->setCustomer($customer->getReference())
            )
        ;
        $response = $request->executeWithClient($this->getClient());
        $result = $request->mapResponse($response);
        $this->deleteRequest->setVersion($result->getVersion());

        $this->assertInstanceOf('\Commercetools\Core\Model\Payment\Payment', $result);
        $this->assertSame($customer->getId(), $result->getCustomer()->getId());
        $this->assertNotSame($payment->getVersion(), $result->getVersion());
    }

    public function testSetExternalId()
    {
        $draft = $this->getDraft();
        $payment = $this->createPayment($draft);

        $externalId = $this->getTestRun() . '-externalId';
        $request = PaymentUpdateRequest::ofIdAndVersion($payment->getId(), $payment->getVersion())
            ->addAction(
                PaymentSetExternalIdAction::of()->setExternalId($externalId)
            )
        ;
        $response = $request->executeWithClient($this->getClient());
        $result = $request->mapResponse($response);
        $this->deleteRequest->setVersion($result->getVersion());

        $this->assertInstanceOf('\Commercetools\Core\Model\Payment\Payment', $result);
        $this->assertSame($externalId, $result->getExternalId());
        $this->assertNotSame($payment->getVersion(), $result->getVersion());
    }

    public function testSetInterfaceId()
    {
        $draft = $this->getDraft();
        $payment = $this->createPayment($draft);

        $interfaceId = $this->getTestRun() . '-interfaceId';
        $request = PaymentUpdateRequest::ofIdAndVersion($payment->getId(), $payment->getVersion())
            ->addAction(
                PaymentSetInterfaceIdAction::of()->setInterfaceId($interfaceId)
            )
        ;
        $response = $request->executeWithClient($this->getClient());
        $result = $request->mapResponse($response);
        $this->deleteRequest->setVersion($result->getVersion());

        $this->assertInstanceOf('\Commercetools\Core\Model\Payment\Payment', $result);
        $this->assertSame($interfaceId, $result->getExternalId());
        $this->assertNotSame($payment->getVersion(), $result->getVersion());
    }

    public function testSetAuthorization()
    {
        $draft = $this->getDraft();<commit_msg>test(Payment): fix set interfaceid action integration test<commit_after><?php
/**
 * @author @jayS-de <<EMAIL>>
 */


namespace Commercetools\Core\Payment;

use Commercetools\Core\ApiTestCase;
use Commercetools\Core\Model\Common\LocalizedString;
use Commercetools\Core\Model\Common\Money;
use Commercetools\Core\Model\Payment\PaymentDraft;
use Commercetools\Core\Model\Payment\PaymentMethodInfo;
use Commercetools\Core\Model\Payment\Transaction;
use Commercetools\Core\Model\Payment\TransactionState;
use Commercetools\Core\Model\State\State;
use Commercetools\Core\Request\Payments\Command\PaymentAddInterfaceInteractionAction;
use Commercetools\Core\Request\Payments\Command\PaymentAddTransactionAction;
use Commercetools\Core\Request\Payments\Command\PaymentChangeAmountPlannedAction;
use Commercetools\Core\Request\Payments\Command\PaymentChangeTransactionInteractionIdAction;
use Commercetools\Core\Request\Payments\Command\PaymentChangeTransactionStateAction;
use Commercetools\Core\Request\Payments\Command\PaymentChangeTransactionTimestampAction;
use Commercetools\Core\Request\Payments\Command\PaymentSetAmountPaidAction;
use Commercetools\Core\Request\Payments\Command\PaymentSetAmountRefundedAction;
use Commercetools\Core\Request\Payments\Command\PaymentSetAuthorizationAction;
use Commercetools\Core\Request\Payments\Command\PaymentSetCustomerAction;
use Commercetools\Core\Request\Payments\Command\PaymentSetCustomFieldAction;
use Commercetools\Core\Request\Payments\Command\PaymentSetCustomTypeAction;
use Commercetools\Core\Request\Payments\Command\PaymentSetExternalIdAction;
use Commercetools\Core\Request\Payments\Command\PaymentSetInterfaceIdAction;
use Commercetools\Core\Request\Payments\Command\PaymentSetMethodInfoInterfaceAction;
use Commercetools\Core\Request\Payments\Command\PaymentSetMethodInfoMethodAction;
use Commercetools\Core\Request\Payments\Command\PaymentSetMethodInfoNameAction;
use Commercetools\Core\Request\Payments\Command\PaymentSetStatusInterfaceCodeAction;
use Commercetools\Core\Request\Payments\Command\PaymentSetStatusInterfaceTextAction;
use Commercetools\Core\Request\Payments\Command\PaymentTransitionStateAction;
use Commercetools\Core\Request\Payments\PaymentCreateRequest;
use Commercetools\Core\Request\Payments\PaymentDeleteRequest;
use Commercetools\Core\Request\Payments\PaymentUpdateRequest;

class PaymentUpdateRequestTest extends ApiTestCase
{
    /**
     * @return PaymentDraft
     */
    protected function getDraft()
    {
        $draft = PaymentDraft::of()
            ->setExternalId('test-' . $this->getTestRun() . '-payment')
            ->setAmountPlanned(Money::ofCurrencyAndAmount('EUR', 100))
            ->setPaymentMethodInfo(
                PaymentMethodInfo::of()
                    ->setPaymentInterface('Test')
                    ->setMethod('CreditCard')
            )
        ;
        return $draft;
    }

    protected function createPayment(PaymentDraft $draft)
    {
        $request = PaymentCreateRequest::ofDraft($draft);
        $response = $request->executeWithClient($this->getClient());
        $payment = $request->mapResponse($response);

        $this->cleanupRequests[] = $this->deleteRequest = PaymentDeleteRequest::ofIdAndVersion(
            $payment->getId(),
            $payment->getVersion()
        );

        return $payment;
    }

    public function testPaymentPlanned()
    {
        $draft = $this->getDraft();
        $payment = $this->createPayment($draft);

        $amount = 200;
        $request = PaymentUpdateRequest::ofIdAndVersion($payment->getId(), $payment->getVersion())
            ->addAction(
                PaymentChangeAmountPlannedAction::of()->setAmount(Money::ofCurrencyAndAmount('EUR', $amount))
            )
        ;
        $response = $request->executeWithClient($this->getClient());
        $result = $request->mapResponse($response);
        $this->deleteRequest->setVersion($result->getVersion());

        $this->assertInstanceOf('\Commercetools\Core\Model\Payment\Payment', $result);
        $this->assertSame($amount, $result->getAmountPlanned()->getCentAmount());
        $this->assertNotSame($payment->getVersion(), $result->getVersion());
    }

    public function testSetCustomer()
    {
        $draft = $this->getDraft();
        $payment = $this->createPayment($draft);

        $customer = $this->getCustomer();
        $request = PaymentUpdateRequest::ofIdAndVersion($payment->getId(), $payment->getVersion())
            ->addAction(
                PaymentSetCustomerAction::of()->setCustomer($customer->getReference())
            )
        ;
        $response = $request->executeWithClient($this->getClient());
        $result = $request->mapResponse($response);
        $this->deleteRequest->setVersion($result->getVersion());

        $this->assertInstanceOf('\Commercetools\Core\Model\Payment\Payment', $result);
        $this->assertSame($customer->getId(), $result->getCustomer()->getId());
        $this->assertNotSame($payment->getVersion(), $result->getVersion());
    }

    public function testSetExternalId()
    {
        $draft = $this->getDraft();
        $payment = $this->createPayment($draft);

        $externalId = $this->getTestRun() . '-externalId';
        $request = PaymentUpdateRequest::ofIdAndVersion($payment->getId(), $payment->getVersion())
            ->addAction(
                PaymentSetExternalIdAction::of()->setExternalId($externalId)
            )
        ;
        $response = $request->executeWithClient($this->getClient());
        $result = $request->mapResponse($response);
        $this->deleteRequest->setVersion($result->getVersion());

        $this->assertInstanceOf('\Commercetools\Core\Model\Payment\Payment', $result);
        $this->assertSame($externalId, $result->getExternalId());
        $this->assertNotSame($payment->getVersion(), $result->getVersion());
    }

    public function testSetInterfaceId()
    {
        $draft = $this->getDraft();
        $payment = $this->createPayment($draft);

        $interfaceId = $this->getTestRun() . '-interfaceId';
        $request = PaymentUpdateRequest::ofIdAndVersion($payment->getId(), $payment->getVersion())
            ->addAction(
                PaymentSetInterfaceIdAction::of()->setInterfaceId($interfaceId)
            )
        ;
        $response = $request->executeWithClient($this->getClient());
        $result = $request->mapResponse($response);
        $this->deleteRequest->setVersion($result->getVersion());

        $this->assertInstanceOf('\Commercetools\Core\Model\Payment\Payment', $result);
        $this->assertSame($interfaceId, $result->getInterfaceId());
        $this->assertNotSame($payment->getVersion(), $result->getVersion());
    }

    public function testSetAuthorization()
    {
        $draft = $this->getDraft();
{'fraction_non_alphanumeric': 0.13609598115707347, 'fraction_numerical': 0.0008832621816575887, 'mean_word_length': 3.889168765743073, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 193, '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': '5391918', 'n_tokens_mistral': 3785, 'n_tokens_neox': 3748, 'n_words': 435}