Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Abdi #243

Open
wants to merge 9 commits into
base: dev
Choose a base branch
from
Open

Abdi #243

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions config/gateway.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
<?php


/*
------------------ This Project forked for Mobisoft ---------------------
__ __ _ _ _____ __ _
| \/ | | | (_)/ ____| / _| |
| \ / | ___ | |__ _| (___ ___ | |_| |_
| |\/| |/ _ \| '_ \| |\___ \ / _ \| _| __|
| | | | (_) | |_) | |____) | (_) | | | |_
|_| |_|\___/|_.__/|_|_____/ \___/|_| \__|

-------------------------------------------------------------------------
*/
return [

//-------------------------------
Expand All @@ -8,6 +20,16 @@
//--------------------------------
'timezone' => '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
//--------------------------------
Expand Down
80 changes: 39 additions & 41 deletions migrations/2016_05_02_193213_create_gateway_transactions_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}
Expand All @@ -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();
Expand Down
100 changes: 48 additions & 52 deletions migrations/2017_04_05_103357_alter_id_in_transactions_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ public function down()
Schema::table('gateway_transactions', function (Blueprint $table) {
//
$table->dropColumn('description');

});
}
}
24 changes: 7 additions & 17 deletions src/Asanpardakht/Asanpardakht.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ public function ready()
*/
public function redirect()
{

return view('gateway::asan-pardakht-redirector')->with([
'refId' => $this->refId
]);
Expand All @@ -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;
Expand All @@ -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()]);

Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -180,7 +179,6 @@ protected function userPayment()
*/
protected function verifyAndSettlePayment()
{

$username = $this->config->get('gateway.asanpardakht.username');
$password = $this->config->get('gateway.asanpardakht.password');

Expand All @@ -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());
Expand All @@ -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.
}
Expand All @@ -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,
Expand All @@ -253,7 +247,6 @@ private function encrypt($string = "")

$response = $soap->EncryptInAES($params);
return $response->EncryptInAESResult;

} catch (\SoapFault $e) {
return "";
}
Expand All @@ -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,
Expand All @@ -282,10 +274,8 @@ private function decrypt($string = "")

$response = $soap->DecryptInAES($params);
return $response->DecryptInAESResult;

} catch (\SoapFault $e) {
return "";
}
}

}
}
Loading