From fedf50ddb030fc7259fa7366d01aa8169b7296e8 Mon Sep 17 00:00:00 2001 From: "osman.cevik" Date: Fri, 20 Nov 2020 15:04:36 +0300 Subject: [PATCH 1/2] mask added, payment method names fixed, requestParams field added --- src/Gateway.php | 25 ++--- src/Mask.php | 26 +++++ src/Messages/AbstractRequest.php | 51 +++++++-- src/Messages/AuthorizeRequest.php | 27 ++++- src/Messages/AuthorizeResponse.php | 4 - src/Messages/CaptureRequest.php | 46 +++++++- src/Messages/CaptureResponse.php | 11 ++ src/Messages/CompletePurchaseRequest.php | 33 ++++-- src/Messages/PreAuthorizeRequest.php | 32 ------ src/Messages/PurchaseRequest.php | 35 +++++- src/Messages/RefundRequest.php | 27 ++++- src/Messages/StatusRequest.php | 26 +++++ src/Messages/VoidRequest.php | 28 ++++- src/RequestInterface.php | 21 ++++ tests/GatewayTest.php | 106 +++++++++++------- tests/Messages/AuthorizeRequestTest.php | 6 +- ...RequestTest.php => CaptureRequestTest.php} | 30 +++-- .../Messages/CompletePurchaseRequestTest.php | 2 - tests/Messages/Mock/AuthorizeFailure.txt | 30 ++--- tests/Messages/Mock/AuthorizeSuccess.txt | 65 +++++++---- tests/Messages/Mock/CaptureFailure.txt | 27 +++++ tests/Messages/Mock/CaptureSuccess.txt | 44 ++++++++ tests/Messages/NestPayTestCase.php | 24 ++-- 23 files changed, 534 insertions(+), 192 deletions(-) create mode 100644 src/Mask.php create mode 100644 src/Messages/CaptureResponse.php delete mode 100644 src/Messages/PreAuthorizeRequest.php create mode 100644 src/RequestInterface.php rename tests/Messages/{PreAuthorizationRequestTest.php => CaptureRequestTest.php} (54%) create mode 100644 tests/Messages/Mock/CaptureFailure.txt create mode 100644 tests/Messages/Mock/CaptureSuccess.txt diff --git a/src/Gateway.php b/src/Gateway.php index 336b279..78d7e96 100644 --- a/src/Gateway.php +++ b/src/Gateway.php @@ -6,11 +6,9 @@ namespace Omnipay\NestPay; use Omnipay\Common\Message\NotificationInterface; -use Omnipay\NestPay\Messages\PreAuthorizeRequest; use Omnipay\NestPay\Messages\CompletePurchaseRequest; use Omnipay\NestPay\Messages\PurchaseRequest; use Omnipay\Common\AbstractGateway; -use Omnipay\Common\Message\AbstractRequest; use Omnipay\Common\Message\RequestInterface; use Omnipay\NestPay\Messages\AuthorizeRequest; use Omnipay\NestPay\Messages\CaptureRequest; @@ -126,7 +124,7 @@ public function getStoreKey(): string /** * @param array $parameters - * @return AbstractRequest|RequestInterface + * @return Messages\AbstractRequest|RequestInterface */ public function authorize(array $parameters = []): RequestInterface { @@ -135,16 +133,7 @@ public function authorize(array $parameters = []): RequestInterface /** * @param array $parameters - * @return AbstractRequest|RequestInterface - */ - public function preAuthorize(array $parameters = []): RequestInterface - { - return $this->createRequest(PreAuthorizeRequest::class, $parameters); - } - - /** - * @param array $parameters - * @return AbstractRequest|RequestInterface + * @return Messages\AbstractRequest|RequestInterface */ public function capture(array $parameters = []): RequestInterface { @@ -153,7 +142,7 @@ public function capture(array $parameters = []): RequestInterface /** * @param array $parameters - * @return AbstractRequest|RequestInterface + * @return Messages\AbstractRequest|RequestInterface */ public function purchase(array $parameters = []): RequestInterface { @@ -162,7 +151,7 @@ public function purchase(array $parameters = []): RequestInterface /** * @param array $parameters - * @return AbstractRequest|RequestInterface + * @return Messages\AbstractRequest|RequestInterface */ public function completePurchase(array $parameters = []): RequestInterface { @@ -171,7 +160,7 @@ public function completePurchase(array $parameters = []): RequestInterface /** * @param array $parameters - * @return AbstractRequest|RequestInterface + * @return Messages\AbstractRequest|RequestInterface */ public function refund(array $parameters = []): RequestInterface { @@ -181,7 +170,7 @@ public function refund(array $parameters = []): RequestInterface /** * @param array $parameters - * @return AbstractRequest|RequestInterface + * @return Messages\AbstractRequest|RequestInterface */ public function void(array $parameters = []): RequestInterface { @@ -190,7 +179,7 @@ public function void(array $parameters = []): RequestInterface /** * @param array $parameters - * @return AbstractRequest|RequestInterface + * @return Messages\AbstractRequest|RequestInterface */ public function status(array $parameters = []): RequestInterface { diff --git a/src/Mask.php b/src/Mask.php new file mode 100644 index 0000000..fd989f2 --- /dev/null +++ b/src/Mask.php @@ -0,0 +1,26 @@ +getProcessType(); + if(!empty($processType)) + { + $data['Type'] = $processType; + } + $shipInfo = $data['ship'] ?? []; + $billInfo = $data['bill'] ?? []; unset($data['ship'], $data['bill']); - $this->document = new \DOMDocument('1.0', 'UTF-8'); + $this->document = new DOMDocument('1.0', 'UTF-8'); $this->root = $this->document->createElement('CC5Request'); foreach ($data as $id => $value) { @@ -125,7 +139,7 @@ public function sendData($data) $response = (string)$httpRequest->getBody()->getContents(); return $this->response = $this->createResponse($response); - } catch (\Exception $e) { + } catch (Exception $e) { throw new InvalidResponseException( 'Error communicating with payment gateway: ' . $e->getMessage(), $e->getCode() @@ -205,7 +219,7 @@ protected function getRequestParams(): array $gateway = $this->getBank(); if (!array_key_exists($gateway, $this->baseUrls)) { - throw new \InvalidArgumentException('Invalid Gateway'); + throw new InvalidArgumentException('Invalid Gateway'); } $data['Mode'] = $this->getTestMode() ? 'T' : 'P'; @@ -245,7 +259,7 @@ protected function getCompletePurchaseParams(ThreeDResponse $threeDResponse): ar $data['GroupId'] = $threeDResponse->getGroupId() ?? ''; $data['TransId'] = $threeDResponse->getTransId() ?? ''; $data['UserId'] = $threeDResponse->getUserId() ?? ''; - $data['Type'] = 'Auth'; + $data['Type'] = $this->getProcessType(); $data['Expires'] = ''; $data['Cvv2Val'] = ''; $data['Total'] = $threeDResponse->getAmount(); @@ -402,7 +416,7 @@ private function getShipTo(): array public function getHash(array $data): string { - $signature = $data['clientid'] . + return $data['clientid'] . $data['oid'] . $data['amount'] . $data['okUrl'] . @@ -410,6 +424,21 @@ public function getHash(array $data): string $data['taksit']. $this->getRnd() . $this->getStoreKey(); - return $signature; + } + + protected function setRequestParams(array $data): void + { + array_walk_recursive($data, [$this, 'updateValue']); + $this->requestParams = $data; + } + + protected function updateValue(&$data, $key): void + { + $sensitiveData = $this->getSensitiveData(); + + if (\in_array($key, $sensitiveData, true)) { + $data = Mask::mask($data); + } + } } diff --git a/src/Messages/AuthorizeRequest.php b/src/Messages/AuthorizeRequest.php index c988f4d..f1cf64a 100644 --- a/src/Messages/AuthorizeRequest.php +++ b/src/Messages/AuthorizeRequest.php @@ -17,8 +17,7 @@ class AuthorizeRequest extends AbstractRequest public function getData(): array { $data = $this->getRequestParams(); - $data['Type'] = 'PostAuth'; - + $this->setRequestParams($data); return $data; } @@ -30,5 +29,29 @@ protected function createResponse($data): AuthorizeResponse { return new AuthorizeResponse($this, $data); } + + /** + * @return array + */ + public function getSensitiveData(): array + { + return ['Number', 'ExpireDate']; + } + + /** + * @inheritDoc + */ + public function getProcessName(): string + { + return 'Authorize'; + } + + /** + * @inheritDoc + */ + public function getProcessType(): string + { + return 'PreAuth'; + } } diff --git a/src/Messages/AuthorizeResponse.php b/src/Messages/AuthorizeResponse.php index 1fa5cf5..ef94a0f 100644 --- a/src/Messages/AuthorizeResponse.php +++ b/src/Messages/AuthorizeResponse.php @@ -7,8 +7,4 @@ class AuthorizeResponse extends AbstractResponse { - public function isRedirect() - { - return false; - } } diff --git a/src/Messages/CaptureRequest.php b/src/Messages/CaptureRequest.php index efbeaea..ccac522 100644 --- a/src/Messages/CaptureRequest.php +++ b/src/Messages/CaptureRequest.php @@ -5,8 +5,52 @@ namespace Omnipay\NestPay\Messages; -class CaptureRequest extends AuthorizeRequest +use Omnipay\Common\Exception\InvalidRequestException; + +class CaptureRequest extends AbstractRequest { + /** + * @return array + * @throws InvalidRequestException + */ + public function getData(): array + { + $data = $this->getRequestParams(); + $this->setRequestParams($data); + return $data; + } + + /** + * @param $data + * @return CaptureResponse + */ + protected function createResponse($data): CaptureResponse + { + return new CaptureResponse($this, $data); + } + + /** + * @inheritDoc + */ + public function getSensitiveData(): array + { + return ['Number', 'ExpireDate']; + } + + /** + * @inheritDoc + */ + public function getProcessName(): string + { + return 'Capture'; + } + /** + * @inheritDoc + */ + public function getProcessType(): string + { + return 'PostAuth'; + } } diff --git a/src/Messages/CaptureResponse.php b/src/Messages/CaptureResponse.php new file mode 100644 index 0000000..678c201 --- /dev/null +++ b/src/Messages/CaptureResponse.php @@ -0,0 +1,11 @@ +checkHash()) { throw new RuntimeException('Hash data invalid'); } - - return $this->getCompletePurchaseParams($this->threeDResponse); + $data = $this->getCompletePurchaseParams($this->threeDResponse); + $this->setRequestParams($data); + return $data; } /** @@ -89,13 +88,27 @@ private function getGeneratedHash(): string $signature = $hashParamsVal . $storeKey; return base64_encode(sha1($signature, true)); } + /** + * @inheritDoc + */ + public function getSensitiveData(): array + { + return []; + } + + /** + * @inheritDoc + */ + public function getProcessName(): string + { + return 'CompletePurchase'; + } - public function getEndpoint(): string + /** + * @inheritDoc + */ + public function getProcessType(): string { - $bank = $this->getBank(); - if ($this->getTestMode()) { - return $this->baseUrls['test']['3d']['baseUrl'] . $this->url['test']['purchase']; - } - return $this->baseUrls[$bank]['baseUrl'] . $this->url['purchase']; + return 'Auth'; } } diff --git a/src/Messages/PreAuthorizeRequest.php b/src/Messages/PreAuthorizeRequest.php deleted file mode 100644 index 047a2b7..0000000 --- a/src/Messages/PreAuthorizeRequest.php +++ /dev/null @@ -1,32 +0,0 @@ -getRequestParams(); - $data['Type'] = 'PreAuth'; - - return $data; - } - - /** - * @param $data - * @return AuthorizeResponse - */ - protected function createResponse($data): AuthorizeResponse - { - return new AuthorizeResponse($this, $data); - } -} - diff --git a/src/Messages/PurchaseRequest.php b/src/Messages/PurchaseRequest.php index 682215a..e7519f6 100644 --- a/src/Messages/PurchaseRequest.php +++ b/src/Messages/PurchaseRequest.php @@ -19,11 +19,12 @@ public function getData() { if ($this->getPaymentMethod() === self::PAYMENT_TYPE_3D) { $this->setAction('3d'); - return $this->getPurchase3DData(); + $data = $this->getPurchase3DData(); + $this->setRequestParams($data); + return $data; } $data = $this->getRequestParams(); - $data['Type'] = 'Auth'; - + $this->setRequestParams($data); return $data; } @@ -43,4 +44,32 @@ protected function createResponse($data): PurchaseResponse { return new PurchaseResponse($this, $data); } + + + /** + * @return array + */ + public function getSensitiveData(): array + { + return ['Number', 'ExpireDate']; + } + + /** + * @inheritDoc + */ + public function getProcessName(): string + { + if ($this->getPaymentMethod() === self::PAYMENT_TYPE_3D) { + return 'Purchase3D'; + } + return 'Purchase'; + } + + /** + * @inheritDoc + */ + public function getProcessType(): string + { + return 'Auth'; + } } diff --git a/src/Messages/RefundRequest.php b/src/Messages/RefundRequest.php index e958cb7..a9e02c8 100644 --- a/src/Messages/RefundRequest.php +++ b/src/Messages/RefundRequest.php @@ -17,7 +17,7 @@ public function getData() { $this->validate('amount'); - $data['Type'] = 'Credit'; + $data['Type'] = $this->getProcessType(); $data['Name'] = $this->getUserName(); $data['Password'] = $this->getPassword(); $data['ClientId'] = $this->getClientId(); @@ -25,6 +25,7 @@ public function getData() $data['Total'] = $this->getAmount(); $data['Currency'] = $this->getCurrencyNumeric(); + $this->setRequestParams($data); return $data; } @@ -36,4 +37,28 @@ protected function createResponse($data): RefundResponse { return new RefundResponse($this, $data); } + + /** + * @return array + */ + public function getSensitiveData(): array + { + return ['Password']; + } + + /** + * @inheritDoc + */ + public function getProcessName(): string + { + return 'Refund'; + } + + /** + * @inheritDoc + */ + public function getProcessType(): string + { + return 'Credit'; + } } \ No newline at end of file diff --git a/src/Messages/StatusRequest.php b/src/Messages/StatusRequest.php index 90fa7c0..7d2290e 100644 --- a/src/Messages/StatusRequest.php +++ b/src/Messages/StatusRequest.php @@ -20,6 +20,7 @@ public function getData() // $data['Currency'] = $this->getCurrencyNumeric(); // $data['Total'] = $this->getAmount(); + $this->setRequestParams($data); return $data; } @@ -31,4 +32,29 @@ protected function createResponse($data): StatusResponse { return new StatusResponse($this, $data); } + + + /** + * @return array + */ + public function getSensitiveData(): array + { + return ['Password']; + } + + /** + * @inheritDoc + */ + public function getProcessName(): string + { + return 'Status'; + } + + /** + * @inheritDoc + */ + public function getProcessType(): string + { + return ''; + } } \ No newline at end of file diff --git a/src/Messages/VoidRequest.php b/src/Messages/VoidRequest.php index 03ba013..15b34b3 100644 --- a/src/Messages/VoidRequest.php +++ b/src/Messages/VoidRequest.php @@ -12,7 +12,7 @@ class VoidRequest extends AbstractRequest */ public function getData() { - $data['Type'] = 'Void'; + $data['Type'] = $this->getProcessType(); $data['OrderId'] = $this->getTransactionId(); $data['Name'] = $this->getUserName(); $data['Password'] = $this->getPassword(); @@ -20,6 +20,7 @@ public function getData() // $data['Currency'] = $this->getCurrencyNumeric(); // $data['Total'] = $this->getAmount(); + $this->setRequestParams($data); return $data; } @@ -31,4 +32,29 @@ protected function createResponse($data): VoidResponse { return new VoidResponse($this, $data); } + + + /** + * @return array + */ + public function getSensitiveData(): array + { + return ['Password']; + } + + /** + * @inheritDoc + */ + public function getProcessName(): string + { + return 'Void'; + } + + /** + * @inheritDoc + */ + public function getProcessType(): string + { + return 'Void'; + } } \ No newline at end of file diff --git a/src/RequestInterface.php b/src/RequestInterface.php new file mode 100644 index 0000000..1c8489c --- /dev/null +++ b/src/RequestInterface.php @@ -0,0 +1,21 @@ +gateway = new Gateway(null, $this->getHttpRequest()); - $this->gateway->setBank('halkbank'); - $this->gateway->setUserName('alegra'); - $this->gateway->setClientId('500100000'); + $this->gateway = new Gateway($this->getHttpClient(), $this->getHttpRequest()); + /*$this->gateway->setBank('akbank'); + $this->gateway->setUserName('akalegra'); + $this->gateway->setClientId('100100000'); $this->gateway->setPassword('ALG*3466'); $this->gateway->setStoreKey('123456'); - $this->gateway->setTestMode(true); + $this->gateway->setTestMode(true);*/ } public function testPurchase(): void @@ -38,62 +49,54 @@ public function testPurchase(): void 'amount' => '2.00', 'currency' => 'TRY' ]; - + $request = $this->gateway->purchase($this->options); /** @var PurchaseResponse $response */ - $response = $this->gateway->purchase($this->options)->send(); + /*$response = $this->gateway->purchase($this->options)->send(); var_dump($response->getRequest()->getEndPoint()); var_dump($response->getMessage()); var_dump($response->getTransactionReference()); - self::assertTrue($response->isSuccessful()); - - } - - public function testPreAuthorize(): void - { - $this->options = [ - 'card' => $this->getCardInfo(), - 'transactionId' => 'sip-121212', - 'amount' => '25.00', - 'currency' => 'TRY' - ]; + self::assertTrue($response->isSuccessful());*/ + self::assertInstanceOf(PurchaseRequest::class, $request); + self::assertSame('nrmlpesin3', $request->getTransactionId()); - /** @var AuthorizeResponse $response */ - $response = $this->gateway->preAuthorize($this->options)->send(); - var_dump($response->getRequest()->getEndPoint()); - var_dump($response->getMessage()); - self::assertTrue($response->isSuccessful()); } public function testAuthorize(): void { $this->options = [ 'card' => $this->getCardInfo(), - 'transactionId' => 'sip-121212', + 'transactionId' => 'authtest01', 'amount' => '25.00', 'currency' => 'TRY' ]; + $request = $this->gateway->authorize($this->options); /** @var AuthorizeResponse $response */ - $response = $this->gateway->authorize($this->options)->send(); + /*$response = $this->gateway->authorize($this->options)->send(); var_dump($response->getRequest()->getEndPoint()); var_dump($response->getMessage()); - self::assertTrue($response->isSuccessful()); + self::assertTrue($response->isSuccessful());*/ + self::assertInstanceOf(AuthorizeRequest::class, $request); + self::assertSame('authtest01', $request->getTransactionId()); } public function testCapture(): void { $this->options = [ 'card' => $this->getCardInfo(), - 'transactionId' => 'sip-5557', + 'transactionId' => 'authtest01', 'amount' => '25.00', 'currency' => 'TRY' ]; - /** @var AuthorizeResponse $response */ - $response = $this->gateway->capture($this->options)->send(); + $request = $this->gateway->capture($this->options); + /** @var CaptureResponse $response */ + /*$response = $this->gateway->capture($this->options)->send(); var_dump($response->getRequest()->getEndPoint()); var_dump($response->getMessage()); - self::assertTrue($response->isSuccessful()); + self::assertTrue($response->isSuccessful());*/ + self::assertInstanceOf(CaptureRequest::class, $request); + self::assertSame('sip-5557', $request->getTransactionId()); } public function testPurchase3D(): void @@ -113,11 +116,15 @@ public function testPurchase3D(): void 'lang' => 'tr' ]; + $request = $this->gateway->purchase($this->options); /** @var Purchase3DResponse $response */ - $response = $this->gateway->purchase($this->options)->send(); + /*$response = $this->gateway->purchase($this->options)->send(); var_dump($response->getRequest()->getEndPoint()); var_dump($response->getRedirectData()); - self::assertTrue($response->isSuccessful()); + self::assertTrue($response->isSuccessful());*/ + self::assertInstanceOf(PurchaseRequest::class, $request); + self::assertSame('3d', $request->getPaymentMethod()); + self::assertSame('3', $request->getInstallment()); } @@ -147,12 +154,16 @@ public function testCompletePurchase3D(): void 'HASHPARAMSVAL' => '500100000testtaksit10581AAABAmdUcgAAAAAhNFRyAAAAAAA=05492024:F59E81638F068A2869788387E89CF72A4AC686D11FD748699486CE48CC02F805:4183:##500100000B1oKmHKc5cVlnP66CpWs', ] ]; + + $request = $this->gateway->completePurchase($this->options); /** @var CompletePurchaseResponse $response */ - $response = $this->gateway->completePurchase($this->options)->send(); + /*$response = $this->gateway->completePurchase($this->options)->send(); var_dump($response->getRequest()->getEndPoint()); var_dump($response->getMessage()); var_dump($response->getTransactionReference()); - self::assertTrue($response->isSuccessful()); + self::assertTrue($response->isSuccessful());*/ + self::assertInstanceOf(CompletePurchaseRequest::class, $request); + self::assertArrayHasKey('cavv', $request->getResponseData()); } @@ -164,11 +175,15 @@ public function testRefund(): void 'amount' => '2.00', 'currency' => 'TRY' ]; - $response = $this->gateway->refund($this->options)->send(); + $request = $this->gateway->refund($this->options); + /** @var RefundResponse $response */ + /*$response = $this->gateway->refund($this->options)->send(); var_dump($response->getRequest()->getEndPoint()); var_dump($response->getMessage()); var_dump($response->getTransactionReference()); - self::assertTrue($response->isSuccessful()); + self::assertTrue($response->isSuccessful());*/ + self::assertInstanceOf(RefundRequest::class, $request); + self::assertSame('nrmlpesin3', $request->getTransactionId()); } @@ -177,11 +192,16 @@ public function testVoid(): void $this->options = [ 'transactionId' => 'testpesin' ]; - $response = $this->gateway->void($this->options)->send(); + $request = $this->gateway->void($this->options); + /** @var VoidResponse $response */ + /*$response = $this->gateway->void($this->options)->send(); var_dump($response->getRequest()->getEndPoint()); var_dump($response->getMessage()); var_dump($response->getTransactionReference()); - self::assertTrue($response->isSuccessful()); + self::assertTrue($response->isSuccessful());*/ + self::assertInstanceOf(VoidRequest::class, $request); + self::assertSame('testpesin', $request->getTransactionId()); + } @@ -190,10 +210,14 @@ public function testStatus(): void $this->options = [ 'transactionId' => 'sip-5557' ]; - $response = $this->gateway->status($this->options)->send(); + $request = $this->gateway->status($this->options); + /** @var StatusResponse $response */ + /*$response = $this->gateway->status($this->options)->send(); var_dump($response->getRequest()->getEndPoint()); var_dump($response->getData()); - self::assertTrue($response->isSuccessful()); + self::assertTrue($response->isSuccessful());*/ + self::assertInstanceOf(StatusRequest::class, $request); + self::assertSame('sip-5557', $request->getTransactionId()); } diff --git a/tests/Messages/AuthorizeRequestTest.php b/tests/Messages/AuthorizeRequestTest.php index 388718b..9af8c35 100644 --- a/tests/Messages/AuthorizeRequestTest.php +++ b/tests/Messages/AuthorizeRequestTest.php @@ -42,9 +42,9 @@ public function testSendSuccess(): void $response = $this->request->send(); self::assertTrue($response->isSuccessful()); - self::assertSame('20321RkaD00131468', $response->getTransactionReference()); + self::assertSame('20325OTRC16419', $response->getTransactionReference()); self::assertSame('https://entegrasyon.asseco-see.com.tr', $this->request->getBaseUrl()); - self::assertSame('P42324', $response->getCode()); + self::assertSame('175923', $response->getCode()); self::assertSame('Approved', $response->getMessage()); } @@ -58,6 +58,6 @@ public function testSendError(): void self::assertNull($response->getTransactionReference()); self::assertSame('https://entegrasyon.asseco-see.com.tr', $this->request->getBaseUrl()); self::assertNull($response->getCode()); - self::assertSame('PostAuth sadece iliskili bir PreAuth icin yapilabilir.', $response->getMessage()); + self::assertSame('Bu siparis numarasi ile zaten basarili bir siparis var.', $response->getMessage()); } } \ No newline at end of file diff --git a/tests/Messages/PreAuthorizationRequestTest.php b/tests/Messages/CaptureRequestTest.php similarity index 54% rename from tests/Messages/PreAuthorizationRequestTest.php rename to tests/Messages/CaptureRequestTest.php index 8f54ccb..9bb2b6b 100644 --- a/tests/Messages/PreAuthorizationRequestTest.php +++ b/tests/Messages/CaptureRequestTest.php @@ -5,21 +5,19 @@ use Exception; -use Omnipay\NestPay\Messages\AuthorizeResponse; -use Omnipay\NestPay\Messages\PreAuthorizeRequest; -use Omnipay\NestPay\Messages\PurchaseRequest; -use Omnipay\NestPay\Messages\PurchaseResponse; +use Omnipay\NestPay\Messages\CaptureRequest; +use Omnipay\NestPay\Messages\CaptureResponse; use OmnipayTest\NestPay\Messages\NestPayTestCase; -class PreAuthorizationRequestTest extends NestPayTestCase +class CaptureRequestTest extends NestPayTestCase { - /** @var $request PreAuthorizeRequest */ + /** @var $request CaptureRequest */ private $request; public function setUp() { - $this->request = new PreAuthorizeRequest($this->getHttpClient(), $this->getHttpRequest()); - $this->request->initialize($this->getPreAuthorizeParams()); + $this->request = new CaptureRequest($this->getHttpClient(), $this->getHttpRequest()); + $this->request->initialize($this->getCaptureParams()); } public function testEndpoint(): void @@ -34,32 +32,32 @@ public function testData(): void { $data = $this->request->getData(); self::assertSame('789878987', $data['OrderId']); - self::assertSame('25.00', $data['Total']); + self::assertSame('949', $data['Currency']); } public function testSendSuccess(): void { - $this->setMockHttpResponse('PreAuthorizeSuccess.txt'); - /** @var AuthorizeResponse $response */ + $this->setMockHttpResponse('CaptureSuccess.txt'); + /** @var CaptureResponse $response */ $response = $this->request->send(); self::assertTrue($response->isSuccessful()); - self::assertSame('20321RUGG00121315', $response->getTransactionReference()); + self::assertSame('20325OWDB16817', $response->getTransactionReference()); self::assertSame('https://entegrasyon.asseco-see.com.tr', $this->request->getBaseUrl()); - self::assertSame('P40241', $response->getCode()); + self::assertSame('175923', $response->getCode()); self::assertSame('Approved', $response->getMessage()); } public function testSendError(): void { - $this->setMockHttpResponse('PreAuthorizeFailure.txt'); - /** @var AuthorizeResponse $response */ + $this->setMockHttpResponse('CaptureFailure.txt'); + /** @var CaptureResponse $response */ $response = $this->request->send(); self::assertFalse($response->isSuccessful()); self::assertNull($response->getTransactionReference()); self::assertSame('https://entegrasyon.asseco-see.com.tr', $this->request->getBaseUrl()); self::assertNull($response->getCode()); - self::assertSame('Bu siparis numarasi ile zaten basarili bir siparis var.', $response->getMessage()); + self::assertSame('PostAuth yapilamaz, uyusan PreAuth yok.', $response->getMessage()); } } \ No newline at end of file diff --git a/tests/Messages/CompletePurchaseRequestTest.php b/tests/Messages/CompletePurchaseRequestTest.php index aa0b7de..7009c0d 100644 --- a/tests/Messages/CompletePurchaseRequestTest.php +++ b/tests/Messages/CompletePurchaseRequestTest.php @@ -5,8 +5,6 @@ use Exception; -use Omnipay\NestPay\Messages\AuthorizeRequest; -use Omnipay\NestPay\Messages\AuthorizeResponse; use Omnipay\NestPay\Messages\CompletePurchaseRequest; use Omnipay\NestPay\Messages\CompletePurchaseResponse; use OmnipayTest\NestPay\Messages\NestPayTestCase; diff --git a/tests/Messages/Mock/AuthorizeFailure.txt b/tests/Messages/Mock/AuthorizeFailure.txt index 8c16671..09e579f 100644 --- a/tests/Messages/Mock/AuthorizeFailure.txt +++ b/tests/Messages/Mock/AuthorizeFailure.txt @@ -3,25 +3,25 @@ Server: NONE Date: Mon, 16 Nov 2020 10:45:52 GMT Strict-Transport-Security: max-age=31536000; includeSubDomains Content-Type: text/xml;charset=ISO-8859-9 -Content-Length: 504 +Content-Length: 537 Connection: close X-XSS-Protection: 1; mode=block X-Content-Type-Options: nosniff - - - Error - - - 99 - 20321Nt2G00130013 - PostAuth sadece iliskili bir PreAuth icin yapilabilir. - - - 20201116 13:45:52 - CORE-2115 - 992115 - + + + Error + + + 99 + 20325OZJJ17137 + Bu siparis numarasi ile zaten basarili bir siparis var. + + + 20201120 14:25:09 + CORE-2507 + 992507 + \ No newline at end of file diff --git a/tests/Messages/Mock/AuthorizeSuccess.txt b/tests/Messages/Mock/AuthorizeSuccess.txt index 0db2bc1..f55e440 100644 --- a/tests/Messages/Mock/AuthorizeSuccess.txt +++ b/tests/Messages/Mock/AuthorizeSuccess.txt @@ -3,30 +3,55 @@ Server: NONE Date: Mon, 16 Nov 2020 14:36:26 GMT Strict-Transport-Security: max-age=31536000; includeSubDomains Content-Type: text/xml;charset=ISO-8859-9 -Content-Length: 680 +Content-Length: 2054 Connection: close X-XSS-Protection: 1; mode=block X-Content-Type-Options: nosniff - 789878987 - 789878987 - Approved - P42324 - 032100058039 - 00 - 20321RkaD00131468 - - - 2096 - 20201116 17:36:26 - - 00658785 - 700658785 - MASTERCARD - T. IS BANKASI A.S. - 1116-173626 - 00 - + authtest01 + authtest01 + Approved + 175923 + 032514612156 + 00 + 20325OTRC16419 + + + 1794 + 20201120 14:19:17 + + 000 ONAY KODU XXXXXX + 00000 + 0000001122 + 0086886 + 000000029397 + 2 + 25 + 000003 + bayi adi + 25 + 000000055342 + 00 + 067042 + 250 + 00010 + pcb chip para aciklama + NI****DE**** + 000000064547 + 23-11-2012 + 00 + 00010 + 1 + 250 + xcb chip para aciklama + 250 + VISA + 2.5 + 00 + 250 + 0 + ccb chip para aciklama + \ No newline at end of file diff --git a/tests/Messages/Mock/CaptureFailure.txt b/tests/Messages/Mock/CaptureFailure.txt new file mode 100644 index 0000000..7803d7c --- /dev/null +++ b/tests/Messages/Mock/CaptureFailure.txt @@ -0,0 +1,27 @@ +HTTP/1.1 200 OK +Server: NONE +Date: Mon, 16 Nov 2020 10:45:52 GMT +Strict-Transport-Security: max-age=31536000; includeSubDomains +Content-Type: text/xml;charset=ISO-8859-9 +Content-Length: 541 +Connection: close +X-XSS-Protection: 1; mode=block +X-Content-Type-Options: nosniff + + + + authtest01 + authtest01 + Error + + + 99 + 20325OXqJ17006 + PostAuth yapilamaz, uyusan PreAuth yok. + + + 20201120 14:23:42 + CORE-2509 + 992509 + + \ No newline at end of file diff --git a/tests/Messages/Mock/CaptureSuccess.txt b/tests/Messages/Mock/CaptureSuccess.txt new file mode 100644 index 0000000..47381bd --- /dev/null +++ b/tests/Messages/Mock/CaptureSuccess.txt @@ -0,0 +1,44 @@ +HTTP/1.1 200 OK +Server: NONE +Date: Mon, 16 Nov 2020 14:36:26 GMT +Strict-Transport-Security: max-age=31536000; includeSubDomains +Content-Type: text/xml;charset=ISO-8859-9 +Content-Length: 1294 +Connection: close +X-XSS-Protection: 1; mode=block +X-Content-Type-Options: nosniff + + + + authtest01 + authtest01 + Approved + 175923 + 032514612156 + 00 + 20325OWDB16817 + + + 1794 + 20201120 14:22:02 + + 000 ONAY KODU XXXXXX + 00010 + 00 + 00010 + 250 + 0000001122 + 0088034 + 25 + 250 + VISA + 2.5 + bayi adi + 00 + 25 + 250 + 00 + 052816 + 250 + + \ No newline at end of file diff --git a/tests/Messages/NestPayTestCase.php b/tests/Messages/NestPayTestCase.php index 34ab66d..bed8d41 100644 --- a/tests/Messages/NestPayTestCase.php +++ b/tests/Messages/NestPayTestCase.php @@ -59,6 +59,18 @@ protected function getAuthorizeParams(): array return $this->provideMergedParams($params); } + protected function getCaptureParams(): array + { + $params = [ + 'card' => $this->getValidCard(), + 'transactionId' => '789878987', + 'amount' => '25.00', + 'currency' => 'TRY' + ]; + + return $this->provideMergedParams($params); + } + protected function getPurchase3DParams(): array { $params = [ @@ -78,18 +90,6 @@ protected function getPurchase3DParams(): array return $this->provideMergedParams($params); } - protected function getPreAuthorizeParams(): array - { - $params = [ - 'card' => $this->getValidCard(), - 'transactionId' => '789878987', - 'amount' => '25.00', - 'currency' => 'TRY' - ]; - - return $this->provideMergedParams($params); - } - protected function getCompletePurchaseParams(): array { $params = [ From 9eb8be3b95e4f929e009aad5532b39bf46625faa Mon Sep 17 00:00:00 2001 From: "osman.cevik" Date: Fri, 20 Nov 2020 15:33:27 +0300 Subject: [PATCH 2/2] sensitive Data modified --- src/Messages/AuthorizeRequest.php | 2 +- src/Messages/CaptureRequest.php | 2 +- src/Messages/CompletePurchaseRequest.php | 2 +- src/Messages/PurchaseRequest.php | 2 +- tests/GatewayTest.php | 12 ++++++------ 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/Messages/AuthorizeRequest.php b/src/Messages/AuthorizeRequest.php index f1cf64a..6e0b111 100644 --- a/src/Messages/AuthorizeRequest.php +++ b/src/Messages/AuthorizeRequest.php @@ -35,7 +35,7 @@ protected function createResponse($data): AuthorizeResponse */ public function getSensitiveData(): array { - return ['Number', 'ExpireDate']; + return ['Number', 'Expires', 'Password']; } /** diff --git a/src/Messages/CaptureRequest.php b/src/Messages/CaptureRequest.php index ccac522..3ee6aaa 100644 --- a/src/Messages/CaptureRequest.php +++ b/src/Messages/CaptureRequest.php @@ -34,7 +34,7 @@ protected function createResponse($data): CaptureResponse */ public function getSensitiveData(): array { - return ['Number', 'ExpireDate']; + return ['Number', 'Expires', 'Password']; } /** diff --git a/src/Messages/CompletePurchaseRequest.php b/src/Messages/CompletePurchaseRequest.php index d356e4c..670265b 100644 --- a/src/Messages/CompletePurchaseRequest.php +++ b/src/Messages/CompletePurchaseRequest.php @@ -93,7 +93,7 @@ private function getGeneratedHash(): string */ public function getSensitiveData(): array { - return []; + return ['Password', 'Number', 'Expires', 'Cvv2Val']; } /** diff --git a/src/Messages/PurchaseRequest.php b/src/Messages/PurchaseRequest.php index e7519f6..6338f4c 100644 --- a/src/Messages/PurchaseRequest.php +++ b/src/Messages/PurchaseRequest.php @@ -51,7 +51,7 @@ protected function createResponse($data): PurchaseResponse */ public function getSensitiveData(): array { - return ['Number', 'ExpireDate']; + return ['Number', 'Expires', 'Password']; } /** diff --git a/tests/GatewayTest.php b/tests/GatewayTest.php index 94616cb..d823287 100644 --- a/tests/GatewayTest.php +++ b/tests/GatewayTest.php @@ -65,7 +65,7 @@ public function testAuthorize(): void { $this->options = [ 'card' => $this->getCardInfo(), - 'transactionId' => 'authtest01', + 'transactionId' => 'authtest02', 'amount' => '25.00', 'currency' => 'TRY' ]; @@ -77,14 +77,14 @@ public function testAuthorize(): void var_dump($response->getMessage()); self::assertTrue($response->isSuccessful());*/ self::assertInstanceOf(AuthorizeRequest::class, $request); - self::assertSame('authtest01', $request->getTransactionId()); + self::assertSame('authtest02', $request->getTransactionId()); } public function testCapture(): void { $this->options = [ 'card' => $this->getCardInfo(), - 'transactionId' => 'authtest01', + 'transactionId' => 'authtest02', 'amount' => '25.00', 'currency' => 'TRY' ]; @@ -96,7 +96,7 @@ public function testCapture(): void var_dump($response->getMessage()); self::assertTrue($response->isSuccessful());*/ self::assertInstanceOf(CaptureRequest::class, $request); - self::assertSame('sip-5557', $request->getTransactionId()); + self::assertSame('authtest02', $request->getTransactionId()); } public function testPurchase3D(): void @@ -171,7 +171,7 @@ public function testCompletePurchase3D(): void public function testRefund(): void { $this->options = [ - 'transactionId' => 'nrmlpesin3', + 'transactionId' => 'authtest02', 'amount' => '2.00', 'currency' => 'TRY' ]; @@ -183,7 +183,7 @@ public function testRefund(): void var_dump($response->getTransactionReference()); self::assertTrue($response->isSuccessful());*/ self::assertInstanceOf(RefundRequest::class, $request); - self::assertSame('nrmlpesin3', $request->getTransactionId()); + self::assertSame('authtest02', $request->getTransactionId()); }