Skip to content

Commit 4285f58

Browse files
committed
Update to 3.4
1 parent be9baa5 commit 4285f58

11 files changed

+222
-19
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
},
2121
"extra": {
2222
"branch-alias": {
23-
"dev-master": "v3.2.x-dev"
23+
"dev-master": "v3.4.x-dev"
2424
}
2525
}
2626
}

src/TpPayment.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ public function getArgs() {
382382
$input["deposit"] = $this->deposit ? '1' : '0';
383383
}
384384
if (!is_null($this->isRecurring)) {
385-
$input["isRecurring"] = $this->isRecurring;
385+
$input["isRecurring"] = $this->isRecurring ? '1' : '0';
386386
}
387387

388388
if (!is_null($this->merchantSpecificSymbol)) {
@@ -412,7 +412,7 @@ public function getSignature() {
412412
}
413413

414414
$str .= "password=".$this->config->password;
415-
return $this->hashFunction($str);
415+
return self::hashFunction($str);
416416
}
417417

418418
/**

src/TpPaymentReturnResponse.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
/**
4+
* @author Michal Kandr
5+
*/
6+
class TpPaymentReturnResponse {
7+
protected $status;
8+
protected $errorDescription;
9+
10+
function __construct(stdClass $data) {
11+
$this->status = $data->status;
12+
if(property_exists($data, 'errorDescription')) {
13+
$this->errorDescription = $data->errorDescription;
14+
}
15+
}
16+
17+
public function getStatus() {
18+
return $this->status;
19+
}
20+
21+
public function getErrorDescription() {
22+
return $this->errorDescription;
23+
}
24+
}

src/TpPermanentPaymentResponseMethod.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,23 @@ function __construct($methodId, $methodName, $url, $accountNumber, $vs) {
1414
$this->vs = $vs;
1515
}
1616

