Skip to content

Commit 358ef54

Browse files
committed
Merge branch 'zarinpal-new-rest-api'
2 parents cf8e4e6 + 0e6e5e5 commit 358ef54

20 files changed

+611
-134
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,5 @@ Temporary Items
4343
.apdisk
4444

4545
.idea
46+
vendor
47+
composer.lock

.travis.yml

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
language: php
2+
3+
sudo: false
4+
5+
php:
6+
- 5.6
7+
- 7.0
8+
- hhvm
9+
10+
before_script:
11+
- curl --version
12+
- composer self-update
13+
- composer install
14+

README.md

+19-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# zarinpal-composer-library
1+
# zarinpal-composer-library [![Build Status](https://travis-ci.org/RTLer/zarinpal-composer-library.svg?branch=zarinpal-new-rest-api)](https://travis-ci.org/RTLer/zarinpal-composer-library)
22
transaction request library for zarinpal
33

44
##laravel ready
@@ -11,8 +11,14 @@ just add :
1111
...
1212
)
1313
```
14-
to providers list in "config/app.php".
15-
14+
to providers list in "config/app.php". and run
15+
'`php artisan vendor:publish --provider="Zarinpal\Laravel\ZarinpalServiceProvider"`'
16+
to add config file to laravel configs directory config it and you are good to go
17+
now you can access the zarinpal lib like this:
18+
```php
19+
Zarinpal::request("example.com/testVerify.php",1000,'testing');
20+
Zarinpal::verify('OK',1000,$answer['Authority']);
21+
```
1622
##usage
1723

1824
###request
@@ -41,13 +47,21 @@ echo json_encode($test->verify('OK',1000,$answer['Authority']));
4147
//'Status'(index) going to be 'success', 'error' or 'canceled'
4248
```
4349
##change driver
44-
driver can be changed between soap and NuSoap with using:
50+
driver can be changed between restAPI , soap and NuSoap with using:
51+
52+
restAPI (recommended):
53+
```php
54+
$test = new Zarinpal('XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX');
55+
```
56+
or soap:
4557
```php
4658
use Zarinpal\Drivers\Soap;
4759
$test = new Zarinpal('XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX',new soap());
4860
```
49-
or:
61+
or nuSoap:
5062
```php
5163
use Zarinpal\Drivers\NuSoap;
5264
$test = new Zarinpal('XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX',new NuSoap());
5365
```
66+
67+

composer.json

