public function send(ApiClient $apiClient) : PaymentResponse
 {
     $requestData = ['merchantId' => $this->merchantId, 'payId' => $this->payId];
     $response = $apiClient->post('payment/oneclick/start', $requestData, new SignatureDataFormatter(['merchantId' => null, 'payId' => null, 'dttm' => null]), new SignatureDataFormatter(['payId' => null, 'dttm' => null, 'resultCode' => null, 'resultMessage' => null, 'paymentStatus' => 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);
 }
 public function send(ApiClient $apiClient) : PaymentResponse
 {
     $requestData = ['merchantId' => $this->merchantId, 'origPayId' => $this->origPayId, 'orderNo' => $this->orderId];
     if ($this->price !== null) {
         $requestData['totalAmount'] = $this->price->getAmount();
         $requestData['currency'] = $this->price->getCurrency()->getValue();
     }
     if ($this->description !== null) {
         $requestData['description'] = $this->description;
     }
     $response = $apiClient->post('payment/oneclick/init', $requestData, new SignatureDataFormatter(['merchantId' => null, 'origPayId' => null, 'orderNo' => null, 'dttm' => null, 'totalAmount' => null, 'currency' => null, 'description' => null]), new SignatureDataFormatter(['payId' => null, 'dttm' => null, 'resultCode' => null, 'resultMessage' => null, 'paymentStatus' => 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);
 }
 /**
  * @param HttpMethod $httpMethod
  * @param string $url
  * @param string $expectedUrl
  * @param mixed[] $requestData
  * @param mixed[]|null $expectedRequestData
  * @param mixed[]|null $responseData
  * @param ResponseCode $responseCode
  * @param mixed[] $responseHeaders
  *
  * @dataProvider getRequests
  */
 public function testRequests(HttpMethod $httpMethod, string $url, string $expectedUrl, array $requestData, array $expectedRequestData = null, array $responseData = null, ResponseCode $responseCode, array $responseHeaders)
 {
     $cryptoService = $this->getMockBuilder(CryptoService::class)->disableOriginalConstructor()->getMock();
     $cryptoService->expects(self::any())->method('signData')->willReturn('signature');
     $cryptoService->expects(self::any())->method('verifyData')->willReturn(true);
     /** @var CryptoService $cryptoService */
     $apiClientDriver = $this->getMockBuilder(ApiClientDriver::class)->getMock();
     if ($httpMethod->equalsValue(HttpMethod::GET)) {
         $apiClientDriver->expects(self::once())->method('request')->with($httpMethod, $this->matchesRegularExpression(sprintf('~^%s/%s$~', preg_quote(self::API_URL, '~'), $expectedUrl)), $expectedRequestData)->willReturn(new Response($responseCode, ($responseData !== null ? $responseData : []) + ['signature' => 'signature'], $responseHeaders));
     } else {
         $apiClientDriver->expects(self::once())->method('request')->willReturnCallback(function (HttpMethod $method, string $url, array $requestData) use($httpMethod, $expectedUrl, $expectedRequestData, $responseCode, $responseData, $responseHeaders) : Response {
             $this->assertEquals($httpMethod, $method);
             $this->assertSame(sprintf('%s/%s', self::API_URL, $expectedUrl), $url);
             $dttm = $requestData['dttm'];
             $this->assertRegExp('~^\\d{14}$~', $dttm);
             unset($requestData['dttm']);
             $this->assertEquals($expectedRequestData + ['signature' => 'signature'], $requestData);
             return new Response($responseCode, ($responseData !== null ? $responseData : []) + ['signature' => 'signature'], $responseHeaders);
         });
     }
     $logger = $this->getMockBuilder(LoggerInterface::class)->disableOriginalConstructor()->getMock();
     $logger->expects(self::once())->method('info')->with($this->isType('string'), $this->isType('array'));
     /** @var ApiClientDriver $apiClientDriver */
     $apiClient = new ApiClient($apiClientDriver, $cryptoService, self::API_URL);
     /** @var LoggerInterface $logger */
     $apiClient->setLogger($logger);
     if ($httpMethod->equalsValue(HttpMethod::GET)) {
         $response = $apiClient->get($url, $requestData, new SignatureDataFormatter([]), new SignatureDataFormatter([]));
     } elseif ($httpMethod->equalsValue(HttpMethod::POST)) {
         $response = $apiClient->post($url, $requestData, new SignatureDataFormatter([]), new SignatureDataFormatter([]));
     } else {
         $response = $apiClient->put($url, $requestData, new SignatureDataFormatter([]), new SignatureDataFormatter([]));
     }
     $this->assertInstanceOf(Response::class, $response);
     $this->assertSame($responseCode->getValue(), $response->getResponseCode()->getValue());
     $this->assertEquals($responseHeaders, $response->getHeaders());
     $this->assertEquals($responseData, $response->getData());
 }
 public function send(ApiClient $apiClient) : EchoResponse
 {
     $response = $apiClient->post('echo', ['merchantId' => $this->merchantId], new SignatureDataFormatter(['merchantId' => null, 'dttm' => null]), new SignatureDataFormatter(['dttm' => null, 'resultCode' => null, 'resultMessage' => null]));
     $data = $response->getData();
     return new EchoResponse(DateTimeImmutable::createFromFormat('YmdHis', $data['dttm']), new ResultCode($data['resultCode']), $data['resultMessage']);
 }
 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);
 }