CMXX - Webhooks and giftcards

This commit is contained in:
“VeLiTi”
2025-02-19 12:11:44 +01:00
parent d85923c299
commit 0e9d133ff9
10 changed files with 358 additions and 335 deletions

View File

@@ -339,9 +339,9 @@ function getAccessoiries($clientsecret, $categoryID){
<img src="'.img_url.$additional_product['full_path'].'" id="'.$additional_product['rowID'].'" width="50" height="50" alt="'.$additional_product['productname'].'">
</a>
<form id="product-form" action="" method="post">
<input type="hidden" name="add_product_id" value="'.$additional_product['rowID'].'">
<input type="hidden" name="add_product_price" value="'.$additional_product['price'].'">
<input type="hidden" name="add_product_weight" value="'.($additional_product['weight'] ?? 0).'">
<input id="product" type="hidden" name="product[product]" value="'.$additional_product['rowID'].'">
<input id="product" type="hidden" name="product[version]" value="'.($additional_product['version_id'] ?? '').'">
<input id="product" type="hidden" name="product[quantity]" value="1">
<input type="submit" name="accessoiries" value="+">
</form>
<a href="'.$additional_product_url.'" id="'.$additional_product['rowID'].'A" class="product">
@@ -431,7 +431,7 @@ function createGiftCart($pdo, $orderID){
$giftcard_ID = giftcard_id;
//Check if Giftcard is ordered
$stmt = $pdo->prepare('SELECT t.payer_email as email, ti.id as id, ti.txn_id as txn, ti.item_price as item_price, ti.item_quantity as item_quantity FROM transactions t INNER JOIN transactions_items ti ON t.txn_id = ti.txn_id INNER JOIN products_categories p ON ti.item_id = p.product_id WHERE p.category_id = ? AND ti.txn_id = ?');
$stmt = $pdo->prepare('SELECT t.payer_email as email, ti.id as id, ti.txn_id as txn, ti.item_price as item_price, ti.item_quantity as item_quantity FROM transactions t INNER JOIN transactions_items ti ON t.id = ti.txn_id INNER JOIN products_categories p ON ti.item_id = p.product_id WHERE p.category_id = ? AND t.txn_id = ?');
$stmt->execute([$giftcard_ID,$orderID]);
$giftcards = $stmt->fetchAll(PDO::FETCH_ASSOC);
@@ -508,46 +508,16 @@ function removeGiftCart($pdo, $orderID){
}
}
function generateInvoice($pdo, $orderID){
function generateInvoice($invoice,$orderID){
// Retrieve order items
$stmt = $pdo->prepare('SELECT ti.*, p.productcode, p.name FROM transactions t JOIN transactions_items ti ON ti.txn_id = t.txn_id LEFT JOIN products p ON p.id = ti.item_id WHERE t.txn_id = ?');
$stmt->execute([ $orderID ]);
$order_items = $stmt->fetchAll(PDO::FETCH_ASSOC);
// Retrieve order details
$stmt = $pdo->prepare('SELECT a.email, a.id AS a_id, a.first_name AS a_first_name, a.last_name AS a_last_name, a.address_street AS a_address_street, a.address_city AS a_address_city, a.address_state AS a_address_state, a.address_zip AS a_address_zip, a.address_country AS a_address_country, t.* FROM transactions t LEFT JOIN transactions_items ti ON ti.txn_id = t.txn_id LEFT JOIN accounts a ON a.id = t.account_id WHERE t.txn_id = ?');
$stmt->execute([ $orderID]);
$order = $stmt->fetch(PDO::FETCH_ASSOC);
// Get tax
$stmt = $pdo->prepare('SELECT * FROM taxes WHERE country = ?');
$stmt->execute([$order['a_address_country']]);
$tax = $stmt->fetch(PDO::FETCH_ASSOC);
$tax_rate = $tax ? $tax['rate'] : 0.00;
//$stmt->debugDumpParams();
//Variables
$customer_email = htmlspecialchars($order['payer_email'] ?? '', ENT_QUOTES);
$address_name = htmlspecialchars($order['first_name'] ?? '', ENT_QUOTES).' '.htmlspecialchars($order['last_name'] ?? '', ENT_QUOTES);
$address_street = htmlspecialchars($order['address_street'] ?? '', ENT_QUOTES);
$address_city = htmlspecialchars($order['address_city'] ?? '', ENT_QUOTES);
$address_state = htmlspecialchars($order['address_state'] ?? '', ENT_QUOTES);
$address_zip = htmlspecialchars($order['address_zip'] ?? '', ENT_QUOTES);
$address_country = htmlspecialchars($order['address_country'] ?? '', ENT_QUOTES);
$order_id = $order['id'];
$products = $order_items;
$shippingtotal = $order['shipping_amount'];
$total = $order['payment_amount'];
$taxtotal = $order['tax_amount'];
$order_created = $order['created'];
$customer_email = htmlspecialchars($invoice['customer']['email'] ?? '', ENT_QUOTES);
//Generate invoice
ob_start();
include dirname(__FILE__).'/custom/email/order-invoice-template.php';
$order_invoice_template = ob_get_clean();
return array($order_invoice_template,$customer_email,$order_id);
return array($order_invoice_template,$customer_email,$orderId);
}
function freeShipment($price, $type){