+10-2
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,20 @@
55
"authors": [
66
{
77
"name": "hooman naghiee",
8-
"email": "hooman@rtler.com"
8+
"email": "hooman@zarinpal.com"
99
}
1010
],
1111
"minimum-stability": "stable",
12-
"require": {},
12+
"require": {
13+
"guzzlehttp/guzzle": "^6.2"
14+
},
15+
"require-dev": {
16+
"phpunit/phpunit": "5.3.*"
17+
},
1318
"autoload": {
19+
"classmap": [
20+
"src/Drivers/lib/nusoap.php"
21+
],
1422
"psr-4": {
1523
"Zarinpal\\": "src/"
1624
}

phpunit.xml

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<phpunit bootstrap="./vendor/autoload.php">
2+
<testsuites>
3+
<testsuite name="sandboxTest">
4+
<file>./test/RestTestCase.php</file>
5+
<file>./test/SoapTestCase.php</file>
6+
<file>./test/NuSoapTestCase.php</file>
7+
</testsuite>
8+
</testsuites>
9+
</phpunit>

src/Drivers/DriverInterface.php

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php namespace Zarinpal\Drivers;
2+
3+
interface DriverInterface
4+
{
5+
/**
6+
* @param $inputs
7+
* @return array|redirect
8+
*/
9+
public function request($inputs);
10+
11+
/**
12+
* @param $inputs
13+
* @return array|redirect
14+
*/
15+
public function requestWithExtra($inputs);
16+
17+
/**
18+
* @param $inputs
19+
* @return array
20+
*/
21+
public function verify($inputs);
22+
23+
/**
24+
* @param $inputs
25+
* @return array
26+
*/
27+
public function verifyWithExtra($inputs);
28+
29+
/**
30+
* @param $inputs
31+
* @return array
32+
*/
33+
public function setAddress($inputs);
34+
}

src/Drivers/NuSoap.php

-42
This file was deleted.

src/Drivers/NuSoapDriver.php

+131
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
<?php namespace Zarinpal\Drivers;
2+
3+
class NuSoapDriver implements DriverInterface
4+
{
5+
protected $client;
6+
private $wsdlAddress = 'https://www.zarinpal.com/pg/services/WebGate/wsdl';
7+
8+
public function __construct()
9+
{
10+
// require_once('./lib/nusoap.php');
11+
$this->client = new \nusoap_client($this->wsdlAddress, 'wsdl');
12+
}
13+
14+
/**
15+
* request driver
16+
*
17+
* @param $inputs
18+
* @return array
19+
*/
20+
public function request($inputs)
21+
{
22+
$this->client->soap_defencoding = 'UTF-8';
23+
$result = $this->client->call('PaymentRequest', [$inputs]);
24+
if ($result['Status'] == 100) {
25+
return ['Authority' => $result['Authority']];
26+
} else {
27+
return ['error' => $result['Status']];
28+
}
29+
}
30+
31+
/**
32+
* request driver.
33+
*
34+
* @param $inputs
35+
*
36+
* @return array
37+
*/
38+
public function requestWithExtra($inputs)
39+
{
40+
$this->client->soap_defencoding = 'UTF-8';
41+
$result = $this->client->call('PaymentRequestWithExtra', [$inputs]);
42+
if ($result['Status'] == 100) {
43+
return ['Authority' => $result['Authority']];
44+
} else {
45+
return ['error' => $result['Status']];
46+
}
47+
}
48+
49+
/**
50+
* verify driver
51+
*
52+
* @param $inputs
53+
* @return array
54+
*/
55+
public function verify($inputs)
56+
{
57+
$this->client->soap_defencoding = 'UTF-8';
58+
$result = $this->client->call('PaymentVerification', [$inputs]);
59+
60+
if ($result['Status'] == 100) {
61+
return ['Status' => 'success', 'RefID' => $result['RefID']];
62+
} else {
63+
return ['Status' => 'error', 'error' => $result['Status']];
64+
}
65+
}
66+
67+
/**
68+
* verify driver.
69+
*
70+
* @param $inputs
71+
*
72+
* @return array
73+
*/
74+
public function verifyWithExtra($inputs)
75+
{
76+
$this->client->soap_defencoding = 'UTF-8';
77+
$result = $this->client->call('PaymentVerificationWithExtra', [$inputs]);
78+
if ($result['Status'] == 100) {
79+
return ['Authority' => $result['Authority']];
80+
} else {
81+
return ['error' => $result['Status']];
82+
}
83+
}
84+
85+
/**
86+
* verify driver.
87+
*
88+
* @param $inputs
89+
*
90+
* @return array
91+
*/
92+
public function unverifiedTransactions($inputs)
93+
{
94+
$this->client->soap_defencoding = 'UTF-8';
95+
$result = $this->client->call('UnverifiedTransactions', [$inputs]);
96+
if ($result['Status'] == 100) {
97+
return ['Authority' => $result['Authority']];
98+
} else {
99+
return ['error' => $result['Status']];
100+
}
101+
102+
}
103+
104+
/**
105+
* verify driver.
106+
*
107+
* @param $inputs
108+
*
109+
* @return array
110+
*/
111+
public function refreshAuthority($inputs)
112+
{
113+
$this->client->soap_defencoding = 'UTF-8';
114+
$result = $this->client->call('RefreshAuthority', [$inputs]);
115+
if ($result['Status'] == 100) {
116+
return ['Authority' => $result['Authority']];
117+
} else {
118+
return ['error' => $result['Status']];
119+
}
120+
}
121+
122+
/**
123+
* @param mixed $wsdlAddress
124+
*/
125+
public function setAddress($wsdlAddress)
126+
{
127+
$this->wsdlAddress = $wsdlAddress;
128+
$this->client = new \nusoap_client($this->wsdlAddress, 'wsdl');
129+
}
130+
131+
}

0 commit comments

Comments
 (0)