Skip to content

Commit

Permalink
Merge pull request larabook#112 from akoSalman/dev
Browse files Browse the repository at this point in the history
Add a description to gateway_transactions table
  • Loading branch information
hpakdaman authored Sep 20, 2018
2 parents e6abdcd + 3625f90 commit 23a0f04
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,16 @@ public function up()
$table->unsignedBigInteger('id', true);
$table->enum('port', [
Enum::MELLAT,
Enum::SADAD,
Enum::ZARINPAL,
Enum::PAYLINE,
Enum::JAHANPAY,
Enum::PARSIAN,
Enum::PASARGAD,
Enum::PAYLINE,
Enum::SADAD,
Enum::ZARINPAL,
Enum::SAMAN,
Enum::ASANPARDAKHT,
Enum::PAYPAL,
Enum::PAYIR,
Enum::PAYIR
]);
$table->decimal('price', 15, 2);
$table->string('ref_id', 100)->nullable();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class AddDescriptionToGatewayTransactions extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('gateway_transactions', function (Blueprint $table) {
//
$table->text('description')->after('ip')->nullable();
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('gateway_transactions', function (Blueprint $table) {
//
$table->dropColumn('description');

});
}
}
44 changes: 37 additions & 7 deletions src/PortAbstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@ abstract class PortAbstract
*/
protected $amount;

/**
* Description of transaction
*
* @var string
*/
protected $description;

/**
* callback URL
*
Expand Down Expand Up @@ -124,6 +131,28 @@ 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;
}

/**
* Return card number
*
Expand Down Expand Up @@ -217,13 +246,14 @@ 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(),
'created_at' => Carbon::now(),
'updated_at' => Carbon::now(),
'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;
Expand Down
38 changes: 31 additions & 7 deletions src/Saman/Saman.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@

class Saman extends PortAbstract implements PortInterface
{
/**
*
* @var Array $optional_data An array of optional data
* that will be sent with the payment request
*
*/
protected $optional_data = [];

/**
* Address of main SOAP server
*
Expand Down Expand Up @@ -36,18 +44,34 @@ public function ready()
return $this;
}

/**
*
* Add optional data to the request
*
* @param Array $data an array of data
*
*/
function setOptionalData (Array $data)
{
$this->optional_data = $data;
}


/**
* {@inheritdoc}
*/
public function redirect()
{

return \View::make('gateway::saman-redirector')->with([
'amount' => $this->amount,
'merchant' => $this->config->get('gateway.saman.merchant'),
'resNum' => $this->transactionId(),
'callBackUrl' => $this->getCallback()
]);
$main_data = [
'amount' => $this->amount,
'merchant' => $this->config->get('gateway.saman.merchant'),
'resNum' => $this->transactionId(),
'callBackUrl' => $this->getCallback()
];

$data = array_merge($main_data, $this->optional_data);

return \View::make('gateway::saman-redirector')->with($data);
}

/**
Expand Down
4 changes: 4 additions & 0 deletions views/saman-redirector.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
MID: '{{$merchant}}',
ResNum: '{{$resNum}}',
RedirectURL: '{{$callBackUrl}}',
ResNum1: '{{ isset( $resNum1 ) ? $resNum1 : "" }}',
ResNum2: '{{ isset( $resNum2 ) ? $resNum2 : "" }}',
ResNum3: '{{ isset( $resNum3 ) ? $resNum3 : "" }}',
ResNum4: '{{ isset( $resNum4 ) ? $resNum4 : "" }}',
};
for(var key in params){
Expand Down

0 comments on commit 23a0f04

Please sign in to comment.