Skip to content

Commit 4594b7e

Browse files
author
dimoncheg12
committed
setting paymentKey by operation type
1 parent 1905e2f commit 4594b7e

File tree

9 files changed

+47
-13
lines changed

9 files changed

+47
-13
lines changed

examples/P2pcredit/p2pcredit.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55

66
//P2P card credit https://docs.fondy.eu/docs/page/24/
77
try {
8-
\Cloudipsp\Configuration::setMerchantId(1000);
9-
\Cloudipsp\Configuration::setCreditKey('testcreditmonche'); // to generate in you need use credit key
8+
\Cloudipsp\Configuration::setMerchantId(1396424);
9+
\Cloudipsp\Configuration::setCreditKey('testcredit'); // to generate in you need use credit key
1010
$TestOrderData = [
1111
'currency' => 'USD',
1212
'amount' => 111,
@@ -49,6 +49,10 @@
4949
<pre><?php print_r($orderData->getData()); ?></pre>
5050
</td>
5151
</tr>
52+
<tr>
53+
<td>Check order is approved:</td>
54+
<td><?php var_dump($orderData->isApproved()); ?></td>
55+
</tr>
5256
<tr>
5357
<td>Check order data is valid:</td>
5458
<td><?php var_dump($orderData->isValid()); ?></td>

examples/configuration.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@
99
define('SDK_ROOTPATH', __DIR__);
1010
require_once SDK_ROOTPATH . '/../vendor/autoload.php';
1111
\Cloudipsp\Configuration::setMerchantId(1396424);
12-
\Cloudipsp\Configuration::setSecretKey('test');
12+
// \Cloudipsp\Configuration::setSecretKey('test');

lib/Api/Api.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class Api
3030
protected $requestType;
3131

3232
/**
33-
* @param $data
33+
* @param $type
3434
* @throws ApiException
3535
*/
3636
public function __construct($type = '')

lib/Api/P2pcredit/Credit.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ class Credit extends Api
2222
/**
2323
* @param $data
2424
* @param array $headers
25+
* @param array $requiredParams
2526
* @return mixed
2627
* @throws \Cloudipsp\Exception\ApiException
2728
*/

lib/Helper/ResultHelper.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,11 @@ class ResultHelper
1717
public static function isPaymentValid($result, $secretKey = '', $ver = '')
1818
{
1919
if ($secretKey == '') {
20-
$secretKey = Configuration::getSecretKey();
20+
if (Configuration::getSecretKey() != '') {
21+
$secretKey = Configuration::getSecretKey();
22+
}elseif (Configuration::getCreditKey() != '') {
23+
$secretKey = Configuration::getCreditKey();
24+
}
2125
}
2226
if ($ver == '') {
2327
$ver = Configuration::getApiVersion();

lib/P2pcredit.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@ public static function start($data, $headers = [])
2020
{
2121
$api = new Api\P2pcredit\Credit('credit');
2222
$result = $api->get($data, $headers);
23-
return new Response($result);
23+
return new Response($result, 'credit');
2424
}
2525
}

lib/Response/Response.php

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ class Response
1313
* @var string
1414
*/
1515
protected $orderID;
16+
/**
17+
* @var string
18+
*/
19+
protected $paymentKey;
1620
/**
1721
* @var string
1822
*/
@@ -29,15 +33,17 @@ class Response
2933
/**
3034
* Response constructor.
3135
* @param $data
36+
* @param $type
3237
* @throws ApiException
3338
*/
34-
public function __construct($data)
39+
public function __construct($data, $type = '')
3540
{
3641
if (isset($data['order_id']))
3742
$this->orderID = $data['order_id'];
3843
$data = $data['response'];
3944
$this->requestType = Configuration::getRequestType();
4045
$this->apiVersion = Configuration::getApiVersion();
46+
$this->setKeyByOperationType($type);
4147
switch ($this->requestType) {
4248
case 'xml':
4349
$response = ResponseHelper::xmlToArray($data);
@@ -144,7 +150,7 @@ public function getOrderID()
144150
public function isApproved()
145151
{
146152
$data = $this->buildVerifyData();
147-
return ResultHelper::isPaymentApproved($data, '', $this->apiVersion);
153+
return ResultHelper::isPaymentApproved($data, $this->paymentKey, $this->apiVersion);
148154
}
149155

150156
/**
@@ -154,6 +160,19 @@ public function isApproved()
154160
public function isValid()
155161
{
156162
$data = $this->buildVerifyData();
157-
return ResultHelper::isPaymentValid($data, '', $this->apiVersion);
163+
return ResultHelper::isPaymentValid($data, $this->paymentKey, $this->apiVersion);
164+
}
165+
166+
/**
167+
* setting secret key by operation type
168+
* @param $type
169+
*/
170+
protected function setKeyByOperationType($type = '')
171+
{
172+
if ($type === 'credit') {
173+
$this->paymentKey = Configuration::getCreditKey();
174+
} else {
175+
$this->paymentKey = Configuration::getSecretKey();
176+
}
158177
}
159178
}

tests/OrderTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,13 +107,13 @@ public function testTransactionList()
107107
/**
108108
* @throws Exception\ApiException
109109
*/
110-
public function testAtolLogs()
110+
/*public function testAtolLogs()
111111
{
112112
$this->setTestConfig();
113113
$data = \Cloudipsp\Order::atolLogs($this->orderID);
114114
$result = $data->getData();
115115
$this->assertInternalType('array', $result);
116-
}
116+
}*/
117117

118118
/**
119119
* @param $data

tests/P2pcreditTest.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,9 @@ public function testCredit()
3131
$this->setTestConfig();
3232
foreach ($this->request_types as $type) {
3333
\Cloudipsp\Configuration::setRequestType($type);
34-
$result = \Cloudipsp\P2pcredit::start($this->TestData)->getData();
35-
$this->validateResult($result);
34+
$result = \Cloudipsp\P2pcredit::start($this->TestData);
35+
$this->validateResult($result->getData());
36+
$this->isValid($result->isValid());
3637
}
3738
}
3839

@@ -42,4 +43,9 @@ private function validateResult($result)
4243
$this->assertNotEmpty($result['payment_id'], 'payment_id is empty');
4344
$this->assertEquals($result['response_status'], 'success');
4445
}
46+
47+
private function isValid($result)
48+
{
49+
$this->assertEquals($result, true);
50+
}
4551
}

0 commit comments

Comments
 (0)