Skip to content

Commit 6c25bca

Browse files
author
has.well
committed
added validation tests
fixed Lhun algorithm #2
1 parent 8b0f2cd commit 6c25bca

File tree

5 files changed

+213
-2
lines changed

5 files changed

+213
-2
lines changed
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<?php
2+
require_once '../configuration.php';
3+
require_once SDK_ROOTPATH . '/../vendor/autoload.php';
4+
5+
6+
//Split order
7+
try {
8+
//Minimal data set, all other required params will generated automatically
9+
$data = [
10+
'currency' => 'USD',
11+
'amount' => 1000, // convert to 10.00$
12+
'order_desc' => 'tests SDK',
13+
];
14+
//some other params
15+
$receiver = [
16+
[
17+
'requisites' => [
18+
'amount' => 500,
19+
'merchant_id' => 600001
20+
],
21+
'type' => 'merchant'
22+
],
23+
[
24+
'requisites' => [
25+
'amount' => 500,
26+
'merchant_id' => 700001
27+
],
28+
'type' => 'merchant'
29+
]
30+
];
31+
$data['receiver'] = $receiver;
32+
//Call method to generate url
33+
\Cloudipsp\Configuration::setMerchantId(600001);
34+
\Cloudipsp\Configuration::setApiVersion('2.0');
35+
$url = Cloudipsp\Checkout::url($data);
36+
//getting returned data
37+
?>
38+
<!doctype html>
39+
<html lang="en-US">
40+
<head>
41+
<meta charset="UTF-8">
42+
<title>Capture pre-purchase</title>
43+
<style>
44+
table tr td, table tr th {
45+
padding: 10px;
46+
}
47+
</style>
48+
</head>
49+
<body>
50+
<table style="margin: auto;" border="1">
51+
<thead>
52+
<tr>
53+
<th style="text-align: center" colspan="2">Request Data</th>
54+
</tr>
55+
<tr>
56+
<th style="text-align: left"
57+
colspan="2"><?php printf("<pre>%s</pre>", json_encode(['request' => $data], JSON_PRETTY_PRINT)) ?></th>
58+
</tr>
59+
</thead>
60+
<tbody>
61+
<tr>
62+
<td>Normal Response:</td>
63+
<td>
64+
<pre><?php print_r($url->getData()) ?></pre>
65+
</td>
66+
</tr>
67+
<tr>
68+
<td>Response url:</td>
69+
<td><a href="<?= $url->getUrl() ?>"><?= $url->getUrl() ?></a></td>
70+
</tr>
71+
</tbody>
72+
</table>
73+
</body>
74+
</html>
75+
<?php
76+
} catch (\Exception $e) {
77+
echo "Fail: " . $e->getMessage();
78+
}
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
<?php
2+
require_once '../configuration.php';
3+
require_once SDK_ROOTPATH . '/../vendor/autoload.php';
4+
5+
6+
//Split order
7+
try {
8+
\Cloudipsp\Configuration::setMerchantId(600001);
9+
//Generating pcidss order to capture see more https://docs.fondy.eu/docs/page/4/
10+
$TestOrderData = [
11+
'order_id' => 'settelment_' . time(),
12+
'card_number' => '4444555511116666',
13+
'cvv2' => '333',
14+
'expiry_date' => '1232',
15+
'currency' => 'USD',
16+
'preauth' => 'Y',
17+
'amount' => 1000,
18+
'client_ip' => '127.2.2.1'
19+
];
20+
//Call method to generate order for capture
21+
$captured_order_data = Cloudipsp\Pcidss::start($TestOrderData); //next order will be captured
22+
//Minimal data set, all other required params will generated automatically
23+
$data = [
24+
'currency' => 'USD',
25+
'amount' => 1000, // convert to 10.00$
26+
'order_desc' => 'tests SDK',
27+
'operation_id' => $TestOrderData['order_id']
28+
];
29+
//some other params
30+
$receiver = [
31+
[
32+
'requisites' => [
33+
'amount' => 500,
34+
'merchant_id' => 600001
35+
],
36+
'type' => 'merchant'
37+
],
38+
[
39+
'requisites' => [
40+
'amount' => 500,
41+
'merchant_id' => 700001
42+
],
43+
'type' => 'merchant'
44+
]
45+
];
46+
$data['receiver'] = $receiver;
47+
//Call method to generate url
48+
\Cloudipsp\Configuration::setApiVersion('2.0');
49+
$url = Cloudipsp\Order::settlement($data);
50+
//getting returned data
51+
?>
52+
<!doctype html>
53+
<html lang="en-US">
54+
<head>
55+
<meta charset="UTF-8">
56+
<title>Capture pre-purchase</title>
57+
<style>
58+
table tr td, table tr th {
59+
padding: 10px;
60+
}
61+
</style>
62+
</head>
63+
<body>
64+
<table style="margin: auto;" border="1">
65+
<thead>
66+
<tr>
67+
<th style="text-align: center" colspan="2">Request Data</th>
68+
</tr>
69+
<tr>
70+
<th style="text-align: left"
71+
colspan="2"><?php printf("<pre>%s</pre>", json_encode(['request' => $data], JSON_PRETTY_PRINT)) ?></th>
72+
</tr>
73+
</thead>
74+
<tbody>
75+
<tr>
76+
<td>Normal Response:</td>
77+
<td>
78+
<pre><?php print_r($url->getData()) ?></pre>
79+
</td>
80+
</tr>
81+
</tbody>
82+
</table>
83+
</body>
84+
</html>
85+
<?php
86+
} catch (\Exception $e) {
87+
echo "Fail: " . $e->getMessage();
88+
}

lib/Api/Api.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,4 +199,4 @@ protected function setKeyByOperationType($type = '')
199199
$this->secretKey = Configuration::getSecretKey();
200200
}
201201
}
202-
}
202+
}

lib/Api/Order/Settlements.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
namespace Cloudipsp\Api\Order;
4+
5+
use Cloudipsp\Api\Api;
6+
7+
class Settlements extends Api
8+
{
9+
private $url = '/settlement/';
10+
/**
11+
* Minimal required params
12+
* @var array
13+
*/
14+
private $requiredParams = [
15+
'merchant_id' => 'integer',
16+
'operation_id' => 'string'
17+
];
18+
19+
/**
20+
* @param $data
21+
* @param array $headers
22+
* @return mixed
23+
* @throws \Cloudipsp\Exception\ApiException
24+
*/
25+
public function get($data, $headers = [])
26+
{
27+
$data['order_type'] = 'settlement';
28+
$requestData = $this->prepareParams($data);
29+
$this->validate($requestData, $this->requiredParams);
30+
return $this->Request($method = 'POST', $this->url, $headers, $requestData);
31+
}
32+
}

lib/Order.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,5 +76,18 @@ public static function atolLogs($data, $headers = [])
7676
$result = $api->get($data, $headers);
7777
return new OrderResponse($result);
7878
}
79+
/**
80+
* Generate request to create settlement order
81+
* @param $data
82+
* @param array $headers
83+
* @return Response\Response
84+
* @throws Exception\ApiException
85+
*/
86+
public static function settlement($data, $headers = [])
87+
{
88+
$api = new Api\Settlements();
89+
$result = $api->get($data, $headers);
90+
return new Response\Response($result);
91+
}
7992

80-
}
93+
}

0 commit comments

Comments
 (0)