Plugin Directory

Changeset 3242781


Ignore:
Timestamp:
02/18/2025 04:52:02 PM (12 months ago)
Author:
planetstudio
Message:

Release version 1.4.9

Location:
arca-payment-gateway
Files:
8 edited
1 copied

Legend:

Unmodified
Added
Removed
  • arca-payment-gateway/tags/1.4.9/arca-payment-gateway.php

    r3241730 r3242781  
    33 * Plugin Name: Planet Studio Payment Gateway for ArCa
    44 * Description: This Plugin allows you to accept online payments from local and international customers to Armenian banks, Idram payment system and adds ArCa paycenter as a payment gateway for WooCommerce and for GiveWP donation Plugin and TATIOSA hotel booking management platform.
    5  * Version: 1.4.8
     5 * Version: 1.4.9
    66 * Author: Planet Studio team
    77 * Author URI: https://planetstudio.am
     
    1515define('ARCAPG_DIR_NAME', dirname(plugin_basename( __FILE__ )));
    1616define('ARCAPG_URL', plugins_url(plugin_basename(dirname(__FILE__))));
    17 define('ARCAPG_VERSION', '1.4.8');
     17define('ARCAPG_VERSION', '1.4.9');
    1818define('ARCAPG_PRO', FALSE);
    1919define('ARCAPG_DELETE_DATA_ACTIONS', false);
  • arca-payment-gateway/tags/1.4.9/endpoints/apg-idram.php

    r3240719 r3242781  
    1515
    1616if ( !class_exists('woocommerce') ) {
    17     add_filter( 'request', function($query_vars){
    18         if( isset($query_vars['wc-api']) ){
    19             do_action( 'woocommerce_api_'. $query_vars['wc-api'] );
    20             die;
    21         }
    22         return $query_vars;
    23     });
     17    add_filter( 'request', function($query_vars){
     18        if( isset($query_vars['wc-api']) ){
     19            do_action( 'woocommerce_api_'. $query_vars['wc-api'] );
     20            die;
     21        }
     22        return $query_vars;
     23    });
    2424}
    2525
    2626function apg_wc_api_idram_result(){
    2727
    28     global $wpdb, $arca_idram_config;
    29     $request = $_REQUEST;
    30 
    31     $orderNumber = $orderId = ( !empty($request["EDP_BILL_NO"]) ) ? intval($request["EDP_BILL_NO"]) : -1;
    32     $wc_orderId     =   ( !empty($request["wc_orderId"]) ) ? intval($request["wc_orderId"]) : null;
    33     $gwp_donationId =   ( !empty($request["gwp_donationId"]) ) ? intval($request["gwp_donationId"]) : null;
    34 
    35     if(isset($request['EDP_PRECHECK']) && isset($request['EDP_BILL_NO']) && isset($request['EDP_REC_ACCOUNT']) && isset($request['EDP_AMOUNT'])){
    36         if($request['EDP_PRECHECK'] == "YES") {
    37             if($request['EDP_REC_ACCOUNT'] == EDP_REC_ACCOUNT) {
    38                 $bill_no = $request['EDP_BILL_NO'];
    39 
    40                 // this code checks if $bill_no exists in your system orders if exists then echo OK otherwise
     28    global $wpdb, $arca_idram_config;
     29    $request = $_REQUEST;
     30
     31    $orderNumber = $orderId = ( !empty($request["EDP_BILL_NO"]) ) ? intval($request["EDP_BILL_NO"]) : -1;
     32    $wc_orderId     =   ( !empty($request["wc_orderId"]) ) ? intval($request["wc_orderId"]) : null;
     33    $gwp_donationId =   ( !empty($request["gwp_donationId"]) ) ? intval($request["gwp_donationId"]) : null;
     34
     35    if(isset($request['EDP_PRECHECK']) && isset($request['EDP_BILL_NO']) && isset($request['EDP_REC_ACCOUNT']) && isset($request['EDP_AMOUNT'])){
     36        if($request['EDP_PRECHECK'] == "YES") {
     37            if($request['EDP_REC_ACCOUNT'] == EDP_REC_ACCOUNT) {
     38                $bill_no = $request['EDP_BILL_NO'];
     39
     40                // this code checks if $bill_no exists in your system orders if exists then echo OK otherwise
    4141                $result = $wpdb->get_var(
    4242                    $wpdb->prepare(
     
    4747                if($result == 1){
    4848
    49                     $OrderStatusExtended = json_encode( array( "Request 1 - confirm" => $_REQUEST ) );
    50 
    51                     // update order row
     49                    $OrderStatusExtended = json_encode( array( "Request 1 - confirm" => $_REQUEST ) );
     50
     51                    // update order row
    5252                    $wpdb->query($wpdb->prepare(
    5353                        "UPDATE " . $wpdb->prefix . "arca_pg_orders
     
    6060                    ));
    6161
    62 
    6362                    echo "OK";
    64                     die;
    65 
    66                 } else {
    67                     echo "EDP_BILL_NO not found";
    68                     die;
    69                 }
    70 
    71             }
    72         }
    73     }
    74 
    75     if(isset($request['EDP_PAYER_ACCOUNT']) && isset($request['EDP_BILL_NO']) && isset($request['EDP_REC_ACCOUNT']) && isset($request['EDP_AMOUNT']) && isset($request['EDP_TRANS_ID']) && isset($request['EDP_CHECKSUM'])) {
    76         $txtToHash = EDP_REC_ACCOUNT . ":" . $request['EDP_AMOUNT'] . ":" . SECRET_KEY . ":" . $request['EDP_BILL_NO'] . ":" . $request['EDP_PAYER_ACCOUNT'] . ":" . $request['EDP_TRANS_ID'] . ":" . $request['EDP_TRANS_DATE'];
    77         if(strtoupper($request['EDP_CHECKSUM']) != strtoupper(md5($txtToHash))) {
    78 
    79             // please, write your code here to handle the payment fail
    80 
    81             // get previous stored requests
     63                    die;
     64
     65                } else {
     66                    echo "EDP_BILL_NO not found";
     67                    die;
     68                }
     69
     70            }
     71        }
     72    }
     73
     74    if(isset($request['EDP_PAYER_ACCOUNT']) && isset($request['EDP_BILL_NO']) && isset($request['EDP_REC_ACCOUNT']) && isset($request['EDP_AMOUNT']) && isset($request['EDP_TRANS_ID']) && isset($request['EDP_CHECKSUM'])) {
     75        $txtToHash = EDP_REC_ACCOUNT . ":" . $request['EDP_AMOUNT'] . ":" . SECRET_KEY . ":" . $request['EDP_BILL_NO'] . ":" . $request['EDP_PAYER_ACCOUNT'] . ":" . $request['EDP_TRANS_ID'] . ":" . $request['EDP_TRANS_DATE'];
     76        if(strtoupper($request['EDP_CHECKSUM']) != strtoupper(md5($txtToHash))) {
     77
     78            // please, write your code here to handle the payment fail
     79
     80            // get previous stored requests
    8281            $OrderStatusExtended = json_decode(
    8382                $wpdb->get_var(
     
    9089            );
    9190
    92 
    9391            // add new request
    94             $OrderStatusExtended = array_merge($OrderStatusExtended, array( "Request 2 - fail" => $_REQUEST ) );
    95 
    96             $OrderStatusExtended = json_encode( $OrderStatusExtended );
    97 
    98             // update error number from REST system
     92            $OrderStatusExtended = array_merge($OrderStatusExtended, array( "Request 2 - fail" => $_REQUEST ) );
     93
     94            $OrderStatusExtended = json_encode( $OrderStatusExtended );
     95
     96            // update error number from REST system
    9997            $wpdb->query($wpdb->prepare(
    10098                "UPDATE " . $wpdb->prefix . "arca_pg_orders
     
    107105
    108106            echo "EDP_CHECKSUM not correct";
    109             die;
    110 
    111         } else {
    112 
    113             // please, write your code here to handle the payment success echo("OK");
    114 
    115             // get order payment state from REST response
    116             $paymentState = "DEPOSITED";
    117 
    118             // get previous stored requests
     107            die;
     108
     109        } else {
     110
     111            // please, write your code here to handle the payment success echo("OK");
     112
     113            // get order payment state from REST response
     114            $paymentState = "DEPOSITED";
     115
     116            // get previous stored requests
    119117            $OrderStatusExtended = json_decode(
    120118                $wpdb->get_var(
     
    127125            );
    128126
    129 
    130127            // add new request
    131             $OrderStatusExtended = array_merge($OrderStatusExtended, array( "Request 2 - confirm" => $_REQUEST ) );
    132 
    133             $OrderStatusExtended = json_encode( $OrderStatusExtended );
    134 
    135             // update order payment REST response data
     128            $OrderStatusExtended = array_merge($OrderStatusExtended, array( "Request 2 - confirm" => $_REQUEST ) );
     129
     130            $OrderStatusExtended = json_encode( $OrderStatusExtended );
     131
     132            // update order payment REST response data
    136133            $wpdb->query($wpdb->prepare(
    137134                "UPDATE " . $wpdb->prefix . "arca_pg_orders
     
    140137                $OrderStatusExtended,
    141138                $paymentState,
    142                 $orderNumber // исправлено с orderId на orderNumber
     139                $orderId
    143140            ));
    144141
    145142            $wc_orderId = ( !empty($_REQUEST["wc_orderId"]) ) ? intval($_REQUEST["wc_orderId"]) : null;
    146             $gwp_donationId = ( !empty($_REQUEST["gwp_donationId"]) ) ? intval($_REQUEST["gwp_donationId"]) : null;
    147 
    148             // if woocommerce
    149             if(isset($wc_orderId)) {
    150 
    151                 // get wc order
    152                 $apg_wc_order = wc_get_order($wc_orderId);
    153 
    154                 // get ws order status processing or failed
    155                 $apg_wc_orderStatus = ( $paymentState == 'DEPOSITED' ) ? $arca_idram_config->wc_order_status : 'failed';
    156 
    157                 // set wc order status
    158                 $apg_wc_order->set_status($apg_wc_orderStatus, 'wc_apg_gatewey');
    159                 $apg_wc_order->save();
    160 
    161                 $apg_wc_order->reduce_order_stock();
    162                 //WC()->cart->empty_cart();
    163 
    164                 // set email sent if email exist in wc order
     143            $gwp_donationId = ( !empty($_REQUEST["gwp_donationId"]) ) ? intval($_REQUEST["gwp_donationId"]) : null;
     144
     145            // if woocommerce
     146            if(isset($wc_orderId)) {
     147
     148                // get wc order
     149                $apg_wc_order = wc_get_order($wc_orderId);
     150
     151                // get ws order status processing or failed
     152                $apg_wc_orderStatus = ( $paymentState == 'DEPOSITED' ) ? $arca_idram_config->wc_order_status : 'failed';
     153
     154
     155                // eHDM print for woocommerce orders
     156
     157                // end eHDM print
     158
     159
     160                // set wc order status
     161                $apg_wc_order->set_status($apg_wc_orderStatus, 'wc_apg_gatewey');
     162                $apg_wc_order->save();
     163
     164                //$apg_wc_order->reduce_order_stock();
     165                WC()->cart->empty_cart();
     166
     167                // set email sent if email exist in wc order
    165168                $wpdb->query($wpdb->prepare(
    166                     "UPDATE " . $wpdb->prefix . "arca_pg_orders
    167                     SET mailSent = 1 
    168                     WHERE orderNumber = %d",
    169                     $orderNumber // исправлено с orderId на orderNumber
     169                    "UPDATE {$wpdb->prefix}arca_pg_orders
     170                    SET mailSent = 1
     171                    WHERE orderNumber = %s",
     172                    $orderId
    170173                ));
    171174
    172175                // if give wp
    173             } else if(isset($gwp_donationId)){
    174 
    175                 // get give wp order status publish or failed
    176                 $apg_givewp_orderStatus = ( $paymentState == 'DEPOSITED' ) ? 'publish' : 'failed';
    177 
    178                 // set give wp donate status
    179                 give_update_payment_status( $gwp_donationId, $apg_givewp_orderStatus );
    180 
    181                 // set email sent if email exist in wc order
     176            } else if(isset($gwp_donationId)){
     177
     178                // get give wp order status publish or failed
     179                $apg_givewp_orderStatus = ( $paymentState == 'DEPOSITED' ) ? 'publish' : 'failed';
     180
     181                // set give wp donate status
     182                give_update_payment_status( $gwp_donationId, $apg_givewp_orderStatus );
     183
     184                // set email sent if email exist in wc order
    182185                $wpdb->query($wpdb->prepare(
    183                     "UPDATE {$wpdb->prefix}arca_pg_orders 
    184                     SET mailSent = 1 
    185                     WHERE orderNumber = %d",
    186                     $orderId // если это число
     186                    "UPDATE {$wpdb->prefix}arca_pg_orders
     187                    SET mailSent = 1
     188                    WHERE orderNumber = %s",
     189                    $orderId
    187190                ));
    188191
    189192                // if tatiosa_booking
    190             } else if(isset($tatiosa_booking_id)){
    191 
    192                 $response = json_decode($response);
    193                 $response = $response->paymentAmountInfo;
    194 
    195                 // get ws order status processing or failed
    196                 $apg_booking_orderStatus = 1; //booking status, 0 (cancelled), 1 (confirmed), 2 (new), 3 (request)
    197                 $code = 0;
    198 
    199                 if( $apg_booking_orderStatus == 1){
    200 
    201                     $tatiosa_booking_Key = wp_parse_url( get_site_url() )['host'];
    202                     $description = 'Paid via Credit Card';
    203                     $payment_status = 'Successful';
    204                     $amount = $response->approvedAmount;
    205 
    206 
    207                     // notify of payment status tatiosa.net
    208                     $booking_orderStatus_url =  "https://tatiosa.net/api/custompaymentgateway/notify.php";
    209                     $args = array(
    210                         'headers'     => array('Content-Type: text/html; charset=UTF-8'),
    211                         'body'        => array(
    212                             'key'       => $tatiosa_booking_Key,
    213                             'bookid'    => $tatiosa_booking_id,
    214                             'status'     => $apg_booking_orderStatus,
    215                             'amount'     => $amount,
    216                             'description' => $description,
    217                             'payment_status' => $payment_status,
    218                         ),
    219                         'method'      => 'POST',
    220                         'data_format' => 'body',
    221                     );
    222                     $response = wp_remote_post( $booking_orderStatus_url, $args );
    223 
    224 
    225                     // get booking system status
    226                     $code = wp_remote_retrieve_response_code( $response );
    227                     if($code != 200){
    228                         arca_pg_errorCatch("Booking system respons error: " . json_encode($response, JSON_UNESCAPED_UNICODE), $wc_orderId, $gwp_donationId);
    229                     }
    230 
    231                 }
    232 
    233 
    234                 // get previous stored requests
    235                 //$OrderStatusExtended =  json_decode( $wpdb->get_var("select OrderStatusExtended from " . $wpdb->prefix . "arca_pg_orders where orderId = '$orderId'"), true );
     193            } else if(isset($tatiosa_booking_id)){
     194
     195                // get ws order status processing or failed
     196                $apg_booking_orderStatus = 1; //booking status, 0 (cancelled), 1 (confirmed), 2 (new), 3 (request)
     197                $code = 0;
     198
     199                if( $apg_booking_orderStatus == 1){
     200
     201                    $tatiosa_booking_Key = wp_parse_url( get_site_url() )['host'];
     202                    $description = 'Paid via Credit Card';
     203                    $payment_status = 'Successful';
     204
     205                    // get amount for $orderId from orders
     206                    $amount = $wpdb->get_var($wpdb->prepare("SELECT amount  from " . $wpdb->prefix . "arca_pg_orders where orderId = %s", $orderId));
     207
     208                    // notify of payment status tatiosa.net
     209                    $booking_orderStatus_url =  "https://tatiosa.net/api/custompaymentgateway/notify.php";
     210                    $args = array(
     211                        'headers'     => array('Content-Type: text/html; charset=UTF-8'),
     212                        'body'        => array(
     213                            'key'       => $tatiosa_booking_Key,
     214                            'bookid'    => $tatiosa_booking_id,
     215                            'status'     => $apg_booking_orderStatus,
     216                            'amount'     => $amount,
     217                            'description' => $description,
     218                            'payment_status' => $payment_status,
     219                        ),
     220                        'method'      => 'POST',
     221                        'data_format' => 'body',
     222                    );
     223                    $response = wp_remote_post( $booking_orderStatus_url, $args );
     224
     225
     226                    // get booking system status
     227                    $code = wp_remote_retrieve_response_code( $response );
     228                    if($code != 200){
     229                        arca_pg_errorCatch("Booking system respons error: " . json_encode($response, JSON_UNESCAPED_UNICODE), $wc_orderId, $gwp_donationId);
     230                    }
     231
     232                }
     233
     234                // get previous stored requests
    236235                $OrderStatusExtended = json_decode(
    237236                    $wpdb->get_var(
     
    244243                );
    245244
    246                 // add new request
    247                 $OrderStatusExtended = array_merge($OrderStatusExtended, array( "Booking System Response 1" => json_decode('{"Status": '.$code.'}', true) ) );
    248 
    249                 $OrderStatusExtended = json_encode( $OrderStatusExtended );
    250 
    251                 // update order payment REST response data
     245                // add new request
     246                $OrderStatusExtended = array_merge($OrderStatusExtended, array( "Booking System Response 1" => json_decode('{"Status": '.$code.'}', true) ) );
     247
     248                $OrderStatusExtended = json_encode( $OrderStatusExtended );
     249
     250                // update order payment REST response data
    252251                $wpdb->query($wpdb->prepare(
    253                     "UPDATE {$wpdb->prefix}arca_pg_orders 
    254                     SET OrderStatusExtended = %s, paymentState = %s 
     252                    "UPDATE {$wpdb->prefix}arca_pg_orders
     253                    SET OrderStatusExtended = %s, paymentState = %s
    255254                    WHERE orderId = %s",
    256255                    $OrderStatusExtended,
     
    261260            }
    262261
    263             echo "OK";
    264             die;
    265         }
    266     }
     262            // eHDM print for apg, tatiosa orders
     263
     264            // end eHDM print
     265
     266            echo "OK";
     267            die;
     268        }
     269    }
    267270
    268271}
     
    270273function apg_wc_api_idram_complete(){
    271274
    272     global $wpdb;
    273     $request = $_REQUEST;
    274 
    275     $orderNumber = $orderId = ( !empty($request["EDP_BILL_NO"]) ) ? intval($request["EDP_BILL_NO"]) : -1;
    276     $wc_orderId     =   ( !empty($request["wc_orderId"]) ) ? intval($request["wc_orderId"]) : null;
    277     $gwp_donationId =   ( !empty($request["gwp_donationId"]) ) ? intval($request["gwp_donationId"]) : null;
    278 
    279     // if woocommerce
    280     if(isset($wc_orderId)) {
    281 
    282         // get wc return url
    283         $wc_apg_gatewey = new wc_apg_gatewey();
    284 
    285         // get wc order
    286         $apg_wc_order = wc_get_order($wc_orderId);
    287 
    288         // redirect to final page with REST payment state
    289         wp_redirect( $wc_apg_gatewey->get_return_url( $apg_wc_order ) );
    290         exit;
    291 
    292         // if give wp
    293     } else if(isset($gwp_donationId)){
    294 
    295         // redirect to final page with REST payment state
    296         give_send_to_success_page();
    297         exit;
    298 
    299     } else if(isset($tatiosa_booking_id)){
    300 
    301 
    302 
    303     }
    304 
    305     // get language
    306     $language = ( isset($_REQUEST["language"]) ) ? $_REQUEST["language"] : null;
    307 
    308     // get order payment state from REST response
    309     $paymentState = "DEPOSITED";
    310 
    311     // redirect to final page with REST payment state
    312     wp_redirect( arca_pg_checkOutPagePermalink($language) . "?state=$paymentState&orderId=$orderId");
    313     exit;
     275    global $wpdb;
     276    $request = $_REQUEST;
     277
     278    $orderNumber = $orderId = ( !empty($request["EDP_BILL_NO"]) ) ? intval($request["EDP_BILL_NO"]) : -1;
     279    $wc_orderId     =   ( !empty($request["wc_orderId"]) ) ? intval($request["wc_orderId"]) : null;
     280    $gwp_donationId =   ( !empty($request["gwp_donationId"]) ) ? intval($request["gwp_donationId"]) : null;
     281
     282    // if woocommerce
     283    if(isset($wc_orderId)) {
     284
     285        // get wc return url
     286        $wc_apg_gatewey = new wc_apg_gatewey();
     287
     288        // get wc order
     289        $apg_wc_order = wc_get_order($wc_orderId);
     290
     291        // redirect to final page with REST payment state
     292        wp_redirect( $wc_apg_gatewey->get_return_url( $apg_wc_order ) );
     293        exit;
     294
     295        // if give wp
     296    } else if(isset($gwp_donationId)){
     297
     298        // redirect to final page with REST payment state
     299        give_send_to_success_page();
     300        exit;
     301
     302    } else if(isset($tatiosa_booking_id)){
     303
     304
     305
     306    }
     307
     308    // get language
     309    $language = ( isset($_REQUEST["language"]) ) ? $_REQUEST["language"] : null;
     310
     311    // get order payment state from REST response
     312    $paymentState = "DEPOSITED";
     313
     314    // redirect to final page with REST payment state
     315    wp_redirect( arca_pg_checkOutPagePermalink($language) . "?state=$paymentState&orderId=$orderId");
     316    exit;
    314317
    315318}
     
    317320function apg_wc_api_idram_fail(){
    318321
    319     global $wpdb;
    320     $request = $_REQUEST;
    321 
    322     $orderNumber = $orderId = ( !empty($request["EDP_BILL_NO"]) ) ? intval($request["EDP_BILL_NO"]) : -1;
    323     $wc_orderId     =   ( !empty($request["wc_orderId"]) ) ? intval($request["wc_orderId"]) : null;
    324     $gwp_donationId =   ( !empty($request["gwp_donationId"]) ) ? intval($request["gwp_donationId"]) : null;
    325 
    326     // get previous stored requests
     322    global $wpdb;
     323    $request = $_REQUEST;
     324
     325    $orderNumber = $orderId = ( !empty($request["EDP_BILL_NO"]) ) ? intval($request["EDP_BILL_NO"]) : -1;
     326    $wc_orderId     =   ( !empty($request["wc_orderId"]) ) ? intval($request["wc_orderId"]) : null;
     327    $gwp_donationId =   ( !empty($request["gwp_donationId"]) ) ? intval($request["gwp_donationId"]) : null;
     328
     329    // get previous stored requests
    327330    $OrderStatusExtended = json_decode(
    328331        $wpdb->get_var(
     
    335338    );
    336339
    337     // add new request
    338     $OrderStatusExtended = ( !empty($OrderStatusExtended) ) ? array_merge($OrderStatusExtended, array( "Request - fail" => $_REQUEST ) ) : array( "Request - fail" => $_REQUEST ) ;
    339 
    340     $OrderStatusExtended = json_encode( $OrderStatusExtended );
    341 
    342     // update error number from REST system
     340    // add new request
     341    $OrderStatusExtended = ( !empty($OrderStatusExtended) ) ? array_merge($OrderStatusExtended, array( "Request - fail" => $_REQUEST ) ) : array( "Request - fail" => $_REQUEST ) ;
     342
     343    $OrderStatusExtended = json_encode( $OrderStatusExtended );
     344
     345    // update error number from REST system
    343346    $wpdb->query($wpdb->prepare(
    344347        "UPDATE {$wpdb->prefix}arca_pg_orders
     
    359362if ($arca_process == "idram"){
    360363
    361     // data validation
    362     $errMgs = array();
    363 
    364     // get form data or defaults values
    365     $wc_orderId     =   ( !empty($_REQUEST["wc_orderId"]) ) ? intval($_REQUEST["wc_orderId"]) : null;
    366     $gwp_donationId =   ( !empty($_REQUEST["gwp_donationId"]) ) ? intval($_REQUEST["gwp_donationId"]) : null;
    367     $productId      =   ( !empty($_REQUEST["productId"]) ) ? intval($_REQUEST["productId"]) : 0;
    368     $amount         =   ( !empty($_REQUEST["amount"]) ) ? doubleval($_REQUEST["amount"]) : 0;
    369     $description    =   ( !empty($_REQUEST["description"]) ) ? sanitize_text_field($_REQUEST["description"]) : __( "Online payment", 'arca-payment-gateway' );
    370     $language       =   ( !empty($_REQUEST["language"]) ) ? sanitize_text_field($_REQUEST["language"]) : $arca_idram_config->default_language;
    371     $currency       =   ( !empty($_REQUEST["currency"]) ) ? sanitize_text_field($_REQUEST["currency"]) : "051";
     364    // data validation
     365    $errMgs = array();
     366
     367    // get form data or defaults values
     368    $wc_orderId     =   ( !empty($_REQUEST["wc_orderId"]) ) ? intval($_REQUEST["wc_orderId"]) : null;
     369    $gwp_donationId =   ( !empty($_REQUEST["gwp_donationId"]) ) ? intval($_REQUEST["gwp_donationId"]) : null;
     370    $productId      =   ( !empty($_REQUEST["productId"]) ) ? intval($_REQUEST["productId"]) : 0;
     371    $amount         =   ( !empty($_REQUEST["amount"]) ) ? doubleval($_REQUEST["amount"]) : 0;
     372    $description    =   ( !empty($_REQUEST["description"]) ) ? sanitize_text_field($_REQUEST["description"]) : __( "Online payment", 'arca-payment-gateway' );
     373    $language       =   ( !empty($_REQUEST["language"]) ) ? sanitize_text_field($_REQUEST["language"]) : $arca_idram_config->default_language;
     374    $currency       =   ( !empty($_REQUEST["currency"]) ) ? sanitize_text_field($_REQUEST["currency"]) : "051";
    372375    $custom_amount  = ( !empty($_REQUEST["custom_amount"]) && intval($_REQUEST["custom_amount"]) == 1 ) ? 1 : 0;
    373376
    374     // get payment initiator, woocommerce, givewp or apg
    375     if(isset($wc_orderId)) {
    376 
    377         // get wc order
    378         $apg_wc_order = wc_get_order($wc_orderId);
    379 
    380         // get order total amount
    381         $amount = $apg_wc_order->get_total();
    382 
    383         // validate currency
    384         $currency = ($apg_wc_order->get_currency()) == "AMD" ? "051" : null;
    385         if ( $currency != "051") array_push($errMgs, "Incorect currency:" . $currency);
    386 
    387     } else if (isset($gwp_donationId)) {
    388 
    389         // get give wp donation amount
    390         $amount = give_donation_amount($gwp_donationId);
    391 
    392         // get give wp donation currency abbr
    393         $apg_givewp_currency = (give_get_payment_currency_code($gwp_donationId)) == "AMD" ? "051" : null;
    394 
    395         // validate currency
    396         if ( $apg_givewp_currency != "051") array_push($errMgs, "Incorect currency:" . $apg_givewp_currency);
    397 
    398     } else {
    399 
    400         if($custom_amount == 0){
    401 
    402             // validate productId
     377    // get payment initiator, woocommerce, givewp or apg
     378    if(isset($wc_orderId)) {
     379
     380        // get wc order
     381        $apg_wc_order = wc_get_order($wc_orderId);
     382
     383        // get order total amount
     384        $amount = $apg_wc_order->get_total();
     385
     386        // validate currency
     387        $currency = ($apg_wc_order->get_currency()) == "AMD" ? "051" : null;
     388        if ( $currency != "051") array_push($errMgs, "Incorect currency:" . $currency);
     389
     390    } else if (isset($gwp_donationId)) {
     391
     392        // get give wp donation amount
     393        $amount = give_donation_amount($gwp_donationId);
     394
     395        // get give wp donation currency abbr
     396        $apg_givewp_currency = (give_get_payment_currency_code($gwp_donationId)) == "AMD" ? "051" : null;
     397
     398        // validate currency
     399        if ( $apg_givewp_currency != "051") array_push($errMgs, "Incorect currency:" . $apg_givewp_currency);
     400
     401    } else {
     402
     403        if($custom_amount == 0){
     404
     405            // validate productId
    403406            $resultCount = $wpdb->get_var(
    404407                $wpdb->prepare(
     
    410413            if ($resultCount == 0) array_push($errMgs, "incorrect productId:" . $productId);
    411414
    412             // get product details
     415            // get product details
    413416            $priceList = $wpdb->get_row(
    414417                $wpdb->prepare(
     
    418421            );
    419422
    420             // get price, validate price
    421             $amount = arca_pg_getPriceFromJson($priceList->productPrice, $currency);
    422             if ($amount == 0) array_push($errMgs, "Incorrect amount:" . $amount . " with the currency:" . $currency);
    423 
    424         }
    425 
    426         // validate currency
    427         if ( $currency != "051") array_push($errMgs, "Incorect currency:" . $currency);
    428 
    429     }
    430 
    431     // validate language
     423            // get price, validate price
     424            $amount = arca_pg_getPriceFromJson($priceList->productPrice, $currency);
     425            if ($amount == 0) array_push($errMgs, "Incorrect amount:" . $amount . " with the currency:" . $currency);
     426
     427        }
     428
     429        // validate currency
     430        if ( $currency != "051") array_push($errMgs, "Incorect currency:" . $currency);
     431
     432    }
     433
     434    // validate language
    432435    $resultCount = $wpdb->get_var($wpdb->prepare(
    433436        "SELECT COUNT(*) FROM {$wpdb->prefix}arca_pg_language WHERE code = %s",
     
    437440    if ($resultCount == 0) $language = $arca_idram_config->default_language;
    438441
    439     // validate checkout form permalink
    440     if (arca_pg_checkOutPagePermalink() == false) array_push($errMgs, "Checkout form not found");
    441 
    442     // get orderDetails
    443     $orderDetails = json_encode($_REQUEST, JSON_UNESCAPED_UNICODE);
    444 
    445     // validation
    446     if (empty($errMgs)){
    447 
    448         // create order blank row in db
    449         $table = $wpdb->prefix . 'arca_pg_orders';
    450         $data = array(
    451             'productId'     => $productId,
    452             'wc_orderId'    => $wc_orderId,
    453             //'gwp_donationId'      => $gwp_donationId,
    454             'amount'        => $amount,
    455             'currency'      => $currency,
    456             'orderDetails'  => $orderDetails,
    457             'rest_serverID' => ($arca_idram_config->testMode) ? 2 : 1,
    458             'orderDate'     => current_time('mysql'),
     442    // validate checkout form permalink
     443    if (arca_pg_checkOutPagePermalink() == false) array_push($errMgs, "Checkout form not found");
     444
     445    // get orderDetails
     446    $orderDetails = json_encode($_REQUEST, JSON_UNESCAPED_UNICODE);
     447
     448    // validation
     449    if (empty($errMgs)){
     450
     451        // create order blank row in db
     452        $table = $wpdb->prefix . 'arca_pg_orders';
     453        $data = array(
     454            'productId'     => $productId,
     455            'wc_orderId'    => $wc_orderId,
     456            //'gwp_donationId'      => $gwp_donationId,
     457            'amount'        => $amount,
     458            'currency'      => $currency,
     459            'orderDetails'  => $orderDetails,
     460            'rest_serverID' => ($arca_idram_config->testMode) ? 2 : 1,
     461            'orderDate'     => current_time('mysql'),
    459462            'bankId'        => 12, // iDram
    460         );
    461         $format = array(
    462             '%d',
    463             '%d',
    464             //'%d',
    465             '%f',
    466             '%s',
    467             '%s',
    468             '%d',
     463        );
     464        $format = array(
     465            '%d',
     466            '%d',
     467            //'%d',
     468            '%f',
     469            '%s',
    469470            '%s',
    470471            '%d',
    471         );
    472         $insert = $wpdb->insert($table, $data, $format);
    473         if ($insert){
    474 
    475             // get orderNumber from created row
    476             $orderNumber  = $wpdb->insert_id;
     472            '%s',
     473            '%d',
     474        );
     475        $insert = $wpdb->insert($table, $data, $format);
     476        if ($insert){
     477
     478            // get orderNumber from created row
     479            $orderNumber  = $wpdb->insert_id;
    477480
    478481            // create idram submit form
     
    494497            die;
    495498
    496         } else {
    497             arca_pg_errorCatch("Error on insert new order row, wpdb error: " . $wpdb->error, $wc_orderId, $gwp_donationId);
    498         }
    499 
    500     } else {
    501         arca_pg_errorCatch("Data validation error: " . implode(', ', $errMgs), $wc_orderId, $gwp_donationId);
    502     }
     499        } else {
     500            arca_pg_errorCatch("Error on insert new order row, wpdb error: " . $wpdb->error, $wc_orderId, $gwp_donationId);
     501        }
     502
     503    } else {
     504        arca_pg_errorCatch("Data validation error: " . implode(', ', $errMgs), $wc_orderId, $gwp_donationId);
     505    }
    503506
    504507}
  • arca-payment-gateway/tags/1.4.9/includes/apg-wc.php

    r3240719 r3242781  
    3131
    3232        // subscription Хук для продления подписок
    33         //add_action('woocommerce_scheduled_subscription_payment_' . $this->id, array($this, 'process_subscription_payment'), 10, 2);
     33//        add_action('woocommerce_scheduled_subscription_payment_' . $this->id, array($this, 'process_subscription_payment'), 10, 2);
    3434    }
    3535
  • arca-payment-gateway/tags/1.4.9/readme.txt

    r3241730 r3242781  
    55Requires PHP: 7.4
    66Tested up to: 6.7.2
    7 Stable tag: 1.4.8
     7Stable tag: 1.4.9
    88License: GPLv3
    99License URI: https://www.gnu.org/licenses/gpl-3.0.html
     
    125125== Changelog ==
    126126
     127= 1.4.9 =
     128*Fixed idram endpoint bug
     129
    127130= 1.4.8 =
    128131*Fixed wc blocks bugs
  • arca-payment-gateway/trunk/arca-payment-gateway.php

    r3241730 r3242781  
    33 * Plugin Name: Planet Studio Payment Gateway for ArCa
    44 * Description: This Plugin allows you to accept online payments from local and international customers to Armenian banks, Idram payment system and adds ArCa paycenter as a payment gateway for WooCommerce and for GiveWP donation Plugin and TATIOSA hotel booking management platform.
    5  * Version: 1.4.8
     5 * Version: 1.4.9
    66 * Author: Planet Studio team
    77 * Author URI: https://planetstudio.am
     
    1515define('ARCAPG_DIR_NAME', dirname(plugin_basename( __FILE__ )));
    1616define('ARCAPG_URL', plugins_url(plugin_basename(dirname(__FILE__))));
    17 define('ARCAPG_VERSION', '1.4.8');
     17define('ARCAPG_VERSION', '1.4.9');
    1818define('ARCAPG_PRO', FALSE);
    1919define('ARCAPG_DELETE_DATA_ACTIONS', false);
  • arca-payment-gateway/trunk/endpoints/apg-idram.php

    r3240719 r3242781  
    1515
    1616if ( !class_exists('woocommerce') ) {
    17     add_filter( 'request', function($query_vars){
    18         if( isset($query_vars['wc-api']) ){
    19             do_action( 'woocommerce_api_'. $query_vars['wc-api'] );
    20             die;
    21         }
    22         return $query_vars;
    23     });
     17    add_filter( 'request', function($query_vars){
     18        if( isset($query_vars['wc-api']) ){
     19            do_action( 'woocommerce_api_'. $query_vars['wc-api'] );
     20            die;
     21        }
     22        return $query_vars;
     23    });
    2424}
    2525
    2626function apg_wc_api_idram_result(){
    2727
    28     global $wpdb, $arca_idram_config;
    29     $request = $_REQUEST;
    30 
    31     $orderNumber = $orderId = ( !empty($request["EDP_BILL_NO"]) ) ? intval($request["EDP_BILL_NO"]) : -1;
    32     $wc_orderId     =   ( !empty($request["wc_orderId"]) ) ? intval($request["wc_orderId"]) : null;
    33     $gwp_donationId =   ( !empty($request["gwp_donationId"]) ) ? intval($request["gwp_donationId"]) : null;
    34 
    35     if(isset($request['EDP_PRECHECK']) && isset($request['EDP_BILL_NO']) && isset($request['EDP_REC_ACCOUNT']) && isset($request['EDP_AMOUNT'])){
    36         if($request['EDP_PRECHECK'] == "YES") {
    37             if($request['EDP_REC_ACCOUNT'] == EDP_REC_ACCOUNT) {
    38                 $bill_no = $request['EDP_BILL_NO'];
    39 
    40                 // this code checks if $bill_no exists in your system orders if exists then echo OK otherwise
     28    global $wpdb, $arca_idram_config;
     29    $request = $_REQUEST;
     30
     31    $orderNumber = $orderId = ( !empty($request["EDP_BILL_NO"]) ) ? intval($request["EDP_BILL_NO"]) : -1;
     32    $wc_orderId     =   ( !empty($request["wc_orderId"]) ) ? intval($request["wc_orderId"]) : null;
     33    $gwp_donationId =   ( !empty($request["gwp_donationId"]) ) ? intval($request["gwp_donationId"]) : null;
     34
     35    if(isset($request['EDP_PRECHECK']) && isset($request['EDP_BILL_NO']) && isset($request['EDP_REC_ACCOUNT']) && isset($request['EDP_AMOUNT'])){
     36        if($request['EDP_PRECHECK'] == "YES") {
     37            if($request['EDP_REC_ACCOUNT'] == EDP_REC_ACCOUNT) {
     38                $bill_no = $request['EDP_BILL_NO'];
     39
     40                // this code checks if $bill_no exists in your system orders if exists then echo OK otherwise
    4141                $result = $wpdb->get_var(
    4242                    $wpdb->prepare(
     
    4747                if($result == 1){
    4848
    49                     $OrderStatusExtended = json_encode( array( "Request 1 - confirm" => $_REQUEST ) );
    50 
    51                     // update order row
     49                    $OrderStatusExtended = json_encode( array( "Request 1 - confirm" => $_REQUEST ) );
     50
     51                    // update order row
    5252                    $wpdb->query($wpdb->prepare(
    5353                        "UPDATE " . $wpdb->prefix . "arca_pg_orders
     
    6060                    ));
    6161
    62 
    6362                    echo "OK";
    64                     die;
    65 
    66                 } else {
    67                     echo "EDP_BILL_NO not found";
    68                     die;
    69                 }
    70 
    71             }
    72         }
    73     }
    74 
    75     if(isset($request['EDP_PAYER_ACCOUNT']) && isset($request['EDP_BILL_NO']) && isset($request['EDP_REC_ACCOUNT']) && isset($request['EDP_AMOUNT']) && isset($request['EDP_TRANS_ID']) && isset($request['EDP_CHECKSUM'])) {
    76         $txtToHash = EDP_REC_ACCOUNT . ":" . $request['EDP_AMOUNT'] . ":" . SECRET_KEY . ":" . $request['EDP_BILL_NO'] . ":" . $request['EDP_PAYER_ACCOUNT'] . ":" . $request['EDP_TRANS_ID'] . ":" . $request['EDP_TRANS_DATE'];
    77         if(strtoupper($request['EDP_CHECKSUM']) != strtoupper(md5($txtToHash))) {
    78 
    79             // please, write your code here to handle the payment fail
    80 
    81             // get previous stored requests
     63                    die;
     64
     65                } else {
     66                    echo "EDP_BILL_NO not found";
     67                    die;
     68                }
     69
     70            }
     71        }
     72    }
     73
     74    if(isset($request['EDP_PAYER_ACCOUNT']) && isset($request['EDP_BILL_NO']) && isset($request['EDP_REC_ACCOUNT']) && isset($request['EDP_AMOUNT']) && isset($request['EDP_TRANS_ID']) && isset($request['EDP_CHECKSUM'])) {
     75        $txtToHash = EDP_REC_ACCOUNT . ":" . $request['EDP_AMOUNT'] . ":" . SECRET_KEY . ":" . $request['EDP_BILL_NO'] . ":" . $request['EDP_PAYER_ACCOUNT'] . ":" . $request['EDP_TRANS_ID'] . ":" . $request['EDP_TRANS_DATE'];
     76        if(strtoupper($request['EDP_CHECKSUM']) != strtoupper(md5($txtToHash))) {
     77
     78            // please, write your code here to handle the payment fail
     79
     80            // get previous stored requests
    8281            $OrderStatusExtended = json_decode(
    8382                $wpdb->get_var(
     
    9089            );
    9190
    92 
    9391            // add new request
    94             $OrderStatusExtended = array_merge($OrderStatusExtended, array( "Request 2 - fail" => $_REQUEST ) );
    95 
    96             $OrderStatusExtended = json_encode( $OrderStatusExtended );
    97 
    98             // update error number from REST system
     92            $OrderStatusExtended = array_merge($OrderStatusExtended, array( "Request 2 - fail" => $_REQUEST ) );
     93
     94            $OrderStatusExtended = json_encode( $OrderStatusExtended );
     95
     96            // update error number from REST system
    9997            $wpdb->query($wpdb->prepare(
    10098                "UPDATE " . $wpdb->prefix . "arca_pg_orders
     
    107105
    108106            echo "EDP_CHECKSUM not correct";
    109             die;
    110 
    111         } else {
    112 
    113             // please, write your code here to handle the payment success echo("OK");
    114 
    115             // get order payment state from REST response
    116             $paymentState = "DEPOSITED";
    117 
    118             // get previous stored requests
     107            die;
     108
     109        } else {
     110
     111            // please, write your code here to handle the payment success echo("OK");
     112
     113            // get order payment state from REST response
     114            $paymentState = "DEPOSITED";
     115
     116            // get previous stored requests
    119117            $OrderStatusExtended = json_decode(
    120118                $wpdb->get_var(
     
    127125            );
    128126
    129 
    130127            // add new request
    131             $OrderStatusExtended = array_merge($OrderStatusExtended, array( "Request 2 - confirm" => $_REQUEST ) );
    132 
    133             $OrderStatusExtended = json_encode( $OrderStatusExtended );
    134 
    135             // update order payment REST response data
     128            $OrderStatusExtended = array_merge($OrderStatusExtended, array( "Request 2 - confirm" => $_REQUEST ) );
     129
     130            $OrderStatusExtended = json_encode( $OrderStatusExtended );
     131
     132            // update order payment REST response data
    136133            $wpdb->query($wpdb->prepare(
    137134                "UPDATE " . $wpdb->prefix . "arca_pg_orders
     
    140137                $OrderStatusExtended,
    141138                $paymentState,
    142                 $orderNumber // исправлено с orderId на orderNumber
     139                $orderId
    143140            ));
    144141
    145142            $wc_orderId = ( !empty($_REQUEST["wc_orderId"]) ) ? intval($_REQUEST["wc_orderId"]) : null;
    146             $gwp_donationId = ( !empty($_REQUEST["gwp_donationId"]) ) ? intval($_REQUEST["gwp_donationId"]) : null;
    147 
    148             // if woocommerce
    149             if(isset($wc_orderId)) {
    150 
    151                 // get wc order
    152                 $apg_wc_order = wc_get_order($wc_orderId);
    153 
    154                 // get ws order status processing or failed
    155                 $apg_wc_orderStatus = ( $paymentState == 'DEPOSITED' ) ? $arca_idram_config->wc_order_status : 'failed';
    156 
    157                 // set wc order status
    158                 $apg_wc_order->set_status($apg_wc_orderStatus, 'wc_apg_gatewey');
    159                 $apg_wc_order->save();
    160 
    161                 $apg_wc_order->reduce_order_stock();
    162                 //WC()->cart->empty_cart();
    163 
    164                 // set email sent if email exist in wc order
     143            $gwp_donationId = ( !empty($_REQUEST["gwp_donationId"]) ) ? intval($_REQUEST["gwp_donationId"]) : null;
     144
     145            // if woocommerce
     146            if(isset($wc_orderId)) {
     147
     148                // get wc order
     149                $apg_wc_order = wc_get_order($wc_orderId);
     150
     151                // get ws order status processing or failed
     152                $apg_wc_orderStatus = ( $paymentState == 'DEPOSITED' ) ? $arca_idram_config->wc_order_status : 'failed';
     153
     154
     155                // eHDM print for woocommerce orders
     156
     157                // end eHDM print
     158
     159
     160                // set wc order status
     161                $apg_wc_order->set_status($apg_wc_orderStatus, 'wc_apg_gatewey');
     162                $apg_wc_order->save();
     163
     164                //$apg_wc_order->reduce_order_stock();
     165                WC()->cart->empty_cart();
     166
     167                // set email sent if email exist in wc order
    165168                $wpdb->query($wpdb->prepare(
    166                     "UPDATE " . $wpdb->prefix . "arca_pg_orders
    167                     SET mailSent = 1 
    168                     WHERE orderNumber = %d",
    169                     $orderNumber // исправлено с orderId на orderNumber
     169                    "UPDATE {$wpdb->prefix}arca_pg_orders
     170                    SET mailSent = 1
     171                    WHERE orderNumber = %s",
     172                    $orderId
    170173                ));
    171174
    172175                // if give wp
    173             } else if(isset($gwp_donationId)){
    174 
    175                 // get give wp order status publish or failed
    176                 $apg_givewp_orderStatus = ( $paymentState == 'DEPOSITED' ) ? 'publish' : 'failed';
    177 
    178                 // set give wp donate status
    179                 give_update_payment_status( $gwp_donationId, $apg_givewp_orderStatus );
    180 
    181                 // set email sent if email exist in wc order
     176            } else if(isset($gwp_donationId)){
     177
     178                // get give wp order status publish or failed
     179                $apg_givewp_orderStatus = ( $paymentState == 'DEPOSITED' ) ? 'publish' : 'failed';
     180
     181                // set give wp donate status
     182                give_update_payment_status( $gwp_donationId, $apg_givewp_orderStatus );
     183
     184                // set email sent if email exist in wc order
    182185                $wpdb->query($wpdb->prepare(
    183                     "UPDATE {$wpdb->prefix}arca_pg_orders 
    184                     SET mailSent = 1 
    185                     WHERE orderNumber = %d",
    186                     $orderId // если это число
     186                    "UPDATE {$wpdb->prefix}arca_pg_orders
     187                    SET mailSent = 1
     188                    WHERE orderNumber = %s",
     189                    $orderId
    187190                ));
    188191
    189192                // if tatiosa_booking
    190             } else if(isset($tatiosa_booking_id)){
    191 
    192                 $response = json_decode($response);
    193                 $response = $response->paymentAmountInfo;
    194 
    195                 // get ws order status processing or failed
    196                 $apg_booking_orderStatus = 1; //booking status, 0 (cancelled), 1 (confirmed), 2 (new), 3 (request)
    197                 $code = 0;
    198 
    199                 if( $apg_booking_orderStatus == 1){
    200 
    201                     $tatiosa_booking_Key = wp_parse_url( get_site_url() )['host'];
    202                     $description = 'Paid via Credit Card';
    203                     $payment_status = 'Successful';
    204                     $amount = $response->approvedAmount;
    205 
    206 
    207                     // notify of payment status tatiosa.net
    208                     $booking_orderStatus_url =  "https://tatiosa.net/api/custompaymentgateway/notify.php";
    209                     $args = array(
    210                         'headers'     => array('Content-Type: text/html; charset=UTF-8'),
    211                         'body'        => array(
    212                             'key'       => $tatiosa_booking_Key,
    213                             'bookid'    => $tatiosa_booking_id,
    214                             'status'     => $apg_booking_orderStatus,
    215                             'amount'     => $amount,
    216                             'description' => $description,
    217                             'payment_status' => $payment_status,
    218                         ),
    219                         'method'      => 'POST',
    220                         'data_format' => 'body',
    221                     );
    222                     $response = wp_remote_post( $booking_orderStatus_url, $args );
    223 
    224 
    225                     // get booking system status
    226                     $code = wp_remote_retrieve_response_code( $response );
    227                     if($code != 200){
    228                         arca_pg_errorCatch("Booking system respons error: " . json_encode($response, JSON_UNESCAPED_UNICODE), $wc_orderId, $gwp_donationId);
    229                     }
    230 
    231                 }
    232 
    233 
    234                 // get previous stored requests
    235                 //$OrderStatusExtended =  json_decode( $wpdb->get_var("select OrderStatusExtended from " . $wpdb->prefix . "arca_pg_orders where orderId = '$orderId'"), true );
     193            } else if(isset($tatiosa_booking_id)){
     194
     195                // get ws order status processing or failed
     196                $apg_booking_orderStatus = 1; //booking status, 0 (cancelled), 1 (confirmed), 2 (new), 3 (request)
     197                $code = 0;
     198
     199                if( $apg_booking_orderStatus == 1){
     200
     201                    $tatiosa_booking_Key = wp_parse_url( get_site_url() )['host'];
     202                    $description = 'Paid via Credit Card';
     203                    $payment_status = 'Successful';
     204
     205                    // get amount for $orderId from orders
     206                    $amount = $wpdb->get_var($wpdb->prepare("SELECT amount  from " . $wpdb->prefix . "arca_pg_orders where orderId = %s", $orderId));
     207
     208                    // notify of payment status tatiosa.net
     209                    $booking_orderStatus_url =  "https://tatiosa.net/api/custompaymentgateway/notify.php";
     210                    $args = array(
     211                        'headers'     => array('Content-Type: text/html; charset=UTF-8'),
     212                        'body'        => array(
     213                            'key'       => $tatiosa_booking_Key,
     214                            'bookid'    => $tatiosa_booking_id,
     215                            'status'     => $apg_booking_orderStatus,
     216                            'amount'     => $amount,
     217                            'description' => $description,
     218                            'payment_status' => $payment_status,
     219                        ),
     220                        'method'      => 'POST',
     221                        'data_format' => 'body',
     222                    );
     223                    $response = wp_remote_post( $booking_orderStatus_url, $args );
     224
     225
     226                    // get booking system status
     227                    $code = wp_remote_retrieve_response_code( $response );
     228                    if($code != 200){
     229                        arca_pg_errorCatch("Booking system respons error: " . json_encode($response, JSON_UNESCAPED_UNICODE), $wc_orderId, $gwp_donationId);
     230                    }
     231
     232                }
     233
     234                // get previous stored requests
    236235                $OrderStatusExtended = json_decode(
    237236                    $wpdb->get_var(
     
    244243                );
    245244
    246                 // add new request
    247                 $OrderStatusExtended = array_merge($OrderStatusExtended, array( "Booking System Response 1" => json_decode('{"Status": '.$code.'}', true) ) );
    248 
    249                 $OrderStatusExtended = json_encode( $OrderStatusExtended );
    250 
    251                 // update order payment REST response data
     245                // add new request
     246                $OrderStatusExtended = array_merge($OrderStatusExtended, array( "Booking System Response 1" => json_decode('{"Status": '.$code.'}', true) ) );
     247
     248                $OrderStatusExtended = json_encode( $OrderStatusExtended );
     249
     250                // update order payment REST response data
    252251                $wpdb->query($wpdb->prepare(
    253                     "UPDATE {$wpdb->prefix}arca_pg_orders 
    254                     SET OrderStatusExtended = %s, paymentState = %s 
     252                    "UPDATE {$wpdb->prefix}arca_pg_orders
     253                    SET OrderStatusExtended = %s, paymentState = %s
    255254                    WHERE orderId = %s",
    256255                    $OrderStatusExtended,
     
    261260            }
    262261
    263             echo "OK";
    264             die;
    265         }
    266     }
     262            // eHDM print for apg, tatiosa orders
     263
     264            // end eHDM print
     265
     266            echo "OK";
     267            die;
     268        }
     269    }
    267270
    268271}
     
    270273function apg_wc_api_idram_complete(){
    271274
    272     global $wpdb;
    273     $request = $_REQUEST;
    274 
    275     $orderNumber = $orderId = ( !empty($request["EDP_BILL_NO"]) ) ? intval($request["EDP_BILL_NO"]) : -1;
    276     $wc_orderId     =   ( !empty($request["wc_orderId"]) ) ? intval($request["wc_orderId"]) : null;
    277     $gwp_donationId =   ( !empty($request["gwp_donationId"]) ) ? intval($request["gwp_donationId"]) : null;
    278 
    279     // if woocommerce
    280     if(isset($wc_orderId)) {
    281 
    282         // get wc return url
    283         $wc_apg_gatewey = new wc_apg_gatewey();
    284 
    285         // get wc order
    286         $apg_wc_order = wc_get_order($wc_orderId);
    287 
    288         // redirect to final page with REST payment state
    289         wp_redirect( $wc_apg_gatewey->get_return_url( $apg_wc_order ) );
    290         exit;
    291 
    292         // if give wp
    293     } else if(isset($gwp_donationId)){
    294 
    295         // redirect to final page with REST payment state
    296         give_send_to_success_page();
    297         exit;
    298 
    299     } else if(isset($tatiosa_booking_id)){
    300 
    301 
    302 
    303     }
    304 
    305     // get language
    306     $language = ( isset($_REQUEST["language"]) ) ? $_REQUEST["language"] : null;
    307 
    308     // get order payment state from REST response
    309     $paymentState = "DEPOSITED";
    310 
    311     // redirect to final page with REST payment state
    312     wp_redirect( arca_pg_checkOutPagePermalink($language) . "?state=$paymentState&orderId=$orderId");
    313     exit;
     275    global $wpdb;
     276    $request = $_REQUEST;
     277
     278    $orderNumber = $orderId = ( !empty($request["EDP_BILL_NO"]) ) ? intval($request["EDP_BILL_NO"]) : -1;
     279    $wc_orderId     =   ( !empty($request["wc_orderId"]) ) ? intval($request["wc_orderId"]) : null;
     280    $gwp_donationId =   ( !empty($request["gwp_donationId"]) ) ? intval($request["gwp_donationId"]) : null;
     281
     282    // if woocommerce
     283    if(isset($wc_orderId)) {
     284
     285        // get wc return url
     286        $wc_apg_gatewey = new wc_apg_gatewey();
     287
     288        // get wc order
     289        $apg_wc_order = wc_get_order($wc_orderId);
     290
     291        // redirect to final page with REST payment state
     292        wp_redirect( $wc_apg_gatewey->get_return_url( $apg_wc_order ) );
     293        exit;
     294
     295        // if give wp
     296    } else if(isset($gwp_donationId)){
     297
     298        // redirect to final page with REST payment state
     299        give_send_to_success_page();
     300        exit;
     301
     302    } else if(isset($tatiosa_booking_id)){
     303
     304
     305
     306    }
     307
     308    // get language
     309    $language = ( isset($_REQUEST["language"]) ) ? $_REQUEST["language"] : null;
     310
     311    // get order payment state from REST response
     312    $paymentState = "DEPOSITED";
     313
     314    // redirect to final page with REST payment state
     315    wp_redirect( arca_pg_checkOutPagePermalink($language) . "?state=$paymentState&orderId=$orderId");
     316    exit;
    314317
    315318}
     
    317320function apg_wc_api_idram_fail(){
    318321
    319     global $wpdb;
    320     $request = $_REQUEST;
    321 
    322     $orderNumber = $orderId = ( !empty($request["EDP_BILL_NO"]) ) ? intval($request["EDP_BILL_NO"]) : -1;
    323     $wc_orderId     =   ( !empty($request["wc_orderId"]) ) ? intval($request["wc_orderId"]) : null;
    324     $gwp_donationId =   ( !empty($request["gwp_donationId"]) ) ? intval($request["gwp_donationId"]) : null;
    325 
    326     // get previous stored requests
     322    global $wpdb;
     323    $request = $_REQUEST;
     324
     325    $orderNumber = $orderId = ( !empty($request["EDP_BILL_NO"]) ) ? intval($request["EDP_BILL_NO"]) : -1;
     326    $wc_orderId     =   ( !empty($request["wc_orderId"]) ) ? intval($request["wc_orderId"]) : null;
     327    $gwp_donationId =   ( !empty($request["gwp_donationId"]) ) ? intval($request["gwp_donationId"]) : null;
     328
     329    // get previous stored requests
    327330    $OrderStatusExtended = json_decode(
    328331        $wpdb->get_var(
     
    335338    );
    336339
    337     // add new request
    338     $OrderStatusExtended = ( !empty($OrderStatusExtended) ) ? array_merge($OrderStatusExtended, array( "Request - fail" => $_REQUEST ) ) : array( "Request - fail" => $_REQUEST ) ;
    339 
    340     $OrderStatusExtended = json_encode( $OrderStatusExtended );
    341 
    342     // update error number from REST system
     340    // add new request
     341    $OrderStatusExtended = ( !empty($OrderStatusExtended) ) ? array_merge($OrderStatusExtended, array( "Request - fail" => $_REQUEST ) ) : array( "Request - fail" => $_REQUEST ) ;
     342
     343    $OrderStatusExtended = json_encode( $OrderStatusExtended );
     344
     345    // update error number from REST system
    343346    $wpdb->query($wpdb->prepare(
    344347        "UPDATE {$wpdb->prefix}arca_pg_orders
     
    359362if ($arca_process == "idram"){
    360363
    361     // data validation
    362     $errMgs = array();
    363 
    364     // get form data or defaults values
    365     $wc_orderId     =   ( !empty($_REQUEST["wc_orderId"]) ) ? intval($_REQUEST["wc_orderId"]) : null;
    366     $gwp_donationId =   ( !empty($_REQUEST["gwp_donationId"]) ) ? intval($_REQUEST["gwp_donationId"]) : null;
    367     $productId      =   ( !empty($_REQUEST["productId"]) ) ? intval($_REQUEST["productId"]) : 0;
    368     $amount         =   ( !empty($_REQUEST["amount"]) ) ? doubleval($_REQUEST["amount"]) : 0;
    369     $description    =   ( !empty($_REQUEST["description"]) ) ? sanitize_text_field($_REQUEST["description"]) : __( "Online payment", 'arca-payment-gateway' );
    370     $language       =   ( !empty($_REQUEST["language"]) ) ? sanitize_text_field($_REQUEST["language"]) : $arca_idram_config->default_language;
    371     $currency       =   ( !empty($_REQUEST["currency"]) ) ? sanitize_text_field($_REQUEST["currency"]) : "051";
     364    // data validation
     365    $errMgs = array();
     366
     367    // get form data or defaults values
     368    $wc_orderId     =   ( !empty($_REQUEST["wc_orderId"]) ) ? intval($_REQUEST["wc_orderId"]) : null;
     369    $gwp_donationId =   ( !empty($_REQUEST["gwp_donationId"]) ) ? intval($_REQUEST["gwp_donationId"]) : null;
     370    $productId      =   ( !empty($_REQUEST["productId"]) ) ? intval($_REQUEST["productId"]) : 0;
     371    $amount         =   ( !empty($_REQUEST["amount"]) ) ? doubleval($_REQUEST["amount"]) : 0;
     372    $description    =   ( !empty($_REQUEST["description"]) ) ? sanitize_text_field($_REQUEST["description"]) : __( "Online payment", 'arca-payment-gateway' );
     373    $language       =   ( !empty($_REQUEST["language"]) ) ? sanitize_text_field($_REQUEST["language"]) : $arca_idram_config->default_language;
     374    $currency       =   ( !empty($_REQUEST["currency"]) ) ? sanitize_text_field($_REQUEST["currency"]) : "051";
    372375    $custom_amount  = ( !empty($_REQUEST["custom_amount"]) && intval($_REQUEST["custom_amount"]) == 1 ) ? 1 : 0;
    373376
    374     // get payment initiator, woocommerce, givewp or apg
    375     if(isset($wc_orderId)) {
    376 
    377         // get wc order
    378         $apg_wc_order = wc_get_order($wc_orderId);
    379 
    380         // get order total amount
    381         $amount = $apg_wc_order->get_total();
    382 
    383         // validate currency
    384         $currency = ($apg_wc_order->get_currency()) == "AMD" ? "051" : null;
    385         if ( $currency != "051") array_push($errMgs, "Incorect currency:" . $currency);
    386 
    387     } else if (isset($gwp_donationId)) {
    388 
    389         // get give wp donation amount
    390         $amount = give_donation_amount($gwp_donationId);
    391 
    392         // get give wp donation currency abbr
    393         $apg_givewp_currency = (give_get_payment_currency_code($gwp_donationId)) == "AMD" ? "051" : null;
    394 
    395         // validate currency
    396         if ( $apg_givewp_currency != "051") array_push($errMgs, "Incorect currency:" . $apg_givewp_currency);
    397 
    398     } else {
    399 
    400         if($custom_amount == 0){
    401 
    402             // validate productId
     377    // get payment initiator, woocommerce, givewp or apg
     378    if(isset($wc_orderId)) {
     379
     380        // get wc order
     381        $apg_wc_order = wc_get_order($wc_orderId);
     382
     383        // get order total amount
     384        $amount = $apg_wc_order->get_total();
     385
     386        // validate currency
     387        $currency = ($apg_wc_order->get_currency()) == "AMD" ? "051" : null;
     388        if ( $currency != "051") array_push($errMgs, "Incorect currency:" . $currency);
     389
     390    } else if (isset($gwp_donationId)) {
     391
     392        // get give wp donation amount
     393        $amount = give_donation_amount($gwp_donationId);
     394
     395        // get give wp donation currency abbr
     396        $apg_givewp_currency = (give_get_payment_currency_code($gwp_donationId)) == "AMD" ? "051" : null;
     397
     398        // validate currency
     399        if ( $apg_givewp_currency != "051") array_push($errMgs, "Incorect currency:" . $apg_givewp_currency);
     400
     401    } else {
     402
     403        if($custom_amount == 0){
     404
     405            // validate productId
    403406            $resultCount = $wpdb->get_var(
    404407                $wpdb->prepare(
     
    410413            if ($resultCount == 0) array_push($errMgs, "incorrect productId:" . $productId);
    411414
    412             // get product details
     415            // get product details
    413416            $priceList = $wpdb->get_row(
    414417                $wpdb->prepare(
     
    418421            );
    419422
    420             // get price, validate price
    421             $amount = arca_pg_getPriceFromJson($priceList->productPrice, $currency);
    422             if ($amount == 0) array_push($errMgs, "Incorrect amount:" . $amount . " with the currency:" . $currency);
    423 
    424         }
    425 
    426         // validate currency
    427         if ( $currency != "051") array_push($errMgs, "Incorect currency:" . $currency);
    428 
    429     }
    430 
    431     // validate language
     423            // get price, validate price
     424            $amount = arca_pg_getPriceFromJson($priceList->productPrice, $currency);
     425            if ($amount == 0) array_push($errMgs, "Incorrect amount:" . $amount . " with the currency:" . $currency);
     426
     427        }
     428
     429        // validate currency
     430        if ( $currency != "051") array_push($errMgs, "Incorect currency:" . $currency);
     431
     432    }
     433
     434    // validate language
    432435    $resultCount = $wpdb->get_var($wpdb->prepare(
    433436        "SELECT COUNT(*) FROM {$wpdb->prefix}arca_pg_language WHERE code = %s",
     
    437440    if ($resultCount == 0) $language = $arca_idram_config->default_language;
    438441
    439     // validate checkout form permalink
    440     if (arca_pg_checkOutPagePermalink() == false) array_push($errMgs, "Checkout form not found");
    441 
    442     // get orderDetails
    443     $orderDetails = json_encode($_REQUEST, JSON_UNESCAPED_UNICODE);
    444 
    445     // validation
    446     if (empty($errMgs)){
    447 
    448         // create order blank row in db
    449         $table = $wpdb->prefix . 'arca_pg_orders';
    450         $data = array(
    451             'productId'     => $productId,
    452             'wc_orderId'    => $wc_orderId,
    453             //'gwp_donationId'      => $gwp_donationId,
    454             'amount'        => $amount,
    455             'currency'      => $currency,
    456             'orderDetails'  => $orderDetails,
    457             'rest_serverID' => ($arca_idram_config->testMode) ? 2 : 1,
    458             'orderDate'     => current_time('mysql'),
     442    // validate checkout form permalink
     443    if (arca_pg_checkOutPagePermalink() == false) array_push($errMgs, "Checkout form not found");
     444
     445    // get orderDetails
     446    $orderDetails = json_encode($_REQUEST, JSON_UNESCAPED_UNICODE);
     447
     448    // validation
     449    if (empty($errMgs)){
     450
     451        // create order blank row in db
     452        $table = $wpdb->prefix . 'arca_pg_orders';
     453        $data = array(
     454            'productId'     => $productId,
     455            'wc_orderId'    => $wc_orderId,
     456            //'gwp_donationId'      => $gwp_donationId,
     457            'amount'        => $amount,
     458            'currency'      => $currency,
     459            'orderDetails'  => $orderDetails,
     460            'rest_serverID' => ($arca_idram_config->testMode) ? 2 : 1,
     461            'orderDate'     => current_time('mysql'),
    459462            'bankId'        => 12, // iDram
    460         );
    461         $format = array(
    462             '%d',
    463             '%d',
    464             //'%d',
    465             '%f',
    466             '%s',
    467             '%s',
    468             '%d',
     463        );
     464        $format = array(
     465            '%d',
     466            '%d',
     467            //'%d',
     468            '%f',
     469            '%s',
    469470            '%s',
    470471            '%d',
    471         );
    472         $insert = $wpdb->insert($table, $data, $format);
    473         if ($insert){
    474 
    475             // get orderNumber from created row
    476             $orderNumber  = $wpdb->insert_id;
     472            '%s',
     473            '%d',
     474        );
     475        $insert = $wpdb->insert($table, $data, $format);
     476        if ($insert){
     477
     478            // get orderNumber from created row
     479            $orderNumber  = $wpdb->insert_id;
    477480
    478481            // create idram submit form
     
    494497            die;
    495498
    496         } else {
    497             arca_pg_errorCatch("Error on insert new order row, wpdb error: " . $wpdb->error, $wc_orderId, $gwp_donationId);
    498         }
    499 
    500     } else {
    501         arca_pg_errorCatch("Data validation error: " . implode(', ', $errMgs), $wc_orderId, $gwp_donationId);
    502     }
     499        } else {
     500            arca_pg_errorCatch("Error on insert new order row, wpdb error: " . $wpdb->error, $wc_orderId, $gwp_donationId);
     501        }
     502
     503    } else {
     504        arca_pg_errorCatch("Data validation error: " . implode(', ', $errMgs), $wc_orderId, $gwp_donationId);
     505    }
    503506
    504507}
  • arca-payment-gateway/trunk/includes/apg-wc.php

    r3240719 r3242781  
    3131
    3232        // subscription Хук для продления подписок
    33         //add_action('woocommerce_scheduled_subscription_payment_' . $this->id, array($this, 'process_subscription_payment'), 10, 2);
     33//        add_action('woocommerce_scheduled_subscription_payment_' . $this->id, array($this, 'process_subscription_payment'), 10, 2);
    3434    }
    3535
  • arca-payment-gateway/trunk/readme.txt

    r3241730 r3242781  
    55Requires PHP: 7.4
    66Tested up to: 6.7.2
    7 Stable tag: 1.4.8
     7Stable tag: 1.4.9
    88License: GPLv3
    99License URI: https://www.gnu.org/licenses/gpl-3.0.html
     
    125125== Changelog ==
    126126
     127= 1.4.9 =
     128*Fixed idram endpoint bug
     129
    127130= 1.4.8 =
    128131*Fixed wc blocks bugs
Note: See TracChangeset for help on using the changeset viewer.