کلاس پرداخت بانک ملت

sajadmaz

Member
سلام کلاس پرداخت بانک ملت رو براتون گذاشتم خیلی پیچوندن هنوز فرصت نکردم کلاس رو کامل و بطور کلی دیباگ کنم امیدوارم بکارتون بیاد سوالی بود در خدمتم

PHP:
<?PHP


class MellatPayment
{


    function __construct($urlConnect1,$urlConnect2,$RedirectBanckURL,$terminalid,$username,$password,$callbackUrl,$mit,$proccCode)
	{
     $this->urlconnect1  =  (string)$urlConnect1;
     $this->urlConnect2 =  (string)$urlConnect2;
     $this->terminalid  =  (int)   $terminalid;
     $this->username    =  (string)$username;
     $this->password    =  (string)$password;
     $this->callbackUrl =  (string)$callbackUrl;
     $this->proccCode   =  (string)$proccCode;
     $this->mit         =  (string)$mit;
     $this->RedirectBanckURL = (string) $RedirectBanckURL;



	}

    function ConnectSoap3Function($functionMode = 3)
    {
    	require_once 'mellatnusoap.php';
    	$this->client = new nusoap_client(
    	($functionMode == 3) ? $this->urlconnect1 : $this->urlConnect2, true);
	    $err = $this->client->getError();
	    if ($err){ $this->msg('Constructor error',$err); }

    }



    function Message($id)
    {
    	$msg = array(
            '00' => 'تراکنش با موفقيت انجام شد',
            '01' => 'با بانک صادر کننده کارت تماس بگيريد',
            '12' =>'تراکنش نامعتبر',
            '13' =>'مبلغ نامعتبر',
            '14' =>'شماره کارت صحيح نميباشد',
            '30' =>'پيام داراي اشکال مي باشد',
            '33' =>'تاريخ استفاده از کارت به پايان رسيده است',
            '38' =>'ورود شماره شناسايي از حد مجاز به پايان رسيده',
            '41' =>'کارت مفقود مي باشد',
            '43' =>'کارت مسروقه است',
            '51' =>'موجودي حساب کافي نميباشد',
            '55' =>'شماره شناسايي وارده صحيح نميباشد',
            '57' =>'دارنده کارت مجاز به استفاده از اين کارت نميباشد',
            '58' =>'پذيرهنده کارت مجاز به استفاده از اين کارت نميباشد',
            '61' =>'مبلغ تراکنش از حد مجاز بالاتر است',
            '65' =>'تعداد دفعات تراکنشاز جد مجاز بيشتر است',
            '76' =>'شماره کارت در سيستم موجود نميباشد',
            '80' =>'تراکنش موفق عمل نکرده است',
            '84' =>'سوئيچ صادر کننده فعال نيست',
            '88' =>'سيستم دچار اشکال شده است',
            '90' => 'سيستم صدور مجوز انجام تراکنش موقتا غير فعال است يا زمان تعيين شده براي مجوز به پايان رسيده',
            '93' => 'عدم انتباق در شناسايي فايل پيکربندي',
            '94' => 'کد رزرو تکراري است',
            '95' => 'ترمينال غير فعال است',
            '96' => 'ترمينال مجاز به انجام تراکنش نيست',
            '97' => 'شماره batch مطابقت ندارد',
            '98' => 'شماره batch موجود نيست',
            '101' => 'ارسال فايل هاي مورد نياز',
            '102' => 'شماره پيگيري صحيح نميباشد',
            '103' => 'براي اين hashcode تراکنشي صورت نگرفته است',
            '110' => 'ساعت و تقويم ترمينال صحيح نميباشد'
          );

         if (in_array($id, $msg))
          {
              return $msg[$id];
          }else{
          	return 'Error is Invalid : '.$id;
          	}


    }

    function msg($mode,$msg)
    {
      exit("<h2>$mode</h2><pre>$msg</pre>");


    }

