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 { $data = ['merchantId' => $this->merchantId, 'payId' => $this->payId]; if ($this->totalAmount !== null) { $data['totalAmount'] = $this->totalAmount; } $response = $apiClient->put('payment/close', $data, new SignatureDataFormatter(['merchantId' => null, 'payId' => null, 'dttm' => null, 'totalAmount' => 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 send(ApiClient $apiClient, array $data) : PaymentResponse { if (array_key_exists('resultCode', $data) && is_numeric($data['resultCode'])) { $data['resultCode'] = (int) $data['resultCode']; } if (array_key_exists('paymentStatus', $data) && is_numeric($data['paymentStatus'])) { $data['paymentStatus'] = (int) $data['paymentStatus']; } $response = $apiClient->createResponseByData($data, new SignatureDataFormatter(['payId' => null, 'dttm' => null, 'resultCode' => null, 'resultMessage' => null, 'paymentStatus' => null, 'authCode' => null, 'merchantData' => 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, isset($data['merchantData']) ? base64_decode($data['merchantData']) : null); }
public function send(ApiClient $apiClient) : ProcessPaymentResponse { $response = $apiClient->get('payment/process/{merchantId}/{payId}/{dttm}/{signature}', ['merchantId' => $this->merchantId, 'payId' => $this->payId], new SignatureDataFormatter(['merchantId' => null, 'payId' => null, 'dttm' => null]), new SignatureDataFormatter(['payId' => null, 'dttm' => null, 'resultCode' => null, 'resultMessage' => null, 'paymentStatus' => null, 'authCode' => null]), function (Response $response) { // This handles edge case when provided payId is missing or already expired on gateway // In this case gateway responds with HTTP 200 and HTML content. Bad API. // See https://github.com/csob/paymentgateway/issues/135 if ($response->getResponseCode()->equalsValue(ResponseCode::S200_OK)) { throw new InvalidPaymentException($this, $response, $this->payId); } }); return new ProcessPaymentResponse($response->getHeaders()['Location']); }
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); }
public function send(ApiClient $apiClient) : EchoResponse { $response = $apiClient->get('echo/{merchantId}/{dttm}/{signature}', ['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 { $response = $apiClient->get('payment/status/{merchantId}/{payId}/{dttm}/{signature}', ['merchantId' => $this->merchantId, 'payId' => $this->payId], new SignatureDataFormatter(['merchantId' => null, 'payId' => null, 'dttm' => null]), new SignatureDataFormatter(['payId' => null, 'dttm' => null, 'resultCode' => null, 'resultMessage' => null, 'paymentStatus' => null, 'authCode' => null]), null, $this->extensions); $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, null, $response->getExtensions()); }
public function testCreateResponseByData() { $data = ['signature' => 'abc', 'foo' => 123, 'bar' => 456]; $cryptoService = $this->getMockBuilder(CryptoService::class)->disableOriginalConstructor()->getMock(); $cryptoService->expects(self::any())->method('verifyData')->willReturn(true); $apiClientDriver = $this->getMockBuilder(ApiClientDriver::class)->getMock(); /** @var CryptoService $cryptoService */ /** @var ApiClientDriver $apiClientDriver */ $apiClient = new ApiClient($apiClientDriver, $cryptoService); $response = $apiClient->createResponseByData($data, new SignatureDataFormatter([])); unset($data['signature']); $this->assertInstanceOf(Response::class, $response); $this->assertSame(ResponseCode::S200_OK, $response->getResponseCode()->getValue()); $this->assertEquals([], $response->getHeaders()); $this->assertEquals($data, $response->getData()); }
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); }