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) : 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 testInvalidSignature() { $response = new Response(new ResponseCode(ResponseCode::S200_OK), ['signature' => 'invalidSignature']); $cryptoService = $this->getMockBuilder(CryptoService::class)->disableOriginalConstructor()->getMock(); $cryptoService->expects(self::once())->method('signData')->willReturn('signature'); $cryptoService->expects(self::any())->method('verifyData')->willReturn(false); $apiClientDriver = $this->getMockBuilder(ApiClientDriver::class)->getMock(); $apiClientDriver->expects(self::once())->method('request')->willReturn($response); /** @var CryptoService $cryptoService */ /** @var ApiClientDriver $apiClientDriver */ $apiClient = new ApiClient($apiClientDriver, $cryptoService); try { $apiClient->get('foo/{dttm}/{signature}', [], new SignatureDataFormatter([]), new SignatureDataFormatter([])); $this->fail(); } catch (InvalidSignatureException $e) { $responseData = $response->getData(); unset($responseData['signature']); $this->assertSame($responseData, $e->getResponseData()); } }