Plugin Directory

Changeset 3165632


Ignore:
Timestamp:
10/09/2024 10:38:46 AM (18 months ago)
Author:
payping
Message:

Add V3

Location:
woo-payping-gateway
Files:
14 added
1 deleted
3 edited

Legend:

Unmodified
Added
Removed
  • woo-payping-gateway/trunk/class-wc-gateway-payping.php

    r3063373 r3165632  
    55    class WC_payping extends WC_Payment_Gateway{
    66       
    7         private $baseurl = 'https://api.payping.ir/v2';
     7        private $baseurl = 'https://api.payping.ir/v3';
    88        private $paypingToken;
    99        private $success_massage;
     
    2121
    2222            $checkserver = $this->settings['ioserver'];
    23             if( $checkserver == 'yes')$this->baseurl  = 'https://api.payping.io/v2';
     23            if( $checkserver == 'yes')$this->baseurl  = 'https://api.payping.ir/v3';
    2424           
    2525            $this->title = $this->settings['title'];
     
    131131            $paypingpayCode = get_post_meta($order_id, '_payping_payCode', true);
    132132            if( $paypingpayCode ){
    133                 wp_redirect( sprintf('%s/pay/gotoipg/%s', $this->baseurl, $paypingpayCode )) ;
     133                wp_redirect( sprintf('%s/pay/start/%s', $this->baseurl, $paypingpayCode )) ;
    134134                exit;
    135135            }
     
    189189                $payerIdentity = $Email;
    190190            $data = array(
    191                 'payerName'=>$Paymenter,
     191                'PayerName'=>$Paymenter,
    192192                'Amount' => $Amount,
    193                 'payerIdentity'=> $payerIdentity ,
    194                 'returnUrl' => $CallbackUrl,
     193                'PayerIdentity'=> $payerIdentity ,
     194                'ReturnUrl' => $CallbackUrl,
    195195                'Description' => $Description ,
    196                 'clientRefId' => $order->get_order_number()
     196                'ClientRefId' => $order->get_order_number(),
     197                'NationalCode'  => ''
    197198            );
    198199
     
    204205                'blocking' => true,
    205206               'headers' => array(
     207                  'X-Platform'         => 'woocommerce',
     208                  'X-Platform-Version' => '4.5.0',
    206209                  'Authorization' => 'Bearer '.$this->paypingToken,
    207210                  'Content-Type'  => 'application/json',
     
    214217
    215218            $api_args = apply_filters( 'WC_payping_Gateway_Payment_api_args', $args, $order_id );
    216 
     219           
    217220            $response = wp_remote_post($api_url, $api_args);
    218221
    219222            $ERR_ID = wp_remote_retrieve_header($response, 'x-paypingrequest-id');
     223           
    220224            if( is_wp_error($response) ){
    221225                $Message = $response->get_error_message();
     
    223227                $code = wp_remote_retrieve_response_code( $response );
    224228                if( $code === 200){
    225                     if (isset($response["body"]) and $response["body"] != '') {
     229                   
     230                    if (isset($response["body"]) && $response["body"] != '') {
    226231                        $code_pay = wp_remote_retrieve_body($response);
    227232                        $code_pay =  json_decode($code_pay, true);
    228                         update_post_meta($order_id, '_payping_payCode', $code_pay["code"] );
    229                         $Note = 'ساخت موفق پرداخت، کد پرداخت: '.$code_pay["code"];
     233                        update_post_meta($order_id, '_payping_payCode', $code_pay["paymentCode"] );
     234                        $Note = 'ساخت موفق پرداخت، کد پرداخت: '.$code_pay["paymentCode"];
    230235                        $order->add_order_note($Note, 1, false);
    231                         wp_redirect(sprintf('%s/pay/gotoipg/%s', $this->baseurl, $code_pay["code"]));
     236                        wp_redirect(sprintf('%s/pay/start/%s', $this->baseurl, $code_pay["paymentCode"]));
    232237                        exit;
    233238                    } else {
     
    253258        public function Return_from_payping_Gateway(){
    254259            global $woocommerce;
    255            
     260            $paypingResponse = stripslashes($_REQUEST['data']);
     261            $responseData = json_decode($paypingResponse, true);
    256262            if( isset( $_REQUEST['wc_order'] ) ){
    257263                $order_id = sanitize_text_field( $_REQUEST['wc_order'] );
     
    262268
    263269            // Get refid
    264             if( isset( $_REQUEST['refid'] ) ){
    265                 $refid = sanitize_text_field( $_REQUEST['refid'] );
     270            if (isset($responseData['paymentRefId'])) {
     271                $refid = sanitize_text_field($responseData['paymentRefId']);
    266272            }else{
    267273                $refid = null;
    268274            }
    269275           
    270             $order_id = apply_filters('WC_payping_return_order_id', $order_id);
    271            
    272            
    273             if( isset( $order_id ) ){
    274                 if( $refid != null && $refid > 1000 ){
    275                     update_post_meta($order_id, 'woo_payping_refid', $refid );
    276                 }
    277 
    278                 // Get Order id
    279                 $order = new WC_Order($order_id);
    280                 // Get Currency Order
    281                 $currency = $order->get_currency();
    282                 // Add Filter For Another Developer
    283                 $currency = apply_filters('WC_payping_Currency', $currency, $order_id);
    284 
     276            // Get Order id
     277            $order = new WC_Order($order_id);
     278            // Get Currency Order
     279            $currency = $order->get_currency();
     280            // Add Filter For Another Developer
     281            $currency = apply_filters('WC_payping_Currency', $currency, $order_id);
     282                   
     283            // Add Filter for ANother Developer
     284            $refid = apply_filters('WC_payping_return_refid', $refid);
     285            $Transaction_ID = $refid;
     286           
     287            if ($_REQUEST['status'] == 0) {
     288                $Status = 'failed';
     289                $Message = "کاربر در صفحه بانک از پرداخت انصراف داده است.";
     290                $Fault = 'تراكنش توسط شما لغو شد.';
     291                   
     292                $tr_id = ($Transaction_ID && $Transaction_ID != 0) ? ('<br/>کد پیگیری: ' . $Transaction_ID) : '';
     293                $Note = sprintf(__('خطا در هنگام تایید پرداخت: %s', 'woocommerce'), $Message, $tr_id);
     294                $Note = apply_filters('WC_payping_Return_from_Gateway_Failed_Note', $Note, $order_id, $Transaction_ID, $Fault);
     295                $Notice = wpautop(wptexturize($Note));
     296                $Notice = str_replace("{transaction_id}", $Transaction_ID, $Notice);
     297                $Notice = str_replace("{fault}", $Message, $Notice);
     298                $Notice = apply_filters('WC_payping_Return_from_Gateway_Failed_Notice', $Notice, $order_id, $Transaction_ID, $Fault);
     299                do_action('WC_payping_Return_from_Gateway_Failed', $order_id, $Transaction_ID, $Fault);
     300                wc_add_notice($Fault, 'error');
     301                   
     302                $order->add_order_note( $Notice, 0, false);
     303                wp_redirect(wc_get_checkout_url());
     304                exit;
     305                   
     306            }else{
     307                $order_id = apply_filters('WC_payping_return_order_id', $order_id);
     308                $order->update_meta_data( 'woo_payping_refid', $refid );
     309               
    285310                if( $order->get_status() != 'completed' ){
    286311                    // Get Amount
     
    291316                    $Amount = $this->payping_check_currency( $Amount, $currency );
    292317
    293                     // Add Filter for ANother Developer
    294                     $refid = apply_filters('WC_payping_return_refid', $refid);
    295                     $Transaction_ID = $refid;
    296                    
    297318                    //Set Data
    298                     $data = array('refId' => $refid, 'amount' => $Amount);
     319                    $data = array('PaymentRefId' => $refid, 'Amount' => $Amount);
     320                   
    299321                    $args = array(
    300322                        'body' => json_encode($data),
     
    304326                        'blocking' => true,
    305327                        'headers' => array(
    306                         'Authorization' => 'Bearer ' . $this->paypingToken,
    307                         'Content-Type'  => 'application/json',
    308                         'Accept' => 'application/json'
     328                            'Authorization' => 'Bearer ' . $this->paypingToken,
     329                            'Content-Type'  => 'application/json',
     330                            'Accept' => 'application/json'
    309331                        ),
    310                      'cookies' => array()
     332                        'cookies' => array()
    311333                    );
    312                    
    313                 // Add Filter for use Another developer
    314                 $verify_api_url = apply_filters( 'WC_payping_Gateway_Payment_verify_api_url', $this->baseurl . '/pay/verify', $order_id );
    315                 //response
    316                 $response = wp_remote_post($verify_api_url, $args);
    317                
    318                 $body = wp_remote_retrieve_body( $response );
    319                 $rbody = json_decode( $body, true );
    320                
    321                 $ERR_ID = wp_remote_retrieve_header($response, 'x-paypingrequest-id');
    322                 if( is_wp_error($response) ){
    323                     $Status = 'failed';
    324                     $Fault = $response->get_error_message();
    325                     $Message = 'خطا در ارتباط به پی‌پینگ : شرح خطا '.$response->get_error_message();
    326                 }else{
    327                     $code = wp_remote_retrieve_response_code( $response );
    328                     $txtmsg = $this->status_message( $code );
    329                    
    330                     //check cardNumber payer
    331                     if(isset($rbody['cardNumber'])){
    332                         $cardNumber = $rbody['cardNumber'];
    333                         update_post_meta($order_id, 'payping_payment_card_number', $cardNumber);
     334
     335                    // Add Filter for use Another developer
     336                    $verify_api_url = apply_filters( 'WC_payping_Gateway_Payment_verify_api_url', $this->baseurl . '/pay/verify', $order_id );
     337                    //response
     338                    $response = wp_remote_post($verify_api_url, $args);
     339                    $body = wp_remote_retrieve_body( $response );
     340                    $rbody = json_decode( $body, true );
     341                   
     342                    if( is_wp_error($response) ){
     343                        $Status = 'failed';
     344                        $Fault = $response->get_error_message();
     345                        $Message = 'خطا در ارتباط به پی‌پینگ : شرح خطا '.$response->get_error_message();
     346                    }elseif (isset($rbody['status']) && $rbody['status'] == 409) {
     347                        $Status = 'completed';
     348                        $Message = 'این سفارش قبلا تایید شده است.';
    334349                    }else{
     350                        $code = wp_remote_retrieve_response_code( $response );
     351                        $txtmsg = $this->status_message( $code );
     352                       
     353                        //check cardNumber payer
    335354                        $cardNumber = '-';
    336                     }
    337                    
    338                     if( $code === 200 ){
    339                         if( isset( $refid ) and $refid != '' ){
     355                        $CardHashPan = '-';
     356                       
     357                        if(isset($rbody['cardNumber']))$cardNumber = $rbody['cardNumber'];
     358                       
     359                        if(isset($rbody['cardHashPan']))$CardHashPan = $rbody['cardHashPan'];
     360                       
     361                        $order->update_meta_data('payping_payment_card_number', $cardNumber);
     362                        $order->update_meta_data('payping_payment_card_hashpan', $CardHashPan);
     363                       
     364                        if( $code === 200 ){
    340365                            $Status = 'completed';
    341                             $Message = $txtmsg.'<br>شماره کارت: <b dir="ltr">'.$cardNumber.'</b>';
     366                            $Message = "{$txtmsg}<br>شماره کارت: <b dir='ltr'>{$cardNumber}</b>";
     367                        }elseif( $code == 400){
     368                                $Status = 'failed';
     369                                $Message = $txtmsg;
     370                                $Fault = 'خطایی رخ داده است، با مدیریت سایت تماس بگیرید.';
    342371                        }else{
    343372                            $Status = 'failed';
    344                             $Message = 'متاسفانه سامانه قادر به دریافت کد پیگیری نمی باشد! نتیجه درخواست : ' . $body .'<br /> شماره خطا: '.$ERR_ID;
    345                             $Fault = 'خطای دریافت کد پیگیری!';
     373                            $Message = $txtmsg;
     374                            $Fault = 'خطای نامشخص در تایید پرداخت!';
    346375                        }
    347                     }elseif( $code == 400){
    348                         if( array_key_exists('15', $rbody) ){
    349                             $Status = 'completed';
    350                             $Message = $txtmsg.'<br>شماره کارت: <b dir="ltr">'.$cardNumber.'</b>';
    351                         }elseif( array_key_exists( '1', $rbody) ){
    352                             $Status = 'failed';
    353                             $Message = "کاربر در صفحه بانک از پرداخت انصراف داده است.<br> شماره خطا: $ERR_ID";
    354                             $Fault = 'تراكنش توسط شما لغو شد.';
    355                         }else{
    356                             $Status = 'failed';
    357                             $Message = $txtmsg."<br> شماره خطا: $ERR_ID";
    358                             $Fault = 'خطایی رخ داده است، با مدیریت سایت تماس بگیرید.';
    359                         }
    360                     }else{
    361                         $Status = 'failed';
    362                         $Message = $txtmsg.'<br> شماره خطا: '.$ERR_ID;
    363                         $Fault = 'خطای نامشخص در تایید پرداخت!';
    364376                    }
    365                 }
    366                
     377                   
    367378                    if( isset( $Transaction_ID ) && $Transaction_ID != 0 ){
    368                         update_post_meta($order_id, '_transaction_id', $Transaction_ID );
     379                       
     380                        $order->update_meta_data( '_transaction_id', $Transaction_ID );
     381                       
    369382                        if( $Status == 'completed' ){
    370383                            $Note = sprintf( __('%s <br> شماره سفارش: %s <br>', 'woocommerce'), $Message, $Transaction_ID) ;
     
    372385                            $Notice = wpautop(wptexturize($this->success_massage));
    373386                            $Notice = str_replace("{transaction_id}", $Transaction_ID, $Notice);
    374                             $Notice = apply_filters('WC_payping_Return_from_Gateway_Success_Notice', $Notice, $order_id, $Transaction_ID);
     387                            $Notice = apply_filters('woocommerce_thankyou_order_received_text', $Notice, $order_id, $Transaction_ID);
     388                           
    375389                            do_action('WC_payping_Return_from_Gateway_Success', $order_id, $Transaction_ID, $response);
    376                             wc_add_notice($Message, 'error');
    377                             $order->add_order_note( $Message, 0, false);
     390                           
    378391                            $woocommerce->cart->empty_cart();
     392                           
     393                            wc_add_notice($Message, 'success');
     394                           
    379395                            $order->payment_complete($Transaction_ID);
     396                           
     397                            // Add order note
     398                            $order->add_order_note( sprintf( __( '%s <br>شماره پیگیری پرداخت: %s', 'woocommerce' ), $Message, $Transaction_ID ) );
     399                           
    380400                            wp_redirect(add_query_arg('wc_status', 'success', $this->get_return_url($order)));
     401                           
    381402                            exit;
    382403                        }else{
     
    394415                            exit;
    395416                        }
     417                       
    396418                    }else{
    397419                        wc_add_notice($Fault, 'error');
     
    399421                        update_post_meta($order_id, '_transaction_id', $Transaction_ID );
    400422                    }
     423                    $order->save();
    401424                }else{
    402425                    $Transaction_ID = get_post_meta($order_id, '_transaction_id', true);
    403                     $Notice = wpautop(wptexturize($this->success_massage.' شناسه خطای پی پینگ:'.$ERR_ID));
    404426                    $Notice = str_replace("{transaction_id}", $Transaction_ID, $Notice);
    405427                    $Notice = apply_filters('WC_payping_Return_from_Gateway_ReSuccess_Notice', $Notice, $order_id, $Transaction_ID);
     
    410432                    exit;
    411433                }
    412             }else{
    413                 $Fault = __('شماره سفارش وجود ندارد .', 'woocommerce');
    414                 $Notice = wpautop(wptexturize($this->failed_massage.' شناسه خطای پی پینگ:'.$ERR_ID));
    415                 $Notice = str_replace("{fault}", $Fault, $Notice);
    416                 $Notice = apply_filters('WC_payping_Return_from_Gateway_No_Order_ID_Notice', $Notice, $order_id, $Fault);
    417                 wc_add_notice($Fault, 'error');
    418                 $order->add_order_note( $Notice, 0, false);
    419                 do_action('WC_payping_Return_from_Gateway_No_Order_ID', $order_id, $Transaction_ID, $Fault);
    420                 wp_redirect(wc_get_checkout_url());
    421                 exit;
    422434            }
    423435        }
  • woo-payping-gateway/trunk/index.php

    r3063373 r3165632  
    22/*
    33Plugin Name: Gateway for PayPing on WooCommerce
    4 Version: 4.4.0
     4Version: 4.5.0
    55Description:  افزونه درگاه پرداخت پی‌پینگ برای ووکامرس
    66Plugin URI: https://www.payping.ir/
  • woo-payping-gateway/trunk/readme.txt

    r3122739 r3165632  
    44Donate link: https://payping.ir
    55Requires at least: 4.0.0
    6 Tested up to: 6.6
     6Tested up to: 6.6.2
    77Requires PHP: 7.4.0
    8 Stable tag: 4.4.0
     8Stable tag: 4.5.0
    99License: GPLv3 or later
    1010License URI: http://www.gnu.org/licenses/gpl-3.0.html
     
    2121
    2222== Changelog ==
     23
     24== 4.5.0 ==
     25بروزرسانی وب سرویس پی پینگ به نسخه جدید.
    2326
    2427== 4.4.0 ==
Note: See TracChangeset for help on using the changeset viewer.