forked from larabook/gateway
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
277 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,172 @@ | ||
<?php | ||
|
||
namespace Larabookir\Gateway\Saman; | ||
|
||
use Illuminate\Support\Facades\Input; | ||
use SoapClient; | ||
use Larabookir\Gateway\PortAbstract; | ||
use Larabookir\Gateway\PortInterface; | ||
|
||
class Saman extends PortAbstract implements PortInterface | ||
{ | ||
/** | ||
* Address of main SOAP server | ||
* | ||
* @var string | ||
*/ | ||
protected $serverUrl = 'https://sep.shaparak.ir/payments/referencepayment.asmx?wsdl'; | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function set($amount) | ||
{ | ||
$this->amount = $amount; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function ready() | ||
{ | ||
$this->newTransaction(); | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function redirect() | ||
{ | ||
|
||
return view('gateway::saman-redirector')->with([ | ||
'amount' => $this->amount, | ||
'merchant' => $this->config->get('gateway.saman.merchant'), | ||
'resNum' => $this->transactionId(), | ||
'callBackUrl' => $this->getCallback() | ||
]); | ||
} | ||
|
||
/** | ||
* {@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.saman.callback-url'); | ||
|
||
$url = $this->makeCallback($this->callbackUrl, ['transaction_id' => $this->transactionId()]); | ||
|
||
return $url; | ||
} | ||
|
||
|
||
/** | ||
* Check user payment | ||
* | ||
* @return bool | ||
* | ||
* @throws SamanException | ||
*/ | ||
protected function userPayment() | ||
{ | ||
$this->refId = Input::get('RefNum'); | ||
$this->trackingCode = Input::get('ResNum'); | ||
$payRequestRes = Input::get('State'); | ||
$payRequestResCode = Input::get('StateCode'); | ||
|
||
if ($payRequestRes == 'OK') { | ||
return true; | ||
} | ||
|
||
$this->transactionFailed(); | ||
$this->newLog($payRequestResCode, @SamanException::$errors[$payRequestRes]); | ||
throw new SamanException($payRequestRes); | ||
} | ||
|
||
|
||
/** | ||
* Verify user payment from bank server | ||
* | ||
* @return bool | ||
* | ||
* @throws SamanException | ||
* @throws SoapFault | ||
*/ | ||
protected function verifyPayment() | ||
{ | ||
$fields = array( | ||
"merchantID" => $this->config->get('gateway.saman.merchant'), | ||
"RefNum" => $this->refId, | ||
"password" => $this->config->get('gateway.saman.password'), | ||
); | ||
|
||
|
||
try { | ||
$soap = new SoapClient($this->serverUrl); | ||
$response = $soap->VerifyTransaction($fields["RefNum"], $fields["merchantID"]); | ||
|
||
} catch (\SoapFault $e) { | ||
$this->transactionFailed(); | ||
$this->newLog('SoapFault', $e->getMessage()); | ||
throw $e; | ||
} | ||
|
||
$response = intval($response); | ||
|
||
if ($response != $this->amount) { | ||
|
||
//Reverse Transaction | ||
if($response>0){ | ||
try { | ||
$soap = new SoapClient($this->serverUrl); | ||
$response = $soap->ReverseTransaction($fields["RefNum"], $fields["merchantID"], $fields["password"], $response); | ||
|
||
} catch (\SoapFault $e) { | ||
$this->transactionFailed(); | ||
$this->newLog('SoapFault', $e->getMessage()); | ||
throw $e; | ||
} | ||
} | ||
|
||
// | ||
$this->transactionFailed(); | ||
$this->newLog($response, SamanException::$errors[$response]); | ||
throw new SamanException($response); | ||
} | ||
|
||
|
||
$this->transactionSucceed(); | ||
|
||
return true; | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php | ||
|
||
namespace Larabookir\Gateway\Saman; | ||
|
||
use Larabookir\Gateway\Exceptions\BankException; | ||
|
||
class SamanException extends BankException | ||
{ | ||
|
||
public static $errors = array( | ||
"OK" => "پرداخت با موفقیت انجام شد", | ||
'Canceled By User' => 'تراکنش توسط خریدار کنسل شد', | ||
'Invalid Amount' => 'مبلغ سند برگشتی از مبلغ تراکنش اصلی بیشتر است', | ||
'Invalid Transaction' => 'درخواست برگشت تراکنش رسیده است در حالی که تراکنش اصلی پیدا نمی شود', | ||
'Invalid Card Number' => 'شماره کارت اشتباه است', | ||
'No Such Issuer' => 'چنین صادر کننده کارتی وجود ندارد', | ||
'Expired Card Pick Up' => 'از تاریخ انقضای کارت گذشته است و کارت دیگر معتبر نیست', | ||
'Incorrect PIN' => 'رمز کارت (PIN) اشتباه وارد شده است', | ||
'No Sufficient Funds' => 'موجودی به اندازه کافی در حساب شما نیست', | ||
'Issuer Down Slm' => 'سیستم کارت بانک صادر کننده فعال نیست', | ||
'TME Error' => 'خطا در شبکه بانکی', | ||
'Exceeds Withdrawal Amount Limit' => 'مبلغ بیش از سقف برداشت است', | ||
'Transaction Cannot Be Completed' => 'امکان سند خوردن وجود ندارد', | ||
'Allowable PIN Tries Exceeded Pick Up' => 'رمز کارت (PIN) 3 مرتبه اشتباه وارد شده است در نتیجه کارت شما غیر فعال خواهد شد', | ||
'Response Received Too Late' => 'تراکنش در شبکه بانکی Timeout خورده است', | ||
'Suspected Fraud Pick Up' => 'فیلد CV2V و یا فیلد ExpDate اشتباه وارد شده و یا اصلا وارد نشده است', | ||
|
||
|
||
-1 => "خطای داخلی شبکه مالی", | ||
-2 => "سپرده ها برابر نیستند", | ||
-3 => "ورودی ها حاوی کاراکترهای غیر مجاز می باشند", | ||
-4 => "کلمه عبور یا کد فروشنده اشتباه می باشد", | ||
-5 => "Database Exception", | ||
-6 => "سند قبلا برگشت کامل یافته است", | ||
-7 => "رسید دیجیتالی تهی است", | ||
-8 => "طول ورودی ها بیش از حد مجاز است", | ||
-9 => "وجود کاراکتر های غیر مجاز در مبلغ برگشتی", | ||
-10 => "رسید دیجیتالی حاوی کاراکترهای غیر مجاز است", | ||
-11 => "طول ورودی ها کمتر از حد مجاز است", | ||
-12 => "مبلغ برگشتی منفی است", | ||
-13 => "مبلغ برگشتی برای برگشت جزئی، بیش از مبلغ برگشت نخورده رسید دیجیتالی است", | ||
-14 => "چنین تراکنشی تعریف نشده است", | ||
-15 => "مبلغ برگشتی به صورت اعشاری داده شده است", | ||
-16 => "خطای داخلی سیستم", | ||
-17 => "برگشت زدن جزئی تراکنشی که با کارت بانکی غیر از بانک سامان انجام پذیرفته است", | ||
-18 => "IP Address فروشنده نا معتبر است" | ||
); | ||
|
||
public function __construct($errorRef) | ||
{ | ||
$this->errorRef = $errorRef; | ||
|
||
parent::__construct(@self::$errors[$this->errorRef].' ('.$this->errorRef.')', intval($this->errorRef)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<html> | ||
<body> | ||
<script> | ||
var form = document.createElement("form"); | ||
form.setAttribute("method", "POST"); | ||
form.setAttribute("action", "https://sep.shaparak.ir/Payment.aspx"); | ||
form.setAttribute("target", "_self"); | ||
var params = { | ||
Amount: '{{$amount}}', | ||
MID: '{{$merchant}}', | ||
ResNum: '{{$resNum}}', | ||
RedirectURL: '{{$callBackUrl}}', | ||
}; | ||
for(var key in params){ | ||
var hiddenField = document.createElement("input"); | ||
hiddenField.setAttribute("name", key); | ||
hiddenField.setAttribute("value", params[key]); | ||
form.appendChild(hiddenField); | ||
} | ||
document.body.appendChild(form); | ||
form.submit(); | ||
document.body.removeChild(form); | ||
</script> | ||
</body> | ||
</html> | ||
|
||
|