diff --git a/config/gateway.php b/config/gateway.php
index fffe3d7e..c18c959f 100644
--- a/config/gateway.php
+++ b/config/gateway.php
@@ -1,5 +1,17 @@
'Asia/Tehran',
+ //--------------------------------
+ // Idpay gateway
+ //--------------------------------
+
+ 'idpay' => [
+ 'api' => '6a7f99eb-7c20-4412-a972-6dfb7cd253a4',
+ 'callback-url' => 'http://igateway.local/bank/response',
+ 'sandbox' => '1', // Types: ['1' || '0']
+ ],
+
//--------------------------------
// Zarinpal gateway
//--------------------------------
diff --git a/migrations/2016_05_02_193213_create_gateway_transactions_table.php b/migrations/2016_05_02_193213_create_gateway_transactions_table.php
index f87a50d6..06ec6bb0 100644
--- a/migrations/2016_05_02_193213_create_gateway_transactions_table.php
+++ b/migrations/2016_05_02_193213_create_gateway_transactions_table.php
@@ -8,47 +8,45 @@
class CreateGatewayTransactionsTable extends Migration
{
- function getTable()
- {
- return config('gateway.table', 'gateway_transactions');
- }
+ public function getTable()
+ {
+ return config('gateway.table', 'gateway_transactions');
+ }
- /**
- * Run the migrations.
- *
- * @return void
- */
- public function up()
- {
-
-
- Schema::create($this->getTable(), function (Blueprint $table) {
- $table->engine = "innoDB";
- $table->unsignedBigInteger('id', true);
- $table->enum('port', (array) Enum::getIPGs());
- $table->decimal('price', 15, 2);
- $table->string('ref_id', 100)->nullable();
- $table->string('tracking_code', 50)->nullable();
- $table->string('card_number', 50)->nullable();
- $table->enum('status', [
- Enum::TRANSACTION_INIT,
- Enum::TRANSACTION_SUCCEED,
- Enum::TRANSACTION_FAILED,
- ])->default(Enum::TRANSACTION_INIT);
- $table->string('ip', 20)->nullable();
- $table->timestamp('payment_date')->nullable();
- $table->nullableTimestamps();
- $table->softDeletes();
- });
- }
+ /**
+ * Run the migrations.
+ *
+ * @return void
+ */
+ public function up()
+ {
+ Schema::create($this->getTable(), function (Blueprint $table) {
+ $table->engine = "innoDB";
+ $table->unsignedBigInteger('id', true);
+ $table->enum('port', (array) Enum::getIPGs());
+ $table->decimal('price', 15, 2);
+ $table->string('ref_id', 100)->nullable();
+ $table->string('tracking_code', 50)->nullable();
+ $table->string('card_number', 50)->nullable();
+ $table->enum('status', [
+ Enum::TRANSACTION_INIT,
+ Enum::TRANSACTION_SUCCEED,
+ Enum::TRANSACTION_FAILED,
+ ])->default(Enum::TRANSACTION_INIT);
+ $table->string('ip', 20)->nullable();
+ $table->timestamp('payment_date')->nullable();
+ $table->nullableTimestamps();
+ $table->softDeletes();
+ });
+ }
- /**
- * Reverse the migrations.
- *
- * @return void
- */
- public function down()
- {
- Schema::drop($this->getTable());
- }
+ /**
+ * Reverse the migrations.
+ *
+ * @return void
+ */
+ public function down()
+ {
+ Schema::drop($this->getTable());
+ }
}
diff --git a/migrations/2016_05_02_193229_create_gateway_status_log_table.php b/migrations/2016_05_02_193229_create_gateway_status_log_table.php
index 0607bca1..17f408fa 100644
--- a/migrations/2016_05_02_193229_create_gateway_status_log_table.php
+++ b/migrations/2016_05_02_193229_create_gateway_status_log_table.php
@@ -5,13 +5,12 @@
class CreateGatewayStatusLogTable extends Migration
{
-
- function getTable()
+ public function getTable()
{
- return config('gateway.table','gateway_transactions');
+ return config('gateway.table', 'gateway_transactions');
}
- function getLogTable()
+ public function getLogTable()
{
return $this->getTable().'_logs';
}
@@ -25,7 +24,7 @@ public function up()
Schema::create($this->getLogTable(), function (Blueprint $table) {
$table->engine="innoDB";
$table->increments('id');
- $table->unsignedBigInteger('transaction_id');
+ $table->unsignedBigInteger('transaction_id');
$table->string('result_code', 10)->nullable();
$table->string('result_message', 255)->nullable();
$table->timestamp('log_date')->nullable();
diff --git a/migrations/2017_04_05_103357_alter_id_in_transactions_table.php b/migrations/2017_04_05_103357_alter_id_in_transactions_table.php
index 7928593b..e8625f73 100644
--- a/migrations/2017_04_05_103357_alter_id_in_transactions_table.php
+++ b/migrations/2017_04_05_103357_alter_id_in_transactions_table.php
@@ -7,56 +7,52 @@
class AlterIdInTransactionsTable extends Migration
{
-
- function getTable()
- {
- return config('gateway.table', 'gateway_transactions');
- }
-
- function getLogTable()
- {
- return $this->getTable().'_logs';
- }
-
-
- /**
- * Run the migrations.
- *
- * @return void
- */
- public function up()
- {
- try {
- DB::statement("ALTER TABLE `" . $this->getLogTable() . "` drop foreign key transactions_logs_transaction_id_foreign;");
- DB::statement("ALTER TABLE `" . $this->getLogTable() . "` DROP INDEX transactions_logs_transaction_id_foreign;");
- } catch (Exception $e) {
-
- }
-
- try {
- DB::statement("update `" . $this->getTable() . "` set `payment_date`=null WHERE `payment_date`=0;");
- DB::statement("ALTER TABLE `" . $this->getTable() . "` CHANGE `id` `id` BIGINT UNSIGNED NOT NULL;");
- DB::statement("ALTER TABLE `" . $this->getLogTable() . "` CHANGE `transaction_id` `transaction_id` BIGINT UNSIGNED NOT NULL;");
- DB::statement("ALTER TABLE `" . $this->getLogTable() . "` ADD INDEX `transactions_logs_transaction_id_foreign` (`transaction_id`);");
- } catch (Exception $e) {
-
- }
- }
-
- /**
- * Reverse the migrations.
- *
- * @return void
- */
- 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');
-
- }
+ public function getTable()
+ {
+ return config('gateway.table', 'gateway_transactions');
+ }
+
+ public function getLogTable()
+ {
+ return $this->getTable().'_logs';
+ }
+
+
+ /**
+ * Run the migrations.
+ *
+ * @return void
+ */
+ public function up()
+ {
+ try {
+ DB::statement("ALTER TABLE `" . $this->getLogTable() . "` drop foreign key transactions_logs_transaction_id_foreign;");
+ DB::statement("ALTER TABLE `" . $this->getLogTable() . "` DROP INDEX transactions_logs_transaction_id_foreign;");
+ } catch (Exception $e) {
+ }
+
+ try {
+ DB::statement("update `" . $this->getTable() . "` set `payment_date`=null WHERE `payment_date`=0;");
+ DB::statement("ALTER TABLE `" . $this->getTable() . "` CHANGE `id` `id` BIGINT UNSIGNED NOT NULL;");
+ DB::statement("ALTER TABLE `" . $this->getLogTable() . "` CHANGE `transaction_id` `transaction_id` BIGINT UNSIGNED NOT NULL;");
+ DB::statement("ALTER TABLE `" . $this->getLogTable() . "` ADD INDEX `transactions_logs_transaction_id_foreign` (`transaction_id`);");
+ } catch (Exception $e) {
+ }
+ }
+
+ /**
+ * Reverse the migrations.
+ *
+ * @return void
+ */
+ 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');
+ }
}
diff --git a/migrations/2018_03_04_224213_add_description_to_gateway_transactions.php b/migrations/2018_03_04_224213_add_description_to_gateway_transactions.php
index 036513cc..1fe6a347 100644
--- a/migrations/2018_03_04_224213_add_description_to_gateway_transactions.php
+++ b/migrations/2018_03_04_224213_add_description_to_gateway_transactions.php
@@ -29,7 +29,6 @@ public function down()
Schema::table('gateway_transactions', function (Blueprint $table) {
//
$table->dropColumn('description');
-
});
}
}
diff --git a/src/Asanpardakht/Asanpardakht.php b/src/Asanpardakht/Asanpardakht.php
index 89363b0b..3f7aa93e 100644
--- a/src/Asanpardakht/Asanpardakht.php
+++ b/src/Asanpardakht/Asanpardakht.php
@@ -41,7 +41,6 @@ public function ready()
*/
public function redirect()
{
-
return view('gateway::asan-pardakht-redirector')->with([
'refId' => $this->refId
]);
@@ -63,7 +62,7 @@ public function verify($transaction)
* Sets callback url
* @param $url
*/
- function setCallback($url)
+ public function setCallback($url)
{
$this->callbackUrl = $url;
return $this;
@@ -73,10 +72,11 @@ function setCallback($url)
* Gets callback url
* @return string
*/
- function getCallback()
+ public function getCallback()
{
- if (!$this->callbackUrl)
+ if (!$this->callbackUrl) {
$this->callbackUrl = $this->config->get('gateway.asanpardakht.callback-url');
+ }
$url = $this->makeCallback($this->callbackUrl, ['transaction_id' => $this->transactionId()]);
@@ -112,7 +112,6 @@ protected function sendPayRequest()
try {
$soap = new SoapClient($this->serverUrl);
$response = $soap->RequestOperation($params);
-
} catch (\SoapFault $e) {
$this->transactionFailed();
$this->newLog('SoapFault', $e->getMessage());
@@ -180,7 +179,6 @@ protected function userPayment()
*/
protected function verifyAndSettlePayment()
{
-
$username = $this->config->get('gateway.asanpardakht.username');
$password = $this->config->get('gateway.asanpardakht.password');
@@ -196,7 +194,6 @@ protected function verifyAndSettlePayment()
$soap = new SoapClient($this->serverUrl);
$response = $soap->RequestVerification($params);
$response = $response->RequestVerificationResult;
-
} catch (\SoapFault $e) {
$this->transactionFailed();
$this->newLog('SoapFault', $e->getMessage());
@@ -211,13 +208,12 @@ protected function verifyAndSettlePayment()
try {
-
$response = $soap->RequestReconciliation($params);
$response = $response->RequestReconciliationResult;
- if ($response != '600')
+ if ($response != '600') {
$this->newLog($response, AsanpardakhtException::getMessageByCode($response));
-
+ }
} catch (\SoapFault $e) {
//If fail, shaparak automatically do it in next 12 houres.
}
@@ -238,12 +234,10 @@ protected function verifyAndSettlePayment()
*/
private function encrypt($string = "")
{
-
$key = $this->config->get('gateway.asanpardakht.key');
$iv = $this->config->get('gateway.asanpardakht.iv');
try {
-
$soap = new SoapClient("https://services.asanpardakht.net/paygate/internalutils.asmx?WSDL");
$params = array(
'aesKey' => $key,
@@ -253,7 +247,6 @@ private function encrypt($string = "")
$response = $soap->EncryptInAES($params);
return $response->EncryptInAESResult;
-
} catch (\SoapFault $e) {
return "";
}
@@ -272,7 +265,6 @@ private function decrypt($string = "")
$iv = $this->config->get('gateway.asanpardakht.iv');
try {
-
$soap = new SoapClient("https://services.asanpardakht.net/paygate/internalutils.asmx?WSDL");
$params = array(
'aesKey' => $key,
@@ -282,10 +274,8 @@ private function decrypt($string = "")
$response = $soap->DecryptInAES($params);
return $response->DecryptInAESResult;
-
} catch (\SoapFault $e) {
return "";
}
}
-
-}
\ No newline at end of file
+}
diff --git a/src/Asanpardakht/AsanpardakhtException.php b/src/Asanpardakht/AsanpardakhtException.php
index 1a8c55b4..e6250fdd 100644
--- a/src/Asanpardakht/AsanpardakhtException.php
+++ b/src/Asanpardakht/AsanpardakhtException.php
@@ -6,7 +6,6 @@
class AsanpardakhtException extends BankException
{
-
public static $errors = array(
0 => "تراکنش با موفقیت انجام شد",
@@ -140,7 +139,7 @@ class AsanpardakhtException extends BankException
709 => "تراکنش در لیست منتظر تسویه ها وجود دارد",
710 => "هویت درخواست کننده عملیات نامعتبر است",
- 911 => "انصراف کاربر از پرداخت",
+ 911 => "انصراف کاربر از پرداخت",
1100 => "موفق",
1101 => "هویت درخواست کننده نامعتبر است",
1102 => "خطا در پردازش",
@@ -160,15 +159,13 @@ public function __construct($errorRef)
public static function getMessageByCode($code)
{
-
$message = "";
- if (isset(self::$errors[$code]))
+ if (isset(self::$errors[$code])) {
$message = self::$errors[$code];
- else if (is_numeric($code) && isset(self::$errors[intval($code)]))
+ } elseif (is_numeric($code) && isset(self::$errors[intval($code)])) {
$message = self::$errors[intval($code)];
+ }
return $message;
}
-
-
}
diff --git a/src/Enum.php b/src/Enum.php
index 266f0a6e..b01ab593 100644
--- a/src/Enum.php
+++ b/src/Enum.php
@@ -4,22 +4,23 @@
class Enum
{
- const MELLAT = 'MELLAT';
- const SADAD = 'SADAD';
- const ZARINPAL = 'ZARINPAL';
- const PAYLINE = 'PAYLINE';
- const JAHANPAY = 'JAHANPAY';
- const PARSIAN = 'PARSIAN';
- const PASARGAD = 'PASARGAD';
- const SAMAN = 'SAMAN';
- const ASANPARDAKHT = 'ASANPARDAKHT';
- const PAYPAL = 'PAYPAL';
- const PAYIR = 'PAYIR';
- const IRANKISH = 'IRANKISH';
- const MASKAN = self::IRANKISH;
-
- static function getIPGs(){
-
+ const MELLAT = 'MELLAT';
+ const SADAD = 'SADAD';
+ const IDPAY = 'IDPAY';
+ const ZARINPAL = 'ZARINPAL';
+ const PAYLINE = 'PAYLINE';
+ const JAHANPAY = 'JAHANPAY';
+ const PARSIAN = 'PARSIAN';
+ const PASARGAD = 'PASARGAD';
+ const SAMAN = 'SAMAN';
+ const ASANPARDAKHT = 'ASANPARDAKHT';
+ const PAYPAL = 'PAYPAL';
+ const PAYIR = 'PAYIR';
+ const IRANKISH = 'IRANKISH';
+ const MASKAN = self::IRANKISH;
+
+ public static function getIPGs()
+ {
$reflect = new \ReflectionClass(static::class);
$excepts=[
'MASKAN',
@@ -31,28 +32,28 @@ static function getIPGs(){
'TRANSACTION_FAILED_TEXT',
];
- if(function_exists('array_except'))
- return array_values(array_except($reflect->getConstants(),$excepts));
- else
- return array_values(\Illuminate\Support\Arr::except($reflect->getConstants(),$excepts));
+ if (function_exists('array_except')) {
+ return array_values(array_except($reflect->getConstants(), $excepts));
+ } else {
+ return array_values(\Illuminate\Support\Arr::except($reflect->getConstants(), $excepts));
+ }
}
- /**
- * Status code for status field in poolport_transactions table
- */
- const TRANSACTION_INIT = 'INIT';
- const TRANSACTION_INIT_TEXT = 'تراکنش ایجاد شد.';
-
- /**
- * Status code for status field in poolport_transactions table
- */
- const TRANSACTION_SUCCEED = 'SUCCEED';
- const TRANSACTION_SUCCEED_TEXT = 'پرداخت با موفقیت انجام شد.';
-
- /**
- * Status code for status field in poolport_transactions table
- */
- const TRANSACTION_FAILED = 'FAILED';
- const TRANSACTION_FAILED_TEXT = 'عملیات پرداخت با خطا مواجه شد.';
-
+ /**
+ * Status code for status field in poolport_transactions table
+ */
+ const TRANSACTION_INIT = 'INIT';
+ const TRANSACTION_INIT_TEXT = 'تراکنش ایجاد شد.';
+
+ /**
+ * Status code for status field in poolport_transactions table
+ */
+ const TRANSACTION_SUCCEED = 'SUCCEED';
+ const TRANSACTION_SUCCEED_TEXT = 'پرداخت با موفقیت انجام شد.';
+
+ /**
+ * Status code for status field in poolport_transactions table
+ */
+ const TRANSACTION_FAILED = 'FAILED';
+ const TRANSACTION_FAILED_TEXT = 'عملیات پرداخت با خطا مواجه شد.';
}
diff --git a/src/Exceptions/BankException.php b/src/Exceptions/BankException.php
index 9bb645be..c7bb1e75 100644
--- a/src/Exceptions/BankException.php
+++ b/src/Exceptions/BankException.php
@@ -1,11 +1,12 @@
message]);
+ }
}
diff --git a/src/Gateway.php b/src/Gateway.php
index 3d2ddf68..e479c7e7 100644
--- a/src/Gateway.php
+++ b/src/Gateway.php
@@ -1,21 +1,21 @@
-config = app('config');
+ $this->request = app('request');
+
+ if ($this->config->has('gateway.timezone')) {
+ date_default_timezone_set($this->config->get('gateway.timezone'));
+ }
+
+ if (!is_null($port)) {
+ $this->make($port);
+ }
+ }
+
+ /**
+ * Get supported ports
+ *
+ * @return array
+ */
+ public function getSupportedPorts()
+ {
+ return (array) Enum::getIPGs();
+ }
+
+ /**
+ * Call methods of current driver
+ *
+ * @return mixed
+ */
+ public function __call($name, $arguments)
+ {
+
+ // calling by this way ( Gateway::mellat()->.. , Gateway::parsian()->.. )
+ if (in_array(strtoupper($name), $this->getSupportedPorts())) {
+ return $this->make($name);
+ }
+
+ return call_user_func_array([$this->port, $name], $arguments);
+ }
+
+ /**
+ * Gets query builder from you transactions table
+ * @return mixed
+ */
+ public function getTable()
+ {
+ return DB::table($this->config->get('gateway.table'));
+ }
+
+ /**
+ * Callback
+ *
+ * @return $this->port
+ *
+ * @throws InvalidRequestException
+ * @throws NotFoundTransactionException
+ * @throws PortNotFoundException
+ * @throws RetryException
+ */
+ public function verify()
+ {
+
+ // if( $this->request->has('status') && $this->request->has('track_id') && $this->request->status == 10 ){ //FIXME: from 10 to 100
+ // $id = $this->request->get('id');
+ // }else{
+
+
+ // }
+
+ if (!$this->request->has('transaction_id') && !$this->request->has('iN')) {
+ throw new InvalidRequestException;
+ }
+ if ($this->request->has('transaction_id')) {
+ $id = \decrypt($this->request->get('transaction_id'));
+ } else {
+ $id = $this->request->get('iN');
+ }
+
+ $transaction = $this->getTable()->whereId($id)->first();
+
+ if (!$transaction) {
+ throw new NotFoundTransactionException;
+ }
+
+ if (in_array($transaction->status, [Enum::TRANSACTION_SUCCEED, Enum::TRANSACTION_FAILED])) {
+ throw new RetryException;
+ }
+
+ $this->make($transaction->port);
+
+ return $this->port->verify($transaction);
+ }
+
- protected $request;
-
- /**
- * @var Config
- */
- public $config;
-
- /**
- * Keep current port driver
- *
- * @var Mellat|Saman|Sadad|Zarinpal|Payir|Parsian
- */
- protected $port;
-
- /**
- * Gateway constructor.
- * @param null $config
- * @param null $port
- */
- public function __construct($config = null, $port = null)
- {
- $this->config = app('config');
- $this->request = app('request');
-
- if ($this->config->has('gateway.timezone'))
- date_default_timezone_set($this->config->get('gateway.timezone'));
-
- if (!is_null($port)) $this->make($port);
- }
-
- /**
- * Get supported ports
- *
- * @return array
- */
- public function getSupportedPorts()
- {
- return (array) Enum::getIPGs();
- }
-
- /**
- * Call methods of current driver
- *
- * @return mixed
- */
- public function __call($name, $arguments)
- {
-
- // calling by this way ( Gateway::mellat()->.. , Gateway::parsian()->.. )
- if(in_array(strtoupper($name),$this->getSupportedPorts())){
- return $this->make($name);
- }
-
- return call_user_func_array([$this->port, $name], $arguments);
- }
-
- /**
- * Gets query builder from you transactions table
- * @return mixed
- */
- function getTable()
- {
- return DB::table($this->config->get('gateway.table'));
- }
-
- /**
- * Callback
- *
- * @return $this->port
- *
- * @throws InvalidRequestException
- * @throws NotFoundTransactionException
- * @throws PortNotFoundException
- * @throws RetryException
- */
- public function verify()
- {
- if (!$this->request->has('transaction_id') && !$this->request->has('iN'))
- throw new InvalidRequestException;
- if ($this->request->has('transaction_id')) {
- $id = $this->request->get('transaction_id');
- }else {
- $id = $this->request->get('iN');
- }
-
- $transaction = $this->getTable()->whereId($id)->first();
-
- if (!$transaction)
- throw new NotFoundTransactionException;
-
- if (in_array($transaction->status, [Enum::TRANSACTION_SUCCEED, Enum::TRANSACTION_FAILED]))
- throw new RetryException;
-
- $this->make($transaction->port);
-
- return $this->port->verify($transaction);
- }
-
-
- /**
- * Create new object from port class
- *
- * @param int $port
- * @throws PortNotFoundException
- */
- function make($port)
+ /**
+ * Create new object from port class
+ *
+ * @param int $port
+ * @throws PortNotFoundException
+ */
+ public function make($port)
{
- if ($port InstanceOf Mellat) {
+ if ($port instanceof Mellat) {
$name = Enum::MELLAT;
- } elseif ($port InstanceOf Parsian) {
+ } elseif ($port instanceof Parsian) {
$name = Enum::PARSIAN;
- } elseif ($port InstanceOf Saman) {
+ } elseif ($port instanceof Idpay) {
+ $name = Enum::IDPAY;
+ } elseif ($port instanceof Saman) {
$name = Enum::SAMAN;
- } elseif ($port InstanceOf Zarinpal) {
+ } elseif ($port instanceof Zarinpal) {
$name = Enum::ZARINPAL;
- } elseif ($port InstanceOf Sadad) {
+ } elseif ($port instanceof Sadad) {
$name = Enum::SADAD;
- } elseif ($port InstanceOf Asanpardakht) {
+ } elseif ($port instanceof Asanpardakht) {
$name = Enum::ASANPARDAKHT;
- } elseif ($port InstanceOf Paypal) {
+ } elseif ($port instanceof Paypal) {
$name = Enum::PAYPAL;
- } elseif ($port InstanceOf Payir) {
+ } elseif ($port instanceof Payir) {
$name = Enum::PAYIR;
- } elseif ($port InstanceOf Pasargad) {
+ } elseif ($port instanceof Pasargad) {
$name = Enum::PASARGAD;
- } elseif ($port InstanceOf Irankish) {
+ } elseif ($port instanceof Irankish) {
$name = Enum::IRANKISH;
} elseif (in_array(strtoupper($port), $this->getSupportedPorts())) {
$port = ucfirst(strtolower($port));
$name = strtoupper($port);
$class = __NAMESPACE__ . '\\' . $port . '\\' . $port;
$port = new $class;
- } else
+ } else {
throw new PortNotFoundException;
+ }
$this->port = $port;
$this->port->setConfig($this->config); // injects config
diff --git a/src/GatewayServiceProvider.php b/src/GatewayServiceProvider.php
index f51e4ae5..79975f03 100644
--- a/src/GatewayServiceProvider.php
+++ b/src/GatewayServiceProvider.php
@@ -7,12 +7,12 @@
class GatewayServiceProvider extends ServiceProvider
{
- /**
- * Indicates if loading of the provider is deferred.
- *
- * @var bool
- */
- protected $defer = false;
+ /**
+ * Indicates if loading of the provider is deferred.
+ *
+ * @var bool
+ */
+ protected $defer = false;
/**
* Actual provider
@@ -34,17 +34,17 @@ public function __construct($app)
$this->provider = $this->getProvider();
}
- /**
- * Bootstrap the application services.
- *
- * @return void
- */
- public function boot()
- {
+ /**
+ * Bootstrap the application services.
+ *
+ * @return void
+ */
+ public function boot()
+ {
if (method_exists($this->provider, 'boot')) {
return $this->provider->boot();
}
- }
+ }
/**
* Return ServiceProvider according to Laravel version
@@ -55,22 +55,22 @@ private function getProvider()
{
if (version_compare(\Illuminate\Foundation\Application::VERSION, '5.0', '<')) {
$provider = 'Larabookir\Gateway\GatewayServiceProviderLaravel4';
- }elseif (version_compare(\Illuminate\Foundation\Application::VERSION, '5.0', '>=') && version_compare(\Illuminate\Foundation\Application::VERSION, '6.0', '<')) {
+ } elseif (version_compare(\Illuminate\Foundation\Application::VERSION, '5.0', '>=') && version_compare(\Illuminate\Foundation\Application::VERSION, '6.0', '<')) {
$provider = 'Larabookir\Gateway\GatewayServiceProviderLaravel5';
- }else {
+ } else {
$provider = 'Larabookir\Gateway\GatewayServiceProviderLaravel6';
}
return new $provider($this->app);
}
- /**
- * Register the application services.
- *
- * @return void
- */
- public function register()
- {
- return $this->provider->register();
- }
+ /**
+ * Register the application services.
+ *
+ * @return void
+ */
+ public function register()
+ {
+ return $this->provider->register();
+ }
}
diff --git a/src/GatewayServiceProviderLaravel4.php b/src/GatewayServiceProviderLaravel4.php
index 7194ab93..4efe2adb 100644
--- a/src/GatewayServiceProviderLaravel4.php
+++ b/src/GatewayServiceProviderLaravel4.php
@@ -7,49 +7,48 @@
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/';
+ /**
+ * 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();
- });
-
- }
+ $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();
+ });
+ }
}
diff --git a/src/GatewayServiceProviderLaravel5.php b/src/GatewayServiceProviderLaravel5.php
index a075b3f1..dbad8e3e 100644
--- a/src/GatewayServiceProviderLaravel5.php
+++ b/src/GatewayServiceProviderLaravel5.php
@@ -7,20 +7,20 @@
class GatewayServiceProviderLaravel5 extends ServiceProvider
{
- /**
- * Indicates if loading of the provider is deferred.
- *
- * @var bool
- */
- protected $defer = false;
-
- /**
- * Bootstrap the application services.
- *
- * @return void
- */
- public function boot()
- {
+ /**
+ * 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/';
@@ -44,18 +44,17 @@ public function boot()
], 'views');
//$this->mergeConfigFrom( $config,'gateway')
- }
-
- /**
- * Register the application services.
- *
- * @return void
- */
- public function register()
- {
- $this->app->singleton('gateway', function () {
- return new GatewayResolver();
- });
-
- }
+ }
+
+ /**
+ * Register the application services.
+ *
+ * @return void
+ */
+ public function register()
+ {
+ $this->app->singleton('gateway', function () {
+ return new GatewayResolver();
+ });
+ }
}
diff --git a/src/GatewayServiceProviderLaravel6.php b/src/GatewayServiceProviderLaravel6.php
index b3df8082..fecee52d 100644
--- a/src/GatewayServiceProviderLaravel6.php
+++ b/src/GatewayServiceProviderLaravel6.php
@@ -7,20 +7,20 @@
class GatewayServiceProviderLaravel6 extends ServiceProvider
{
- /**
- * Indicates if loading of the provider is deferred.
- *
- * @var bool
- */
- protected $defer = false;
-
- /**
- * Bootstrap the application services.
- *
- * @return void
- */
- public function boot()
- {
+ /**
+ * 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/';
@@ -45,18 +45,17 @@ public function boot()
], 'views');
//$this->mergeConfigFrom( $config,'gateway')
- }
-
- /**
- * Register the application services.
- *
- * @return void
- */
- public function register()
- {
- $this->app->singleton('gateway', function () {
- return new GatewayResolver();
- });
-
- }
+ }
+
+ /**
+ * Register the application services.
+ *
+ * @return void
+ */
+ public function register()
+ {
+ $this->app->singleton('gateway', function () {
+ return new GatewayResolver();
+ });
+ }
}
diff --git a/src/Idpay/Idpay.php b/src/Idpay/Idpay.php
new file mode 100644
index 00000000..a1df942d
--- /dev/null
+++ b/src/Idpay/Idpay.php
@@ -0,0 +1,239 @@
+amount = $amount * 10;
+ return $this;
+ }
+
+ /**
+ * تعیین شماره فاکتور (اختیاری)
+ *
+ * @param $factorNumber
+ *
+ * @return $this
+ */
+ public function setFactorNumber($factorNumber)
+ {
+ $this->factorNumber = $factorNumber;
+ return $this;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+
+ public function ready()
+ {
+ $this->sendPayRequest();
+ return $this;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function redirect()
+ {
+ return redirect()->to($this->gateUrl);
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+
+ public function setConfig($config)
+ {
+ parent::setConfig($config);
+ $this->header = array(
+ 'Content-Type: application/json',
+ 'X-API-KEY: ' . $this->config->get('gateway.idpay.api'),
+ 'X-SANDBOX: ' . $this->config->get('gateway.idpay.sandbox'),
+ );
+ }
+
+ public function verify($transaction)
+ {
+ parent::verify($transaction);
+ $this->userPayment();
+ $this->verifyPayment();
+ return $this;
+ }
+
+ /**
+ * Sets callback url
+ *
+ * @param $url
+ */
+ public function setCallback($url)
+ {
+ $this->callbackUrl = $url;
+ return $this;
+ }
+
+ /**
+ * Gets callback url
+ * @return string
+ */
+ public function getCallback()
+ {
+ if (!$this->callbackUrl) {
+ $this->callbackUrl = $this->config->get('gateway.idpay.callback-url');
+ }
+ return urlencode($this->makeCallback($this->callbackUrl, ['transaction_id' => $this->transactionId()]));
+ }
+
+ /**
+ * Send pay request to server
+ *
+ * @return void
+ *
+ * @throws IdpaySendException
+ */
+ protected function sendPayRequest()
+ {
+ if (is_null($this->factorNumber)) {
+ throw new IdpaySendException(32);
+ }
+
+ $this->newTransaction();
+
+ $fields = array(
+ 'order_id' => $this->factorNumber,
+ 'amount' => $this->amount,
+ 'callback' => $this->makeCallback($this->callbackUrl, ['transaction_id' => $this->transactionId() , 'order_id' => $this->factorNumber]),
+ );
+
+
+ $ch = curl_init();
+ curl_setopt($ch, CURLOPT_URL, $this->serverUrl);
+ curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
+ curl_setopt($ch, CURLOPT_HTTPHEADER, $this->header);
+
+ $response = curl_exec($ch);
+ $response = json_decode($response, true);
+ curl_close($ch);
+
+
+
+ if (isset($response['link'])) {
+ $this->gateUrl = $response['link'];
+ $this->refId = $response['id'];
+ $this->transactionSetRefId();
+ return true;
+ }
+
+ if (isset($response['status']) && $response['status'] > 0) {
+ $this->refId = $response['transId'];
+ $this->transactionSetRefId();
+ return true;
+ }
+
+
+ $this->transactionFailed();
+ $this->newLog($response['error_code'], IdpaySendException::$errors[ $response['error_code'] ]);
+ throw new IdpaySendException($response['error_code']);
+ }
+
+ public function setCustomDesc($description)
+ {
+ $this->description = $description;
+ }
+
+
+
+ /**
+ * Check user payment with GET data
+ *
+ * @return bool
+ *
+ * @throws IdpayReceiveException
+ */
+ protected function userPayment()
+ {
+ $status = Request::input('status');
+ $transId = Request::input('transId');
+ $this->cardNumber = Request::input('cardNumber');
+ $message = Request::input('message');
+ if (is_numeric($status) && $status > 0) {
+ $this->trackingCode = $transId;
+ return true;
+ }
+ $this->transactionFailed();
+ $this->newLog(-5, $message);
+ throw new IdpayReceiveException(-5);
+ }
+
+ /**
+ * Verify user payment from zarinpal server
+ *
+ * @return bool
+ *
+ * @throws IdpayReceiveException
+ */
+ protected function verifyPayment()
+ {
+ $fields = array(
+ 'id' => $this->refId,
+ 'order_id' => request()->order_id,
+ );
+
+ $ch = curl_init();
+ curl_setopt($ch, CURLOPT_URL, $this->serverVerifyUrl);
+ curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
+ curl_setopt($ch, CURLOPT_HTTPHEADER, $this->header);
+
+ $response = curl_exec($ch);
+ $response = json_decode($response, true);
+ curl_close($ch);
+
+ if (isset($response['status']) && $response['status'] == 100) {
+ $this->refId = $response['id'];
+ $this->cardNumber = $response['payment']['card_no'];
+ $this->trackingCode = $response['payment']['track_id'];
+
+ $this->transactionSucceed();
+ $this->newLog(1, Enum::TRANSACTION_SUCCEED_TEXT);
+ return true;
+ }
+
+ if (isset($response['error_code'])) {
+ $this->transactionFailed();
+ $this->newLog($response['error_code'], IdpayReceiveException::$errors[ $response['error_code'] ]);
+ throw new IdpayReceiveException($response['error_code']);
+ }
+ }
+}
diff --git a/src/Idpay/IdpayReceiveException.php b/src/Idpay/IdpayReceiveException.php
new file mode 100644
index 00000000..da69384f
--- /dev/null
+++ b/src/Idpay/IdpayReceiveException.php
@@ -0,0 +1,36 @@
+ 'ارسال api الزامی می باشد',
+ -2 => 'ارسال transId الزامی می باشد',
+ -3 => 'درگاه پرداختی با api ارسالی یافت نشد و یا غیر فعال می باشد',
+ -4 => 'فروشنده غیر فعال می باشد',
+ -5 => 'تراکنش با خطا مواجه شده است',
+
+ 11 => 'کاربر مسدود شده است.',
+ 12 => 'API Key یافت نشد.',
+ 13 => 'درخواست شما از ارسال شده است. این IP با IP های ثبت شده در وب سرویس همخوانی ندارد.',
+ 14 => 'وب سرویس شما در حال بررسی است و یا تایید نشده است.',
+ 21 => 'حساب بانکی متصل به وب سرویس تایید نشده است.',
+ 22 => 'وب سریس یافت نشد.',
+ 23 => 'اعتبار سنجی وب سرویس ناموفق بود.',
+ 24 => 'حساب بانکی مرتبط با این وب سرویس غیر فعال شده است.',
+
+ 53 => 'تایید پرداخت امکان پذیر نیست.',
+ 54 => 'مدت زمان تایید پرداخت سپری شده است.',
+ 51 => 'تراکنش ایجاد نشد.',
+ ];
+
+ public function __construct($errorId)
+ {
+ $this->errorId = $errorId;
+
+ parent::__construct(@self::$errors[ $errorId ] . ' #' . $errorId, $errorId);
+ }
+}
diff --git a/src/Idpay/IdpaySendException.php b/src/Idpay/IdpaySendException.php
new file mode 100644
index 00000000..de617ff6
--- /dev/null
+++ b/src/Idpay/IdpaySendException.php
@@ -0,0 +1,30 @@
+ 'در حال حاضر درگاه پرداخت قطع می باشد. به زودی مشکل برطرف خواهد شد' ,
+ -1 => 'ارسال api الزامی می باشد',
+ -2 => 'ارسال amount ( مبلغ تراکنش ) الزامی می باشد',
+ -3 => 'amount ( مبلغ تراکنش )باید به صورت عددی باشد',
+ -4 => 'amount نباید کمتر از 1000 باشد',
+ -5 => 'ارسال redirect الزامی می باشد',
+ -6 => 'درگاه پرداختی با api ارسالی یافت نشد و یا غیر فعال می باشد',
+ -7 => 'فروشنده غیر فعال می باشد',
+ -8 => 'آدرس بازگشتی با آدرس درگاه پرداخت ثبت شده همخوانی ندارد',
+ 32 => 'شماره سفارش order_id نباید خالی باشد.',
+
+ 'failed' => 'تراکنش با خطا مواجه شد',
+ ];
+
+ public function __construct($errorId)
+ {
+ $this->errorId = $errorId;
+
+ parent::__construct(@self::$errors[ $errorId ] . ' #' . $errorId, $errorId);
+ }
+}
diff --git a/src/Irankish/Irankish.php b/src/Irankish/Irankish.php
index e6a61be6..ccff64a6 100644
--- a/src/Irankish/Irankish.php
+++ b/src/Irankish/Irankish.php
@@ -53,7 +53,7 @@ public function redirect()
$token = $this->refId;
$merchantId = $this->config->get('gateway.irankish.merchantId');
- return view('gateway::irankish-redirector')->with(compact('token', 'merchantId','gateUrl'));
+ return view('gateway::irankish-redirector')->with(compact('token', 'merchantId', 'gateUrl'));
}
/**
@@ -73,7 +73,7 @@ public function verify($transaction)
*
* @param $url
*/
- function setCallback($url)
+ public function setCallback($url)
{
$this->callbackUrl = $url;
@@ -84,7 +84,7 @@ function setCallback($url)
* Gets callback url
* @return string
*/
- function getCallback()
+ public function getCallback()
{
if (!$this->callbackUrl) {
$this->callbackUrl = $this->config->get('gateway.irankish.callback-url');
@@ -118,7 +118,6 @@ protected function sendPayRequest()
try {
$soap = new SoapClient($this->serverUrl, ['soap_version' => SOAP_1_1]);
$response = $soap->MakeToken($fields);
-
} catch (\SoapFault $e) {
$this->transactionFailed();
$this->newLog('SoapFault', $e->getMessage());
@@ -143,11 +142,11 @@ protected function sendPayRequest()
*/
protected function userPayment()
{
-
$this->refId = Request::input('token');
$this->trackingCode = Request::input('referenceId');
- if(Request::has('cardNo'))
+ if (Request::has('cardNo')) {
$this->cardNumber = Request::input('cardNo');
+ }
$payRequestResCode = Request::input('resultCode');
if ($payRequestResCode == '100') {
@@ -179,7 +178,6 @@ protected function verifyPayment()
try {
$soap = new SoapClient($this->serverVerifyUrl);
$response = $soap->KicccPaymentsVerification($fields);
-
} catch (\SoapFault $e) {
$this->transactionFailed();
$this->newLog('SoapFault', $e->getMessage());
@@ -198,5 +196,4 @@ protected function verifyPayment()
return true;
}
-
}
diff --git a/src/JahanPay/JahanPay.php b/src/JahanPay/JahanPay.php
index 200c19b0..fe825fd4 100644
--- a/src/JahanPay/JahanPay.php
+++ b/src/JahanPay/JahanPay.php
@@ -69,7 +69,7 @@ public function verify($transaction)
* Sets callback url
* @param $url
*/
- function setCallback($url)
+ public function setCallback($url)
{
$this->callbackUrl = $url;
return $this;
@@ -79,10 +79,11 @@ function setCallback($url)
* Gets callback url
* @return string
*/
- function getCallback()
+ public function getCallback()
{
- if (!$this->callbackUrl)
+ if (!$this->callbackUrl) {
$this->callbackUrl = $this->config->get('gateway.jahanpay.callback-url');
+ }
return $this->makeCallback($this->callbackUrl, ['transaction_id' => $this->transactionId()]);
}
@@ -107,8 +108,7 @@ protected function sendPayRequest()
$this->transactionId(),
''
);
-
- } catch(\SoapFault $e) {
+ } catch (\SoapFault $e) {
$this->transactionFailed();
$this->newLog('SoapFault', $e->getMessage());
throw $e;
@@ -161,8 +161,7 @@ protected function verifyPayment()
$this->amount,
$this->refId
);
-
- } catch(\SoapFault $e) {
+ } catch (\SoapFault $e) {
$this->transactionFailed();
$this->newLog('SoapFault', $e->getMessage());
throw $e;
diff --git a/src/Maskan/Maskan.php b/src/Maskan/Maskan.php
index 4821797a..c5d91897 100644
--- a/src/Maskan/Maskan.php
+++ b/src/Maskan/Maskan.php
@@ -71,7 +71,7 @@ public function verify($transaction)
*
* @param $url
*/
- function setCallback($url)
+ public function setCallback($url)
{
$this->callbackUrl = $url;
@@ -82,7 +82,7 @@ function setCallback($url)
* Gets callback url
* @return string
*/
- function getCallback()
+ public function getCallback()
{
return $this->makeCallback($this->callbackUrl, ['transaction_id' => $this->transactionId()]);
}
@@ -128,7 +128,6 @@ protected function sendPayRequest()
$error_code = 505;
$this->transactionFailed();
$this->newLog($error_code, MaskanException::$errors[$error_code]);
-
} else {
$confirm = json_decode($result, false);
$ActionCode = strval($confirm->ActionCode);
diff --git a/src/Mellat/Mellat.php b/src/Mellat/Mellat.php
index 341c534b..7723eb7d 100644
--- a/src/Mellat/Mellat.php
+++ b/src/Mellat/Mellat.php
@@ -11,224 +11,222 @@
class Mellat extends PortAbstract implements PortInterface
{
- /**
- * Address of main SOAP server
- *
- * @var string
- */
- protected $serverUrl = 'https://bpm.shaparak.ir/pgwchannel/services/pgw?wsdl';
-
- /**
- * {@inheritdoc}
- */
- public function set($amount)
- {
- $this->amount = $amount;
-
- return $this;
- }
-
- /**
- * {@inheritdoc}
- */
- public function ready()
- {
- $this->sendPayRequest();
-
- return $this;
- }
-
- /**
- * {@inheritdoc}
- */
- public function redirect()
- {
- $refId = $this->refId;
+ /**
+ * Address of main SOAP server
+ *
+ * @var string
+ */
+ protected $serverUrl = 'https://bpm.shaparak.ir/pgwchannel/services/pgw?wsdl';
+
+ /**
+ * {@inheritdoc}
+ */
+ public function set($amount)
+ {
+ $this->amount = $amount;
+
+ return $this;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function ready()
+ {
+ $this->sendPayRequest();
+
+ return $this;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function redirect()
+ {
+ $refId = $this->refId;
return \View::make('gateway::mellat-redirector')->with(compact('refId'));
- }
-
- /**
- * {@inheritdoc}
- */
- public function verify($transaction)
- {
- parent::verify($transaction);
-
- $this->userPayment();
- $this->verifyPayment();
- $this->settleRequest();
-
- return $this;
- }
-
- /**
- * Sets callback url
- * @param $url
- */
- function setCallback($url)
- {
- $this->callbackUrl = $url;
- return $this;
- }
-
- /**
- * Gets callback url
- * @return string
- */
- function getCallback()
- {
- if (!$this->callbackUrl)
- $this->callbackUrl = $this->config->get('gateway.mellat.callback-url');
-
- return $this->makeCallback($this->callbackUrl, ['transaction_id' => $this->transactionId()]);
- }
-
- /**
- * Send pay request to server
- *
- * @return void
- *
- * @throws MellatException
- */
- protected function sendPayRequest()
- {
- $dateTime = new DateTime();
-
- $this->newTransaction();
-
- $fields = array(
- 'terminalId' => $this->config->get('gateway.mellat.terminalId'),
- 'userName' => $this->config->get('gateway.mellat.username'),
- 'userPassword' => $this->config->get('gateway.mellat.password'),
- 'orderId' => $this->transactionId(),
- 'amount' => $this->amount,
- 'localDate' => $dateTime->format('Ymd'),
- 'localTime' => $dateTime->format('His'),
- 'additionalData' => '',
- 'callBackUrl' => $this->getCallback(),
- 'payerId' => 0,
- );
-
- try {
- $soap = new \SoapClient($this->serverUrl);
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function verify($transaction)
+ {
+ parent::verify($transaction);
+
+ $this->userPayment();
+ $this->verifyPayment();
+ $this->settleRequest();
+
+ return $this;
+ }
+
+ /**
+ * Sets callback url
+ * @param $url
+ */
+ public function setCallback($url)
+ {
+ $this->callbackUrl = $url;
+ return $this;
+ }
+
+ /**
+ * Gets callback url
+ * @return string
+ */
+ public function getCallback()
+ {
+ if (!$this->callbackUrl) {
+ $this->callbackUrl = $this->config->get('gateway.mellat.callback-url');
+ }
+
+ return $this->makeCallback($this->callbackUrl, ['transaction_id' => $this->transactionId()]);
+ }
+
+ /**
+ * Send pay request to server
+ *
+ * @return void
+ *
+ * @throws MellatException
+ */
+ protected function sendPayRequest()
+ {
+ $dateTime = new DateTime();
+
+ $this->newTransaction();
+
+ $fields = array(
+ 'terminalId' => $this->config->get('gateway.mellat.terminalId'),
+ 'userName' => $this->config->get('gateway.mellat.username'),
+ 'userPassword' => $this->config->get('gateway.mellat.password'),
+ 'orderId' => $this->transactionId(),
+ 'amount' => $this->amount,
+ 'localDate' => $dateTime->format('Ymd'),
+ 'localTime' => $dateTime->format('His'),
+ 'additionalData' => '',
+ 'callBackUrl' => $this->getCallback(),
+ 'payerId' => 0,
+ );
+
+ try {
+ $soap = new \SoapClient($this->serverUrl);
$response = $soap->bpPayRequest($fields);
-
- } catch (\SoapFault $e) {
- $this->transactionFailed();
- $this->newLog('SoapFault', $e->getMessage());
- throw $e;
- }
-
- $response = explode(',', $response->return);
-
- if ($response[0] != '0') {
- $this->transactionFailed();
- $this->newLog($response[0], MellatException::$errors[$response[0]]);
- throw new MellatException($response[0]);
- }
- $this->refId = $response[1];
- $this->transactionSetRefId();
- }
-
- /**
- * Check user payment
- *
- * @return bool
- *
- * @throws MellatException
- */
- protected function userPayment()
- {
- $this->refId = Request::input('RefId');
- $this->trackingCode = Request::input('SaleReferenceId');
- $this->cardNumber = Request::input('CardHolderPan');
- $payRequestResCode = Request::input('ResCode');
-
- if ($payRequestResCode == '0') {
- return true;
- }
-
- $this->transactionFailed();
- $this->newLog($payRequestResCode, @MellatException::$errors[$payRequestResCode]);
- throw new MellatException($payRequestResCode);
- }
-
- /**
- * Verify user payment from bank server
- *
- * @return bool
- *
- * @throws MellatException
- * @throws SoapFault
- */
- protected function verifyPayment()
- {
- $fields = array(
- 'terminalId' => $this->config->get('gateway.mellat.terminalId'),
- 'userName' => $this->config->get('gateway.mellat.username'),
- 'userPassword' => $this->config->get('gateway.mellat.password'),
- 'orderId' => $this->transactionId(),
- 'saleOrderId' => $this->transactionId(),
- 'saleReferenceId' => $this->trackingCode()
- );
-
- try {
- $soap = new SoapClient($this->serverUrl);
- $response = $soap->bpVerifyRequest($fields);
-
- } catch (\SoapFault $e) {
- $this->transactionFailed();
- $this->newLog('SoapFault', $e->getMessage());
- throw $e;
- }
-
- if ($response->return != '0') {
- $this->transactionFailed();
- $this->newLog($response->return, MellatException::$errors[$response->return]);
- throw new MellatException($response->return);
- }
-
- return true;
- }
-
- /**
- * Send settle request
- *
- * @return bool
- *
- * @throws MellatException
- * @throws SoapFault
- */
- protected function settleRequest()
- {
- $fields = array(
- 'terminalId' => $this->config->get('gateway.mellat.terminalId'),
- 'userName' => $this->config->get('gateway.mellat.username'),
- 'userPassword' => $this->config->get('gateway.mellat.password'),
- 'orderId' => $this->transactionId(),
- 'saleOrderId' => $this->transactionId(),
- 'saleReferenceId' => $this->trackingCode
- );
-
- try {
- $soap = new SoapClient($this->serverUrl);
- $response = $soap->bpSettleRequest($fields);
-
- } catch (\SoapFault $e) {
- $this->transactionFailed();
- $this->newLog('SoapFault', $e->getMessage());
- throw $e;
- }
-
- if ($response->return == '0' || $response->return == '45') {
- $this->transactionSucceed();
- $this->newLog($response->return, Enum::TRANSACTION_SUCCEED_TEXT);
- return true;
- }
-
- $this->transactionFailed();
- $this->newLog($response->return, MellatException::$errors[$response->return]);
- throw new MellatException($response->return);
- }
+ } catch (\SoapFault $e) {
+ $this->transactionFailed();
+ $this->newLog('SoapFault', $e->getMessage());
+ throw $e;
+ }
+
+ $response = explode(',', $response->return);
+
+ if ($response[0] != '0') {
+ $this->transactionFailed();
+ $this->newLog($response[0], MellatException::$errors[$response[0]]);
+ throw new MellatException($response[0]);
+ }
+ $this->refId = $response[1];
+ $this->transactionSetRefId();
+ }
+
+ /**
+ * Check user payment
+ *
+ * @return bool
+ *
+ * @throws MellatException
+ */
+ protected function userPayment()
+ {
+ $this->refId = Request::input('RefId');
+ $this->trackingCode = Request::input('SaleReferenceId');
+ $this->cardNumber = Request::input('CardHolderPan');
+ $payRequestResCode = Request::input('ResCode');
+
+ if ($payRequestResCode == '0') {
+ return true;
+ }
+
+ $this->transactionFailed();
+ $this->newLog($payRequestResCode, @MellatException::$errors[$payRequestResCode]);
+ throw new MellatException($payRequestResCode);
+ }
+
+ /**
+ * Verify user payment from bank server
+ *
+ * @return bool
+ *
+ * @throws MellatException
+ * @throws SoapFault
+ */
+ protected function verifyPayment()
+ {
+ $fields = array(
+ 'terminalId' => $this->config->get('gateway.mellat.terminalId'),
+ 'userName' => $this->config->get('gateway.mellat.username'),
+ 'userPassword' => $this->config->get('gateway.mellat.password'),
+ 'orderId' => $this->transactionId(),
+ 'saleOrderId' => $this->transactionId(),
+ 'saleReferenceId' => $this->trackingCode()
+ );
+
+ try {
+ $soap = new SoapClient($this->serverUrl);
+ $response = $soap->bpVerifyRequest($fields);
+ } catch (\SoapFault $e) {
+ $this->transactionFailed();
+ $this->newLog('SoapFault', $e->getMessage());
+ throw $e;
+ }
+
+ if ($response->return != '0') {
+ $this->transactionFailed();
+ $this->newLog($response->return, MellatException::$errors[$response->return]);
+ throw new MellatException($response->return);
+ }
+
+ return true;
+ }
+
+ /**
+ * Send settle request
+ *
+ * @return bool
+ *
+ * @throws MellatException
+ * @throws SoapFault
+ */
+ protected function settleRequest()
+ {
+ $fields = array(
+ 'terminalId' => $this->config->get('gateway.mellat.terminalId'),
+ 'userName' => $this->config->get('gateway.mellat.username'),
+ 'userPassword' => $this->config->get('gateway.mellat.password'),
+ 'orderId' => $this->transactionId(),
+ 'saleOrderId' => $this->transactionId(),
+ 'saleReferenceId' => $this->trackingCode
+ );
+
+ try {
+ $soap = new SoapClient($this->serverUrl);
+ $response = $soap->bpSettleRequest($fields);
+ } catch (\SoapFault $e) {
+ $this->transactionFailed();
+ $this->newLog('SoapFault', $e->getMessage());
+ throw $e;
+ }
+
+ if ($response->return == '0' || $response->return == '45') {
+ $this->transactionSucceed();
+ $this->newLog($response->return, Enum::TRANSACTION_SUCCEED_TEXT);
+ return true;
+ }
+
+ $this->transactionFailed();
+ $this->newLog($response->return, MellatException::$errors[$response->return]);
+ throw new MellatException($response->return);
+ }
}
diff --git a/src/Parsian/Parsian.php b/src/Parsian/Parsian.php
index cd2e93fb..0e1d438c 100644
--- a/src/Parsian/Parsian.php
+++ b/src/Parsian/Parsian.php
@@ -10,196 +10,197 @@
class Parsian extends PortAbstract implements PortInterface
{
- /**
- * Url of parsian gateway web service
- *
- * @var string
- */
+ /**
+ * Url of parsian gateway web service
+ *
+ * @var string
+ */
protected $serverUrl = 'https://pec.shaparak.ir/NewIPGServices/Sale/SaleService.asmx?wsdl';
protected $serverUrlConfirm = "https://pec.shaparak.ir/NewIPGServices/Confirm/ConfirmService.asmx?WSDL";
/**
- * Address of gate for redirect
- *
- * @var string
- */
- protected $gateUrl = 'https://pec.shaparak.ir/NewIPG/?Token=';
-
- /**
- * {@inheritdoc}
- */
- public function set($amount)
- {
- $this->amount = intval($amount);
- return $this;
- }
-
- /**
- * {@inheritdoc}
- */
- public function ready()
- {
- $this->sendPayRequest();
-
- return $this;
- }
-
- /**
- * {@inheritdoc}
- */
- public function redirect()
- {
- $url = $this->gateUrl . $this->refId();
-
- return \View::make('gateway::parsian-redirector')->with(compact('url'));
- }
-
- /**
- * {@inheritdoc}
- */
- public function verify($transaction)
- {
- parent::verify($transaction);
-
- $this->verifyPayment();
-
- return $this;
- }
-
- /**
- * Sets callback url
- * @param $url
- */
- function setCallback($url)
- {
- $this->callbackUrl = $url;
- return $this;
- }
-
- /**
- * Gets callback url
- * @return string
- */
- function getCallback()
- {
- if (!$this->callbackUrl)
- $this->callbackUrl = $this->config->get('gateway.parsian.callback-url');
-
- return $this->makeCallback($this->callbackUrl, ['transaction_id' => $this->transactionId()]);
- }
-
- /**
- * Send pay request to parsian gateway
- *
- * authority === Token
- * @return bool
- *
- * @throws ParsianErrorException
- */
- protected function sendPayRequest()
- {
- $this->newTransaction();
-
- $params = array(
+ * Address of gate for redirect
+ *
+ * @var string
+ */
+ protected $gateUrl = 'https://pec.shaparak.ir/NewIPG/?Token=';
+
+ /**
+ * {@inheritdoc}
+ */
+ public function set($amount)
+ {
+ $this->amount = intval($amount);
+ return $this;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function ready()
+ {
+ $this->sendPayRequest();
+
+ return $this;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function redirect()
+ {
+ $url = $this->gateUrl . $this->refId();
+
+ return \View::make('gateway::parsian-redirector')->with(compact('url'));
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function verify($transaction)
+ {
+ parent::verify($transaction);
+
+ $this->verifyPayment();
+
+ return $this;
+ }
+
+ /**
+ * Sets callback url
+ * @param $url
+ */
+ public function setCallback($url)
+ {
+ $this->callbackUrl = $url;
+ return $this;
+ }
+
+ /**
+ * Gets callback url
+ * @return string
+ */
+ public function getCallback()
+ {
+ if (!$this->callbackUrl) {
+ $this->callbackUrl = $this->config->get('gateway.parsian.callback-url');
+ }
+
+ return $this->makeCallback($this->callbackUrl, ['transaction_id' => $this->transactionId()]);
+ }
+
+ /**
+ * Send pay request to parsian gateway
+ *
+ * authority === Token
+ * @return bool
+ *
+ * @throws ParsianErrorException
+ */
+ protected function sendPayRequest()
+ {
+ $this->newTransaction();
+
+ $params = array(
'LoginAccount' => $this->config->get('gateway.parsian.pin'),
'Amount' => $this->amount . "",
'OrderId' => $this->transactionId(),
'CallBackUrl' => $this->getCallback(),
'AdditionalData' => ""
- );
+ );
- try {
- $soap = new SoapClient($this->serverUrl);
+ try {
+ $soap = new SoapClient($this->serverUrl);
$response = $soap->SalePaymentRequest(["requestData" => $params]);
+ } catch (\SoapFault $e) {
+ $this->transactionFailed();
+ $this->newLog('SoapFault', $e->getMessage());
+ throw $e;
+ }
+ if (!isset($response->SalePaymentRequestResult)
+ || isset($response->SalePaymentRequestResult)
+ && !isset($response->SalePaymentRequestResult->Token)
+ || isset($response->SalePaymentRequestResult->Token)
+ && $response->SalePaymentRequestResult->Token == '') {
+ $errorMessage = ParsianResult::errorMessage($response->SalePaymentRequestResult->Status);
+ $this->transactionFailed();
+ $this->newLog($response->SalePaymentRequestResult->Status, $errorMessage);
+ throw new ParsianErrorException($errorMessage, $response->SalePaymentRequestResult->Status);
+ }
+ if ($response !== false) {
+ $authority = $response->SalePaymentRequestResult->Token;
+ $status = $response->SalePaymentRequestResult->Status;
+
+ if ($authority && $status == 0) {
+ $this->refId = $authority;
+ $this->transactionSetRefId();
+ return true;
+ }
+
+ $errorMessage = ParsianResult::errorMessage($status);
+ $this->transactionFailed();
+ $this->newLog($status, $errorMessage);
+ throw new ParsianErrorException($errorMessage, $status);
+ } else {
+ $this->transactionFailed();
+ $this->newLog(-1, 'خطا در اتصال به درگاه پارسیان');
+ throw new ParsianErrorException('خطا در اتصال به درگاه پارسیان', -1);
+ }
+ }
- } catch (\SoapFault $e) {
- $this->transactionFailed();
- $this->newLog('SoapFault', $e->getMessage());
- throw $e;
- }
- if (!isset($response->SalePaymentRequestResult)
- || isset($response->SalePaymentRequestResult)
- && !isset($response->SalePaymentRequestResult->Token)
- || isset($response->SalePaymentRequestResult->Token)
- && $response->SalePaymentRequestResult->Token == '') {
- $errorMessage = ParsianResult::errorMessage($response->SalePaymentRequestResult->Status);
- $this->transactionFailed();
- $this->newLog($response->SalePaymentRequestResult->Status, $errorMessage);
- throw new ParsianErrorException($errorMessage, $response->SalePaymentRequestResult->Status);
- }
- if ($response !== false) {
- $authority = $response->SalePaymentRequestResult->Token;
- $status = $response->SalePaymentRequestResult->Status;
-
- if ($authority && $status == 0) {
- $this->refId = $authority;
- $this->transactionSetRefId();
- return true;
- }
-
- $errorMessage = ParsianResult::errorMessage($status);
- $this->transactionFailed();
- $this->newLog($status, $errorMessage);
- throw new ParsianErrorException($errorMessage, $status);
-
- } else {
- $this->transactionFailed();
- $this->newLog(-1, 'خطا در اتصال به درگاه پارسیان');
- throw new ParsianErrorException('خطا در اتصال به درگاه پارسیان', -1);
- }
- }
-
- /**
- * Verify payment
- * @throws ParsianErrorException
- */
- protected function verifyPayment()
- {
- if (!Request::has('Token') && !Request::has('status'))
+ /**
+ * Verify payment
+ * @throws ParsianErrorException
+ */
+ protected function verifyPayment()
+ {
+ if (!Request::has('Token') && !Request::has('status')) {
throw new ParsianErrorException('درخواست غیر معتبر', -1);
+ }
- $authority = Request::input('Token');
- $status = Request::input('status');
+ $authority = Request::input('Token');
+ $status = Request::input('status');
- if ($status != 0) {
- $errorMessage = ParsianResult::errorMessage($status);
- $this->newLog($status, $errorMessage);
- throw new ParsianErrorException($errorMessage, $status);
- }
+ if ($status != 0) {
+ $errorMessage = ParsianResult::errorMessage($status);
+ $this->newLog($status, $errorMessage);
+ throw new ParsianErrorException($errorMessage, $status);
+ }
- if ($this->refId != $authority)
- throw new ParsianErrorException('تراکنشی یافت نشد', -1);
+ if ($this->refId != $authority) {
+ throw new ParsianErrorException('تراکنشی یافت نشد', -1);
+ }
- $params = array(
+ $params = array(
'LoginAccount' => $this->config->get('gateway.parsian.pin'),
'Token' => $authority,
- );
+ );
- try {
+ try {
$soap = new SoapClient($this->serverUrlConfirm);
$result = $soap->ConfirmPayment([
"requestData" => $params
]);
+ } catch (\SoapFault $e) {
+ throw new ParsianErrorException($e->getMessage(), -1);
+ }
- } catch (\SoapFault $e) {
- throw new ParsianErrorException($e->getMessage(), -1);
- }
-
- if ($result === false || !isset($result->ConfirmPaymentResult->Status))
- throw new ParsianErrorException('پاسخ دریافتی از بانک نامعتبر است.', -1);
+ if ($result === false || !isset($result->ConfirmPaymentResult->Status)) {
+ throw new ParsianErrorException('پاسخ دریافتی از بانک نامعتبر است.', -1);
+ }
if ($result->ConfirmPaymentResult->Status != 0) {
$errorMessage = ParsianResult::errorMessage($result->ConfirmPaymentResult->Status);
- $this->transactionFailed();
+ $this->transactionFailed();
$this->newLog($result->ConfirmPaymentResult->Status, $errorMessage);
throw new ParsianErrorException($errorMessage, $result->ConfirmPaymentResult->Status);
- }
+ }
- $this->trackingCode = $result->ConfirmPaymentResult->RRN;
- $this->cardNumber = $result->ConfirmPaymentResult->CardNumberMasked;
- $this->transactionSucceed();
+ $this->trackingCode = $result->ConfirmPaymentResult->RRN;
+ $this->cardNumber = $result->ConfirmPaymentResult->CardNumberMasked;
+ $this->transactionSucceed();
$this->newLog($result->ConfirmPaymentResult->Status, ParsianResult::errorMessage($result->ConfirmPaymentResult->Status));
- }
+ }
}
diff --git a/src/Parsian/ParsianErrorException.php b/src/Parsian/ParsianErrorException.php
index 3d6fbcc6..ef78421c 100644
--- a/src/Parsian/ParsianErrorException.php
+++ b/src/Parsian/ParsianErrorException.php
@@ -4,4 +4,6 @@
use Larabookir\Gateway\Exceptions\BankException;
-class ParsianErrorException extends BankException {}
+class ParsianErrorException extends BankException
+{
+}
diff --git a/src/Parsian/ParsianResult.php b/src/Parsian/ParsianResult.php
index 0ea4b38c..b21275f3 100644
--- a/src/Parsian/ParsianResult.php
+++ b/src/Parsian/ParsianResult.php
@@ -2,7 +2,6 @@
namespace Larabookir\Gateway\Parsian;
-
class ParsianResult
{
public static $errors
@@ -29,8 +28,8 @@ class ParsianResult
34 => 'شماره تراکنش فروشنده درست نمی باشد.',
];
- public static function errorMessage($errorId)
- {
- return isset(self::$errors[$errorId]) ? self::$errors[$errorId] : $errorId;
- }
+ public static function errorMessage($errorId)
+ {
+ return isset(self::$errors[$errorId]) ? self::$errors[$errorId] : $errorId;
+ }
}
diff --git a/src/Pasargad/Parser.php b/src/Pasargad/Parser.php
index 3e944720..47f76d76 100644
--- a/src/Pasargad/Parser.php
+++ b/src/Pasargad/Parser.php
@@ -35,7 +35,7 @@ public static function makeXMLTree($data)
break;
case 'complete':
array_push($hash_stack, $val['tag']);
- if(!isset($val['value'])){
+ if (!isset($val['value'])) {
$val['value'] = $temp[$val['tag']];
}
@@ -72,7 +72,7 @@ public static function post2https($fields_arr, $url)
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, count($fields_arr));
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string);
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
+ curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
diff --git a/src/Pasargad/Pasargad.php b/src/Pasargad/Pasargad.php
index 792c2160..a65fbf76 100644
--- a/src/Pasargad/Pasargad.php
+++ b/src/Pasargad/Pasargad.php
@@ -51,7 +51,6 @@ public function ready($payment_id, $callback_url)
*/
public function redirect()
{
-
$processor = new RSAProcessor($this->config->get('gateway.pasargad.certificate-path'), RSAKeyType::XMLFile);
$url = $this->gateUrl;
@@ -88,7 +87,7 @@ public function verify($transaction)
* @param $url
* @return $this|string
*/
- function setCallback($url)
+ public function setCallback($url)
{
$this->callbackUrl = $url;
return $this;
@@ -98,10 +97,11 @@ function setCallback($url)
* Gets callback url
* @return string
*/
- function getCallback()
+ public function getCallback()
{
- if (!$this->callbackUrl)
+ if (!$this->callbackUrl) {
$this->callbackUrl = $this->config->get('gateway.pasargad.callback-url');
+ }
return $this->callbackUrl;
}
@@ -190,6 +190,6 @@ private function convertXMLtoArray($xmlString)
$xml = simplexml_load_string($xmlString, "SimpleXMLElement", LIBXML_NOCDATA);
$json = json_encode($xml);
- return json_decode($json,True);
+ return json_decode($json, true);
}
}
diff --git a/src/Pasargad/PasargadErrorException.php b/src/Pasargad/PasargadErrorException.php
index 205e56bd..4522729a 100644
--- a/src/Pasargad/PasargadErrorException.php
+++ b/src/Pasargad/PasargadErrorException.php
@@ -4,4 +4,6 @@
use Larabookir\Gateway\Exceptions\BankException;
-class PasargadErrorException extends BankException {}
+class PasargadErrorException extends BankException
+{
+}
diff --git a/src/Pasargad/PasargadResult.php b/src/Pasargad/PasargadResult.php
index 9bc75c7e..c1a4235f 100644
--- a/src/Pasargad/PasargadResult.php
+++ b/src/Pasargad/PasargadResult.php
@@ -2,116 +2,116 @@
namespace Larabookir\Gateway\Pasargad;
-
class PasargadResult
{
- public static function errorMessage($state) {
- $state = strtolower((string)$state);
- switch ($state) {
- case "canceled by user" :
- $message = _("Canceled By User");
- break;
- case "invalid amount" :
- $message = _("Invalid Amount");
- break;
- case "invalid transaction" :
- $message = _("Invalid Transaction");
- break;
- case "invalid card number" :
- $message = _("Invalid Card Number");
- break;
- case "no such issuer" :
- $message = _("No Such Issuer");
- break;
- case "expired card pick up" :
- $message = _("Expired Card Pick Up");
- break;
- case "allowable pin tries exceeded pick up" :
- $message = _("Allowable PIN Tries Exceeded Pick Up");
- break;
- case "incorrect pin" :
- $message = _("Incorrect PIN");
- break;
- case "exceeds withdrawal amount limit" :
- $message = _("Exceeds Withdrawal Amount Limit");
- break;
- case "transaction cannot be completed" :
- $message = _("Transaction Cannot Be Completed");
- break;
- case "response received too late" :
- $message = _("Response Received Too Late");
- break;
- case "suspected fraud pick up" :
- $message = _("Suspected Fraud Pick Up");
- break;
- case "no sufficient funds" :
- $message = _("No Sufficient Funds");
- break;
- case "issuer down slm" :
- $message = _("Issuer Down Slm");
- break;
- case "tme error" :
- $message = _("TME Error");
- break;
- // errorNumber
- case "-1" :
- $message = _("Internal Error");
- break;
- case "-3" :
- $message = _("TME Error");
- break;
- case "-4" :
- $message = _("Merchant Authentication Failed");
- break;
- case "-6" :
- $message = _("Transaction Refunded");
- break;
- case "-7" :
- $message = _("Transaction Id Empty");
- break;
- case "-8" :
- $message = _("Parameter is too long");
- break;
- case "-9" :
- $message = _("amount value is invalid");
- break;
- case "-10" :
- $message = _("Transaction Id Not Base64");
- break;
- case "-11" :
- $message = _("Parameter is too short");
- break;
- case "-12" :
- $message = _("amount value is invalid");
- break;
- case "-13" :
- $message = _("refund amount value is invalid");
- break;
- case "-14" :
- $message = _("Transaction Id invalid");
- break;
- case "-15" :
- $message = _("refund amount value is float!");
- break;
- case "-16" :
- $message = _("Internal Error");
- break;
- case "-17" :
- $message = _("refund amount is not saman");
- break;
- case "-18" :
- $message = _("Merchant IP Invalid");
- break;
+ public static function errorMessage($state)
+ {
+ $state = strtolower((string)$state);
+ switch ($state) {
+ case "canceled by user":
+ $message = _("Canceled By User");
+ break;
+ case "invalid amount":
+ $message = _("Invalid Amount");
+ break;
+ case "invalid transaction":
+ $message = _("Invalid Transaction");
+ break;
+ case "invalid card number":
+ $message = _("Invalid Card Number");
+ break;
+ case "no such issuer":
+ $message = _("No Such Issuer");
+ break;
+ case "expired card pick up":
+ $message = _("Expired Card Pick Up");
+ break;
+ case "allowable pin tries exceeded pick up":
+ $message = _("Allowable PIN Tries Exceeded Pick Up");
+ break;
+ case "incorrect pin":
+ $message = _("Incorrect PIN");
+ break;
+ case "exceeds withdrawal amount limit":
+ $message = _("Exceeds Withdrawal Amount Limit");
+ break;
+ case "transaction cannot be completed":
+ $message = _("Transaction Cannot Be Completed");
+ break;
+ case "response received too late":
+ $message = _("Response Received Too Late");
+ break;
+ case "suspected fraud pick up":
+ $message = _("Suspected Fraud Pick Up");
+ break;
+ case "no sufficient funds":
+ $message = _("No Sufficient Funds");
+ break;
+ case "issuer down slm":
+ $message = _("Issuer Down Slm");
+ break;
+ case "tme error":
+ $message = _("TME Error");
+ break;
+ // errorNumber
+ case "-1":
+ $message = _("Internal Error");
+ break;
+ case "-3":
+ $message = _("TME Error");
+ break;
+ case "-4":
+ $message = _("Merchant Authentication Failed");
+ break;
+ case "-6":
+ $message = _("Transaction Refunded");
+ break;
+ case "-7":
+ $message = _("Transaction Id Empty");
+ break;
+ case "-8":
+ $message = _("Parameter is too long");
+ break;
+ case "-9":
+ $message = _("amount value is invalid");
+ break;
+ case "-10":
+ $message = _("Transaction Id Not Base64");
+ break;
+ case "-11":
+ $message = _("Parameter is too short");
+ break;
+ case "-12":
+ $message = _("amount value is invalid");
+ break;
+ case "-13":
+ $message = _("refund amount value is invalid");
+ break;
+ case "-14":
+ $message = _("Transaction Id invalid");
+ break;
+ case "-15":
+ $message = _("refund amount value is float!");
+ break;
+ case "-16":
+ $message = _("Internal Error");
+ break;
+ case "-17":
+ $message = _("refund amount is not saman");
+ break;
+ case "-18":
+ $message = _("Merchant IP Invalid");
+ break;
- case "refunded amount" :
- $message = _("Refunded Amount");
- break;
+ case "refunded amount":
+ $message = _("Refunded Amount");
+ break;
- default :
- $message = _("UNKOWN_ERROR");
- break;
- }
+ default:
+ $message = _("UNKOWN_ERROR");
+ break;
+ }
- return $message;
- }
+ return $message;
+ }
}
diff --git a/src/Pasargad/RSA.php b/src/Pasargad/RSA.php
index 1ac393ea..1f43acee 100644
--- a/src/Pasargad/RSA.php
+++ b/src/Pasargad/RSA.php
@@ -1,5 +1,6 @@
callbackUrl = $url;
return $this;
@@ -96,10 +96,11 @@ function setCallback($url)
* Gets callback url
* @return string
*/
- function getCallback()
+ public function getCallback()
{
- if (!$this->callbackUrl)
+ if (!$this->callbackUrl) {
$this->callbackUrl = $this->config->get('gateway.payir.callback-url');
+ }
return urlencode($this->makeCallback($this->callbackUrl, ['transaction_id' => $this->transactionId()]));
}
@@ -119,8 +120,9 @@ protected function sendPayRequest()
'redirect' => $this->getCallback(),
];
- if (isset($this->factorNumber))
+ if (isset($this->factorNumber)) {
$fields['factorNumber'] = $this->factorNumber;
+ }
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $this->serverUrl);
diff --git a/src/Payline/Payline.php b/src/Payline/Payline.php
index 7ea98146..5c5dc5cd 100644
--- a/src/Payline/Payline.php
+++ b/src/Payline/Payline.php
@@ -9,185 +9,186 @@
class Payline extends PortAbstract implements PortInterface
{
- /**
- * Address of main CURL server
- *
- * @var string
- */
- protected $serverUrl = 'https://pay.ir/payment/send';
-
- /**
- * Address of CURL server for verify payment
- *
- * @var string
- */
- protected $serverVerifyUrl = 'https://pay.ir/payment/verify';
-
- /**
- * Address of gate for redirect
- *
- * @var string
- */
- protected $gateUrl = 'https://pay.ir/payment/gateway/';
-
- /**
- * {@inheritdoc}
- */
- public function set($amount)
- {
- $this->amount = $amount;
-
- return $this;
- }
-
- /**
- * {@inheritdoc}
- */
- public function ready()
- {
- $this->sendPayRequest();
-
- return $this;
- }
-
- /**
- * {@inheritdoc}
- */
- public function redirect()
- {
- return \Redirect::to($this->gateUrl . $this->refId);
- }
-
- /**
- * {@inheritdoc}
- */
- public function verify($transaction)
- {
- parent::verify($transaction);
-
- $this->userPayment();
- $this->verifyPayment();
-
- return $this;
- }
-
- /**
- * Sets callback url
- * @param $url
- */
- function setCallback($url)
- {
- $this->callbackUrl = $url;
- return $this;
- }
-
- /**
- * Gets callback url
- * @return string
- */
- function getCallback()
- {
- if (!$this->callbackUrl)
- $this->callbackUrl = $this->config->get('gateway.payline.callback-url');
-
- return urlencode($this->makeCallback($this->callbackUrl, ['transaction_id' => $this->transactionId()]));
- }
-
- /**
- * Send pay request to server
- *
- * @return void
- *
- * @throws PaylineSendException
- */
- protected function sendPayRequest()
- {
- $this->newTransaction();
-
- $fields = array(
- 'api' => $this->config->get('gateway.payline.api'),
- 'amount' => $this->amount,
- 'redirect' => $this->getCallback(),
- );
-
- $ch = curl_init();
-
- curl_setopt($ch, CURLOPT_URL, $this->serverUrl);
- curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($fields));
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
-
- $response = curl_exec($ch);
- curl_close($ch);
-
- if (is_numeric($response) && $response > 0) {
- $this->refId = $response;
- $this->transactionSetRefId();
-
- return true;
- }
-
- $this->transactionFailed();
- $this->newLog($response, PaylineSendException::$errors[$response]);
- throw new PaylineSendException($response);
- }
-
- /**
- * Check user payment with GET data
- *
- * @return bool
- *
- * @throws PaylineReceiveException
- */
- protected function userPayment()
- {
- $this->refIf = Request::input('id_get');
- $trackingCode = Request::input('trans_id');
-
- if (is_numeric($trackingCode) && $trackingCode > 0) {
- $this->trackingCode = $trackingCode;
- return true;
- }
-
- $this->transactionFailed();
- $this->newLog(-4, PaylineReceiveException::$errors[-4]);
- throw new PaylineReceiveException(-4);
- }
-
- /**
- * Verify user payment from zarinpal server
- *
- * @return bool
- *
- * @throws PaylineReceiveException
- */
- protected function verifyPayment()
- {
- $fields = array(
- 'api' => $this->config->get('gateway.payline.api'),
- 'id_get' => $this->refId(),
- 'trans_id' => $this->trackingCode()
- );
-
- $ch = curl_init();
-
- curl_setopt($ch, CURLOPT_URL, $this->serverVerifyUrl);
- curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($fields));
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
-
- $response = curl_exec($ch);
- curl_close($ch);
-
- if ($response == 1) {
- $this->transactionSucceed();
- $this->newLog($response, Enum::TRANSACTION_SUCCEED_TEXT);
-
- return true;
- }
-
- $this->transactionFailed();
- $this->newLog($response, PaylineReceiveException::$errors[$response]);
- throw new PaylineReceiveException($response);
- }
+ /**
+ * Address of main CURL server
+ *
+ * @var string
+ */
+ protected $serverUrl = 'https://pay.ir/payment/send';
+
+ /**
+ * Address of CURL server for verify payment
+ *
+ * @var string
+ */
+ protected $serverVerifyUrl = 'https://pay.ir/payment/verify';
+
+ /**
+ * Address of gate for redirect
+ *
+ * @var string
+ */
+ protected $gateUrl = 'https://pay.ir/payment/gateway/';
+
+ /**
+ * {@inheritdoc}
+ */
+ public function set($amount)
+ {
+ $this->amount = $amount;
+
+ return $this;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function ready()
+ {
+ $this->sendPayRequest();
+
+ return $this;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function redirect()
+ {
+ return \Redirect::to($this->gateUrl . $this->refId);
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function verify($transaction)
+ {
+ parent::verify($transaction);
+
+ $this->userPayment();
+ $this->verifyPayment();
+
+ return $this;
+ }
+
+ /**
+ * Sets callback url
+ * @param $url
+ */
+ public function setCallback($url)
+ {
+ $this->callbackUrl = $url;
+ return $this;
+ }
+
+ /**
+ * Gets callback url
+ * @return string
+ */
+ public function getCallback()
+ {
+ if (!$this->callbackUrl) {
+ $this->callbackUrl = $this->config->get('gateway.payline.callback-url');
+ }
+
+ return urlencode($this->makeCallback($this->callbackUrl, ['transaction_id' => $this->transactionId()]));
+ }
+
+ /**
+ * Send pay request to server
+ *
+ * @return void
+ *
+ * @throws PaylineSendException
+ */
+ protected function sendPayRequest()
+ {
+ $this->newTransaction();
+
+ $fields = array(
+ 'api' => $this->config->get('gateway.payline.api'),
+ 'amount' => $this->amount,
+ 'redirect' => $this->getCallback(),
+ );
+
+ $ch = curl_init();
+
+ curl_setopt($ch, CURLOPT_URL, $this->serverUrl);
+ curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($fields));
+ curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
+
+ $response = curl_exec($ch);
+ curl_close($ch);
+
+ if (is_numeric($response) && $response > 0) {
+ $this->refId = $response;
+ $this->transactionSetRefId();
+
+ return true;
+ }
+
+ $this->transactionFailed();
+ $this->newLog($response, PaylineSendException::$errors[$response]);
+ throw new PaylineSendException($response);
+ }
+
+ /**
+ * Check user payment with GET data
+ *
+ * @return bool
+ *
+ * @throws PaylineReceiveException
+ */
+ protected function userPayment()
+ {
+ $this->refIf = Request::input('id_get');
+ $trackingCode = Request::input('trans_id');
+
+ if (is_numeric($trackingCode) && $trackingCode > 0) {
+ $this->trackingCode = $trackingCode;
+ return true;
+ }
+
+ $this->transactionFailed();
+ $this->newLog(-4, PaylineReceiveException::$errors[-4]);
+ throw new PaylineReceiveException(-4);
+ }
+
+ /**
+ * Verify user payment from zarinpal server
+ *
+ * @return bool
+ *
+ * @throws PaylineReceiveException
+ */
+ protected function verifyPayment()
+ {
+ $fields = array(
+ 'api' => $this->config->get('gateway.payline.api'),
+ 'id_get' => $this->refId(),
+ 'trans_id' => $this->trackingCode()
+ );
+
+ $ch = curl_init();
+
+ curl_setopt($ch, CURLOPT_URL, $this->serverVerifyUrl);
+ curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($fields));
+ curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
+
+ $response = curl_exec($ch);
+ curl_close($ch);
+
+ if ($response == 1) {
+ $this->transactionSucceed();
+ $this->newLog($response, Enum::TRANSACTION_SUCCEED_TEXT);
+
+ return true;
+ }
+
+ $this->transactionFailed();
+ $this->newLog($response, PaylineReceiveException::$errors[$response]);
+ throw new PaylineReceiveException($response);
+ }
}
diff --git a/src/Paypal/Paypal.php b/src/Paypal/Paypal.php
index fbf3bc5f..03f675e1 100644
--- a/src/Paypal/Paypal.php
+++ b/src/Paypal/Paypal.php
@@ -44,7 +44,7 @@ public function set($amount)
* Sets callback url
* @param $url
*/
- function setCallback($url)
+ public function setCallback($url)
{
$this->callbackUrl = $url;
return $this;
@@ -59,10 +59,11 @@ public function redirect()
* Gets callback url
* @return string
*/
- function getCallback()
+ public function getCallback()
{
- if (!$this->callbackUrl)
+ if (!$this->callbackUrl) {
$this->callbackUrl = $this->config->get('gateway.paypal.settings.call_back_url');
+ }
return $this->makeCallback($this->callbackUrl, ['transaction_id' => $this->transactionId()]);
}
@@ -110,7 +111,8 @@ public function verify($transaction)
return $this;
}
- public function setProductName($name){
+ public function setProductName($name)
+ {
$this->productName = $name;
return $this;
@@ -234,21 +236,21 @@ protected function verifyPayment()
}
}
- public function getProductName(){
- if(!$this->productName){
+ public function getProductName()
+ {
+ if (!$this->productName) {
return $this->config->get('gateway.paypal.default_product_name');
}
return $this->productName;
}
- public function getShipmentPrice(){
- if(!$this->shipmentPrice){
+ public function getShipmentPrice()
+ {
+ if (!$this->shipmentPrice) {
return $this->config->get('gateway.paypal.default_shipment_price');
}
return $this->shipmentPrice;
}
-
-
-}
\ No newline at end of file
+}
diff --git a/src/PortAbstract.php b/src/PortAbstract.php
index bccbf060..3264d49a 100644
--- a/src/PortAbstract.php
+++ b/src/PortAbstract.php
@@ -7,286 +7,287 @@
abstract class PortAbstract
{
- /**
- * Transaction id
- *
- * @var null|int
- */
- protected $transactionId = null;
-
- /**
- * Transaction row in database
- */
- protected $transaction = null;
-
- /**
- * Customer card number
- *
- * @var string
- */
- protected $cardNumber = '';
-
- /**
- * @var Config
- */
- protected $config;
-
- /**
- * Port id
- *
- * @var int
- */
- protected $portName;
-
- /**
- * Reference id
- *
- * @var string
- */
- protected $refId;
-
- /**
- * Amount in Rial
- *
- * @var int
- */
- protected $amount;
-
- /**
- * Description of transaction
- *
- * @var string
- */
- protected $description;
-
- /**
- * Custom Invoice Number of transaction
- *
- * @var string
- */
- protected $customInvoiceNo;
-
- /**
- * callback URL
- *
- * @var url
- */
- protected $callbackUrl;
-
- /**
- * Tracking code payment
- *
- * @var string
- */
- protected $trackingCode;
-
- /**
- * Initialize of class
- *
- * @param Config $config
- * @param DataBaseManager $db
- * @param int $port
- */
- function __construct()
- {
- $this->db = app('db');
- }
-
- /** bootstraper */
- function boot(){
-
- }
-
- function setConfig($config)
- {
- $this->config = $config;
- }
-
- /**
- * @return mixed
- */
- function getTable()
- {
- return $this->db->table($this->config->get('gateway.table'));
- }
-
- /**
- * @return mixed
- */
- function getLogTable()
- {
- return $this->db->table($this->config->get('gateway.table') . '_logs');
- }
-
- /**
- * Get port id, $this->port
- *
- * @return int
- */
- function getPortName()
- {
- return $this->portName;
- }
-
- /**
- * Get port id, $this->port
- *
- * @return int
- */
- function setPortName($name)
- {
- $this->portName = $name;
- }
-
- /**
- * Set custom description on current transaction
- *
- * @param string $description
- *
- * @return void
- */
- function setCustomDesc ($description)
- {
- $this->description = $description;
- }
-
- /**
- * Get custom description of current transaction
- *
- * @return string | null
- */
- function getCustomDesc ()
- {
- return $this->description;
- }
-
- /**
- * Set custom Invoice number on current transaction
- *
- * @param string $description
- *
- * @return void
- */
- function setCustomInvoiceNo ($invoiceNo)
- {
- $this->customInvoiceNo = $invoiceNo;
- }
-
- /**
- * Get custom Invoice number of current transaction
- *
- * @return string | null
- */
- function getCustomInvoiceNo ()
- {
- return $this->customInvoiceNo;
- }
-
- /**
- * Return card number
- *
- * @return string
- */
- function cardNumber()
- {
- return $this->cardNumber;
- }
-
- /**
- * Return tracking code
- */
- function trackingCode()
- {
- return $this->trackingCode;
- }
-
- /**
- * Get transaction id
- *
- * @return int|null
- */
- function transactionId()
- {
- return $this->transactionId;
- }
-
- /**
- * Return reference id
- */
- function refId()
- {
- return $this->refId;
- }
-
- /**
- * Sets price
- * @param $price
- * @return mixed
- */
- function price($price)
- {
- return $this->set($price);
- }
-
- /**
- * get price
- */
- function getPrice()
- {
- return $this->amount;
- }
-
- /**
- * Return result of payment
- * If result is done, return true, otherwise throws an related exception
- *
- * This method must be implements in child class
- *
- * @param object $transaction row of transaction in database
- *
- * @return $this
- */
- function verify($transaction)
- {
- $this->transaction = $transaction;
- $this->transactionId = $transaction->id;
- $this->amount = intval($transaction->price);
- $this->refId = $transaction->ref_id;
- }
-
- function getTimeId()
- {
- $genuid = function(){
- return substr(str_pad(str_replace('.','', microtime(true)),12,0),0,12);
- };
- $uid=$genuid();
- while ($this->getTable()->whereId($uid)->first())
- $uid = $genuid();
- return $uid;
- }
-
- /**
- * Insert new transaction to poolport_transactions table
- *
- * @return int last inserted id
- */
- protected function newTransaction()
- {
- $uid = $this->getTimeId();
-
- $this->transactionId = $this->getTable()->insert([
- 'id' => $uid,
- 'port' => $this->getPortName(),
- 'price' => $this->amount,
- 'status' => Enum::TRANSACTION_INIT,
- 'ip' => Request::getClientIp(),
- 'description' => $this->description,
- 'created_at' => Carbon::now(),
- 'updated_at' => Carbon::now(),
- ]) ? $uid : null;
-
- return $this->transactionId;
- }
+ /**
+ * Transaction id
+ *
+ * @var null|int
+ */
+ protected $transactionId = null;
+
+ /**
+ * Transaction row in database
+ */
+ protected $transaction = null;
+
+ /**
+ * Customer card number
+ *
+ * @var string
+ */
+ protected $cardNumber = '';
+
+ /**
+ * @var Config
+ */
+ protected $config;
+
+ /**
+ * Port id
+ *
+ * @var int
+ */
+ protected $portName;
+
+ /**
+ * Reference id
+ *
+ * @var string
+ */
+ protected $refId;
+
+ /**
+ * Amount in Rial
+ *
+ * @var int
+ */
+ protected $amount;
+
+ /**
+ * Description of transaction
+ *
+ * @var string
+ */
+ protected $description;
+
+ /**
+ * Custom Invoice Number of transaction
+ *
+ * @var string
+ */
+ protected $customInvoiceNo;
+
+ /**
+ * callback URL
+ *
+ * @var url
+ */
+ protected $callbackUrl;
+
+ /**
+ * Tracking code payment
+ *
+ * @var string
+ */
+ protected $trackingCode;
+
+ /**
+ * Initialize of class
+ *
+ * @param Config $config
+ * @param DataBaseManager $db
+ * @param int $port
+ */
+ public function __construct()
+ {
+ $this->db = app('db');
+ }
+
+ /** bootstraper */
+ public function boot()
+ {
+ }
+
+ public function setConfig($config)
+ {
+ $this->config = $config;
+ }
+
+ /**
+ * @return mixed
+ */
+ public function getTable()
+ {
+ return $this->db->table($this->config->get('gateway.table'));
+ }
+
+ /**
+ * @return mixed
+ */
+ public function getLogTable()
+ {
+ return $this->db->table($this->config->get('gateway.table') . '_logs');
+ }
+
+ /**
+ * Get port id, $this->port
+ *
+ * @return int
+ */
+ public function getPortName()
+ {
+ return $this->portName;
+ }
+
+ /**
+ * Get port id, $this->port
+ *
+ * @return int
+ */
+ public function setPortName($name)
+ {
+ $this->portName = $name;
+ }
+
+ /**
+ * Set custom description on current transaction
+ *
+ * @param string $description
+ *
+ * @return void
+ */
+ public function setCustomDesc($description)
+ {
+ $this->description = $description;
+ }
+
+ /**
+ * Get custom description of current transaction
+ *
+ * @return string | null
+ */
+ public function getCustomDesc()
+ {
+ return $this->description;
+ }
+
+ /**
+ * Set custom Invoice number on current transaction
+ *
+ * @param string $description
+ *
+ * @return void
+ */
+ public function setCustomInvoiceNo($invoiceNo)
+ {
+ $this->customInvoiceNo = $invoiceNo;
+ }
+
+ /**
+ * Get custom Invoice number of current transaction
+ *
+ * @return string | null
+ */
+ public function getCustomInvoiceNo()
+ {
+ return $this->customInvoiceNo;
+ }
+
+ /**
+ * Return card number
+ *
+ * @return string
+ */
+ public function cardNumber()
+ {
+ return $this->cardNumber;
+ }
+
+ /**
+ * Return tracking code
+ */
+ public function trackingCode()
+ {
+ return $this->trackingCode;
+ }
+
+ /**
+ * Get transaction id
+ *
+ * @return int|null
+ */
+ public function transactionId()
+ {
+ return $this->transactionId;
+ }
+
+ /**
+ * Return reference id
+ */
+ public function refId()
+ {
+ return $this->refId;
+ }
+
+ /**
+ * Sets price
+ * @param $price
+ * @return mixed
+ */
+ public function price($price)
+ {
+ return $this->set($price);
+ }
+
+ /**
+ * get price
+ */
+ public function getPrice()
+ {
+ return $this->amount;
+ }
+
+ /**
+ * Return result of payment
+ * If result is done, return true, otherwise throws an related exception
+ *
+ * This method must be implements in child class
+ *
+ * @param object $transaction row of transaction in database
+ *
+ * @return $this
+ */
+ public function verify($transaction)
+ {
+ $this->transaction = $transaction;
+ $this->transactionId = $transaction->id;
+ $this->amount = intval($transaction->price);
+ $this->refId = $transaction->ref_id;
+ }
+
+ public function getTimeId()
+ {
+ $genuid = function () {
+ return substr(str_pad(str_replace('.', '', microtime(true)), 12, 0), 0, 12);
+ };
+ $uid=$genuid();
+ while ($this->getTable()->whereId($uid)->first()) {
+ $uid = $genuid();
+ }
+ return $uid;
+ }
+
+ /**
+ * Insert new transaction to poolport_transactions table
+ *
+ * @return int last inserted id
+ */
+ protected function newTransaction()
+ {
+ $uid = $this->getTimeId();
+
+ $this->transactionId = $this->getTable()->insert([
+ 'id' => $uid,
+ 'port' => $this->getPortName(),
+ 'price' => $this->amount,
+ 'status' => Enum::TRANSACTION_INIT,
+ 'ip' => Request::getClientIp(),
+ 'description' => $this->description,
+ 'created_at' => Carbon::now(),
+ 'updated_at' => Carbon::now(),
+ ]) ? $uid : null;
+
+ return $this->transactionId;
+ }
/**
* Commit transaction
@@ -295,9 +296,9 @@ protected function newTransaction()
* @param array $fields
* @return mixed
*/
- protected function transactionSucceed(array $fields = [])
- {
- $updateFields = [
+ protected function transactionSucceed(array $fields = [])
+ {
+ $updateFields = [
'status' => Enum::TRANSACTION_SUCCEED,
'tracking_code' => $this->trackingCode,
'card_number' => $this->cardNumber,
@@ -305,93 +306,102 @@ protected function transactionSucceed(array $fields = [])
'updated_at' => Carbon::now(),
];
- if (!empty($fields)) {
- $updateFields = array_merge($updateFields, $fields);
+ if (!empty($fields)) {
+ $updateFields = array_merge($updateFields, $fields);
+ }
+
+ return $this->getTable()->whereId($this->transactionId)->update($updateFields);
+ }
+
+ /**
+ * Failed transaction
+ * Set status field to error status
+ *
+ * @return bool
+ */
+ protected function transactionFailed()
+ {
+ return $this->getTable()->whereId($this->transactionId)->update([
+ 'status' => Enum::TRANSACTION_FAILED,
+ 'updated_at' => Carbon::now(),
+ ]);
+ }
+
+ /**
+ * Update transaction refId
+ *
+ * @return void
+ */
+ protected function transactionSetRefId()
+ {
+ return $this->getTable()->whereId($this->transactionId)->update([
+ 'ref_id' => $this->refId,
+ 'updated_at' => Carbon::now(),
+ ]);
+ }
+
+ /**
+ * New log
+ *
+ * @param string|int $statusCode
+ * @param string $statusMessage
+ */
+ protected function newLog($statusCode, $statusMessage)
+ {
+ return $this->getLogTable()->insert([
+ 'transaction_id' => $this->transactionId,
+ 'result_code' => $statusCode,
+ 'result_message' => $statusMessage,
+ 'log_date' => Carbon::now(),
+ ]);
+ }
+
+ /**
+ * Add query string to a url
+ *
+ * @param string $url
+ * @param array $query
+ * @return string
+ */
+ protected function makeCallback($url, array $query)
+ {
+ if (isset($query['transaction_id'])) {
+ $query['transaction_id'] = \encrypt($query['transaction_id']);
+ }
+ return $this->url_modify(array_merge($query, ['_token' => csrf_token()]), url($url));
+ }
+
+ /**
+ * manipulate the Current/Given URL with the given parameters
+ * @param $changes
+ * @param $url
+ * @return string
+ */
+
+ protected function url_modify($changes, $url)
+ {
+ // Parse the url into pieces
+ $url_array = parse_url($url);
+
+ // The original URL had a query string, modify it.
+ if (!empty($url_array['query'])) {
+ parse_str($url_array['query'], $query_array);
+ $query_array = array_merge($query_array, $changes);
+ } // The original URL didn't have a query string, add it.
+ else {
+ $query_array = $changes;
}
- return $this->getTable()->whereId($this->transactionId)->update($updateFields);
- }
-
- /**
- * Failed transaction
- * Set status field to error status
- *
- * @return bool
- */
- protected function transactionFailed()
- {
- return $this->getTable()->whereId($this->transactionId)->update([
- 'status' => Enum::TRANSACTION_FAILED,
- 'updated_at' => Carbon::now(),
- ]);
- }
-
- /**
- * Update transaction refId
- *
- * @return void
- */
- protected function transactionSetRefId()
- {
- return $this->getTable()->whereId($this->transactionId)->update([
- 'ref_id' => $this->refId,
- 'updated_at' => Carbon::now(),
- ]);
-
- }
-
- /**
- * New log
- *
- * @param string|int $statusCode
- * @param string $statusMessage
- */
- protected function newLog($statusCode, $statusMessage)
- {
- return $this->getLogTable()->insert([
- 'transaction_id' => $this->transactionId,
- 'result_code' => $statusCode,
- 'result_message' => $statusMessage,
- 'log_date' => Carbon::now(),
- ]);
- }
-
- /**
- * Add query string to a url
- *
- * @param string $url
- * @param array $query
- * @return string
- */
- protected function makeCallback($url, array $query)
- {
- return $this->url_modify(array_merge($query, ['_token' => csrf_token()]), url($url));
- }
-
- /**
- * manipulate the Current/Given URL with the given parameters
- * @param $changes
- * @param $url
- * @return string
- */
- protected function url_modify($changes, $url)
- {
- // Parse the url into pieces
- $url_array = parse_url($url);
-
- // The original URL had a query string, modify it.
- if (!empty($url_array['query'])) {
- parse_str($url_array['query'], $query_array);
- $query_array = array_merge($query_array, $changes);
- } // The original URL didn't have a query string, add it.
- else {
- $query_array = $changes;
- }
-
- return (!empty($url_array['scheme']) ? $url_array['scheme'] . '://' : null) .
- (!empty($url_array['host']) ? $url_array['host'] : null) .
- (!empty($url_array['port']) ? ':' . $url_array['port'] : null) .
+ return (!empty($url_array['scheme']) ? $url_array['scheme'] . '://' : null) .
+ (!empty($url_array['host']) ? $url_array['host'] : null) .
+ (!empty($url_array['port']) ? ':' . $url_array['port'] : null) .
(!empty($url_array['path']) ? $url_array['path'] : null) .
'?' . http_build_query($query_array);
- }
+ }
+
+ public function setFactorNumber($factorNumber)
+ {
+ $this->factorNumber = $factorNumber;
+ return $this;
+ }
}
diff --git a/src/Sadad/Sadad.php b/src/Sadad/Sadad.php
index 7010c6b5..2439fa6e 100644
--- a/src/Sadad/Sadad.php
+++ b/src/Sadad/Sadad.php
@@ -8,197 +8,197 @@
class Sadad extends PortAbstract implements PortInterface
{
- /**
- * Url of sadad gateway web service
- *
- * @var string
- */
- protected $serverUrl = 'https://sadad.shaparak.ir/services/MerchantUtility.asmx?wsdl';
-
- /**
- * Form generated by sadad gateway
- *
- * @var string
- */
- private $form = '';
-
-
- /**
- * {@inheritdoc}
- */
- public function set($amount)
- {
- $this->amount = intval($amount);
-
- return $this;
- }
-
- /**
- * {@inheritdoc}
- */
- public function ready()
- {
- $this->sendPayRequest();
-
- return $this;
- }
-
- /**
- * {@inheritdoc}
- */
- public function redirect()
- {
- $form = $this->form;
-
- return \View::make('gateway::sadad-redirector')->with(compact('form'));
- }
-
- /**
- * {@inheritdoc}
- */
- public function verify($transaction)
- {
- parent::verify($transaction);
-
- $this->verifyPayment();
-
- return $this;
- }
-
- /**
- * Sets callback url
- * @param $url
- */
- function setCallback($url)
- {
- $this->callbackUrl = $url;
- return $this;
- }
-
- /**
- * Gets callback url
- * @return string
- */
- function getCallback()
- {
- if (!$this->callbackUrl)
- $this->callbackUrl = $this->config->get('gateway.sadad.callback-url');
-
- return $this->makeCallback($this->callbackUrl, ['transaction_id' => $this->transactionId()]);
- }
-
- /**
- * Send pay request to server
- *
- * @return void
- *
- * @throws SadadException
- */
- protected function sendPayRequest()
- {
- $this->newTransaction();
-
- $this->form = '';
-
- try {
- $soap = new SoapClient($this->serverUrl);
-
- $response = $soap->PaymentUtility(
- $this->config->get('gateway.sadad.merchant'),
- $this->amount,
- $this->transactionId(),
- $this->config->get('gateway.sadad.transactionKey'),
- $this->config->get('gateway.sadad.terminalId'),
- $this->getCallback()
- );
-
- } catch (\SoapFault $e) {
- $this->transactionFailed();
- $this->newLog('SoapFault', $e->getMessage());
- throw $e;
- }
-
- if (!isset($response['RequestKey']) || !isset($response['PaymentUtilityResult'])) {
- $this->newLog(SadadResult::INVALID_RESPONSE_CODE, SadadResult::INVALID_RESPONSE_MESSAGE);
- throw new SadadException(SadadResult::INVALID_RESPONSE_MESSAGE, SadadResult::INVALID_RESPONSE_CODE);
- }
-
- $this->form = $response['PaymentUtilityResult'];
-
- $this->refId = $response['RequestKey'];
-
- $this->transactionSetRefId();
- }
-
- /**
- * Verify user payment from bank server
- *
- * @throws SadadException
- */
- protected function verifyPayment()
- {
- try {
- $soap = new SoapClient($this->serverUrl);
-
- $result = $soap->CheckRequestStatusResult(
- $this->transactionId(),
- $this->config->get('gateway.sadad.merchant'),
- $this->config->get('gateway.sadad.terminalId'),
- $this->config->get('gateway.sadad.transactionKey'),
- $this->refId(),
- $this->amount
- );
-
- } catch (\SoapFault $e) {
- $this->transactionFailed();
- $this->newLog('SoapFault', $e->getMessage());
- throw $e;
- }
-
- if (empty($result) || !isset($result->AppStatusCode))
- throw new SadadException('در دریافت اطلاعات از بانک خطایی رخ داده است.');
-
- $statusResult = strval($result->AppStatusCode);
- $appStatus = strtolower($result->AppStatusDescription);
-
- $message = $this->getMessage($statusResult, $appStatus);
-
- $this->newLog($statusResult, $message['fa']);
-
- if ($statusResult != 0 || $appStatus !== 'commit') {
- $this->transactionFailed();
- throw new SadadException($message['fa'], $statusResult);
- }
- $this->trackingCode = $result->TraceNo;
- $this->cardNumber = $result->CustomerCardNumber;
- $this->transactionSucceed();
- }
-
- /**
- * Register error to error list
- *
- * @param int $code
- * @param string $message
- *
- * @return array|null
- *
- * @throws SadadException
- */
- private function getMessage($code, $message)
- {
- $result = SadadResult::codeResponse($code, $message);
- if ($result) {
- return $result;
- }
- $result = array(
- 'code' => SadadResult::UNKNOWN_CODE,
- 'message' => SadadResult::UNKNOWN_MESSAGE,
- 'fa' => 'خطای ناشناخته',
- 'en' => 'Unknown Error',
- 'retry' => false
- );
-
-
- return $result;
- }
+ /**
+ * Url of sadad gateway web service
+ *
+ * @var string
+ */
+ protected $serverUrl = 'https://sadad.shaparak.ir/services/MerchantUtility.asmx?wsdl';
+
+ /**
+ * Form generated by sadad gateway
+ *
+ * @var string
+ */
+ private $form = '';
+
+
+ /**
+ * {@inheritdoc}
+ */
+ public function set($amount)
+ {
+ $this->amount = intval($amount);
+
+ return $this;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function ready()
+ {
+ $this->sendPayRequest();
+
+ return $this;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function redirect()
+ {
+ $form = $this->form;
+
+ return \View::make('gateway::sadad-redirector')->with(compact('form'));
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function verify($transaction)
+ {
+ parent::verify($transaction);
+
+ $this->verifyPayment();
+
+ return $this;
+ }
+
+ /**
+ * Sets callback url
+ * @param $url
+ */
+ public function setCallback($url)
+ {
+ $this->callbackUrl = $url;
+ return $this;
+ }
+
+ /**
+ * Gets callback url
+ * @return string
+ */
+ public function getCallback()
+ {
+ if (!$this->callbackUrl) {
+ $this->callbackUrl = $this->config->get('gateway.sadad.callback-url');
+ }
+
+ return $this->makeCallback($this->callbackUrl, ['transaction_id' => $this->transactionId()]);
+ }
+
+ /**
+ * Send pay request to server
+ *
+ * @return void
+ *
+ * @throws SadadException
+ */
+ protected function sendPayRequest()
+ {
+ $this->newTransaction();
+
+ $this->form = '';
+
+ try {
+ $soap = new SoapClient($this->serverUrl);
+
+ $response = $soap->PaymentUtility(
+ $this->config->get('gateway.sadad.merchant'),
+ $this->amount,
+ $this->transactionId(),
+ $this->config->get('gateway.sadad.transactionKey'),
+ $this->config->get('gateway.sadad.terminalId'),
+ $this->getCallback()
+ );
+ } catch (\SoapFault $e) {
+ $this->transactionFailed();
+ $this->newLog('SoapFault', $e->getMessage());
+ throw $e;
+ }
+
+ if (!isset($response['RequestKey']) || !isset($response['PaymentUtilityResult'])) {
+ $this->newLog(SadadResult::INVALID_RESPONSE_CODE, SadadResult::INVALID_RESPONSE_MESSAGE);
+ throw new SadadException(SadadResult::INVALID_RESPONSE_MESSAGE, SadadResult::INVALID_RESPONSE_CODE);
+ }
+
+ $this->form = $response['PaymentUtilityResult'];
+
+ $this->refId = $response['RequestKey'];
+
+ $this->transactionSetRefId();
+ }
+
+ /**
+ * Verify user payment from bank server
+ *
+ * @throws SadadException
+ */
+ protected function verifyPayment()
+ {
+ try {
+ $soap = new SoapClient($this->serverUrl);
+
+ $result = $soap->CheckRequestStatusResult(
+ $this->transactionId(),
+ $this->config->get('gateway.sadad.merchant'),
+ $this->config->get('gateway.sadad.terminalId'),
+ $this->config->get('gateway.sadad.transactionKey'),
+ $this->refId(),
+ $this->amount
+ );
+ } catch (\SoapFault $e) {
+ $this->transactionFailed();
+ $this->newLog('SoapFault', $e->getMessage());
+ throw $e;
+ }
+
+ if (empty($result) || !isset($result->AppStatusCode)) {
+ throw new SadadException('در دریافت اطلاعات از بانک خطایی رخ داده است.');
+ }
+
+ $statusResult = strval($result->AppStatusCode);
+ $appStatus = strtolower($result->AppStatusDescription);
+
+ $message = $this->getMessage($statusResult, $appStatus);
+
+ $this->newLog($statusResult, $message['fa']);
+
+ if ($statusResult != 0 || $appStatus !== 'commit') {
+ $this->transactionFailed();
+ throw new SadadException($message['fa'], $statusResult);
+ }
+ $this->trackingCode = $result->TraceNo;
+ $this->cardNumber = $result->CustomerCardNumber;
+ $this->transactionSucceed();
+ }
+
+ /**
+ * Register error to error list
+ *
+ * @param int $code
+ * @param string $message
+ *
+ * @return array|null
+ *
+ * @throws SadadException
+ */
+ private function getMessage($code, $message)
+ {
+ $result = SadadResult::codeResponse($code, $message);
+ if ($result) {
+ return $result;
+ }
+ $result = array(
+ 'code' => SadadResult::UNKNOWN_CODE,
+ 'message' => SadadResult::UNKNOWN_MESSAGE,
+ 'fa' => 'خطای ناشناخته',
+ 'en' => 'Unknown Error',
+ 'retry' => false
+ );
+
+
+ return $result;
+ }
}
diff --git a/src/Sadad/SadadException.php b/src/Sadad/SadadException.php
index 25f7e734..1f503fd6 100644
--- a/src/Sadad/SadadException.php
+++ b/src/Sadad/SadadException.php
@@ -2,7 +2,8 @@
namespace Larabookir\Gateway\Sadad;
-
use Larabookir\Gateway\Exceptions\BankException;
-class SadadException extends BankException {}
+class SadadException extends BankException
+{
+}
diff --git a/src/Sadad/SadadResult.php b/src/Sadad/SadadResult.php
index bccc7a4b..b7cca7ea 100644
--- a/src/Sadad/SadadResult.php
+++ b/src/Sadad/SadadResult.php
@@ -170,13 +170,14 @@ class SadadResult
* @param string $message
* @return null
*/
- public static function codeResponse($code,$message)
+ public static function codeResponse($code, $message)
{
$code = intval($code);
- foreach(self::$results as $v) {
- if ($v['message'] == $message && $v['code'] == $code)
+ foreach (self::$results as $v) {
+ if ($v['message'] == $message && $v['code'] == $code) {
return $v;
+ }
}
return null;
diff --git a/src/Saman/Saman.php b/src/Saman/Saman.php
index af4e8d97..0c4069ac 100644
--- a/src/Saman/Saman.php
+++ b/src/Saman/Saman.php
@@ -55,7 +55,7 @@ public function ready()
* @param Array $data an array of data
*
*/
- function setOptionalData (Array $data)
+ public function setOptionalData(array $data)
{
$this->optional_data = $data;
}
@@ -75,7 +75,7 @@ public function redirect()
$data = array_merge($main_data, $this->optional_data);
- return \View::make('gateway::saman-redirector')->with($data)->with('gateUrl',$this->gateUrl);
+ return \View::make('gateway::saman-redirector')->with($data)->with('gateUrl', $this->gateUrl);
}
/**
@@ -95,7 +95,7 @@ public function verify($transaction)
* Sets callback url
* @param $url
*/
- function setCallback($url)
+ public function setCallback($url)
{
$this->callbackUrl = $url;
return $this;
@@ -105,10 +105,11 @@ function setCallback($url)
* Gets callback url
* @return string
*/
- function getCallback()
+ public function getCallback()
{
- if (!$this->callbackUrl)
+ if (!$this->callbackUrl) {
$this->callbackUrl = $this->config->get('gateway.saman.callback-url');
+ }
$url = $this->makeCallback($this->callbackUrl, ['transaction_id' => $this->transactionId()]);
@@ -167,7 +168,6 @@ protected function verifyPayment()
try {
$soap = new SoapClient($this->serverVerifyUrl);
$response = $soap->VerifyTransaction($fields["RefNum"], $fields["merchantID"]);
-
} catch (\SoapFault $e) {
$this->transactionFailed();
$this->newLog('SoapFault', $e->getMessage());
@@ -182,11 +182,10 @@ protected function verifyPayment()
}
//Reverse Transaction
- if($response>0){
+ if ($response>0) {
try {
$soap = new SoapClient($this->serverVerifyUrl);
$response = $soap->ReverseTransaction($fields["RefNum"], $fields["merchantID"], $fields["password"], $response);
-
} catch (\SoapFault $e) {
$this->transactionFailed();
$this->newLog('SoapFault', $e->getMessage());
@@ -199,10 +198,5 @@ protected function verifyPayment()
$this->transactionFailed();
$this->newLog($response, SamanException::$errors[$response]);
throw new SamanException($response);
-
-
-
}
-
-
}
diff --git a/src/Saman/SamanException.php b/src/Saman/SamanException.php
index d8663f80..a83362db 100644
--- a/src/Saman/SamanException.php
+++ b/src/Saman/SamanException.php
@@ -6,7 +6,6 @@
class SamanException extends BankException
{
-
public static $errors = array(
"OK" => "پرداخت با موفقیت انجام شد",
'Canceled By User' => 'تراکنش توسط خریدار کنسل شد',
diff --git a/src/Zarinpal/Zarinpal.php b/src/Zarinpal/Zarinpal.php
index 7b436110..7f8126f5 100644
--- a/src/Zarinpal/Zarinpal.php
+++ b/src/Zarinpal/Zarinpal.php
@@ -11,308 +11,306 @@
class Zarinpal extends PortAbstract implements PortInterface
{
- /**
- * Address of germany SOAP server
- *
- * @var string
- */
- protected $germanyServer = 'https://de.zarinpal.com/pg/services/WebGate/wsdl';
-
- /**
- * Address of iran SOAP server
- *
- * @var string
- */
- protected $iranServer = 'https://ir.zarinpal.com/pg/services/WebGate/wsdl';
+ /**
+ * Address of germany SOAP server
+ *
+ * @var string
+ */
+ protected $germanyServer = 'https://de.zarinpal.com/pg/services/WebGate/wsdl';
+
+ /**
+ * Address of iran SOAP server
+ *
+ * @var string
+ */
+ protected $iranServer = 'https://ir.zarinpal.com/pg/services/WebGate/wsdl';
/**
- * Address of sandbox SOAP server
- *
- * @var string
- */
- protected $sandboxServer = 'https://sandbox.zarinpal.com/pg/services/WebGate/wsdl';
-
- /**
- * Address of main SOAP server
- *
- * @var string
- */
- protected $serverUrl;
-
- /**
- * Payment Description
- *
- * @var string
- */
- protected $description;
-
- /**
- * Payer Email Address
- *
- * @var string
- */
- protected $email;
-
- /**
- * Payer Mobile Number
- *
- * @var string
- */
- protected $mobileNumber;
-
- /**
- * Address of gate for redirect
- *
- * @var string
- */
- protected $gateUrl = 'https://www.zarinpal.com/pg/StartPay/';
+ * Address of sandbox SOAP server
+ *
+ * @var string
+ */
+ protected $sandboxServer = 'https://sandbox.zarinpal.com/pg/services/WebGate/wsdl';
+
+ /**
+ * Address of main SOAP server
+ *
+ * @var string
+ */
+ protected $serverUrl;
+
+ /**
+ * Payment Description
+ *
+ * @var string
+ */
+ protected $description;
+
+ /**
+ * Payer Email Address
+ *
+ * @var string
+ */
+ protected $email;
+
+ /**
+ * Payer Mobile Number
+ *
+ * @var string
+ */
+ protected $mobileNumber;
+
+ /**
+ * Address of gate for redirect
+ *
+ * @var string
+ */
+ protected $gateUrl = 'https://www.zarinpal.com/pg/StartPay/';
/**
- * Address of sandbox gate for redirect
- *
- * @var string
- */
- protected $sandboxGateUrl = 'https://sandbox.zarinpal.com/pg/StartPay/';
-
- /**
- * Address of zarin gate for redirect
- *
- * @var string
- */
- protected $zarinGateUrl = 'https://www.zarinpal.com/pg/StartPay/$Authority/ZarinGate';
-
- public function boot()
- {
- $this->setServer();
- }
-
- /**
- * {@inheritdoc}
- */
- public function set($amount)
- {
- $this->amount = ($amount / 10);
-
- return $this;
- }
-
- /**
- * {@inheritdoc}
- */
- public function ready()
- {
- $this->sendPayRequest();
-
- return $this;
- }
-
- /**
- * {@inheritdoc}
- */
- public function redirect()
- {
- switch ($this->config->get('gateway.zarinpal.type')) {
- case 'zarin-gate':
- return \Redirect::to(str_replace('$Authority', $this->refId, $this->zarinGateUrl));
- break;
-
- case 'normal':
- default:
- return \Redirect::to($this->gateUrl . $this->refId);
- break;
- }
- }
-
- /**
- * {@inheritdoc}
- */
- public function verify($transaction)
- {
- parent::verify($transaction);
-
- $this->userPayment();
- $this->verifyPayment();
-
- return $this;
- }
-
- /**
- * Sets callback url
- * @param $url
- */
- function setCallback($url)
- {
- $this->callbackUrl = $url;
- return $this;
- }
-
- /**
- * Gets callback url
- * @return string
- */
- function getCallback()
- {
- if (!$this->callbackUrl)
- $this->callbackUrl = $this->config->get('gateway.zarinpal.callback-url');
-
- return $this->makeCallback($this->callbackUrl, ['transaction_id' => $this->transactionId()]);
- }
-
- /**
- * Send pay request to server
- *
- * @return void
- *
- * @throws ZarinpalException
- */
- protected function sendPayRequest()
- {
- $this->newTransaction();
-
- $fields = array(
- 'MerchantID' => $this->config->get('gateway.zarinpal.merchant-id'),
- 'Amount' => $this->amount,
- 'CallbackURL' => $this->getCallback(),
- 'Description' => $this->description ? $this->description : $this->config->get('gateway.zarinpal.description', ''),
- 'Email' => $this->email ? $this->email :$this->config->get('gateway.zarinpal.email', ''),
- 'Mobile' => $this->mobileNumber ? $this->mobileNumber : $this->config->get('gateway.zarinpal.mobile', ''),
- );
-
- try {
- $soap = new SoapClient($this->serverUrl, ['encoding' => 'UTF-8']);
- $response = $soap->PaymentRequest($fields);
-
- } catch (\SoapFault $e) {
- $this->transactionFailed();
- $this->newLog('SoapFault', $e->getMessage());
- throw $e;
- }
-
- if ($response->Status != 100) {
- $this->transactionFailed();
- $this->newLog($response->Status, ZarinpalException::$errors[$response->Status]);
- throw new ZarinpalException($response->Status);
- }
-
- $this->refId = $response->Authority;
- $this->transactionSetRefId();
- }
-
- /**
- * Check user payment with GET data
- *
- * @return bool
- *
- * @throws ZarinpalException
- */
- protected function userPayment()
- {
- $this->authority = Request::input('Authority');
- $status = Request::input('Status');
-
- if ($status == 'OK') {
- return true;
- }
-
- $this->transactionFailed();
- $this->newLog(-22, ZarinpalException::$errors[-22]);
- throw new ZarinpalException(-22);
- }
-
- /**
- * Verify user payment from zarinpal server
- *
- * @return bool
- *
- * @throws ZarinpalException
- */
- protected function verifyPayment()
- {
-
- $fields = array(
- 'MerchantID' => $this->config->get('gateway.zarinpal.merchant-id'),
- 'Authority' => $this->refId,
- 'Amount' => $this->amount,
- );
-
- try {
- $soap = new SoapClient($this->serverUrl, ['encoding' => 'UTF-8']);
- $response = $soap->PaymentVerification($fields);
-
- } catch (\SoapFault $e) {
- $this->transactionFailed();
- $this->newLog('SoapFault', $e->getMessage());
- throw $e;
- }
-
- if ($response->Status != 100 && $response->Status != 101) {
- $this->transactionFailed();
- $this->newLog($response->Status, ZarinpalException::$errors[$response->Status]);
- throw new ZarinpalException($response->Status);
- }
-
- $this->trackingCode = $response->RefID;
- $this->transactionSucceed();
- $this->newLog($response->Status, Enum::TRANSACTION_SUCCEED_TEXT);
- return true;
- }
-
- /**
- * Set server for soap transfers data
- *
- * @return void
- */
- protected function setServer()
- {
- $server = $this->config->get('gateway.zarinpal.server', 'germany');
- switch ($server) {
- case 'iran':
- $this->serverUrl = $this->iranServer;
- break;
+ * Address of sandbox gate for redirect
+ *
+ * @var string
+ */
+ protected $sandboxGateUrl = 'https://sandbox.zarinpal.com/pg/StartPay/';
+
+ /**
+ * Address of zarin gate for redirect
+ *
+ * @var string
+ */
+ protected $zarinGateUrl = 'https://www.zarinpal.com/pg/StartPay/$Authority/ZarinGate';
+
+ public function boot()
+ {
+ $this->setServer();
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function set($amount)
+ {
+ $this->amount = ($amount / 10);
+
+ return $this;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function ready()
+ {
+ $this->sendPayRequest();
+
+ return $this;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function redirect()
+ {
+ switch ($this->config->get('gateway.zarinpal.type')) {
+ case 'zarin-gate':
+ return \Redirect::to(str_replace('$Authority', $this->refId, $this->zarinGateUrl));
+ break;
+
+ case 'normal':
+ default:
+ return \Redirect::to($this->gateUrl . $this->refId);
+ break;
+ }
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function verify($transaction)
+ {
+ parent::verify($transaction);
+
+ $this->userPayment();
+ $this->verifyPayment();
+
+ return $this;
+ }
+
+ /**
+ * Sets callback url
+ * @param $url
+ */
+ public function setCallback($url)
+ {
+ $this->callbackUrl = $url;
+ return $this;
+ }
+
+ /**
+ * Gets callback url
+ * @return string
+ */
+ public function getCallback()
+ {
+ if (!$this->callbackUrl) {
+ $this->callbackUrl = $this->config->get('gateway.zarinpal.callback-url');
+ }
+
+ return $this->makeCallback($this->callbackUrl, ['transaction_id' => $this->transactionId()]);
+ }
+
+ /**
+ * Send pay request to server
+ *
+ * @return void
+ *
+ * @throws ZarinpalException
+ */
+ protected function sendPayRequest()
+ {
+ $this->newTransaction();
+
+ $fields = array(
+ 'MerchantID' => $this->config->get('gateway.zarinpal.merchant-id'),
+ 'Amount' => $this->amount,
+ 'CallbackURL' => $this->getCallback(),
+ 'Description' => $this->description ? $this->description : $this->config->get('gateway.zarinpal.description', ''),
+ 'Email' => $this->email ? $this->email :$this->config->get('gateway.zarinpal.email', ''),
+ 'Mobile' => $this->mobileNumber ? $this->mobileNumber : $this->config->get('gateway.zarinpal.mobile', ''),
+ );
+
+ try {
+ $soap = new SoapClient($this->serverUrl, ['encoding' => 'UTF-8']);
+ $response = $soap->PaymentRequest($fields);
+ } catch (\SoapFault $e) {
+ $this->transactionFailed();
+ $this->newLog('SoapFault', $e->getMessage());
+ throw $e;
+ }
+
+ if ($response->Status != 100) {
+ $this->transactionFailed();
+ $this->newLog($response->Status, ZarinpalException::$errors[$response->Status]);
+ throw new ZarinpalException($response->Status);
+ }
+
+ $this->refId = $response->Authority;
+ $this->transactionSetRefId();
+ }
+
+ /**
+ * Check user payment with GET data
+ *
+ * @return bool
+ *
+ * @throws ZarinpalException
+ */
+ protected function userPayment()
+ {
+ $this->authority = Request::input('Authority');
+ $status = Request::input('Status');
+
+ if ($status == 'OK') {
+ return true;
+ }
+
+ $this->transactionFailed();
+ $this->newLog(-22, ZarinpalException::$errors[-22]);
+ throw new ZarinpalException(-22);
+ }
+
+ /**
+ * Verify user payment from zarinpal server
+ *
+ * @return bool
+ *
+ * @throws ZarinpalException
+ */
+ protected function verifyPayment()
+ {
+ $fields = array(
+ 'MerchantID' => $this->config->get('gateway.zarinpal.merchant-id'),
+ 'Authority' => $this->refId,
+ 'Amount' => $this->amount,
+ );
+
+ try {
+ $soap = new SoapClient($this->serverUrl, ['encoding' => 'UTF-8']);
+ $response = $soap->PaymentVerification($fields);
+ } catch (\SoapFault $e) {
+ $this->transactionFailed();
+ $this->newLog('SoapFault', $e->getMessage());
+ throw $e;
+ }
+
+ if ($response->Status != 100 && $response->Status != 101) {
+ $this->transactionFailed();
+ $this->newLog($response->Status, ZarinpalException::$errors[$response->Status]);
+ throw new ZarinpalException($response->Status);
+ }
+
+ $this->trackingCode = $response->RefID;
+ $this->transactionSucceed();
+ $this->newLog($response->Status, Enum::TRANSACTION_SUCCEED_TEXT);
+ return true;
+ }
+
+ /**
+ * Set server for soap transfers data
+ *
+ * @return void
+ */
+ protected function setServer()
+ {
+ $server = $this->config->get('gateway.zarinpal.server', 'germany');
+ switch ($server) {
+ case 'iran':
+ $this->serverUrl = $this->iranServer;
+ break;
- case 'test':
- $this->serverUrl = $this->sandboxServer;
- $this->gateUrl = $this->sandboxGateUrl;
- break;
-
- case 'germany':
- default:
- $this->serverUrl = $this->germanyServer;
- break;
- }
- }
-
-
- /**
- * Set Description
- *
- * @param $description
- * @return void
- */
- public function setDescription($description)
- {
- $this->description = $description;
- }
-
- /**
- * Set Payer Email Address
- *
- * @param $email
- * @return void
- */
- public function setEmail($email)
- {
- $this->email = $email;
- }
-
- /**
- * Set Payer Mobile Number
- *
- * @param $number
- * @return void
- */
- public function setMobileNumber($number)
- {
- $this->mobileNumber = $number;
- }
+ case 'test':
+ $this->serverUrl = $this->sandboxServer;
+ $this->gateUrl = $this->sandboxGateUrl;
+ break;
+
+ case 'germany':
+ default:
+ $this->serverUrl = $this->germanyServer;
+ break;
+ }
+ }
+
+
+ /**
+ * Set Description
+ *
+ * @param $description
+ * @return void
+ */
+ public function setDescription($description)
+ {
+ $this->description = $description;
+ }
+
+ /**
+ * Set Payer Email Address
+ *
+ * @param $email
+ * @return void
+ */
+ public function setEmail($email)
+ {
+ $this->email = $email;
+ }
+
+ /**
+ * Set Payer Mobile Number
+ *
+ * @param $number
+ * @return void
+ */
+ public function setMobileNumber($number)
+ {
+ $this->mobileNumber = $number;
+ }
}
diff --git a/src/Zarinpal/ZarinpalException.php b/src/Zarinpal/ZarinpalException.php
index 2951e3d9..7b17ec9e 100644
--- a/src/Zarinpal/ZarinpalException.php
+++ b/src/Zarinpal/ZarinpalException.php
@@ -8,7 +8,7 @@ class ZarinpalException extends BankException
{
public static $errors = array(
-1 => 'اطلاعات ارسال شده ناقص است.',
- -2 => 'IP و یا مرچنت کد پذیرنده صحیح نیست',
+ -2 => 'IP و یا مرچنت کد پذیرنده صحیح نیست',
-3 => 'رقم باید بالای 100 تومان باشد',
-4 => 'سطح پذیرنده پایین تر از سطح نقره ای است',
-11 => 'درخواست مورد نظر یافت نشد',
diff --git a/views/irankish-redirector.blade.php b/views/irankish-redirector.blade.php
index 09e20318..04ab0571 100644
--- a/views/irankish-redirector.blade.php
+++ b/views/irankish-redirector.blade.php
@@ -11,13 +11,9 @@
///////////////////////////////////
session_start();
$Err = '';
-if($_POST['action'] == 'pay')
-{
-
- if(intval($_POST['PayAmount']) >= 1000)
- {
- if(!empty($_POST['fullname']))
- {
+if ($_POST['action'] == 'pay') {
+ if (intval($_POST['PayAmount']) >= 1000) {
+ if (!empty($_POST['fullname'])) {
$_SESSION['merchantId'] = $MerchantId;
$_SESSION['sha1Key'] = $sha1Key;
$_SESSION['admin_email'] = $admin_email;
@@ -40,21 +36,16 @@
$_SESSION['token'] = $result->MakeTokenResult->token;
$data['token'] = $_SESSION['token'];
$data['merchantId'] = $_SESSION['merchantId'];
- redirect_post('https://ikc.shaparak.ir/TPayment/Payment/index',$data);
- }
- else
- {
+ redirect_post('https://ikc.shaparak.ir/TPayment/Payment/index', $data);
+ } else {
$Err .='نام را وارد کنید
';
}
- }else
- {
+ } else {
$Err .='مبلغ صحیح نیست
';
}
-
}
function redirect_post($url, array $data)
{
-
echo '