    function getSaleCode($sql)
    {
       do{
            $SaleCode = rand(111111,999999);

           
            $query = mysql_query("SELECT `salecode` FROM `payment` WHERE `salecode` = $SaleCode");
            
            
            if( mysql_num_rows($query) == 0 ) {
                break;
            }
        }while( true );

       return $SaleCode;
    }


	function executeservice($amount,$date,$username,$sql)
	{
      $this->ConnectSoap3Function();
      $orderId = $this->getSaleCode($sql);

      $result = $this->client->call('executeservice',
            array(

			'trmID'    => $this->terminalid,
			'userID'   => $this->username,
			'Pass'     => $this->password,
			'datetime' => $date,
			'SaleCode' => $orderId,
			'amunt'    => $amount,
			'MTI'      => $this->mit,
			'ProccCode'=> $this->proccCode,
			'trnsID'   => 0,
			'PURl'     => $this->callbackUrl

			)


       );

      if ($this->client->fault)
      {
          $this->msg('Fault',$result['faultstring']);

      }elseif($this->client->getError())
      {
          $this->msg('Error',$this->client->getError());

      }else{


       $result=explode (',',$result);

			if ($result[0] == 00)
			{
              //insert Info in DB 
              // insert into payment table
              
                 'values' => array(
                            'hashcode'  => $result[1],
                            'price'     => $amount,
                            'salecode'  => $orderId,
                            'timestamp' => time(),
                            'datestr'   => $date,
                            'username'  => $username
                            );

			 if(!@header("Location: ".$this->RedirectBanckURL."?refID=".$result[1]))
			 {
               $this->msg('Error',"Could't Redirect To $this->RedirectBanckURL");
			 }
			}else{

			 $this->msg('خطا',$this->Message($result[0]));

           	}


      }

	}

	function verify($date,$refID,$amount)
	{
     $this->ConnectSoap3Function();

     $result = $this->client->call('verify',
	      array(
                'trmID'    => $this->terminalid,
                'userID'   => $this->username,
                'Pass'     => $this->password,
                'datetime' => $date ,
                'hash'     => $refID,
				'amunt'    => $amount)
            	);



	 if ($this->client->fault)
      {
          $this->msg('Fault',$result['faultstring']);

      }elseif($this->client->getError())
      {
          $this->msg('Error',$this->client->getError());

      }elseif ($result){
         return explode(",", $result);

       }else{return false;}

      }

    function settleSoap($trnsID)
    {

       $this->ConnectSoap3Function(4);


       $result = $this->client->call('settle',
        array(
					'trmId'         => $this->terminalid,
					'transactionNo' => (int)$trnsID,
					'userId'        => $this->username,
					'pass'          => $this->password
		      )
		      );



	   if ($this->client->fault)
      {

          $this->msg('Fault',$result['faultstring']);

      }elseif($this->client->getError())
      {
          $this->msg('Error',$this->client->getError());

      }elseif ($result){

        return  $result;
       }else{return false;}


    }

    function inquirySoap($trnsID,$salecode,$hashCode)
    {
     $trnsID = (int) $trnsID;
     $this->ConnectSoap3Function(4);

     $result = $this->client->call('inquiry',
        array(
					'trmId'         => $this->terminalid,
					'saleCode'      => $salecode,
					'TransactionNo' => $trnsID,
					'Hashcode'      => $hashCode,
					'UserID'        => $this->username ,
					'Pass'          => $this->password
		      ));



	  if ($this->client->fault)
      {
          $this->msg('Fault',$result['faultstring']);

      }elseif($this->client->getError())
      {
          $this->msg('Error',$this->client->getError());

      }elseif ($result){

         return explode(",", $result);
       }else{return false;}


     }

