Skip to content

Instantly share code, notes, and snippets.

@bobper
Last active July 15, 2023 15:04
Show Gist options
  • Save bobper/c82cd87be07bd9b7b6f8dc6ffc616918 to your computer and use it in GitHub Desktop.
Save bobper/c82cd87be07bd9b7b6f8dc6ffc616918 to your computer and use it in GitHub Desktop.
saman payment gatway
<?php
use App\Models\Payment;
interface PaymentStrategy
{
public function pay(Payment $payment );
public function cancel($transactionId);
public function verify($request , $amount );
}
<!doctype html>
<html lang="fa">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>درحال هدایت به درگاه سامان</title>
</head>
<body>
<form id="myfrm" action="https://sep.shaparak.ir/payment.aspx" method="POST">
<input name="token" type="hidden" value="{{$Token}}"">
<input name="RedirectURL" type="hidden" value="{{$RedirectURL}}"">
</form>
<script>
var frm = document.getElementById("myfrm");
frm.submit();
</script>
</body>
</html>
use SoapClient;
use Str;
class SamanGateway implements PaymentStrategy
{
private function getToken($amount)
{
$client = new soapclient('https://sep.shaparak.ir/Payments/InitPayment.asmx?WSDL');
$result = $client->RequestToken('???????', /// MID
'1', /// ResNum
$amount /// TotalAmount
, '0' /// Optional
, '0' /// Optional
, '0' /// Optional
, '0' /// Optional
, '0' /// Optional
, '0' /// Optional
, 'ResNum1' /// Optional
, 'ResNum2' /// Optional
, '0' /// Optional
, '' //$RedirectURL /// Optional
);
return $result;
}
public function pay(Payment $payment)
{
$token = $this->getToken($payment->amount);
if (Str::length($token) > 10) {
$result['status'] = 1;
$result['Token'] = $token;
$result['method'] = 'POST';
$result['base_url'] = 'https://sep.shaparak.ir/payment.aspx';
$result['RedirectURL'] = route('api.verifyPayment', $payment->id);
// $result['url'] = 'https://sep.shaparak.ir/payment.aspx';
return $result;
}
$result['status'] = 0;
$result['error'] = $token;
return $result;
}
public function cancel($transactionId)
{
// TODO: Implement cancel() method.
}
public function verify($request , $amount )
{
// dd($request->all());
$soapclient = new SoapClient("https://sep.shaparak.ir/payments/referencepayment.asmx?WSDL");
#$soapclient->debug_flag=true;
// $soapProxy = $soapclient->getProxy() ;
#if( $err = $soapclient->getError() )
# echo $err ;
#echo $soapclient->debug_str;
$response = $soapclient->VerifyTransaction($request->RefNum, "????????"); #reference number and sellerid
if($response <= 0 ){
//خطا رخ داده است
$ret['status'] = 0;
$ret['price'] = $amount ;
$ret['message'] = 'تراکنش ناموفق بود. ' ;
$ret['ref_id'] = $request->RefNum;
return $ret;
}
if ($response == $amount ) {
//موفق
$ret['status'] = 1;
$ret['price'] = $amount ;
$ret['ref_id'] = $request->RefNum;
return $ret;
}
//پرداخت موفق ولی مبالغ پرداختی تطابق ندارد
$ret['status'] =0;
$ret['price'] = $amount;
$ret['ref_id'] = $request->RefNum;
$ret['message'] = 'عدم تطابق مبلغ پرداختی';
return $ret;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment