Skip to content

Commit 0a45cea

Browse files
committed
Change public API
1 parent 61a1bc9 commit 0a45cea

File tree

8 files changed

+62
-21
lines changed

8 files changed

+62
-21
lines changed

README.md

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,28 +27,45 @@ $request = $epay->buildRequest('payment', [
2727
'order_id' => 1234,
2828
'amount' => 1000,
2929
'currency' => 398,
30-
fields => [
30+
'fields' => [
3131
'RL' => 1234567,
3232
'abonent_id' => 1234567,
3333
...
3434
]
35-
])->getXML();
35+
]);
3636

3737
// Статус платежа
38-
$request = $epay->buildRequest('status', ['order_id' => 1234])->getXML();
39-
38+
$request = $epay->buildRequest('status', ['order_id' => 1234]);
39+
```
40+
```php
4041
//Обработка ответов Epay
41-
$response = $epay->parseResponse('payment', $_POST['response']); // $_POST только для примера, не делайте так в реальной жизни
4242

43-
$client = new GuzzleHttp\Client();
44-
$resp = $client->get('https://testpay.kkb.kz/jsp/remote/checkOrdern.jsp?' . urlencode($request));
43+
// PostLink
44+
$response = $epay->parseResponse('payment', $_POST['response']);
45+
46+
// Ответ на запрос о статусе платежа
47+
$curl = curl_init('https://testpay.kkb.kz/jsp/remote/checkOrdern.jsp?' . urlencode($request));
48+
49+
curl_setopt_array($curl, array(
50+
CURLOPT_RETURNTRANSFER => 1,
51+
CURLOPT_POST => 1,
52+
CURLOPT_POSTFIELDS => [
53+
'Signed_Order_B64' => $request,
54+
'BackLink' => 'asdads',
55+
'PostLink' => 'asdads',
56+
'FailurePostLink' => 'asdads',
57+
]
58+
));
59+
60+
$result = curl_exec($curl);
61+
curl_close($curl);
4562

46-
$response = $epay->parseResponse('status', $resp->getBody()->getContent());
63+
$response = $epay->parseResponse('status', $result);
4764

4865
//verify() проверяет подпись ответа.
4966
if($response->verify()) {
50-
print_r($response->getProps());
51-
// getProps возвращает массив с параметрами ответа
67+
print_r($response->get());
68+
// get возвращает массив с параметрами ответа
5269
} else {
5370
echo 'Response not valid';
5471
}

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"description": "A PHP client for the Qazkom Epay payment gateway",
44
"type": "library",
55
"license": "MIT",
6-
"version": "0.0.4",
6+
"version": "0.0.5",
77
"authors": [
88
{
99
"name": "Margulan Baimbet",

src/Epay.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ public function __construct($params = [])
2020
$this->certManager = new CertManager($params);
2121
}
2222

23-
public function buildRequest(string $type, array $params): Requests\AbstractRequest
23+
public function buildRequest(string $type, array $params)
2424
{
25-
return RequestFactory::create($type, array_merge($params, $this->params), $this->certManager);
25+
return RequestFactory::create($type, array_merge($params, $this->params), $this->certManager)->getXML();
2626
}
2727

2828
public function parseResponse(string $type, string $body)

src/Requests/AbstractRequest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public function getXML() {
3030
return preg_replace('/^.+\n/', '', $this->xml->saveXML());
3131
}
3232

33-
private function signXML()
33+
protected function signXML()
3434
{
3535
$merchant = $this->xml->xpath('/document/merchant')[0];
3636

src/Requests/PaymentRequest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,12 @@ public function buildXML()
3030

3131
return $document;
3232
}
33+
34+
public function getXML()
35+
{
36+
$this->signXML();
37+
$xml = preg_replace('/^.+\n/', '', $this->xml->saveXML());
38+
39+
return base64_encode($xml);
40+
}
3341
}

src/Responses/AbstractResponse.php

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@ abstract class AbstractResponse
1616
/** @var array $props */
1717
protected $props = [];
1818

19+
/** @var string $merchantPath */
1920
protected $merchantPath = '';
21+
22+
/** @var string $merchantSignPath */
2023
protected $merchantSignPath = '';
2124

2225
public function __construct(string $body, CertManager $certManager)
@@ -27,6 +30,15 @@ public function __construct(string $body, CertManager $certManager)
2730
$this->props = $this->fillProps($this->xml);
2831
}
2932

33+
/**
34+
* @param \SimpleXMLElement $xml
35+
* @return mixed
36+
*/
37+
abstract protected function parse(\SimpleXMLElement $xml);
38+
39+
/**
40+
* @return int
41+
*/
3042
public function verify()
3143
{
3244
$signature = strrev(
@@ -38,9 +50,10 @@ public function verify()
3850
return $this->certManager->verify($data, $signature);
3951
}
4052

41-
abstract protected function fillProps(\SimpleXMLElement $sxi);
42-
43-
public function getProps()
53+
/**
54+
* @return array
55+
*/
56+
public function get()
4457
{
4558
return $this->props;
4659
}

src/Responses/PaymentResponse.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class PaymentResponse extends AbstractResponse
88
protected $merchantPath = '/document/bank/customer/merchant';
99
protected $merchantSignPath = '/document/bank/customer/merchant_sign';
1010

11-
protected function fillProps(\SimpleXMLElement $sxi)
11+
protected function fillProps(\SimpleXMLElement $sxi) : array
1212
{
1313
$props = [];
1414

src/Responses/StatusResponse.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ class StatusResponse extends AbstractResponse
88
protected $merchantPath = '/document/bank/merchant';
99
protected $merchantSignPath = '/document/bank/merchant_sign';
1010

11-
protected function fillProps(\SimpleXMLElement $sxi)
11+
/**
12+
* @inheritdoc
13+
*/
14+
protected function parse(\SimpleXMLElement $xml)
1215
{
1316
$props = [];
1417

@@ -17,11 +20,11 @@ protected function fillProps(\SimpleXMLElement $sxi)
1720
$response = $this->xml->xpath('/document/bank/response')[0];
1821

1922
foreach ($order->attributes() as $name => $value) {
20-
$props['order_' . $name] = $value;
23+
$props['order'][$name] = (string)$value;
2124
}
2225

2326
foreach ($response->attributes() as $name => $value) {
24-
$props['response_' . $name] = $value;
27+
$props['response'][$name] = (string)$value;
2528
}
2629

2730
return $props;

0 commit comments

Comments
 (0)