コード例 #1
0
function tzs_pay_order_p24($order_pay_method)
{
    global $wpdb;
    $errors = array();
    $user_id = get_current_user_id();
    $order_status = 1;
    $PrivatAPI = new privat24api(get_option('t3s_setting_merchant_id'), get_option('t3s_setting_merchant_pass'));
    if ($order_pay_method == 1) {
        $pay_res = $PrivatAPI->GetPaymentResult();
    } elseif ($order_pay_method == 2) {
        $pay_res = $PrivatAPI->GetPaymentStatus();
    } else {
        $pay_res = array();
    }
    // Если результирующий массив пустой
    if (count($pay_res) > 0) {
        $order_array = explode('.', $pay_res['order']);
        $order_id = $order_array[1];
        $order_dt_pay = substr($pay_res['date'], 0, 2) . '.' . substr($pay_res['date'], 2, 2) . '.20' . substr($pay_res['date'], 4, 2) . ' ' . substr($pay_res['date'], 6, 2) . ':' . substr($pay_res['date'], 8, 2) . ':' . substr($pay_res['date'], 10, 2);
        // Временное смещение
        if (isset($_SESSION['timezone_offset_enabled']) && isset($_SESSION['timezone_offset']) && $_SESSION['timezone_offset_enabled'] && is_numeric($_SESSION['timezone_offset'])) {
            $timezone_offset = $_SESSION['timezone_offset'] * -1;
        } else {
            $timezone_offset = 0;
        }
        $ts = strtotime($order_dt_pay) + $timezone_offset * 3600;
        $dt = date('Y-m-d H:i:s', $ts);
        $tse = new DateTime($dt);
        date_add($tse, date_interval_create_from_date_string(get_option('t3s_setting_record_pickup_days') + 1 . ' days'));
        $dte = date_format($tse, 'Y-m-d');
        $sql = $wpdb->prepare("UPDATE " . TZS_ORDERS_TABLE . " SET " . " dt_pay=%s, dt_expired=%s, status=%d, pay_method=%d" . " WHERE id=%d AND user_id=%d;", stripslashes_deep($dt), stripslashes_deep($dte), intval($order_status), intval($order_pay_method), intval($order_id), $user_id);
        $sql = str_replace("'null'", "null", $sql);
        if (false === $wpdb->query($sql)) {
            array_push($errors, "Не удалось обновить счет. Свяжитесь, пожалуйста, с администрацией сайта");
            array_push($errors, $wpdb->last_error);
        } else {
        }
    } else {
        array_push($errors, $PrivatAPI->errmess);
    }
    $output = array('output_error' => implode('<br>', $errors), 'order_id' => $order_id, 'order_dt_pay' => $order_dt_pay, 'ts' => $ts, 'dt' => $dt, 'dte' => $dte, 'tse' => $tse);
    return $output;
}