За последние 24 часа нас посетили 20678 программистов и 1106 роботов. Сейчас ищет 531 программист ...

Передать переменную в функцию

Тема в разделе "PHP Free-Lance", создана пользователем winston14, 25 июн 2020.

  1. winston14

    winston14 Активный пользователь

    С нами с:
    30 окт 2013
    Сообщения:
    21
    Симпатии:
    1
    Зада описана в комментариях в коде
    PHP:
    1. <?php
    2. if (!defined('__DIR__')) define('__DIR__', dirname(__FILE__)); //getting current directory using magic constants __DIR__ is deprecated in php 5.3.+
    3. $path = explode('wp-content',__DIR__); //getting main web root path for including further files.
    4. include_once($path[0].'wp-load.php'); //for getting global variables like wpdb
    5. global $current_user;
    6. use WP_Jobsearch\Package_Limits;
    7.  
    8.    
    9. add_action('parse_request', 'YMcheckPayment', 10, 1);
    10. function YMcheckPayment()
    11. {
    12.     global $wpdb;
    13.        
    14.         // для теста старт
    15.         $user_id = get_current_user_id();
    16.         $candidate_id = jobsearch_get_user_candidate_id($user_id);
    17.         $candidate_id = trim(str_replace(' ', '', $candidate_id));
    18.        
    19.         if ($candidate_id > 0){
    20.             update_post_meta($candidate_id, 'money', '0', false); // Выполняется
    21.         } else {
    22.             update_post_meta('288', 'money', '2', false); // Не выполняется
    23.         }
    24.         // для теста конец
    25.  
    26.     if ($_REQUEST['yandex_money'] == 'check') {
    27.        
    28.         if ($_REQUEST['notification_type'] == 'card-incoming' || $_REQUEST['notification_type'] == 'p2p-incoming'){
    29.             $hash = sha1($_REQUEST['notification_type'].'&'.$_REQUEST['operation_id'].'&'.$_REQUEST['amount'].'&'.$_REQUEST['currency'].'&'.
    30.             $_REQUEST['datetime'].'&'.$_REQUEST['sender'].'&'.$_REQUEST['codepro'].'&'.get_option('ym_Secret').'&'.$_REQUEST['label']);
    31.  
    32.             if ($_REQUEST['test_notification'] != 'true' && $hash == $_REQUEST['sha1_hash']){
    33.                 $order_w = new WC_Order( $_REQUEST['label'] );
    34.                 $order_w->update_status('processing', __( 'Платеж успешно оплачен', 'woocommerce' ));
    35.                 $order_w->reduce_order_stock();
    36.  
    37.                 if ($candidate_id > 0){
    38.                     update_post_meta($candidate_id, 'money', '3', false); // Не выполняется, а должно
    39.                 } else {
    40.                     update_post_meta('288', 'money', '4', false); // Выполняется но не должно
    41.                 }
    42.             }
    43.            
    44.         } else { // дальше код не выполняется и не должен выполнятся так как $_REQUEST['notification_type'] всегда будет равно 'p2p-incoming' или 'card-incoming'
    45.        
    46.             $hash = md5($_POST['action'].';'.$_POST['orderSumAmount'].';'.$_POST['orderSumCurrencyPaycash'].';'.
    47.                         $_POST['orderSumBankPaycash'].';'.$_POST['shopId'].';'.$_POST['invoiceId'].';'.
    48.                         $_POST['customerNumber'].';'.get_option('ym_shopPassword'));
    49.             header('Content-Type: application/xml');
    50.             if (strtolower($hash) != strtolower($_POST['md5']) and (isset($_POST['md5']))) { // !=
    51.                 $code = 1;
    52.                 echo '<?xml version="1.0" encoding="UTF-8"?><checkOrderResponse performedDatetime="'. $_POST['requestDatetime'] .'" code="'.$code.'"'. ' invoiceId="'. $_POST['invoiceId'] .'" shopId="'. get_option('ym_ShopID') .'" message="bad md5"/>';
    53.             } else {
    54.                 $order = $wpdb->get_row('SELECT * FROM '.$wpdb->prefix.'posts WHERE ID = '.(int)$_POST['customerNumber']);
    55.                 $order_summ = get_post_meta($order->ID,'_order_total',true);
    56.                 if (!$order) {
    57.                     $code = 200;
    58.                     $answer = '<?xml version="1.0" encoding="UTF-8"?><checkOrderResponse performedDatetime="'. $_POST['requestDatetime'] .'" code="'.$code.'"'. ' invoiceId="'. $_POST['invoiceId'] .'" shopId="'. get_option('ym_ShopID') .'" message="wrong customerNumber"/>';
    59.                 } elseif ($order_summ != $_POST['orderSumAmount']) { // !=
    60.                     $code = 100;
    61.                     $answer = '<?xml version="1.0" encoding="UTF-8"?><checkOrderResponse performedDatetime="'. $_POST['requestDatetime'] .'" code="'.$code.'"'. ' invoiceId="'. $_POST['invoiceId'] .'" shopId="'. get_option('ym_ShopID') .'" message="wrong orderSumAmount"/>';
    62.                 } else {
    63.                     $code = 0;
    64.                     if ($_POST['action'] == 'paymentAviso') {
    65.                         $order_w = new WC_Order( $order->ID );
    66.                         $order_w->update_status('processing', __( 'Платеж успешно оплачен', 'woocommerce' ));
    67.                         $order_w->reduce_order_stock();
    68.  
    69.                             if (isset($candidate_id) && $candidate_id != '0'){
    70.                                 update_post_meta($candidate_id, 'money', '5', false);
    71.                             } else {
    72.                                 update_post_meta('1496', 'money', '6', false);
    73.                             }
    74.  
    75.                         $answer = '<?xml version="1.0" encoding="UTF-8"?><paymentAvisoResponse performedDatetime="'.date('c').'" code="'.$code.'" invoiceId="'.$_POST['invoiceId'].'" shopId="'.get_option('ym_ShopID').'" />';
    76.                     }
    77.                     else{
    78.                         $answer = '<?xml version="1.0" encoding="UTF-8"?><checkOrderResponse performedDatetime="'.date('c').'" code="'.$code.'" invoiceId="'.$_POST['invoiceId'].'" shopId="'.get_option('ym_ShopID').'" />';
    79.                     }
    80.                 }
    81.             }
    82.             die($answer);
    83.         }
    84.     }
    85. }
    Напишите стоимость и время/число когда сможете сделать.
     
  2. winston14

    winston14 Активный пользователь

    С нами с:
    30 окт 2013
    Сообщения:
    21
    Симпатии:
    1
    проблема на строке 38
     
  3. ADSoft

    ADSoft Старожил

    С нами с:
    12 мар 2007
    Сообщения:
    3.816
    Симпатии:
    735
    Адрес:
    Татарстан
    Проблема не в строке 38, а в понимании ))
    См. Строку 17, переменная это строка

    Сделайте
    PHP:
    1.  $candidate_id = intval(trim(str_replace(' ', '', $candidate_id)));