Skip to content

Commit

Permalink
completed test files
Browse files Browse the repository at this point in the history
  • Loading branch information
osman.cevik committed Nov 27, 2020
1 parent cc9fd6c commit cefb9c4
Show file tree
Hide file tree
Showing 30 changed files with 424 additions and 723 deletions.
6 changes: 3 additions & 3 deletions src/Messages/AbstractRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function sendData($data)
$body);

$response = (string)$httpRequest->getBody()->getContents();
return $this->createResponse($response, $httpRequest->getStatusCode());
return $this->createResponse($response);
}

public function getPurchaseRequestParams(): array
Expand Down Expand Up @@ -96,7 +96,7 @@ public function getPurchaseRequestParamsFor3D(): array
'tid' => $this->getTerminalId(),
$this->action => [
'posnetid' => $this->getPosNetId(),
'XID' => $this->getXidByOrderId(),
'XID' => $this->getXid(),
'amount' => $this->getAmountInteger(),
'currencyCode' => $this->getMatchingCurrency(),
'installment' => $this->getInstallment(),
Expand Down Expand Up @@ -211,7 +211,7 @@ protected function updateValue(&$data, $key): void
{
$sensitiveData = $this->getSensitiveData();

if (\in_array($key, $sensitiveData, true)) {
if (in_array($key, $sensitiveData, true)) {
$data = Mask::mask($data);
}

Expand Down
19 changes: 2 additions & 17 deletions src/Messages/BaseParametersTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,6 @@ public function getEndpoint(): string
return ($this->getTestMode()) ? $this->xmlServiceUrls['test'] : $this->xmlServiceUrls['live'];
}

public function getPaymentType(): ?string
{
return $this->getParameter('paymentType');
}

public function setPaymentType(string $paymentType)
{
return $this->setParameter('paymentType', $paymentType);
}

public function getOrderID(): ?string
{
return $this->getParameter('orderID');
Expand All @@ -87,11 +77,6 @@ public function setOrderId(string $orderId)
return $this->setParameter('orderID', $orderId);
}

public function getXidByOrderId(): string
{
return str_pad($this->getOrderID(), 20, '0', STR_PAD_LEFT);
}

public function setXid(string $xid)
{
return $this->setParameter('xid', $xid);
Expand Down Expand Up @@ -154,7 +139,7 @@ public function setSign($sign)

public function getCcPrefix(): string
{
return $this->getParameter('sign');
return $this->getParameter('ccPrefix');
}

public function setCcPrefix($ccPrefix)
Expand Down Expand Up @@ -251,7 +236,7 @@ public function getMac(): string
$encKey = $this->getEncKey();
$terminalID = $this->getTerminalId();
$xid = $this->getXid();
$amount = $this->getAmountInteger();
$amount = $this->getParameter('amount');
$currency = $this->getMatchingCurrency();
$merchantId = $this->getMerchantId();
$firstHash = $this->hashString($encKey . ';' . $terminalID);
Expand Down
6 changes: 2 additions & 4 deletions src/Messages/CompletePurchaseRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,11 @@ public function getData()

/**
* @param $data
* @param $statusCode
* @return CompletePurchaseResponse
* @throws Exception
*/
protected function createResponse($data, $statusCode): CompletePurchaseResponse
protected function createResponse($data): CompletePurchaseResponse
{
$response = new CompletePurchaseResponse($this, $data, $statusCode);
$response = new CompletePurchaseResponse($this, $data);
$requestParams = $this->getRequestParams();
$response->setServiceRequestParams($requestParams);

Expand Down
6 changes: 2 additions & 4 deletions src/Messages/MacValidationRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,11 @@ public function getData()

/**
* @param $data
* @param $statusCode
* @return MacValidationResponse
* @throws Exception
*/
protected function createResponse($data, $statusCode): MacValidationResponse
protected function createResponse($data): MacValidationResponse
{
$response = new MacValidationResponse($this, $data, $statusCode);
$response = new MacValidationResponse($this, $data);
$requestParams = $this->getRequestParams();
$response->setServiceRequestParams($requestParams);

Expand Down
16 changes: 11 additions & 5 deletions src/Messages/Purchase3DResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,20 +61,26 @@ public function getThreeDSFormData(): ?array
$posnetData = $responseData['oosRequestDataResponse']['data1'];
$posnetData2 = $responseData['oosRequestDataResponse']['data2'];
$digest = $responseData['oosRequestDataResponse']['sign'];

/** @var PurchaseRequest $request */
$request = $this->request;

$requestParameters = $this->request->getParameters();

$this->parameters = $this->parameters ?? $requestParameters;

$formData = [
'mid' => $this->parameters['merchantId'],
'posnetID' => $this->parameters['posNetId'],
'mid' => $request->getMerchantId(),
'posnetID' => $request->getPosNetId(),
'posnetData' => $posnetData,
'posnetData2' => $posnetData2,
'digest' => $digest,
'vftCode' => $this->parameters['vftCode'] ?? '',
'merchantReturnURL' => $this->parameters['merchantReturnUrl'],
'merchantReturnURL' => $request->getMerchantReturnUrl(),
'lang' => 'tr',
'url' => $this->parameters['websiteUrl'],
'url' => $request->getWebsiteUrl(),
'openANewWindow' => '0',
'oosTdsServiceUrl' => $this->request->getOosTdsServiceUrl()
'oosTdsServiceUrl' => $request->getOosTdsServiceUrl()
];
if (isset($this->parameters['useJokerVadaa'])) {
$formData['useJokerVadaa'] = $this->parameters['useJokerVadaa'];
Expand Down
9 changes: 3 additions & 6 deletions src/Messages/PurchaseRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

namespace Omnipay\PosNet\Messages;

use Exception;
use Omnipay\Common\Exception\InvalidCreditCardException;
use Omnipay\Common\Exception\InvalidRequestException;

Expand Down Expand Up @@ -39,16 +38,14 @@ public function getData()

/**
* @param $data
* @param $statusCode
* @return PurchaseResponse|Purchase3DResponse
* @throws Exception
*/
protected function createResponse($data, $statusCode): PurchaseResponse
protected function createResponse($data)
{
if ($this->getPaymentMethod() === self::PAYMENT_TYPE_3D) {
$response = new Purchase3DResponse($this, $data, $statusCode);
$response = new Purchase3DResponse($this, $data);
} else {
$response = new PurchaseResponse($this, $data, $statusCode);
$response = new PurchaseResponse($this, $data);
}

$requestParams = $this->getRequestParams();
Expand Down
6 changes: 2 additions & 4 deletions src/Messages/RefundRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,11 @@ public function getData()

/**
* @param $data
* @param $statusCode
* @return RefundResponse
* @throws Exception
*/
protected function createResponse($data, $statusCode): RefundResponse
protected function createResponse($data): RefundResponse
{
$response = new RefundResponse($this, $data, $statusCode);
$response = new RefundResponse($this, $data);
$requestParams = $this->getRequestParams();
$response->setServiceRequestParams($requestParams);

Expand Down
10 changes: 6 additions & 4 deletions src/Messages/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

namespace Omnipay\PosNet\Messages;

use Exception;
use Omnipay\Common\Message\AbstractResponse;
use Omnipay\Common\Message\RedirectResponseInterface;
use Omnipay\Common\Message\RequestInterface;
Expand All @@ -21,10 +20,8 @@ class Response extends AbstractResponse implements RedirectResponseInterface
* Response constructor.
* @param RequestInterface $request
* @param $data
* @param int $statusCode
* @throws Exception
*/
public function __construct(RequestInterface $request, $data, $statusCode = 200)
public function __construct(RequestInterface $request, $data)
{
parent::__construct($request, $data);
$parsedXML = @simplexml_load_string($this->data);
Expand Down Expand Up @@ -53,6 +50,11 @@ public function getTransactionReference(): ?string
}

public function getCode(): ?string
{
return $this->data['authCode'] ?? null;
}

public function getErrorCode(): ?string
{
return $this->data['respCode'] ?? null;
}
Expand Down
6 changes: 2 additions & 4 deletions src/Messages/VoidRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,11 @@ public function getData()

/**
* @param $data
* @param $statusCode
* @return VoidResponse
* @throws Exception
*/
protected function createResponse($data, $statusCode): VoidResponse
protected function createResponse($data): VoidResponse
{
$response = new VoidResponse($this, $data, $statusCode);
$response = new VoidResponse($this, $data);
$requestParams = $this->getRequestParams();
$response->setServiceRequestParams($requestParams);

Expand Down
13 changes: 12 additions & 1 deletion src/PosNetGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,17 @@ class PosNetGateway extends AbstractGateway

use BaseParametersTrait;

public function getDefaultParameters(): array
{
return [
'merchantId' => '',
'terminalId' => '',
'posNetId' => '',
'encKey' => '',
'oosTdsServiceUrl' => '',
];
}

/**
* Get gateway display name
*
Expand Down Expand Up @@ -61,7 +72,7 @@ public function purchase(array $parameters = [])
public function completePurchase(array $parameters = [])
{
$macValidationResponse = $this->createRequest(MacValidationRequest::class, $parameters)->send();
if ($macValidationResponse->isSuccessful() && $macValidationResponse->getMdStatus() === 1) {
if ($macValidationResponse->isSuccessful() && (($this->getTestMode() && $macValidationResponse->getMdStatus() === 9) || $macValidationResponse->getMdStatus() === 1)) {
return $this->createRequest(CompletePurchaseRequest::class, $parameters);
}

Expand Down
21 changes: 11 additions & 10 deletions tests/Messages/CompletePurchaseRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ public function setUp(): void

public function testEndpoint(): void
{
self::assertSame('https://setmpos.ykb.com/3DSWebService/YKBPaymentService', $this->request->getEndpoint());
self::assertSame('https://setmpos.ykb.com/PosnetWebService/XML', $this->request->getEndpoint());
}

public function testOrderId(): void
public function testSign(): void
{
self::assertSame('', $this->request->getOrderId());
self::assertSame('7D12250A1313A3E7C71192371EFC71F2', $this->request->getSign());
}

public function testSendSuccess(): void
Expand All @@ -34,8 +34,10 @@ public function testSendSuccess(): void

self::assertTrue($response->isSuccessful());
self::assertFalse($response->isRedirect());
self::assertSame('https://setmpos.ykb.com/3DSWebService/YKBPaymentService', $this->request->getEndpoint());
self::assertSame('', $response->getTransactionReference());
self::assertNotEmpty($response->getServiceRequestParams());
self::assertSame('https://setmpos.ykb.com/PosnetWebService/XML', $this->request->getEndpoint());
self::assertSame('031141873090000201', $response->getTransactionReference());
self::assertSame('418730', $response->getCode());
}

public function testSendError(): void
Expand All @@ -44,10 +46,9 @@ public function testSendError(): void
$response = $this->request->send();

self::assertFalse($response->isSuccessful());
self::assertFalse($response->isRedirect());
self::assertSame('', $response->getTransactionReference());
self::assertSame('https://setmpos.ykb.com/3DSWebService/YKBPaymentService', $this->request->getEndpoint());
self::assertSame('', $response->getCode());
self::assertSame('', $response->getMessage());
self::assertEmpty($response->getTransactionReference());
self::assertSame('https://setmpos.ykb.com/PosnetWebService/XML', $this->request->getEndpoint());
self::assertSame('0127', $response->getErrorCode());
self::assertSame('ORDERID DAHA ONCE KULLANILMIS 0127', $response->getMessage());
}
}
20 changes: 9 additions & 11 deletions tests/Messages/MacValidationRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ public function setUp(): void

public function testEndpoint(): void
{
self::assertSame('https://setmpos.ykb.com/3DSWebService/YKBPaymentService', $this->request->getEndpoint());
self::assertSame('https://setmpos.ykb.com/PosnetWebService/XML', $this->request->getEndpoint());
}

public function testOrderId(): void
public function testData(): void
{
self::assertSame('181683681', $this->request->getOrderId());
self::assertSame('517041', $this->request->getCcPrefix());
}

public function testSendSuccess(): void
Expand All @@ -34,20 +34,18 @@ public function testSendSuccess(): void

self::assertTrue($response->isSuccessful());
self::assertFalse($response->isRedirect());
self::assertSame('https://setmpos.ykb.com/3DSWebService/YKBPaymentService', $this->request->getEndpoint());
self::assertSame('', $response->getTransactionReference());
self::assertSame('https://setmpos.ykb.com/PosnetWebService/XML', $this->request->getEndpoint());
}

public function testSendError(): void
{
$this->setMockHttpResponse('MacValidationSuccess.txt');
$this->setMockHttpResponse('MacValidationFailure.txt');
$response = $this->request->send();

self::assertFalse($response->isSuccessful());
self::assertFalse($response->isRedirect());
self::assertSame('', $response->getTransactionReference());
self::assertSame('https://setmpos.ykb.com/3DSWebService/YKBPaymentService', $this->request->getEndpoint());
self::assertSame('', $response->getCode());
self::assertSame('', $response->getMessage());
self::assertEmpty($response->getTransactionReference());
self::assertSame('https://setmpos.ykb.com/PosnetWebService/XML', $this->request->getEndpoint());
self::assertSame('0600', $response->getErrorCode());
self::assertSame('Mac Dogrulama hatali', $response->getMessage());
}
}
Loading

0 comments on commit cefb9c4

Please sign in to comment.