Skip to content

Commit

Permalink
Merge branch 'dev' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
hpakdaman authored Feb 8, 2018
2 parents 19bf5d8 + c693d38 commit 55710bd
Show file tree
Hide file tree
Showing 22 changed files with 535 additions and 62 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/vendor
/.idea
17 changes: 13 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package's home : [larabook.ir](http://larabook.ir/اتصال-درگاه-بانک

by this package we are able to connect to all Iranian bank with one unique API.

( This Package is now compatible with both **4.\* and 5.\* versions of Laravel** )

Please inform us once you've encountered [bug](https://github.com/larabook/gateway/issues) or [issue](https://github.com/larabook/gateway/issues) .

Available Banks:
Expand All @@ -14,6 +16,7 @@ Available Banks:
5. ZARINPAL
6. ~~JAHANPAY~~ (Disabled)
7. ~~PAYLINE~~ (Disabled)
8. PayPal (**New**)

----------

Expand Down Expand Up @@ -55,16 +58,22 @@ You can make connection to bank by several way (Facade , Service container):
try {
$gateway = \Gateway::make(new \Mellat());
// $gateway->setCallback(url('/path/to/calback/route')); You can also change the callback
$gateway->price(1000)->ready();

// $gateway->setCallback(url('/path/to/callback/route')); You can also change the callback
$gateway
->price(1000)
// setShipmentPrice(10) // optional - just for paypal
// setProductName("My Product") // optional - just for paypal
->ready();

$refId = $gateway->refId();
$transID = $gateway->transactionId();

// Your code here

return $gateway->redirect();
} catch (Exception $e) {
} catch (\Exception $e) {
echo $e->getMessage();
}
Expand All @@ -90,7 +99,7 @@ and in your callback :
// Your code here
} catch (Exception $e) {
} catch (\Exception $e) {
echo $e->getMessage();
}
Expand Down
17 changes: 14 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,31 @@
"name": "MohammadReza Honarkhah",
"email": "[email protected]"
},

{
"name": "Amir Khorsandi",
"email": "[email protected]"
}
],
"require": {
"nesbot/carbon": "~1.20"
"nesbot/carbon": "~1.20",
"paypal/rest-api-sdk-php": "*"
},
"autoload": {
"psr-4": {
"Larabookir\\Gateway\\": "src/",
"Larabookir\\Gateway\\Tests\\": "tests/"
}
},
"minimum-stability": "dev"
"minimum-stability": "dev",
"extra": {
"laravel": {
"providers": [
"Larabookir\\Gateway\\GatewayServiceProvider"
],
"aliases": {
"Gateway": "Larabookir\\Gateway\\Gateway"
}
}
},
}
28 changes: 27 additions & 1 deletion config/gateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,34 @@
'callback-url' => '/',
],

//--------------------------------
// Paypal gateway
//--------------------------------
'paypal' => [
// Default product name that appear on paypal payment items
'default_product_name' => 'My Product',
'default_shipment_price' => 0,
// set your paypal credential
'client_id' => 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
'secret' => 'xxxxxxxxxx_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
'settings' => [
'mode' => 'sandbox', //'sandbox' or 'live'
'http.ConnectionTimeOut' => 30,
'log.LogEnabled' => true,
'log.FileName' => storage_path() . '/logs/paypal.log',
/**
* Available option 'FINE', 'INFO', 'WARN' or 'ERROR'
*
* Logging is most verbose in the 'FINE' level and decreases as you
* proceed towards ERROR
*/
'call_back_url' => '/gateway/callback/paypal',
'log.LogLevel' => 'FINE'

]
],
//-------------------------------
// Tables names
//--------------------------------
'table'=> 'gateway_transactions',
'table' => 'gateway_transactions',
];
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ public function up()
Enum::PAYLINE,
Enum::SADAD,
Enum::ZARINPAL,
Enum::SAMAN,
Enum::ASANPARDAKHT
Enum::SAMAN,
Enum::ASANPARDAKHT
Enum::PAYPAL,
]);
$table->decimal('price', 15, 2);
$table->string('ref_id', 100)->nullable();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ public function up()
*/
public function down()
{
// Don't check for foreign key constraints when executing below query in current session
DB::statement('set foreign_key_checks=0');

DB::statement("ALTER TABLE `" . $this->getTable() . "` CHANGE `id` `id` INT(10) UNSIGNED NOT NULL;");

// Ok! now DBMS can check for foregin key constraints
DB::statement('set foreign_key_checks=1');

}
}
7 changes: 4 additions & 3 deletions src/Enum.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ class Enum
const JAHANPAY = 'JAHANPAY';
const PARSIAN = 'PARSIAN';
const PASARGAD = 'PASARGAD';
const SAMAN = 'SAMAN';
const ASANPARDAKHT = 'ASANPARDAKHT';

const SAMAN = 'SAMAN';
const ASANPARDAKHT = 'ASANPARDAKHT';
const PAYPAL = 'PAYPAL';

/**
* Status code for status field in poolport_transactions table
*/
Expand Down
18 changes: 16 additions & 2 deletions src/GatewayResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Larabookir\Gateway;

