Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased][unreleased]
### Added
- WSS2S class with support for callRequestTokenS2S and callRequestTokenS2S methods

## [1.3.0] - 2015-11-06
### Changed
Expand Down Expand Up @@ -59,4 +61,4 @@ This project adheres to [Semantic Versioning](http://semver.org/).
[1.1.1]: https://github.com/endelwar/GestPayWS/compare/v1.1.0...v1.1.1
[1.1.0]: https://github.com/endelwar/GestPayWS/compare/v1.0.0...v1.1.0
[1.0.0]: https://github.com/endelwar/GestPayWS/compare/v0.1.0...v1.0.0
[0.1.0]: https://github.com/endelwar/GestPayWS/compare/67d07c5c9c4d1873ba9620af25b91e0a53664d80...v0.1.0
[0.1.0]: https://github.com/endelwar/GestPayWS/compare/67d07c5c9c4d1873ba9620af25b91e0a53664d80...v0.1.0
155 changes: 155 additions & 0 deletions src/Parameter/PagamParameter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
<?php

/*
* This file is part of the GestPayWS library.
*
* (c) Manuel Dalla Lana <endelwar@aregar.it>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/

namespace EndelWar\GestPayWS\Parameter;

use InvalidArgumentException;

/**
* Class PagamParameter
* @package EndelWar\GestPayWS\Parameter
*
* @property string $shopLogin
* @property string $uicCode;
* @property string $amount;
* @property string $shopTransactionId;
* @property string $cardNumber;
* @property int $expiryMonth;
* @property int $expiryYear;
* @property string $buyerName;
* @property string $buyerEmail;
* @property string $languageId;
* @property int $cvv;
* @property string $min;
* @property string $transKey;
* @property string $PARes;
* @property string $customInfo;
* @property string $IDEA;
* @property string $requestToken;
* @property string $tokenValue;
* @property string $clientIP;
* @property string $itemType;
* @property string $shippingDetails;
* @property string $redFraudPrevention;
* @property string $Red_CustomerInfo;
* @property string $Red_ShippingInfo;
* @property string $Red_BillingInfo;
* @property string $Red_CustomerData;
* @property string $Red_CustomInfo;
* @property string $Red_Items;
*/
class PagamParameter extends Parameter
{
protected $parametersName = array(
'shopLogin',
'uicCode',
'amount',
'shopTransactionId',
'cardNumber',
'expiryMonth',
'expiryYear',
'buyerName',
'buyerEmail',
'languageId',
'cvv',
'min',
'transKey',
'PARes',
'customInfo',
'IDEA',
'requestToken',
'tokenValue',
'clientIP',
'itemType',
'shippingDetails',
'redFraudPrevention',
'Red_CustomerInfo',
'Red_ShippingInfo',
'Red_BillingInfo',
'Red_CustomerData',
'Red_CustomInfo',
'Red_Items',
);
protected $mandatoryParameters = array(
'shopLogin',
'uicCode',
'amount',
'shopTransactionId',
);
private $invalidChars = array(
'&',
' ',
'§', //need also to be added programmatically, because UTF-8
'(',
')',
'*',
'<',
'>',
',',
';',
':',
'*P1*',
'/',
'[',
']',
'?',
'=',
'--',
'/*',
'%',
'//',
);
private $invalidCharsFlattened = '';

/**
* @param array $parameters
*/
public function __construct(array $parameters = array())
{
$this->invalidChars[] = chr(167); //§ ascii char

parent::__construct($parameters);
}

/**
* @param string $key
* @param mixed $value
*/
public function set($key, $value)
{
if (!in_array($key, $this->parametersName, true)) {
throw new InvalidArgumentException(sprintf('%s is not a valid parameter name.', $key));
}
$this->verifyParameterValidity($value);
parent::set($key, $value);
}

/**
* @param $value
* @return bool
*/
public function verifyParameterValidity($value)
{
if (strlen($this->invalidCharsFlattened) === 0) {
$invalidCharsQuoted = array_map('preg_quote', $this->invalidChars);
$this->invalidCharsFlattened = implode('|', $invalidCharsQuoted);
}

if (preg_match_all('#' . $this->invalidCharsFlattened . '#', $value, $matches)) {
$invalidCharsMatched = '"' . implode('", "', $matches[0]) . '"';
throw new InvalidArgumentException(
'String ' . $value . ' contains invalid chars (i.e.: ' . $invalidCharsMatched . ').'
);
}

return true;
}
}
116 changes: 116 additions & 0 deletions src/Parameter/RequestTokenParameter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
<?php

/*
* This file is part of the GestPayWS library.
*
* (c) Manuel Dalla Lana <endelwar@aregar.it>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/

namespace EndelWar\GestPayWS\Parameter;

use InvalidArgumentException;

/**
* Class RequestTokenParameter
* @package EndelWar\GestPayWS\Parameter
*
* @property string $shopLogin
* @property string $requestToken;
* @property string $cardNumber;
* @property int $expiryMonth;
* @property int $expiryYear;
* @property int $cvv;
* @property string $withAuth;
*/
class RequestTokenParameter extends Parameter
{
protected $parametersName = array(
// Mandatory parameters
'shopLogin',
'requestToken',
'cardNumber',
'expiryMonth',
'expiryYear',
// Optional parameters
'cvv',
'withAuth'
);
protected $mandatoryParameters = array(
'shopLogin',
'requestToken',
'cardNumber',
'expiryMonth',
'expiryYear',
);
private $invalidChars = array(
'&',
' ',
'§', //need also to be added programmatically, because UTF-8
'(',
')',
'*',
'<',
'>',
',',
';',
':',
'*P1*',
'/',
'[',
']',
'?',
'=',
'--',
'/*',
'%',
'//',
);
private $invalidCharsFlattened = '';

/**
* @param array $parameters
*/
public function __construct(array $parameters = array())
{
$this->invalidChars[] = chr(167); //§ ascii char

parent::__construct($parameters);
}

/**
* @param string $key
* @param mixed $value
*/
public function set($key, $value)
{
if (!in_array($key, $this->parametersName, true)) {
throw new InvalidArgumentException(sprintf('%s is not a valid parameter name.', $key));
}
$this->verifyParameterValidity($value);
parent::set($key, $value);
}

/**
* @param $value
* @return bool
*/
public function verifyParameterValidity($value)
{
if (strlen($this->invalidCharsFlattened) === 0) {
$invalidCharsQuoted = array_map('preg_quote', $this->invalidChars);
$this->invalidCharsFlattened = implode('|', $invalidCharsQuoted);
}

if (preg_match_all('#' . $this->invalidCharsFlattened . '#', $value, $matches)) {
$invalidCharsMatched = '"' . implode('", "', $matches[0]) . '"';
throw new InvalidArgumentException(
'String ' . $value . ' contains invalid chars (i.e.: ' . $invalidCharsMatched . ').'
);
}

return true;
}
}
52 changes: 52 additions & 0 deletions src/Response/PagamResponse.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

/*
* This file is part of the GestPayWS library.
*
* (c) Manuel Dalla Lana <endelwar@aregar.it>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/

namespace EndelWar\GestPayWS\Response;

/**
* Class PagamResponse
* @package EndelWar\GestPayWS\Response
*/
class PagamResponse extends Response
{
protected $parametersName = array(
'TransactionType',
'TransactionResult',
'ShopTransactionID',
'BankTransactionID',
'AuthorizationCode',
'Currency',
'Amount',
'Country',
'CardBIN',
'Buyer',
'CustomInfo',
'TDLevel',
'ErrorCode',
'ErrorDescription',
'AlertCode',
'AlertDescription',
'TransactionKey',
'VbV',
'RedResponseCode',
'RedResponseDescription',
);

/**
* @param \stdClass $soapResponse
* @throws \Exception
*/
public function __construct($soapResponse)
{
$xml = simplexml_load_string($soapResponse->callPagamS2SResult->any);
parent::__construct($xml);
}
}
Loading