From df13604a996840cde2342f843feb4b0613a832b1 Mon Sep 17 00:00:00 2001 From: Erfan Ebrahimi Date: Thu, 25 Oct 2018 19:44:31 +0330 Subject: [PATCH] Add files via upload --- PayPingDonate.php | 567 ++++++++++++++++++++++++++++++++++++ payPingDonate_AdminPage.php | 107 +++++++ payPingDonate_Hamian.php | 1 + 3 files changed, 675 insertions(+) create mode 100644 PayPingDonate.php create mode 100644 payPingDonate_AdminPage.php create mode 100644 payPingDonate_Hamian.php diff --git a/PayPingDonate.php b/PayPingDonate.php new file mode 100644 index 0000000..ae45622 --- /dev/null +++ b/PayPingDonate.php @@ -0,0 +1,567 @@ +\r\n"; + } + + + $Amount = filter_input(INPUT_POST, 'payPingDonate_Amount', FILTER_SANITIZE_SPECIAL_CHARS); + + if(is_numeric($Amount) != false) + { + //Amount will be based on Toman - Required + if($payPingDonate_Unit == 'ریال') + $SendAmount = $Amount / 10; + else + $SendAmount = $Amount; + } + else + { + $error .= 'مبلغ به درستی وارد نشده است' . "
\r\n"; + } + + $Description = filter_input(INPUT_POST, 'payPingDonate_Description', FILTER_SANITIZE_SPECIAL_CHARS); // Required + $Name = filter_input(INPUT_POST, 'payPingDonate_Name', FILTER_SANITIZE_SPECIAL_CHARS); // Required + $Mobile = filter_input(INPUT_POST, 'mobile', FILTER_SANITIZE_SPECIAL_CHARS); // Optional + $Email = filter_input(INPUT_POST, 'email', FILTER_SANITIZE_SPECIAL_CHARS); // Optional + + $SendDescription = $Name . ' | ' . $Mobile . ' | ' . $Email . ' | ' . $Description ; + + if($error == '') // اگر خطایی نباشد + { + + $code = payPingDonate_AddDonate(array( + 'Name' => $Name, + 'AmountTomaan' => $SendAmount, + 'Mobile' => $Mobile, + 'Email' => $Email, + 'InputDate' => current_time( 'mysql' ), + 'Description' => $Description, + 'Status' => 'SEND' + ),array( + '%s', + '%s', + '%d', + '%s', + '%s', + '%s', + '%s', + '%s' + )); + $CallbackURL = payPingDonate_GetCallBackURL(); // Required + $data = array('payerName'=>$Name, 'Amount' => $SendAmount,'payerIdentity'=> $Mobile , 'returnUrl' => $CallbackURL, 'Description' => $SendDescription , 'clientRefId' => $code ); + try { + $curl = curl_init(); + curl_setopt_array($curl, array( + CURLOPT_URL => "https://api.payping.ir/v1/pay", + CURLOPT_RETURNTRANSFER => true, + CURLOPT_ENCODING => "", + CURLOPT_MAXREDIRS => 10, + CURLOPT_TIMEOUT => 30, + CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, + CURLOPT_CUSTOMREQUEST => "POST", + CURLOPT_POSTFIELDS => json_encode($data), + CURLOPT_HTTPHEADER => array( + "accept: application/json", + "authorization: Bearer " .$MerchantID, + "cache-control: no-cache", + "content-type: application/json"), + ) + ); + $response = curl_exec($curl); + $header = curl_getinfo($curl); + $err = curl_error($curl); + curl_close($curl); + if ($err) { + echo "cURL Error #:" . $err; + } else { + if ($header['http_code'] == 200) { + $response = json_decode($response, true); + if (isset($response["code"]) and $response["code"] != '') { + + wp_redirect(sprintf('https://api.payping.ir/v1/pay/gotoipg/%s', $response["code"])); + exit; + } else { + $error .= ' تراکنش ناموفق بود- شرح خطا : عدم وجود کد ارجاع '. "
\r\n"; + } + } elseif ($header['http_code'] == 400) { + $error .= ' تراکنش ناموفق بود- شرح خطا : ' . implode('. ',array_values (json_decode($response,true))). "
\r\n" ; + } else { + $error .= ' تراکنش ناموفق بود- شرح خطا : ' . payPingDonate_GetResaultStatusString($header['http_code']) . '(' . $header['http_code'] . ')'. "
\r\n"; + } + } + } catch (Exception $e){ + $error .= ' تراکنش ناموفق بود- شرح خطا سمت برنامه شما : ' . $e->getMessage(). "
\r\n"; + } + } + } + //// END REQUEST + + + //////////////////////////////////////////////////// + /// RESPONSE + if(isset($_GET['clientrefid'])) + { + $id = filter_input(INPUT_GET, 'clientrefid', FILTER_SANITIZE_SPECIAL_CHARS); + $refid = filter_input(INPUT_GET, 'refid', FILTER_SANITIZE_SPECIAL_CHARS); + + + + $Record = payPingDonate_GetDonate($id); + if( $Record === false) + { + $error .= 'چنین تراکنشی در سایت ثبت نشده است' . "
\r\n"; + } + else + { + + + $data = array('refId' => $refid, 'amount' => $Record['AmountTomaan']); + try { + $curl = curl_init(); + curl_setopt_array($curl, array( + CURLOPT_URL => "https://api.payping.ir/v1/pay/verify", + CURLOPT_RETURNTRANSFER => true, + CURLOPT_ENCODING => "", + CURLOPT_MAXREDIRS => 10, + CURLOPT_TIMEOUT => 30, + CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, + CURLOPT_CUSTOMREQUEST => "POST", + CURLOPT_POSTFIELDS => json_encode($data), + CURLOPT_HTTPHEADER => array( + "accept: application/json", + "authorization: Bearer ".$MerchantID, + "cache-control: no-cache", + "content-type: application/json", + ), + )); + $response = curl_exec($curl); + $err = curl_error($curl); + $header = curl_getinfo($curl); + curl_close($curl); + if ($err) { + payPingDonate_ChangeStatus($id, 'ERROR'); + $error .= get_option( 'payPingDonate_IsError') . "
\r\n"; + $error .= 'خطا در ارتباط به پی‌پینگ : شرح خطا '.$err. "
\r\n"; + payPingDonate_SetAuthority($id, $refid); + } else { + if ($header['http_code'] == 200) { + $response = json_decode($response, true); + if (isset($_GET["refid"]) and $_GET["refid"] != '') { + payPingDonate_ChangeStatus($id, 'OK'); + $message .= get_option( 'payPingDonate_IsOk') . "
\r\n"; + $message .= 'کد پیگیری تراکنش:'. $refid . "
\r\n"; + $payPingDonate_TotalAmount = get_option("payPingDonate_TotalAmount"); + update_option("payPingDonate_TotalAmount" , $payPingDonate_TotalAmount + $Record['AmountTomaan']); + } else { + payPingDonate_ChangeStatus($id, 'ERROR'); + $error .= get_option( 'payPingDonate_IsError') . "
\r\n"; + payPingDonate_SetAuthority($id, $refid); + $error .= 'متافسانه سامانه قادر به دریافت کد پیگیری نمی باشد! نتیجه درخواست : ' . payPingDonate_GetResaultStatusString($header['http_code']) . '(' . $header['http_code'] . ')' . "
\r\n"; + } + } elseif ($header['http_code'] == 400) { + payPingDonate_ChangeStatus($id, 'ERROR'); + $error .= get_option( 'payPingDonate_IsError') . "
\r\n"; + payPingDonate_SetAuthority($id, $refid); + $error .= 'تراکنش ناموفق بود- شرح خطا : ' . implode('. ',array_values (json_decode($response,true))) . "
\r\n"; + } else { + payPingDonate_ChangeStatus($id, 'ERROR'); + $error .= get_option( 'payPingDonate_IsError') . "
\r\n"; + payPingDonate_SetAuthority($id, $refid); + $error .= ' تراکنش ناموفق بود- شرح خطا : ' . payPingDonate_GetResaultStatusString($header['http_code']) . '(' . $header['http_code'] . ')'. "
\r\n"; + } + } + } catch (Exception $e){ + payPingDonate_ChangeStatus($id, 'ERROR'); + $error .= get_option( 'payPingDonate_IsError') . "
\r\n"; + payPingDonate_SetAuthority($id, $refid); + $error .= ' تراکنش ناموفق بود- شرح خطا سمت برنامه شما : ' . $e->getMessage(). "
\r\n"; + } + + } + + } + /// END RESPONSE + + $style = ''; + + if(get_option('payPingDonate_UseCustomStyle') == 'true') + { + $style = get_option('payPingDonate_CustomStyle'); + } + else + { + $style = '#payPingDonate_MainForm { width: 400px; height: auto; margin: 0 auto; direction: rtl; } #payPingDonate_Form { width: 96%; height: auto; float: right; padding: 10px 2%; } #payPingDonate_Message,#payPingDonate_Error { width: 90%; margin-top: 10px; margin-right: 2%; float: right; padding: 5px 2%; border-right: 2px solid #006704; background-color: #e7ffc5; color: #00581f; } #payPingDonate_Error { border-right: 2px solid #790000; background-color: #ffc9c5; color: #580a00; } .payPingDonate_FormItem { width: 90%; margin-top: 10px; margin-right: 2%; float: right; padding: 5px 2%; } .payPingDonate_FormLabel { width: 35%; float: right; padding: 3px 0; } .payPingDonate_ItemInput { width: 64%; float: left; } .payPingDonate_ItemInput input { width: 90%; float: right; border-radius: 3px; box-shadow: 0 0 2px #00c4ff; border: 0px solid #c0fff0; font-family: inherit; font-size: inherit; padding: 3px 5px; } .payPingDonate_ItemInput input:focus { box-shadow: 0 0 4px #0099d1; } .payPingDonate_ItemInput input.error { box-shadow: 0 0 4px #ef0d1e; } input.payPingDonate_Submit { background: none repeat scroll 0 0 #2ea2cc; border-color: #0074a2; box-shadow: 0 1px 0 rgba(120, 200, 230, 0.5) inset, 0 1px 0 rgba(0, 0, 0, 0.15); color: #fff; text-decoration: none; border-radius: 3px; border-style: solid; border-width: 1px; box-sizing: border-box; cursor: pointer; display: inline-block; font-size: 13px; line-height: 26px; margin: 0; padding: 0 10px 1px; margin: 10px auto; width: 50%; font: inherit; float: right; margin-right: 24%; }'; + } + + + $out = ' + +
+
+
'; + +if($message != '') +{ + $out .= "
+ ${message} +
"; +} + +if($error != '') +{ + $out .= "
+ ${error} +
"; +} + + $out .= '
+
+ +
+ + '. $payPingDonate_Unit .' +
+
+ +
+ +
+
+ +
+ +
+
+ +
+ +
+
+ +
+ +
+
+ +
+ +
+
+
+
+
+ '; + + return $out; +} + +///////////////////////////////////////////////// + +register_activation_hook(__FILE__,'payPingDonate_install'); +function payPingDonate_install() +{ + payPingDonate_CreateDatabaseTables(); +} +function payPingDonate_CreateDatabaseTables() +{ + global $wpdb; + $DonateTable = $wpdb->prefix . TABLE_DONATE; + // Creat table + $nazrezohoor = "CREATE TABLE IF NOT EXISTS `$DonateTable` ( + `DonateID` int(11) NOT NULL AUTO_INCREMENT, + `Authority` varchar(50) NOT NULL, + `Name` varchar(50) CHARACTER SET utf8 COLLATE utf8_persian_ci NOT NULL, + `AmountTomaan` int(11) NOT NULL, + `Mobile` varchar(11) , + `Email` varchar(50), + `InputDate` varchar(20), + `Description` varchar(100) CHARACTER SET utf8 COLLATE utf8_persian_ci, + `Status` varchar(5), + PRIMARY KEY (`DonateID`), + KEY `DonateID` (`DonateID`) + ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;"; + dbDelta($nazrezohoor); + // Other Options + add_option("payPingDonate_TotalAmount", 0, '', 'yes'); + add_option("payPingDonate_TotalPayment", 0, '', 'yes'); + add_option("payPingDonate_IsOK", 'با تشکر پرداخت شما به درستی انجام شد.', '', 'yes'); + add_option("payPingDonate_IsError", 'متاسفانه پرداخت انجام نشد.', '', 'yes'); + + $style = '#payPingDonate_MainForm { + width: 400px; + height: auto; + margin: 0 auto; + direction: rtl; +} + +#payPingDonate_Form { + width: 96%; + height: auto; + float: right; + padding: 10px 2%; +} + +#payPingDonate_Message,#payPingDonate_Error { + width: 90%; + margin-top: 10px; + margin-right: 2%; + float: right; + padding: 5px 2%; + border-right: 2px solid #006704; + background-color: #e7ffc5; + color: #00581f; +} + +#payPingDonate_Error { + border-right: 2px solid #790000; + background-color: #ffc9c5; + color: #580a00; +} + +.payPingDonate_FormItem { + width: 90%; + margin-top: 10px; + margin-right: 2%; + float: right; + padding: 5px 2%; +} + +.payPingDonate_FormLabel { + width: 35%; + float: right; + padding: 3px 0; +} + +.payPingDonate_ItemInput { + width: 64%; + float: left; +} + +.payPingDonate_ItemInput input { + width: 90%; + float: right; + border-radius: 3px; + box-shadow: 0 0 2px #00c4ff; + border: 0px solid #c0fff0; + font-family: inherit; + font-size: inherit; + padding: 3px 5px; +} + +.payPingDonate_ItemInput input:focus { + box-shadow: 0 0 4px #0099d1; +} + +.payPingDonate_ItemInput input.error { + box-shadow: 0 0 4px #ef0d1e; +} + +input.payPingDonate_Submit { + background: none repeat scroll 0 0 #2ea2cc; + border-color: #0074a2; + box-shadow: 0 1px 0 rgba(120, 200, 230, 0.5) inset, 0 1px 0 rgba(0, 0, 0, 0.15); + color: #fff; + text-decoration: none; + border-radius: 3px; + border-style: solid; + border-width: 1px; + box-sizing: border-box; + cursor: pointer; + display: inline-block; + font-size: 13px; + line-height: 26px; + margin: 0; + padding: 0 10px 1px; + margin: 10px auto; + width: 50%; + font: inherit; + float: right; + margin-right: 24%; +}'; + add_option("payPingDonate_CustomStyle", $style, '', 'yes'); + add_option("payPingDonate_UseCustomStyle", 'false', '', 'yes'); +} + +function payPingDonate_GetDonate($id) +{ + global $wpdb; + $id = strip_tags($wpdb->escape($id)); + + if($id == '') + return false; + + $DonateTable = $wpdb->prefix . TABLE_DONATE; + + $res = $wpdb->get_results( "SELECT * FROM ${DonateTable} WHERE `DonateID` = '${$id}' LIMIT 1",ARRAY_A); + + if(count($res) == 0) + return false; + + return $res[0]; +} + +function payPingDonate_AddDonate($Data, $Format) +{ + global $wpdb; + + if(!is_array($Data)) + return false; + + $DonateTable = $wpdb->prefix . TABLE_DONATE; + + $res = $wpdb->insert( $DonateTable , $Data, $Format); + + if($res == 1) + { + $totalPay = get_option('payPingDonate_TotalPayment'); + $totalPay += 1; + update_option('payPingDonate_TotalPayment', $totalPay); + } + + return $wpdb->insert_id; +} + +function payPingDonate_ChangeStatus($id,$Status) +{ + global $wpdb; + $id = strip_tags($wpdb->escape($id)); + $Status = strip_tags($wpdb->escape($Status)); + + if($id == '' || $Status == '') + return false; + + $DonateTable = $wpdb->prefix . TABLE_DONATE; + + $res = $wpdb->query( "UPDATE ${DonateTable} SET `Status` = '${Status}' WHERE `DonateID` = '${$id}'"); + + return $res; +} +function payPingDonate_SetAuthority($id,$Authority) +{ + global $wpdb; + $id = strip_tags($wpdb->escape($id)); + $Authority = strip_tags($wpdb->escape($Authority)); + + if($id == '' || $Authority == '') + return false; + + $DonateTable = $wpdb->prefix . TABLE_DONATE; + + $res = $wpdb->query( "UPDATE ${DonateTable} SET `Authority` = '${$Authority}' WHERE `DonateID` = '${$id}'"); + + return $res; +} + +function payPingDonate_GetResaultStatusString($StatusNumber) +{ + switch($StatusNumber) { + case 200 : + return 'عملیات با موفقیت انجام شد'; + break ; + case 400 : + return 'مشکلی در ارسال درخواست وجود دارد'; + break ; + case 500 : + return 'مشکلی در سرور رخ داده است'; + break; + case 503 : + return 'سرور در حال حاضر قادر به پاسخگویی نمی‌باشد'; + break; + case 401 : + return 'عدم دسترسی'; + break; + case 403 : + return 'دسترسی غیر مجاز'; + break; + case 404 : + return 'آیتم درخواستی مورد نظر موجود نمی‌باشد'; + break; + } + + return ''; +} + +function payPingDonate_GetCallBackURL() +{ + $pageURL = (@$_SERVER["HTTPS"] == "on") ? "https://" : "http://"; + + $ServerName = htmlspecialchars($_SERVER["SERVER_NAME"], ENT_QUOTES, "utf-8"); + $ServerPort = htmlspecialchars($_SERVER["SERVER_PORT"], ENT_QUOTES, "utf-8"); + $ServerRequestUri = htmlspecialchars($_SERVER["REQUEST_URI"], ENT_QUOTES, "utf-8"); + + if ($_SERVER["SERVER_PORT"] != "80") + { + $pageURL .= $ServerName .":". $ServerPort . $_SERVER["REQUEST_URI"]; + } + else + { + $pageURL .= $ServerName . $ServerRequestUri; + } + return $pageURL; +} + +?> \ No newline at end of file diff --git a/payPingDonate_AdminPage.php b/payPingDonate_AdminPage.php new file mode 100644 index 0000000..e490525 --- /dev/null +++ b/payPingDonate_AdminPage.php @@ -0,0 +1,107 @@ +

تنظیمات ذخیره شد.

'; + +} + +?> +

تنظیمات افزونه حمایت مالی - پی‌پینگ

+

جمع تمام پرداخت ها : تومان

+

برای استفاده تنها کافی است کد زیر را درون بخشی از برگه یا نوشته خود قرار دهید [PayPingDonate]

+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + > + + + + + +
+ +

توکن درگاه پی‌پینگ

+
+ + +
استفاده از استایل سفارشی + + />
+
استایل سفارشی +
+
+

+
+ + + diff --git a/payPingDonate_Hamian.php b/payPingDonate_Hamian.php new file mode 100644 index 0000000..55da3b8 --- /dev/null +++ b/payPingDonate_Hamian.php @@ -0,0 +1 @@ +

حامیان مالی

مبلغ کل حمایت شده : تومان

1) $Start ++; $Limit = " LIMIT $Start , $End"; } /// global $wpdb; $DonateTable = $wpdb->prefix . TABLE_DONATE; if(isset($_REQUEST['searchbyname']) && $_REQUEST['searchbyname'] != '') { $SearchName = htmlspecialchars(strip_tags(trim($_REQUEST['searchbyname'])), ENT_QUOTES); $result = $wpdb->get_results( "SELECT * FROM `$DonateTable` where `Name` LIKE '%$SearchName%' ORDER BY DonateID DESC ".$Limit); } else { $result = $wpdb->get_results( "SELECT * FROM `$DonateTable` ORDER BY DonateID DESC ".$Limit); } echo $resault; foreach($result as $row) : ?>
نام و نام خانوادگی مبلغ (تومان) موبایل شماره پیگیری ایمیل توضیحات تاریخ
نام و نام خانوادگی مبلغ (تومان) موبایل شماره پیگیری ایمیل توضیحات تاریخ
Name; ?> Status; ?>
AmountTomaan; ?> Mobile; ?> Authority; ?> Email; ?> Description; ?> InputDate; ?>
0) { $PagesNum = $totalPay / 30; $PageNumInt = intval($PagesNum); if($PageNumInt < $PagesNum) $PageNumInt++; } $currentPage = 1; if(isset($_REQUEST['pageid'])) $currentPage = htmlspecialchars(strip_tags(trim($_REQUEST['pageid'])), ENT_QUOTES); //echo $PageNumInt; ?>
مورد '. $i .''; else echo ''. $i .''; } ?>


\ No newline at end of file