Skip to content

Commit

Permalink
move laravel configs to services.php
Browse files Browse the repository at this point in the history
  • Loading branch information
RTLer committed Oct 26, 2017
1 parent 804aa23 commit 4306b4a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 34 deletions.
44 changes: 15 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,24 @@

transaction request library for zarinpal

##laravel ready
## laravel ready
this package is going to work with all kinds of projects, but for laravel i add provider to make it as easy as possible.
just add :
```php
'providers' => array(
'providers' => [
...
Zarinpal\Laravel\ZarinpalServiceProvider::class
...
)
]
```
to providers list in "config/app.php". and run
'`php artisan vendor:publish --provider="Zarinpal\Laravel\ZarinpalServiceProvider"`'
to add config file to laravel configs directory config it and you are good to go
to providers list in "config/app.php". then add this to `config/services.php`
```php
'zarinpal' => [
'merchantID' => 'XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX',
'driver' => 'Rest',
],
```
and you are good to go (legacy config still works)
now you can access the zarinpal lib like this:
```php
use Zarinpal\Laravel\Facade\Zarinpal;
Expand All @@ -28,8 +33,8 @@ Zarinpal::verify('OK',1000,$answer['Authority']);
```


##usage
###installation
## usage
### installation
``composer require zarinpal/zarinpal``
or
```json
Expand All @@ -40,7 +45,7 @@ or
},
```

###request
### request
```php
use Zarinpal\Zarinpal;

Expand All @@ -54,7 +59,7 @@ if(isset($answer['Authority'])) {
//$answer['Authority'] must save somewhere to do the verification
```

###verify
### verify
```php
use Zarinpal\Zarinpal;

Expand All @@ -63,22 +68,3 @@ $answer['Authority'] = file_get_contents('Authority');
echo json_encode($test->verify('OK',1000,$answer['Authority']));
//'Status'(index) going to be 'success', 'error' or 'canceled'
```
##change driver
driver can be changed between restAPI , soap and NuSoap with using:

restAPI (recommended):
```php
$test = new Zarinpal('XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX');
```
or soap:
```php
use Zarinpal\Drivers\SoapDriver;
$test = new Zarinpal('XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX',new soapDriver());
```
or nuSoap:
```php
use Zarinpal\Drivers\NuSoapDriver;
$test = new Zarinpal('XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX',new NuSoapDriver());
```


8 changes: 3 additions & 5 deletions src/Laravel/ZarinpalServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ class ZarinpalServiceProvider extends ServiceProvider
public function register()
{
$this->app->singleton('Zarinpal', function () {
$merchantID = config('Zarinpal.merchantID', 'XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX');
$driver = config('Zarinpal.driver', 'Rest');
$merchantID = config('services.zarinpal.merchantID', config('Zarinpal.merchantID', 'XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX'));
$driver = config('services.zarinpal.driver', config('Zarinpal.driver', 'Rest'));
switch ($driver) {
case 'Soap':
$driver = new SoapDriver();
Expand All @@ -43,8 +43,6 @@ public function register()
*/
public function boot()
{
$this->publishes([
__DIR__.'/config/Zarinpal.php' => config_path('Zarinpal.php'),
]);
//
}
}

0 comments on commit 4306b4a

Please sign in to comment.