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); }