index.php
//بارگذاری کلاس مربوط به انجام عملیات های پرداخت
require_once '../PecRequestClass.php';
$pecRequest = new PecRequestClass();
$res = false;
$success = false;
if(isset($_POST['callback'])){
$callback = $_POST['callback'];
}else{
$callback = 'http://localhost/gov/callback.php';
}
if ($_POST) {
if ($_POST['pin'] == '' || $_POST['orderId'] == '' || $_POST['amount'] == '' || $_POST['callback'] == '' || $_POST['GovId'] == '') {
$pecRequest->errorMsg = 'لطفا اطلاعات درخواست شده را تکمیل نمایید.';
$res = $pecRequest->alertMsg();
}else{
// دریافت اطلاعات از فرم
$pecRequest->pin = $_POST['pin'];
$pecRequest->callbackUrl = $_POST['callback'];
$orderId = $_POST['orderId'];
$amount = $_POST['amount'];
$govId = $_POST['GovId'];
$orginator = $_POST['orginator'];
// ارسال درخواست
$res = $pecRequest->GovermentIdSaleService($orderId,$amount,$govId,$orginator);
if ($res == false) {
$res = $pecRequest->alertMsg();
}
else{
$success = true;
}
}
}
PecRequestClass.php
// سرویس خرید با شناسه حساب دولتی
public function GovermentIdSaleService($orderId,$amount,$GovId,$orginator=""){
$this->url = "https://pec.shaparak.ir/NewIPGServices/Sale/GovermentIdSaleServiceSW2.asmx?wsdl";
$additionalData = "GOVId=".$GovId;
$this->orderId = $orderId;
$params = array (
"LoginAccount" => $this->pin,
"Amount" => $amount,
"OrderId" => $orderId,
"CallBackUrl" => $this->callbackUrl,
"AdditionalData" => $additionalData,
"Originator" => $orginator
);
// در این مرحله میتوانید اطلاعات را قبل از ارسال ذخیره سازی کنید.
$client = new SoapClient ( $this->url );
try {
$result = $client->SalePaymentRequest ( array (
"requestData" => $params
) );
if ($result->SalePaymentRequestResult->Token && $result->SalePaymentRequestResult->Status === 0) {
// توکن دریافت شده را در این مرحله به تراکنش مورد نظر مرتبط نموده و ذخیره سازی کنید.
// $token = $result->SalePaymentRequestResult->Token;
header ( "Location: https://pec.shaparak.ir/NewIPG/?Token=" . $result->SalePaymentRequestResult->Token ); /* Redirect browser */
exit ();
}
elseif ( $result->SalePaymentRequestResult->Status != '0') {
$err_msg = "( کد خطا : " . $result->SalePaymentRequestResult->Status . ") " .
$result->SalePaymentRequestResult->Message ;
$this->errorMsg = $err_msg;
return false;
}
} catch ( Exception $ex ) {
$err_msg = $ex->getMessage();
}
}