Plugin Directory

Changeset 3151743


Ignore:
Timestamp:
09/14/2024 11:21:04 AM (19 months ago)
Author:
payping
Message:

Compatibility with PayPing v3

Location:
payping-donate/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • payping-donate/trunk/assets/js/script.js

    r3151688 r3151743  
    2828            mobile: $('input[name="mobile"]').val(),
    2929            email: $('input[name="email"]').val(),
    30             payPingDonate_Description: $('input[name="payPingDonate_Description"]').val(),
     30            payPingDonate_Description: $('.payping_description_input').val(),
    3131            page_url: returnPageUrl
    3232        };
  • payping-donate/trunk/payping-donate.php

    r3151688 r3151743  
    22/*
    33Plugin Name: Payping Donate
    4 Version: 1.3
     4Version: 1.4.0
    55Description:  افزونه دریافت حمایت مالی وردپرس
    66Plugin URI: https://payping.io/
     
    106106    }
    107107
    108     $SendDescription = $Name . ' | ' . $Mobile . ' | ' . $Email . ' | ' . $Description;
    109 
    110108    // Insert the donation record into the database
    111109    global $wpdb;
     
    119117        'Status' => 'SEND'
    120118    ));
    121 
     119   
    122120    $code = $wpdb->insert_id;
    123121
    124122    $data = array(
    125         'payerName' => $Name,
    126123        'Amount' => $SendAmount,
    127         'payerIdentity' => $Mobile,
    128         'returnUrl' => $returnUrl,
    129         'Description' => $SendDescription,
    130         'clientRefId' => $code
     124        'ReturnUrl' => $returnUrl,
     125        'PayerIdentity' => $Mobile,
     126        'PayerName' => $Name,
     127        'Description' => $Description,
     128        'ClientRefId' => "{$code}",
     129        'NationalCode' => ''
    131130    );
    132     $response = wp_remote_post('https://api.payping.ir/v1/pay', array(
     131    $response = wp_remote_post('https://api.payping.ir/v3/pay', array(
    133132        'body' => wp_json_encode($data),
    134133        'headers' => array(
     
    141140        'redirection' => 10,
    142141    ));
    143 
    144142    if (is_wp_error($response)) {
    145143        wp_send_json_error($response->get_error_message());
     
    147145        $status_code = wp_remote_retrieve_response_code($response);
    148146        $response_body = wp_remote_retrieve_body($response);
    149 
    150147        if ($status_code == 200) {
    151148            $response_data = json_decode($response_body, true);
    152             if (isset($response_data['code']) && $response_data['code'] != '') {
    153                 $url = sprintf('https://api.payping.ir/v1/pay/gotoipg/%s', $response_data['code']);
     149            if (isset($response_data['paymentCode']) && $response_data['paymentCode'] != '') {
     150                $url = sprintf('https://api.payping.ir/v3/pay/start/%s', $response_data['paymentCode']);
    154151                wp_send_json_success($url);
    155152            } else {
     
    187184    ////////////////////////////////////////////////////
    188185    ///             RESPONSE
    189     if (isset($_GET['clientrefid'])) {
    190         // Sanitize input
    191         $id = filter_input(INPUT_GET, 'clientrefid', FILTER_SANITIZE_STRING);
    192         $refid = filter_input(INPUT_GET, 'refid', FILTER_SANITIZE_STRING);
    193    
    194         $Record = payPingDonate_GetDonate($id);
    195         if ($Record === false) {
    196             $error .= 'چنین تراکنشی در سایت ثبت نشده است' . "<br>\r\n";
    197         } else {
    198             $data = array('refId' => $refid, 'amount' => $Record['AmountTomaan']);
    199             try {
    200                 $response = wp_remote_post('https://api.payping.ir/v1/pay/verify', array(
    201                     'body'        => wp_json_encode($data),
    202                     'headers'     => array(
    203                         'Accept'        => 'application/json',
    204                         'Authorization' => 'Bearer ' . esc_attr($Token),
    205                         'Cache-Control' => 'no-cache',
    206                         'Content-Type'  => 'application/json'
    207                     ),
    208                     'timeout'     => 30,
    209                     'redirection' => 10,
    210                 ));
    211            
    212                 if (is_wp_error($response)) {
    213                     $error_message = $response->get_error_message();
    214                     payPingDonate_ChangeStatus($id, 'ERROR');
    215                     $error .= esc_html(get_option('payPingDonate_IsError')) . "<br>\r\n";
    216                     $error .= 'خطا در ارتباط به پی‌پینگ : شرح خطا ' . esc_html($error_message) . "<br>\r\n";
    217                     payPingDonate_SetAuthority($id, $refid);
    218                 } else {
    219                     $status_code = wp_remote_retrieve_response_code($response);
    220                     $response_body = wp_remote_retrieve_body($response);
    221            
    222                     if ($status_code == 200) {
    223                         $response_data = json_decode($response_body, true);
    224                         if (!empty($_GET["refid"])) {
    225                             payPingDonate_ChangeStatus($id, 'OK');
    226                             payPingDonate_SetAuthority($id, $refid);
    227                             $message .= esc_html(get_option('payPingDonate_IsOk')) . "<br>\r\n";
    228                             $message .= 'کد پیگیری تراکنش: ' . esc_html($refid) . "<br>\r\n";
    229                             $payPingDonate_TotalAmount = get_option("payPingDonate_TotalAmount");
    230                             update_option("payPingDonate_TotalAmount", $payPingDonate_TotalAmount + $Record['AmountTomaan']);
    231                         } else {
    232                             payPingDonate_ChangeStatus($id, 'ERROR');
    233                             $error .= esc_html(get_option('payPingDonate_IsError')) . "<br>\r\n";
    234                             payPingDonate_SetAuthority($id, $refid);
    235                             $error .= 'متاسفانه سامانه قادر به دریافت کد پیگیری نمی باشد! نتیجه درخواست : ' . esc_html(payPingDonate_GetResaultStatusString($status_code)) . '(' . esc_html($status_code) . ')' . "<br>\r\n";
    236                         }
    237                     } elseif ($status_code == 400) {
    238                         payPingDonate_ChangeStatus($id, 'ERROR');
    239                         $error .= esc_html(get_option('payPingDonate_IsError')) . "<br>\r\n";
    240                         payPingDonate_SetAuthority($id, $refid);
    241                         $error .= 'تراکنش ناموفق بود- شرح خطا : ' . esc_html(implode('. ', array_values(json_decode($response_body, true)))) . "<br>\r\n";
    242                     } else {
    243                         payPingDonate_ChangeStatus($id, 'ERROR');
    244                         $error .= esc_html(get_option('payPingDonate_IsError')) . "<br>\r\n";
    245                         payPingDonate_SetAuthority($id, $refid);
    246                         $error .= ' تراکنش ناموفق بود- شرح خطا : ' . esc_html(payPingDonate_GetResaultStatusString($status_code)) . '(' . esc_html($status_code) . ')' . "<br>\r\n";
    247                     }
    248                 }
    249             } catch (Exception $e) {
    250                 payPingDonate_ChangeStatus($id, 'ERROR');
    251                 $error .= esc_html(get_option('payPingDonate_IsError')) . "<br>\r\n";
    252                 payPingDonate_SetAuthority($id, $refid);
    253                 $error .= ' تراکنش ناموفق بود- شرح خطا سمت برنامه شما : ' . esc_html($e->getMessage()) . "<br>\r\n";
    254             }
    255         }
     186    if (isset($_REQUEST['Status'])) {
     187        $id = $_REQUEST['ClientRefId'];
     188        $status = $_REQUEST['Status'];
     189       
     190        if ($status == -1) {
     191            payPingDonate_ChangeStatus($id, 'ERROR');
     192            $error .= esc_html(get_option('payPingDonate_IsError')) . "<br>\r\n";
     193            $error .= 'پرداخت توسط کاربر لغو شد!';
     194            payPingDonate_SetAuthority($id, $status);
     195        } else {
     196            $refid = $_REQUEST['PaymentRefId'];
     197            $Record = payPingDonate_GetDonate($id);
     198            if ($Record === false) {
     199                $error .= 'چنین تراکنشی در سایت ثبت نشده است' . "<br>\r\n";
     200            } else {
     201                $data = array('PaymentRefId' => $refid, 'Amount' => $_REQUEST['Amount']);
     202                try {
     203                    $response = wp_remote_post('https://api.payping.ir/v3/pay/verify', array(
     204                        'body'        => wp_json_encode($data),
     205                        'headers'     => array(
     206                            'Accept'        => 'application/json',
     207                            'Authorization' => 'Bearer ' . esc_attr($Token),
     208                            'Cache-Control' => 'no-cache',
     209                            'Content-Type'  => 'application/json'
     210                        ),
     211                        'timeout'     => 30,
     212                        'redirection' => 10,
     213                    ));
     214               
     215                    if (is_wp_error($response)) {
     216                        $error_message = $response->get_error_message();
     217                        payPingDonate_ChangeStatus($id, 'ERROR');
     218                        $error .= esc_html(get_option('payPingDonate_IsError')) . "<br>\r\n";
     219                        $error .= 'خطا در ارتباط به پی‌پینگ : شرح خطا ' . esc_html($error_message) . "<br>\r\n";
     220                        payPingDonate_SetAuthority($id, $refid);
     221                    } else {
     222                        $status_code = wp_remote_retrieve_response_code($response);
     223                        $response_body = wp_remote_retrieve_body($response);
     224               
     225                        if ($status_code == 200) {
     226                            $response_data = json_decode($response_body, true);
     227                            if (!empty($_REQUEST["PaymentRefId"])) {
     228                                payPingDonate_ChangeStatus($id, 'OK');
     229                                payPingDonate_SetAuthority($id, $refid);
     230                                $message .= esc_html(get_option('payPingDonate_IsOk')) . "<br>\r\n";
     231                                $message .= 'کد پیگیری تراکنش: ' . esc_html($refid) . "<br>\r\n";
     232                                $payPingDonate_TotalAmount = get_option("payPingDonate_TotalAmount");
     233                                update_option("payPingDonate_TotalAmount", $payPingDonate_TotalAmount + $_REQUEST['Amount']);
     234                            } else {
     235                                payPingDonate_ChangeStatus($id, 'ERROR');
     236                                $error .= esc_html(get_option('payPingDonate_IsError')) . "<br>\r\n";
     237                                payPingDonate_SetAuthority($id, $refid);
     238                                $error .= 'متاسفانه سامانه قادر به دریافت کد پیگیری نمی باشد! نتیجه درخواست : ' . esc_html(payPingDonate_GetResaultStatusString($status_code)) . '(' . esc_html($status_code) . ')' . "<br>\r\n";
     239                            }
     240                        } elseif ($status_code == 400) {
     241                            payPingDonate_ChangeStatus($id, 'ERROR');
     242                            $error .= esc_html(get_option('payPingDonate_IsError')) . "<br>\r\n";
     243                            payPingDonate_SetAuthority($id, $refid);
     244                            $error .= 'تراکنش ناموفق بود- شرح خطا : ' . esc_html(implode('. ', array_values(json_decode($response_body, true)))) . "<br>\r\n";
     245                        } else {
     246                            payPingDonate_ChangeStatus($id, 'ERROR');
     247                            $error .= esc_html(get_option('payPingDonate_IsError')) . "<br>\r\n";
     248                            payPingDonate_SetAuthority($id, $refid);
     249                            $error .= ' تراکنش ناموفق بود- شرح خطا : ' . esc_html(payPingDonate_GetResaultStatusString($status_code)) . '(' . esc_html($status_code) . ')' . "<br>\r\n";
     250                        }
     251                    }
     252                } catch (Exception $e) {
     253                    payPingDonate_ChangeStatus($id, 'ERROR');
     254                    $error .= esc_html(get_option('payPingDonate_IsError')) . "<br>\r\n";
     255                    payPingDonate_SetAuthority($id, $refid);
     256                    $error .= ' تراکنش ناموفق بود- شرح خطا سمت برنامه شما : ' . esc_html($e->getMessage()) . "<br>\r\n";
     257                }
     258            }
     259        }
     260   
     261   
     262       
    256263    }
    257264   
     
    292299                    <div class="payPingDonate_FormItem">
    293300                        <label class="payPingDonate_FormLabel">توضیحات :</label>
    294                         <div class="payPingDonate_ItemInput"><textarea type="text" class="payPingDonate_input" name="payPingDonate_Description" value="' . esc_attr($Description) . '" /></textarea></div>
     301                        <div class="payPingDonate_ItemInput"><textarea type="text" class="payPingDonate_input payping_description_input" name="payPingDonate_Description" value="' . esc_attr($Description) . '" /></textarea></div>
    295302                    </div>
    296303                    <div class="payPingDonate_FormItem">
  • payping-donate/trunk/readme.txt

    r3151688 r3151743  
    55Tested up to: 6.6.0
    66Requires PHP: 7.0.0
    7 Stable tag: 1.3
     7Stable tag: 1.4.0
    88License: GPLv3 or later
    99License URI: http://www.gnu.org/licenses/gpl-3.0.html
     
    2424This plugin leverages the following third-party services:
    2525
    26 1. api.payping.ir/v1/pay/verify: To verify payments in our plugin.
    27 2. api.payping.ir/v1/pay: For create order in our plugin and send user to gateway.
     261. api.payping.ir/v3/pay/verify: To verify payments in our plugin.
     272. api.payping.ir/v3/pay: For create order in our plugin and send user to gateway.
    2828
    2929
     
    3535== 1.3 ==
    3636Add Custom CSS feature
     37
     38== 1.4.0 ==
     39Compatibility with PayPing v3
Note: See TracChangeset for help on using the changeset viewer.