HEX
Server: Apache/2.4.58 (Ubuntu)
System: Linux ip-172-31-18-78 6.17.0-1017-aws #17~24.04.1-Ubuntu SMP Tue May 26 21:09:53 UTC 2026 aarch64
User: ubuntu (1000)
PHP: 8.2.31
Disabled: NONE
Upload Files
File: /var/www/unbox/uc-live/api/all-platform-payment.php
<?php
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: POST, GET, OPTIONS');
header('Content-Type: application/json');
include '../wp-config.php';

global $wpdb;

// ini_set('display_errors', 1);
// ini_set('display_startup_errors', 1);
// error_reporting(E_ALL);

date_default_timezone_set('Asia/Calcutta');
$curDate = date('Y-m-d H:i:s');
$cipher = "aes-256-cbc";
$encryption_key = "unbox-enc2022";
$jsonRequest = file_get_contents('php://input');

$decryptedData = openssl_decrypt($jsonRequest, $cipher, $encryption_key);
$base64DecodeData = base64_decode($decryptedData);
$finalDecryptedData = json_decode($base64DecodeData);
//  echo "final page data: finalDecryptedData="; print_r($finalDecryptedData);echo "<br/>";

$from_domain = $finalDecryptedData->from_domain;
$if_vendor = $finalDecryptedData->if_vendor;
$transaction_type = $finalDecryptedData->transaction_type;
$payment_for = $finalDecryptedData->payment_for;
$payment_type = $finalDecryptedData->payment_type;
$order_id = $finalDecryptedData->order_id;
$product_mrp = $finalDecryptedData->product_mrp;
$gst_rate = $finalDecryptedData->gst_rate;
$unbox_amount = $finalDecryptedData->gepl_amount;
$discount_amount = $finalDecryptedData->discount_amount;
$net_amount = $finalDecryptedData->net_amount;
$customer_name = $finalDecryptedData->customer_name;
$customer_address = $finalDecryptedData->customer_address;
$customer_mobile = $finalDecryptedData->customer_mobile;
$customer_email = $finalDecryptedData->customer_email;
$customer_gst_name = $finalDecryptedData->customer_gst_name;
$customer_gstin = $finalDecryptedData->customer_gstin;
$customer_state_id = $finalDecryptedData->customer_state_id;
$customer_state_code = $finalDecryptedData->customer_state_code;
$customer_state_name = $finalDecryptedData->customer_state_name;
$transaction_id1 = $finalDecryptedData->transaction_id1;
$year_extn = $finalDecryptedData->year_extn;
$transaction_id2 = $finalDecryptedData->transaction_id2;
$transaction_date = $finalDecryptedData->transaction_date;
$ref_name1 = $finalDecryptedData->ref_name1;
$ref_id1 = $finalDecryptedData->ref_id1;
$ref_name2 = $finalDecryptedData->ref_name2;
$ref_id2 = $finalDecryptedData->ref_id2;
$ref_name3 = $finalDecryptedData->ref_name3;
$ref_id3 = $finalDecryptedData->ref_id3;
$payment_gateway_name = $finalDecryptedData->payment_gateway_name;

