| Server IP : 13.126.101.145 / Your IP : 216.73.217.84 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/api-phone/ |
Upload File : |
<?php
/**
* custom APIs for BillDesk 1cc
*/
use io\billdesk\client\hmacsha256\BillDeskJWEHS256Client;
use io\billdesk\client\hmacsha256\JWEHS256Helper;
function createOrderf($request)
{
$parametersen = $request->get_body_params();
// die($parametersen);
$parameters = decryptdaata($parametersen['params']);
// die( json_encode($parameters));
$filestatus = "";
$user_id = intval($parameters['user_id']);
$pMethod = intval($parameters['p_method']);
$customer = $parameters['codata']['customer'];
// $requestd = array(
// 'message'=>" customerdata" . $customer['first_name']
// );
// return new WP_REST_Response($requestd, 400);
// wp-content/plugins/woocommerce-billdesk-plugin
if (file_exists(dirname(__DIR__) . '/woocommerce-billdesk-plugin/vendor/autoload.php')) {
require_once dirname(__DIR__) . '/woocommerce-billdesk-plugin/vendor/autoload.php';
$filestatus = "File exist";
} else {
$filestatus = "File Not exist";
}
require_once dirname(__DIR__) . '/woocommerce-billdesk-plugin/logger.php';
$log = WooBillDeskLogger::logger("Test PG Connectivity ");
$woocommerce_billdesk_merchant_id = "BDUAT2K358"; //sanitize_text_field($params['woocommerce_billdesk_merchant_id']);
$woocommerce_billdesk_merchant_key = "ueXld3eX4ZT5W1lE0tgxX8mUtRQrrh2e"; // sanitize_text_field($params['woocommerce_billdesk_merchant_key']);
$woocommerce_billdesk_client_id = "bduat2k358"; //sanitize_text_field($params['woocommerce_billdesk_client_id']);
$woocommerce_billdesk_environment = sanitize_text_field($parameters['env']);
// $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);
// Example input (you'd receive this via POST or another method)
$datab = $parameters['billing_address'] ?? [];
$datas = $parameters['billing_address'] ?? [];
$datap = $parameters['cartdata'] ?? [];
$billing = array(
'first_name' => $datab['billing_first_name'],
'last_name' => $datab['billing_last_name'],
'email' => $datab['billing_email'],
'phone' => $datab['billing_phone'],
'address_1' => $datab['billing_address_1'] ?? '',
'address_2' => $datab['billing_address_2'] ?? '',
'city' => $datab['billing_city'] ?? '',
'state' => $datab['billing_state_code'] ?? '',
'postcode' => $datab['billing_postcode'] ?? '',
'country' => $datab['billing_country'] ?? 'IN',
);
$shipping = array(
'first_name' => $datas['shipping_first_name'],
'last_name' => $datas['shipping_last_name'],
'email' => $datas['shipping_email'],
'phone' => $datas['shipping_phone'],
'address_1' => $datas['shipping_address_1'] ?? '',
'address_2' => $datas['shipping_address_2'] ?? '',
'city' => $datas['shipping_city'] ?? '',
'state' => $datas['shipping_state_code'] ?? '',
'postcode' => $datas['shipping_postcode'] ?? '',
'country' => $datas['shipping_country'] ?? 'IN',
);
$order = wc_create_order();
$order->set_customer_id($user_id);
// Add products
// foreach ( $data['items'] as $item ) {
$order->add_product(wc_get_product($datap['product_id']), 1);
// }
// Set address
$order->set_address($billing, 'billing');
$order->set_address($shipping, 'shipping');
// Set payment method
$order->set_payment_method(($pMethod == 0) ? 'COD' : 'Billdesk_gateway'); // You can use any registered payment method ID
$order->set_payment_method_title('Flutter Payment');
// Mark as paid
$order->set_status('processing'); // Or 'processing', 'on-hold', etc.
$order->payment_complete();
// Calculate totals
$order->calculate_totals();
$orderId = $order->get_id(); // Or $order if you want the full object
if ($pMethod == 1) {
try {
$requestd = array(
'mercid' => $woocommerce_billdesk_merchant_id,
'orderid' => $orderId,
'amount' => $parameters['codata']['amount'],
'order_date' => date_format(new \DateTime(), DATE_W3C),
'currency' => $parameters['codata']['currency'],
'ru' => $parameters['codata']['ru'],
'itemcode' => 'DIRECT',
'device' => array(
'init_channel' => 'app',
'ip' => $ipaddress,
'user_agent' => $userAgent
),
'customer' => array('first_name' => $customer['first_name'], 'last_name' => $customer['last_name'], 'mobile' => $customer['user_phone'], 'email' => $datap['user_email']),
);
// $encrypted = encryptdaata(array('message' =>"" ,'data'=>$requestd ));
// return new WP_REST_Response($encrypted, 200);
$response = $client->createOrder($requestd);
$results = $response->getResponse();
$res = json_encode($results);
$encrypted = encryptdaata(array('message' => "", 'data' => $res));
return new WP_REST_Response($encrypted, 200);
} catch (Exception $exp) {
// $log->debug("Exception on creating connection with php client $exp");
// error_log("Server responded with error1: " . $exp . PHP_EOL, 0);
$encrypted = encryptdaata(array('message' => "Exception on creating connection with php client $exp"));
return new WP_REST_Response($encrypted, 400);
}
} else {
$res = array("message" => "Cash on delivery. Order generated.", "success" => 1);
$encrypted = encryptdaata($res);
return new WP_REST_Response($encrypted, 200);
}
} catch (Exception $exp) {
$encrypted = encryptdaata(array('message' => "Client connection Error: " . $e));
return new WP_REST_Response($encrypted, 400);
}
} catch (Exception $e) {
$encrypted = encryptdaata(array('message' => "Failed in initiate order " . $e));
return new WP_REST_Response($encrypted, 400);
}
}
// {"mercid":"BDUAT2K358","transaction_date":"2025-03-08T15:38:17+05:30",
// "surcharge":"0.00","payment_method_type":"netbanking","amount":"1076785.00",
// "ru":"http://192.168.29.95/gmmco4/index.php/woo/billdesk/woo_autoclose/","orderid":"67cc16c307beb",
// "transaction_error_type":"success","discount":"0.00","payment_category":"02",
// "bank_ref_no":"BILLDESK12","transactionid":"USBIPTO000H8LB","txn_process_type":"nb",
// "bankid":"SBI","additional_info":{"additional_info7":"platform,woocommerce_9.4.3_Wordpress_6.7.1-pluginv,1.0.9",
// "additional_info1":"9555","additional_info3":"venkats084@gmail.com","additional_info2":"Venkat,S",
// "additional_info5":"Bangalore,Bangalore,560035,KA,IN","additional_info4":"+919632164471"},
// "itemcode":"DIRECT","transaction_error_code":"TRS0000","currency":"356","auth_status":"0300",
// "transaction_error_desc":"Transaction Successful","objectid":"transaction","charge_amount":"1076785.00"};