public function send(ApiClient $apiClient) : PaymentResponse
 {
     $price = $this->cart->getCurrentPrice();
     $requestData = ['merchantId' => $this->merchantId, 'orderNo' => $this->orderId, 'payOperation' => $this->payOperation->getValue(), 'payMethod' => $this->payMethod->getValue(), 'totalAmount' => $price->getAmount(), 'currency' => $price->getCurrency()->getValue(), 'closePayment' => $this->closePayment, 'returnUrl' => $this->returnUrl, 'returnMethod' => $this->returnMethod->getValue(), 'cart' => array_map(function (CartItem $cartItem) {
         $cartItemValues = ['name' => $cartItem->getName(), 'quantity' => $cartItem->getQuantity(), 'amount' => $cartItem->getAmount()];
         if ($cartItem->getDescription() !== null) {
             $cartItemValues['description'] = $cartItem->getDescription();
         }
         return $cartItemValues;
     }, $this->cart->getItems()), 'description' => $this->description, 'language' => $this->language->getValue()];
     if ($this->merchantData !== null) {
         $requestData['merchantData'] = base64_encode($this->merchantData);
     }
     if ($this->customerId !== null) {
         $requestData['customerId'] = $this->customerId;
     }
     if ($this->ttlSec !== null) {
         $requestData['ttlSec'] = $this->ttlSec;
     }
     if ($this->logoVersion !== null) {
         $requestData['logoVersion'] = $this->logoVersion;
     }
     if ($this->colorSchemeVersion !== null) {
         $requestData['colorSchemeVersion'] = $this->colorSchemeVersion;
     }
     $response = $apiClient->post('payment/init', $requestData, new SignatureDataFormatter(['merchantId' => null, 'orderNo' => null, 'dttm' => null, 'payOperation' => null, 'payMethod' => null, 'totalAmount' => null, 'currency' => null, 'closePayment' => null, 'returnUrl' => null, 'returnMethod' => null, 'cart' => ['name' => null, 'quantity' => null, 'amount' => null, 'description' => null], 'description' => null, 'merchantData' => null, 'customerId' => null, 'language' => null, 'ttlSec' => null, 'logoVersion' => null, 'colorSchemeVersion' => null]), new SignatureDataFormatter(['payId' => null, 'dttm' => null, 'resultCode' => null, 'resultMessage' => null, 'paymentStatus' => null, 'authCode' => null]));
     $data = $response->getData();
     return new PaymentResponse($data['payId'], DateTimeImmutable::createFromFormat('YmdHis', $data['dttm']), new ResultCode($data['resultCode']), $data['resultMessage'], isset($data['paymentStatus']) ? new PaymentStatus($data['paymentStatus']) : null, $data['authCode'] ?? null);
 }
 public function testSend()
 {
     $apiClient = $this->getMockBuilder(ApiClient::class)->disableOriginalConstructor()->getMock();
     $apiClient->expects(self::once())->method('post')->with('payment/init', ['merchantId' => '012345', 'orderNo' => '5547', 'payOperation' => 'payment', 'payMethod' => 'card', 'totalAmount' => 1789600, 'currency' => 'CZK', 'closePayment' => true, 'returnUrl' => 'https://vasobchod.cz/gateway-return', 'returnMethod' => 'POST', 'cart' => [['name' => 'Nákup na vasobchodcz', 'quantity' => 1, 'amount' => 1789600, 'description' => 'Lenovo ThinkPad Edge E540'], ['name' => 'Poštovné', 'quantity' => 1, 'amount' => 0, 'description' => 'Doprava PPL']], 'description' => 'Nákup na vasobchod.cz (Lenovo ThinkPad Edge E540, Doprava PPL)', 'merchantData' => base64_encode('some-base64-encoded-merchant-data'), 'customerId' => '123', 'language' => 'CZ', 'ttlSec' => 1800, 'logoVersion' => 1, 'colorSchemeVersion' => 2])->willReturn(new Response(new ResponseCode(ResponseCode::S200_OK), ['payId' => '123456789', 'dttm' => '20140425131559', 'resultCode' => 0, 'resultMessage' => 'OK', 'paymentStatus' => 1]));
     /** @var ApiClient $apiClient */
     $cart = new Cart(new Currency(Currency::CZK));
     $cart->addItem('Nákup na vasobchodcz', 1, 1789600, 'Lenovo ThinkPad Edge E540');
     $cart->addItem('Poštovné', 1, 0, 'Doprava PPL');
     $initPaymentRequest = new InitPaymentRequest('012345', '5547', new PayOperation(PayOperation::PAYMENT), new PayMethod(PayMethod::CARD), true, 'https://vasobchod.cz/gateway-return', new HttpMethod(HttpMethod::POST), $cart, 'Nákup na vasobchod.cz (Lenovo ThinkPad Edge E540, Doprava PPL)', 'some-base64-encoded-merchant-data', '123', new Language(Language::CZ), 1800, 1, 2);
     $paymentResponse = $initPaymentRequest->send($apiClient);
     $this->assertInstanceOf(PaymentResponse::class, $paymentResponse);
     $this->assertSame('123456789', $paymentResponse->getPayId());
     $this->assertEquals(DateTimeImmutable::createFromFormat('YmdHis', '20140425131559'), $paymentResponse->getResponseDateTime());
     $this->assertEquals(new ResultCode(ResultCode::C0_OK), $paymentResponse->getResultCode());
     $this->assertSame('OK', $paymentResponse->getResultMessage());
     $this->assertEquals(new PaymentStatus(PaymentStatus::S1_CREATED), $paymentResponse->getPaymentStatus());
     $this->assertNull($paymentResponse->getAuthCode());
 }