if ($from_domain == '' || $from_domain == '0') {
    $rstatus = 'failed';
    $rmsg = 'Domain name can not be empty for Invoice';
    $invoiceId = '0';
} else if ($if_vendor == '' || $if_vendor == '0') {
    $rstatus = 'failed';
    $rmsg = 'Vendor name can not be empty for Invoice, send UNBOX in case of direct payment';
    $invoiceId = '0';
}
 else if ($order_id == '' || $order_id == '0') {
    $rstatus = 'failed';
    $rmsg = 'Order id can not be empty for Invoice';
    $invoiceId = '0';
} else if ($product_mrp == '' || $product_mrp == '0') {
    $rstatus = 'failed';
    $rmsg = 'Product MRP can not be empty for Invoice';
    $invoiceId = '0';
} else if ($customer_name == '' || $customer_name == '0') {
    $rstatus = 'failed';
    $rmsg = 'Customer name can not be empty for Invoice';
    $invoiceId = '0';
} 
 else {  
    // echo "select invoice_id from `unbox_invoice` where `from_domain`='$from_domain' and `if_vendor`='$if_vendor' and `order_id`='$order_id' and `transaction_id1`='$transaction_id1' limit 1";
    $checkExist = $wpdb->get_var("select invoice_id from `unbox_invoice` where `from_domain`='$from_domain' and `if_vendor`='$if_vendor' and `order_id`='$order_id' and `transaction_id1`='$transaction_id1' limit 1");

    if ($discount_amount != 0) {
        $totalAmount = $product_mrp - $discount_amount;
    } else {
        $totalAmount = $product_mrp;
    }

    if ($customer_state_code == 'DL' || $customer_state_name == 'Delhi') {
        $amount = $totalAmount;
        $total_amount = round(($amount / 118 * 100), 2);
        $igst_amount = 0;
        $cgst_amount = round(($total_amount * 9 / 100), 2);
        $sgst_amount = round(($total_amount * 9 / 100), 2);
        $grand_amount = round((($amount / 118 * 100) + ($total_amount * 9 / 100) + ($total_amount * 9 / 100)), 2);
    } else {
        $cgst_amount = 0;
        $sgst_amount = 0;
        $amount = $totalAmount;
        $total_amount = round(($amount / 118 * 100), 2);
        $igst_amount = round(($total_amount * 18 / 100), 2);
        $grand_amount = round((($amount / 118 * 100) + ($total_amount * 18 / 100)), 2);
    }
    if ($checkExist == 0) {
        $insertQuery = "INSERT INTO unbox_invoice set from_domain='$from_domain', if_vendor='$if_vendor', transaction_type='$transaction_type', payment_for='$payment_for', payment_type='$payment_type', order_id='$order_id', product_mrp='$product_mrp', gst_rate='$gst_rate', igst_amount='$igst_amount', cgst_amount='$cgst_amount', sgst_amount='$sgst_amount', taxable_amount='$total_amount', unbox_amount='$unbox_amount', discount_amount='$discount_amount', net_amount='$net_amount', customer_name='$customer_name', customer_address='$customer_address', customer_mobile='$customer_mobile', customer_email='$customer_email', customer_gst_name='$customer_gst_name', customer_gstin='$customer_gstin', customer_state_id='$customer_state_id', customer_state_code='$customer_state_code', customer_state_name='$customer_state_name', transaction_id1='$transaction_id1', transaction_id2='', transaction_date='$transaction_date', invoice_issue_date='$curDate', year_extn='$year_extn', invoice_status='1', system_datetime='$curDate', cancelled_reason_if_any='', cancelled_datetime='$curDate', ref_name1='$ref_name1', ref_id1='$ref_id1', ref_name2='$ref_name2', ref_id2='$ref_id2', ref_name3='$ref_name3', ref_id3='$ref_id3', payment_gateway_name='$payment_gateway_name'";
     //   echo $insertQuery; 
        if ($wpdb->query($insertQuery)) {
            $insertId = $wpdb->insert_id;
            $rstatus = 'success';
            $rmsg = 'Invoice data captured successfully';
            $invoiceId = $insertId;
        } else {
            $rstatus = 'failed';
            $rmsg = 'Error: Something wrong, please try again';
            $invoiceId = '0';
        }
      //   echo $wpdb->show_errors;
    } else {
        $rstatus = 'failed';
        $rmsg = 'Error: Transaction details already exist';
        $invoiceId = '0';
    }
}

if ($rstatus == "success") {
    $response["status"] = $rstatus;
    $response["message"] = $rmsg;
    $response["invoiceId"] = $invoiceId;
    $responseArray[] = $response;
} else {
    $response["status"] = $rstatus;
    $response["message"] = $rmsg;
    $response["invoiceId"] = $invoiceId;
    $responseArray[] = $response;
}
echo json_encode($responseArray);

?>