Skip to content

Commit

Permalink
Merge pull request #7 from alegraio/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
cansozeri authored Nov 27, 2020
2 parents ff8ce5a + a711969 commit 1b07c4a
Show file tree
Hide file tree
Showing 37 changed files with 1,530 additions and 429 deletions.
5 changes: 5 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@
"ext-simplexml": "*",
"ext-dom": "*"
},
"autoload-dev": {
"psr-4": {
"OmnipayTest\\PosNet\\": "tests/"
}
},
"require-dev": {
"omnipay/tests": "^3",
"squizlabs/php_codesniffer": "^3",
Expand Down
22 changes: 22 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
bootstrap="vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false">
<testsuites>
<testsuite name="Omnipay Posnet(YapıKredi) Test Suite">
<directory>./tests/</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory>./src</directory>
</whitelist>
</filter>
</phpunit>
26 changes: 26 additions & 0 deletions src/Mask.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace Omnipay\PosNet;

class Mask
{
/**
* @param string $value
* @param null $maskSymbol
* @param int $showLast
* @return string
*/
public static function mask(string $value, $maskSymbol = null, $showLast = 3): string
{
$maskSymbol = $maskSymbol ?: 'X';
$showLast = max(0, $showLast);

if (false === $showLast || mb_strlen($value) <= ($showLast + 1) * 2) {
$showRegExpPart = "";
} else {
$showRegExpPart = "(?!(.){0,$showLast}$)";
}

return preg_replace("/(?!^.?)[^-_\s]$showRegExpPart/u", $maskSymbol, $value);
}
}
156 changes: 153 additions & 3 deletions src/Messages/AbstractRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@

namespace Omnipay\PosNet\Messages;

use Omnipay\Common\Exception\InvalidCreditCardException;
use Omnipay\Common\Exception\InvalidRequestException;
use Omnipay\Common\Message\ResponseInterface;
use Omnipay\PosNet\Mask;
use Omnipay\PosNet\RequestInterface;
use SimpleXMLElement;

abstract class AbstractRequest extends \Omnipay\Common\Message\AbstractRequest
abstract class AbstractRequest extends \Omnipay\Common\Message\AbstractRequest implements RequestInterface
{

use HelperTrait, BaseParametersTrait;
Expand All @@ -20,6 +24,8 @@ abstract class AbstractRequest extends \Omnipay\Common\Message\AbstractRequest
'USD' => 'US'
];

protected $requestParams;

public function getHeaders(): array
{
return [
Expand Down Expand Up @@ -48,14 +54,130 @@ public function sendData($data)
$this::postParameterKey => $xmlStr
];
$body = http_build_query($bodyArr, '', '&');
$httpRequest = $this->httpClient->request($this->getHttpMethod(), $this->getXmlServiceUrl(),
$httpRequest = $this->httpClient->request($this->getHttpMethod(), $this->getEndpoint(),
$this->getHeaders(),
$body);

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

public function getPurchaseRequestParams(): array
{
return [
'mid' => $this->getMerchantId(),
'tid' => $this->getTerminalId(),
'tranDateRequired' => $this->getTranDateRequired(),
$this->action => [
'amount' => $this->getAmountInteger(),
'ccno' => $this->getCard()->getNumber(),
'currencyCode' => $this->getMatchingCurrency(),
'cvc' => $this->getCard()->getCvv(),
'expDate' => $this->getCard()->getExpiryDate('ym'),
'orderID' => $this->getOrderID(),
'installment' => $this->getInstallment()
]

];
}

/**
* @return array
* @throws InvalidCreditCardException
* @throws InvalidRequestException
*/
public function getPurchaseRequestParamsFor3D(): array
{
$this->validate('card');
$this->getCard()->validate();

return [
'mid' => $this->getMerchantId(),
'tid' => $this->getTerminalId(),
$this->action => [
'posnetid' => $this->getPosNetId(),
'XID' => $this->getXid(),
'amount' => $this->getAmountInteger(),
'currencyCode' => $this->getMatchingCurrency(),
'installment' => $this->getInstallment(),
'tranType' => $this->getTranType(),
'cardHolderName' => $this->getCard()->getName(),
'ccno' => $this->getCard()->getNumber(),
'expDate' => $this->getCard()->getExpiryDate('ym'),
'cvc' => $this->getCard()->getCvv()

]
];
}

public function getCompletePurchaseParams(): array
{
return [
'mid' => $this->getMerchantId(),
'tid' => $this->getTerminalId(),
$this->action => [
'bankData' => $this->getBankPacket(),
'wpAmount' => $this->getWpAmount(),
'mac' => $this->getMac()
]
];
}

public function getMacValidationParams(): array
{
return [
'mid' => $this->getMerchantId(),
'tid' => $this->getTerminalId(),
$this->action => [
'bankData' => $this->getBankPacket(),
'merchantData' => $this->getMerchantPacket(),
'sign' => $this->getSign(),
'mac' => $this->getMac()

]
];
}

public function getRefundParams(): array
{
$data = [
'mid' => $this->getMerchantId(),
'tid' => $this->getTerminalId(),
'tranDateRequired' => $this->getTranDateRequired(),
$this->action => [
'amount' => $this->getAmountInteger(),
'currencyCode' => $this->getMatchingCurrency()
]
];
if ($this->getHostLogKey() !== null) {
$data[$this->action]['hostLogKey'] = $this->getHostLogKey();
return $data;
}
if ($this->getOrderID() !== null) {
$data[$this->action]['orderID'] = $this->getOrderID();
}
return $data;
}

public function getVoidParams(): array
{
$data = [
'mid' => $this->getMerchantId(),
'tid' => $this->getTerminalId(),
$this->action => [
'transaction' => $this->getTransaction(),
'hostLogKey' => $this->getHostLogKey()
]
];
if ($this->getAuthCode() !== null) { // Used for VFT (Transaction with different maturity)
$data[$this->action]['authCode'] = $this->getAuthCode();
return $data;
}
if ($this->getOrderID() !== null) {
$data[$this->action]['orderID'] = $this->getOrderID();
}
return $data;
}
/**
* Get HTTP Method.
*
Expand All @@ -79,4 +201,32 @@ public function getMatchingCurrency()
return self::CURRENCIES[$currency] ?? $currency;
}

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);
}

}

/**
* @return array
*/
protected function getRequestParams(): array
{
return [
'url' => $this->getEndPoint(),
'data' => $this->requestParams,
'method' => $this->getHttpMethod()
];
}

}
66 changes: 0 additions & 66 deletions src/Messages/AuthorizeRequest.php

This file was deleted.

Loading

0 comments on commit 1b07c4a

Please sign in to comment.