use Larabookir\Gateway\Parsian\Parsian;
use Larabookir\Gateway\Paypal\Paypal;
use Larabookir\Gateway\Sadad\Sadad;
use Larabookir\Gateway\Mellat\Mellat;
use Larabookir\Gateway\Payline\Payline;
Expand Down Expand Up @@ -57,7 +58,18 @@ public function __construct($config = null, $port = null)
*/
public function getSupportedPorts()
{
return [Enum::MELLAT, Enum::SADAD, Enum::ZARINPAL, Enum::PAYLINE, Enum::JAHANPAY, Enum::PARSIAN, Enum::PASARGAD, Enum::SAMAN, Enum::ASANPARDAKHT];
return [
Enum::MELLAT,
Enum::SADAD,
Enum::ZARINPAL,
Enum::PAYLINE,
Enum::JAHANPAY,
Enum::PARSIAN,
Enum::PASARGAD,
Enum::SAMAN,
Enum::PAYPAL,
Enum::ASANPARDAKHT
];
}

/**
Expand Down Expand Up @@ -143,7 +155,9 @@ function make($port)
$name = Enum::SADAD;
} elseif ($port InstanceOf Asanpardakht) {
$name = Enum::ASANPARDAKHT;
}elseif(in_array(strtoupper($port),$this->getSupportedPorts())){
} elseif ($port InstanceOf Paypal) {
$name = Enum::PAYPAL;
} elseif(in_array(strtoupper($port),$this->getSupportedPorts())){
$port=ucfirst(strtolower($port));
$name=strtoupper($port);
$class=__NAMESPACE__.'\\'.$port.'\\'.$port;
Expand Down
74 changes: 39 additions & 35 deletions src/GatewayServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,46 +14,53 @@ class GatewayServiceProvider extends ServiceProvider
*/
protected $defer = false;

/**
* Actual provider
*
* @var \Illuminate\Support\ServiceProvider
*/
protected $provider;

/**
* Create a new service provider instance.
*
* @param \Illuminate\Contracts\Foundation\Application $app
* @return void
*/
public function __construct($app)
{
parent::__construct($app);

$this->provider = $this->getProvider();
}

/**
* Bootstrap the application services.
*
* @return void
*/
public function boot()
{
$config = __DIR__ . '/../config/gateway.php';
$migrations = __DIR__ . '/../migrations/';
$views = __DIR__ . '/../views/';

//php artisan vendor:publish --provider=Larabookir\Gateway\GatewayServiceProvider --tag=config
$this->publishes([
$config => config_path('gateway.php'),
], 'config');

// php artisan vendor:publish --provider=Larabookir\Gateway\GatewayServiceProvider --tag=migrations
$this->publishes([
$migrations => base_path('database/migrations')
], 'migrations');



if (
File::glob(base_path('/database/migrations/*create_gateway_status_log_table\.php'))
&& !File::exists(base_path('/database/migrations/2017_04_05_103357_alter_id_in_transactions_table.php'))
) {
@File::copy($migrations.'/2017_04_05_103357_alter_id_in_transactions_table.php',base_path('database/migrations/2017_04_05_103357_alter_id_in_transactions_table.php'));
}

if (method_exists($this->provider, 'boot')) {
return $this->provider->boot();
}
}

$this->loadViewsFrom($views, 'gateway');
/**
* Return ServiceProvider according to Laravel version
*
* @return \Intervention\Image\Provider\ProviderInterface
*/
private function getProvider()
{
if (version_compare(\Illuminate\Foundation\Application::VERSION, '5.0', '<')) {
$provider = 'Larabookir\Gateway\GatewayServiceProviderLaravel4';
} else {
$provider = 'Larabookir\Gateway\GatewayServiceProviderLaravel5';
}

// php artisan vendor:publish --provider=Larabookir\Gateway\GatewayServiceProvider --tag=views
$this->publishes([
$views => base_path('resources/views/vendor/gateway'),
], 'views');

//$this->mergeConfigFrom( $config,'gateway')
}
return new $provider($this->app);
}

/**
* Register the application services.
Expand All @@ -62,9 +69,6 @@ public function boot()
*/
public function register()
{
$this->app->singleton('gateway', function () {
return new GatewayResolver();
});

return $this->provider->register();
}
}
55 changes: 55 additions & 0 deletions src/GatewayServiceProviderLaravel4.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

namespace Larabookir\Gateway;

use Illuminate\Support\Facades\File;
use Illuminate\Support\ServiceProvider;

class GatewayServiceProviderLaravel4 extends ServiceProvider
{
/**
* Indicates if loading of the provider is deferred.
*
* @var bool
*/
protected $defer = false;

/**
* Bootstrap the application services.
*
* @return void
*/
public function boot()
{
$config = __DIR__ . '/../config/gateway.php';
$migrations = __DIR__ . '/../migrations/';
$views = __DIR__ . '/../views/';




// for laravel 4.2
$this->package('larabook/gateway',null,__DIR__.'/../');


if (
File::glob(base_path('/database/migrations/*create_gateway_status_log_table\.php'))
&& !File::exists(base_path('/database/migrations/2017_04_05_103357_alter_id_in_transactions_table.php'))
) {
@File::copy($migrations.'/2017_04_05_103357_alter_id_in_transactions_table.php',base_path('database/migrations/2017_04_05_103357_alter_id_in_transactions_table.php'));
}
}

/**
* Register the application services.
*
* @return void
*/
public function register()
{
$this->app->singleton('gateway', function () {
return new GatewayResolver();
});

}
}
Loading

0 comments on commit 55710bd

Please sign in to comment.