17-
public function setMethodId($methodId) {
18-
$this->methodId = $methodId;
17+
function getMethodId() {
18+
return $this->methodId;
1919
}
2020

21-
public function setMethodName($methodName) {
22-
$this->methodName = $methodName;
21+
function getMethodName() {
22+
return $this->methodName;
2323
}
2424

25-
public function setUrl($url) {
26-
$this->url = $url;
25+
function getUrl() {
26+
return $this->url;
2727
}
2828

29-
public function setAccountNumber($accountNumber) {
30-
$this->accountNumber = $accountNumber;
29+
function getAccountNumber() {
30+
return $this->accountNumber;
3131
}
3232

33-
public function setVs($vs) {
34-
$this->vs = $vs;
33+
function getVs() {
34+
return $this->vs;
3535
}
3636
}

src/dataApi/requests/TpDataApiRequestFactory.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ class TpDataApiRequestFactory {
99
public static function getRequest($operation, TpMerchantConfig $config, array $data) {
1010
/** @var TpDataApiRequest $className Only class name. */
1111
$className = preg_replace(
12-
'/^get(.+)$/', 'TpDataApiGet$1Request', $operation
12+
array('/^get(.+)$/', '/^set(.+)$/'),
13+
array('TpDataApiGet$1Request', 'TpDataApiSet$1Request'),
14+
$operation
1315
);
1416

1517
$fileName = $className . '.php';
@@ -21,4 +23,4 @@ public static function getRequest($operation, TpMerchantConfig $config, array $d
2123
return $request;
2224
}
2325

24-
}
26+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?php
2+
TpUtils::requirePaths(array(
3+
array('dataApi', 'requests', 'TpDataApiRequest.php'),
4+
array('dataApi', 'TpValueFormatter.php')
5+
));
6+
7+
class TpDataApiSetPaymentMethodsRequest extends TpDataApiRequest {
8+
const TYPE_ALL = 'all';
9+
const TYPE_WHITELIST = 'whitelist';
10+
11+
/**
12+
* @var string
13+
*/
14+
protected $type = self::TYPE_WHITELIST;
15+
/**
16+
* @var int[]|null
17+
*/
18+
protected $paymentMethods = null;
19+
20+
/**
21+
* @return string
22+
*/
23+
function getType() {
24+
return $this->type;
25+
}
26+
/**
27+
* @param string $type one of TYPE_* constants
28+
*/
29+
function setType($type) {
30+
$this->type = $type;
31+
}
32+
33+
/**
34+
* @return int[]
35+
*/
36+
function getPaymentMethods() {
37+
return $this->paymentMethods;
38+
}
39+
40+
/**
41+
* Payment methods which should be available to merchant account
42+
* @param int[] $paymentMethods id's of payment methods
43+
*/
44+
function setPaymentMethods(array $paymentMethods = null) {
45+
if($paymentMethods){
46+
$this->paymentMethods = TpValueFormatter::formatList('int', $paymentMethods);
47+
}
48+
}
49+
50+
51+
/**
52+
* @return array
53+
*/
54+
protected function configArray() {
55+
$configArray = parent::configArray();
56+
$configArray['accountId'] = $this->_config->accountId;
57+
return $configArray;
58+
}
59+
60+
}

src/dataApi/responses/TpDataApiResponseFactory.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,18 @@
88
class TpDataApiResponseFactory {
99

1010
/**
11-
* @param string $operation
11+
* @param string $operation
1212
* @param TpMerchantConfig $config
13-
* @param stdClass $data
13+
* @param stdClass $data
1414
* @return TpDataApiResponse
1515
* @throws TpInvalidSignatureException
1616
*/
1717
public static function getResponse($operation, TpMerchantConfig $config, stdClass $data) {
1818
/** @var string|TpDataApiResponse $className Only class name. */
1919
$className = preg_replace(
20-
'/^get(.+)$/', 'TpDataApiGet$1Response', $operation
20+
array('/^get(.+)$/', '/^set(.+)$/'),
21+
array('TpDataApiGet$1Response', 'TpDataApiSet$1Response'),
22+
$operation
2123
);
2224

2325
$fileName = $className . '.php';
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?php
2+
TpUtils::requirePaths(array(
3+
array('dataApi', 'responses', 'TpDataApiResponse.php')
4+
));
5+
6+
class TpDataApiSetPaymentMethodsResponse extends TpDataApiResponse {
7+
const STATUS_OK = 'OK';
8+
const STATUS_ERROR = 'ERROR';
9+
10+
/**
11+
* @var int
12+
*/
13+
protected $accountId;
14+
/**
15+
* @var string
16+
*/
17+
protected $status;
18+
19+
/**
20+
* @param array $response
21+
* @return TpDataApiSetPaymentMethodsResponse
22+
*/
23+
public static function createFromResponse(array $response) {
24+
$keys = array('merchantId', 'accountId', 'status');
25+
$data = TpUtils::filterKeys($response, $keys);
26+
$instance = new static($data);
27+
return $instance;
28+
}
29+
30+
/**
31+
* @return int
32+
*/
33+
public function getAccountId() {
34+
return $this->accountId;
35+
}
36+
37+
/**
38+
* @param int $accountId
39+
*/
40+
public function setAccountId($accountId) {
41+
$this->accountId = TpValueFormatter::format('int', $accountId);
42+
}
43+
44+
/**
45+
* @return string
46+
*/
47+
public function getStatus() {
48+
return $this->status;
49+
}
50+
51+
/**
52+
* @param string $status
53+
*/
54+
public function setStatus($status = null) {
55+
$this->status = TpValueFormatter::formatString($status);
56+
}
57+
}

src/helpers/TpDataApiHelper.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,25 @@ public static function getPayments(TpMerchantConfig $config, TpDataApiGetPayment
9696
return $response;
9797
}
9898

99+
/**
100+
* @param TpMerchantConfig $config
101+
* @param type $type
102+
* @param array $paymentMethods
103+
* @return type
104+
*/
105+
public static function setPaymentMethods(TpMerchantConfig $config, $type, array $paymentMethods = null){
106+
$data = array(
107+
'type' => $type,
108+
'paymentMethods' => $paymentMethods
109+
);
110+
$request = TpDataApiRequestFactory::getRequest(
111+
__FUNCTION__, $config, $data
112+
);
113+
114+
$response = self::call(__FUNCTION__, $config, $request);
115+
return $response;
116+
}
117+
99118
/**
100119
* @param string $operation
101120
* @param TpMerchantConfig $config
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
require_once implode(DIRECTORY_SEPARATOR, array(__DIR__, '..', 'TpUtils.php'));
3+
4+
// …everything else can be loaded using TpUtils::requirePaths.
5+
TpUtils::requirePaths(array(
6+
array('TpPaymentReturnResponse.php'),
7+
array('exceptions', 'TpException.php')
8+
));
9+
10+
/**
11+
* @author Michal Kandr
12+
*/
13+
class TpPaymentReturnHelper {
14+
protected static function getSignature($data) {
15+
return md5(http_build_query(array_filter($data)));
16+
}
17+
18+
public static function returnPayment(TpMerchantConfig $config, $paymentId, $reason = null){
19+
$client = new SoapClient($config->webServicesWsdl, ['cache_wsdl' => WSDL_CACHE_NONE]);
20+
$signature = static::getSignature(array(
21+
'merchantId' => $config->merchantId,
22+
'accountId' => $config->accountId,
23+
'paymentId' => $paymentId,
24+
'reason' => $reason,
25+
'password' => $config->password
26+
));
27+
$result = $client->returnPaymentRequest(array(
28+
'merchantId' => $config->merchantId,
29+
'accountId' => $config->accountId,
30+
'paymentId' => $paymentId,
31+
'reason' => $reason,
32+
'signature' => $signature
33+
));
34+
if( ! $result){
35+
throw new TpException();
36+
}
37+
return new TpPaymentReturnResponse($result);
38+
}
39+
}

0 commit comments

Comments
 (0)