| Server IP : 13.126.101.145 / Your IP : 216.73.217.33 Web Server : Apache/2.4.52 (Ubuntu) System : Linux ip-11-115-0-196 6.8.0-1039-aws #41~22.04.1-Ubuntu SMP Thu Sep 11 10:54:48 UTC 2025 x86_64 User : www-data ( 33) PHP Version : 8.3.17 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /var/www/html/rentals_updated/wp-content/plugins/woocommerce-billdesk-plugin/ |
Upload File : |
<?php
/**
* custom APIs for BillDesk 1cc
*/
use io\billdesk\client\hmacsha256\BillDeskJWEHS256Client;
use io\billdesk\client\hmacsha256\JWEHS256Helper;
if (!defined('ABSPATH')) {
exit; // Exit if accessed directly
}
if (file_exists(dirname(__FILE__) . '/vendor/autoload.php')) {
require_once dirname(__FILE__) . '/vendor/autoload.php';
}
require_once dirname(__FILE__) . '/logger.php';
function BilldeskPgConnectivityRestApi()
{
// test pg connectivity
register_rest_route(
'woo/billdesk',
'/api/test-connection',
array(
'methods' => 'POST',
'callback' => 'woo_testconnection',
'permission_callback' => '__return_true'
)
);
function woo_testconnection(WP_REST_Request $request)
{
// error_log("Inside Callback Test Connection: ".var_dump($request). PHP_EOL, 0);
$params = $request->get_params();
$log = WooBillDeskLogger::logger("Test PG Connectivity ");
$woocommerce_billdesk_merchant_id = sanitize_text_field($params['woocommerce_billdesk_merchant_id']);
$woocommerce_billdesk_merchant_id = sanitize_text_field($params['woocommerce_billdesk_merchant_id']);
$woocommerce_billdesk_merchant_key = sanitize_text_field($params['woocommerce_billdesk_merchant_key']);
$woocommerce_billdesk_client_id = sanitize_text_field($params['woocommerce_billdesk_client_id']);
$woocommerce_billdesk_environment = sanitize_text_field($params['woocommerce_billdesk_environment']);
error_log("Inside Callback woocommerce_billdesk_merchant_id: ".$woocommerce_billdesk_merchant_id. PHP_EOL, 0);
$currency_value = get_woocommerce_currency();
try{
// TODO: Need to create a list of all supported currencies or list of all ISO currencies
$arr = array(
'INR' =>'356' ,'USD' => '840','GBP' => '826', 'EUR' => '978', 'AED' => '784'
);
// FIXME: Possibility of currency being null at this point.
// If we have all the currencies in the table, this will lead to
// error from PG which is a more appropriate scenario.
$currency = $arr[$currency_value];
$log->debug("Identified order currency: $currency");
$returnUrl = get_option('siteurl') ;
$ip = getenv('HTTP_CLIENT_IP') ?:
getenv('HTTP_X_FORWARDED_FOR') ?:
getenv('HTTP_X_FORWARDED') ?:
getenv('HTTP_FORWARDED_FOR') ?:
getenv('HTTP_FORWARDED') ?:
getenv('REMOTE_ADDR');
$ipaddress = strtok($ip, ",");
$userAgent = $_SERVER['HTTP_USER_AGENT'];
try {
if ($woocommerce_billdesk_environment == 'UAT') {
$client = new BillDeskJWEHS256Client('https://uat1.billdesk.com/u2', $woocommerce_billdesk_client_id, $woocommerce_billdesk_merchant_key);
}
if ($woocommerce_billdesk_environment == 'PROD') {
$client = new BillDeskJWEHS256Client('https://api.billdesk.com', $woocommerce_billdesk_client_id, $woocommerce_billdesk_merchant_key);
}
$client->setLogger($log);
try {
$request = array(
'mercid' => $woocommerce_billdesk_merchant_id,
'orderid' => uniqid(),
'amount' => "100",
'order_date' => date_format(new \DateTime(), DATE_W3C),
'currency' => $currency,
'ru' => $returnUrl,
'itemcode' => 'DIRECT',
'device' => array(
'init_channel' => 'internet',
'ip' => $ipaddress,
'user_agent' => $userAgent
),
);
$response = $client->createOrder($request);
$results = $response->getResponse();
$res = json_encode($results);
return $res;
} catch (Exception $exp) {
$log->debug("Exception on creating connection with php client $exp");
error_log("Server responded with error1: " . $exp . PHP_EOL, 0);
return true;
}
}catch (Exception $exp) {
error_log("Server responded with error2: " . $e . PHP_EOL, 0);
//print($exp->getMessage());
return true;
}
}catch (Exception $e) {
$log->debug("Exception on creating connection with php client $e");
error_log("Server responded with error3: " . $e . PHP_EOL, 0);
print("Failed to create order.Currency is not there in list");
return true;
}
}
}
add_action('rest_api_init', 'BilldeskPgConnectivityRestApi');