    function reverseSoap($trnsID)
    {
     $trnsID = (int) $trnsID;
     $this->ConnectSoap3Function(4);

     $result= $this->client->call('reverse',
        array(
					'trmId'         => $this->terminalid,
					'transactionNo' => $trnsID,
					'UserID'        => $this->username ,
					'pass'          => $this->password
		      ));

	   if ($this->client->fault)
      {
          $this->msg('Fault',$result);

      }elseif($this->client->getError())
      {
          $this->msg('Error',$this->client->getError());

      }elseif ($result){

        return explode(",", $result);
       }else{return false;}
    }


}?>
DB SQL
PHP:
CREATE TABLE IF NOT EXISTS `payment` (
  `id` int(10) NOT NULL AUTO_INCREMENT,
  `hashcode` varchar(50) COLLATE latin1_general_ci NOT NULL,
  `digitalcode` varchar(100) COLLATE latin1_general_ci NOT NULL,
  `price` int(100) NOT NULL,
  `payment` int(100) NOT NULL,
  `salecode` int(10) NOT NULL,
  `timestamp` int(10) NOT NULL,
  `datestr` int(100) NOT NULL,
  `username` varchar(255) COLLATE latin1_general_ci NOT NULL,
  `comment` text COLLATE latin1_general_ci NOT NULL,
  `resultpayment` varchar(255) COLLATE latin1_general_ci NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci AUTO_INCREMENT=1 ;

payment.php

PHP:
require_once 'mellat.payment.class.php';

set_time_limit(180);

$mellatPayment = new MellatPayment
       (
         'http://217.218.45.25:8080/axis/services/BPSService?wsdl',
         'none',
         'https://217.218.45.25/Behpardakht/pspsite.mellat',
         termid,
         'User',
         '0000',
         'http://mydomain.com/back.php',
         '0100',
         '000000'
       );

if(isset($_POST['price']))
{
  $price   = preg_replace("([^0-9]*)", '',$_POST['price']);
  $mellatPayment->executeservice($price,date("Y-m-d H:i:s"),'quest',$sql);

}else{

// Show Template
}

back.php

PHP:
<?PHP

require_once 'mellat.payment.class.php';

$mellatPayment = new MellatPayment
       (
         'http://217.218.45.25:8080/axis/services/BPSService?wsdl',
         'http://217.218.45.25/bps/services/PSPWS?wsdl',
         'none',
         termid,
         'User',
         '0000',
         'none',
         '0100',
         '000000'
       );


if(@$_POST['status'] == 00  AND isset($_POST['trnsID']) AND isset($_POST['refID']) AND isset($_POST['rdate']))
  {

    $trnsID   = preg_replace("([^0-9]*)", '',$_POST['trnsID']);
    $SaleCode = preg_replace("([^0-9]*)", '',$_POST['saleCode']);
    $refid    = preg_replace("([^A-z0-9]*)", '',$_POST['refID']);
    $datestr  = preg_replace("([^0-9]*)", '',$_POST['rdate']);

    
    $paymentInformation = mysql_query("SELECT `salecode`,`hashcode` FROM `payment` WHERE `salecode` = '$SaleCode'
     AND `hashcode` = '$refid' LIMIT 1");
    

    if(mysql_num_rows($paymentInformation) != 1)
    {
      templateShow_(array('msg' => 'عمليات پرداخت غير مجاز است با پشتيباني سيستم تماس بگيريد'),'error');
      exit;

    }elseif(mysql_num_rows($paymentInformation) == 1)
    {
      $callverify = $mellatPayment->verify($datestr,$refid,$paymentInformation[0]['price']);

      if(!$callverify)
      {
        $callverify = $mellatPayment->inquirySoap($trnsID,$SaleCode,$refid);
        $inq = true;
      }




     if(!isset($inq))
     {

      if($callverify[0] == 00)
      {

		   $OrderMount = $paymentInformation[0]['price'];
           $callsettle = $mellatPayment->settleSoap($callverify[2]);

          if ($callsettle['return'] == 'SUCCESS' )
		   {
             $comment = "پرداخت شما با موفقيت انجام شد";
             templateShow_(array('msg' => $comment),'success1');
             exit;
		   }else{
			 $comment = "پرداخت انجام نشد";
             templateShow_(array('msg' => $comment),'error');
             exit;
		   }



      }else{

            templateShow_(array('msg' => $mellatPayment->Message($callverify[0])),'error');
            exit;

      }





    }



  }

  }

  ?>
 
آخرین ویرایش:
سلام سجاد جان . فقط واسه بانک ملت هست ؟
اون کلاسی که قبلا saidshp واسه بانک سامان گذاشته بود ، مگه بانک ملت و کلیه بانکهای عضو شبکه شتاب رو ساپورت نمی کرد ؟
ممنون . دستت درد نکنه :rose:
 

sajadmaz

Member
سلام ، این کلاس واسه اتصال به پرداخت بانک ملت هست و اون ماله پرداخت بانک سامان بود با هم کمی فرق میکنه

ببخشین یادم رفته بود بقیه کد هارو بزارم :d
 
آخرین ویرایش:
اگر با بانک ملت قرار داد داشته باشیم مگه نمیشه با همون کلاس سامان انجامش داد ؟
من که تا حالا با بانک ملت پایمنت ننوشتم فقط پارسیان و سامان بوده
 

sajadmaz

Member
نه !

هربانکی پرداختش و کلاس هاش فرق میکنه تنها سامان و اقتصاد نوین هستند که مثل هم هستند ملت کلا فرق میکنه و این مزیت رو هم داره که همه کارتهای عضو شتاب که تنها فقط رمز دوم دارند رو قبول میکنه
 

foranyone

Well-Known Member
سلام دستتون درد نکنه

لطفا در مورد مسائل زیر توضیح بدین :

اصولا چه اطلاعاتی باید از سمت کاربر به بانک فرستاده شه و چه اطلاعاتی رو بانک برا کاربر میفرسته دوست دارم با مسائل تئوری قضیه

کامل آشنا باشم
 

sajadmaz

Member
بصورت کلی میگم (بانک سامان )


مبلغ ، شماره ترمینال پذیرنده ، شماره فاکتور (که خودتون تعریف میکنید) ، و آدرس برگشتی که کاربر بعد از عملیات پرداخت باید بهش برگرده


وقتی پرداخت انجام شد سیستم بانک یه رشته 20 کاراکتری برمیگردونه که همون رسید دیجیتال هست اینجا بانک
PHP:
$_POST['MID'] AND $_POST['State'] AND $_POST['ResNum']
رو پست میکنه به همون آدرس برگشتی شما با توجه به اون stat عملیات مورد نظر رو انجام میدی اگه stat == ok بود و رسید 20 کاراکتر verifay میکنی (Soap Function ) و پیام بازگشتی از سمت بانک رو handle میکنی همین
 

foranyone

Well-Known Member
شماره ترمینال پذیرنده

این شماره رو موقع قرارداد برا وب سایت صادر میکنن درسته ؟

سیستم بانک یه رشته 20 کاراکتری برمیگردونه که همون رسید دیجیتال هست

فقط همین فرستاده میشه ؟ پس از کجا سایت ما تشخیص میده که خطای بانکی اتفاق افتاده ؟
به همون آدرس برگشتی شما با توجه به اون stat عملیات مورد نظر رو انجام میدی اگه stat == ok بود و رسید 20 کاراکتر verifay میکنی (soap function ) و پیام بازگشتی از سمت بانک رو handle میکنی همین

این قسمت رو ممنون میشم بیشتر توضیح بدین
 

sajadmaz

Member
بله شما یه merchantID و یک Merchantpassword از بانک دریافت میکنید برای ارتبات با سیستم اونا

پیغام بازگشنی هم توی stat هست

خوب ما ازکجا بدونیم پرداختمون موفق بوده ؟؟ شرط میزاریم وقتی که stat برابر ok و رسید دیجیتال 20 کاراکتر بود و همینطور مبلغ رو از طوی دیتا بیس چک می کنیم که درست باشه وقتی این شرط ها برقرار بود فانکشن verifay را مورد استفاده قرار میدیم که بانک مبلغ رو به حساب ما واریز کنه اگه این کار رو انجام ندیم تراکنش از نظر بانک نا موفق و به حساب کاربر برگشت میخوره
 

جدیدترین ارسال ها

بالا