HEX
Server: nginx/1.24.0
System: Linux ip-172-31-22-109 6.17.0-1012-aws #12~24.04.1-Ubuntu SMP Mon Apr 6 17:36:28 UTC 2026 x86_64
User: ubuntu (1000)
PHP: 8.3.6
Disabled: NONE
Upload Files
File: /home/ubuntu/public/wp-content/plugins/woocommerce-xpay-plugin/utils.php
<?php



function httpPost($url, $data, $api_key, $debug = 'no')
{
    $curl = curl_init($url);
    curl_setopt($curl, CURLOPT_POST, true);
    curl_setopt( $curl, CURLOPT_POSTFIELDS, $data );
	curl_setopt( $curl, CURLOPT_HTTPHEADER, array('Content-Type:application/json', 
												'User-Agent:XPay',
												'x-api-key: '.$api_key,
											)
				);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    $response = curl_exec($curl);
    curl_close($curl);
	if($debug == 'yes') {
		jsprint($response);
	}
    return $response;
}

function httpGet($url, $api_key, $debug = 'no')
{
    $headers = array(
        'x-api-key: '.$api_key,
        'Content-Type:application/json'
   );
    $curl = curl_init($url);
	curl_setopt( $curl, CURLOPT_HTTPHEADER, $headers);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);


    $response = curl_exec($curl);
    curl_close($curl);
    if($debug == 'yes') {
		jsprint($response);
	}
    return $response;
}

function jsprint($output, $is_alert=true, $with_script_tags = true) {
    // For server-side logging
    if (defined('DOING_AJAX') && DOING_AJAX) {
        error_log(print_r($output, true));
        return;
    }
    
    // For client-side output
    if($is_alert) {
        $js_code = 'alert(' . json_encode($output, JSON_HEX_TAG) . ');';
    } else {
        $js_code = 'console.log(' . json_encode($output, JSON_HEX_TAG) . ');';
    }
    if ($with_script_tags) {
        $js_code = '<script>' . $js_code . '</script>';
    }
    echo $js_code;
}


add_action('wp_ajax_fetch_installment_plans', 'fetch_installment_plans');
add_action('wp_ajax_nopriv_fetch_installment_plans', 'fetch_installment_plans');

function fetch_installment_plans() {
     $amount = isset($_POST['amount']) ? sanitize_text_field($_POST['amount']) : null; 
    $url = isset($_POST['url']) ? esc_url_raw($_POST['url']) : null; 

    
    $api_key = isset($_POST['api_key']) ? sanitize_text_field($_POST['api_key']) : null; 
    $selected_payment_method = "installment";
    $community_id = isset($_POST['community_id']) ? sanitize_text_field($_POST['community_id']) : null; 
    $debug = true;
    $payload = json_encode(array(
        'amount' => $amount,
        'selected_payment_method' => $selected_payment_method,
        'community_id' => $community_id,
    ));
    $resp = httpPost($url, $payload, $api_key, FALSE);
    $decoded_resp = json_decode($resp, TRUE);
    
    echo json_encode($resp);
   

    wp_die();
}

?>