codeigniter3 as you can see in the below PHP code I’m using the Paytm payment gateway in my code for checkout process
But when I want to show the order info to the user, I get a ‘Transaction Failed’ message. Want to show order information to my user.
controller- Checkout.php
method-> process_order
$cartItems = $this->cart->contents();
if($this->cart->total_items() > 0){ foreach($cartItems as $item){
header("Pragma: no-cache");
header("Cache-Control: no-cache");
header("Expires: 0");
$checkSum = "";
$paramList = array();
$CHANNEL_ID = 'WEB';
$paramList["MID"] = PAYTM_MERCHANT_MID;
$paramList["ORDER_ID"] = 'ORDS' . rand(10000,99999999);
$paramList["CUST_ID"] = '44667226220';
$paramList["INDUSTRY_TYPE_ID"] = INDUSTRY_TYPE_ID;
$paramList["CHANNEL_ID"] = $CHANNEL_ID;
$paramList["TXN_AMOUNT"] = $item["subtotal"];
$paramList["WEBSITE"] = PAYTM_MERCHANT_WEBSITE;
$paramList["CALLBACK_URL"] = base_url('Checkout/payment_response');
$paramList["MSISDN"] = 'xxxxxxxxxx'; //Mobile number of customer
$paramList["EMAIL"] = 'xxxxxxxxxx'; //Email ID of customer
$paramList["VERIFIED_BY"] = "MSISDN";
$paramList["IS_USER_VERIFIED"] = "YES";
$checkSum = $this->paytm->getChecksumFromArray($paramList,PAYTM_MERCHANT_KEY);
$transaction_url = PAYTM_TXN_URL;
$data = array('paramList' => $paramList,'transaction_url' => $transaction_url,'checkSum' => $checkSum);
// ,'order_id' => $order_id
$this->load->view('order_process',$data);
}
}
}
method-> payment_response
$paytmChecksum = "";
$paramList = array();
$isValidChecksum = FALSE;
$paramList = $_POST;
$paytmChecksum = isset($_POST["CHECKSUMHASH"]) ? $_POST["CHECKSUMHASH"] : "";
$isValidChecksum = $this->paytm->verifychecksum_e($paramList, PAYTM_MERCHANT_KEY, $paytmChecksum);
if($isValidChecksum == "TRUE") {
$orderId = $paramList['ORDERID'];
$amount = $paramList['TXNAMOUNT'];
// Load the user's order based on the order ID
$order = $this->Product->getOrderByOrderId($orderId);
if ($order) {
// Update the order status and generate a delivery ID
$deliveryId = 'D' . uniqid(); // Example: D12345678
// Update the order status and delivery ID in the database
$this->Product->updateOrderStatus($orderId, 'Delivered');
$this->Product->updateDeliveryId($orderId, $deliveryId);
// Load a view to display the order status to the user
$data['order_status'] = 'Delivered';
$data['delivery_id'] = $deliveryId;
$data['order_details'] = $order;
$this->load->view('checkout_view', $data);
}
else{
echo 'Transaction Failed';
}
}else{
echo 'Not Valid Check Sum';
}
}
}
Product.php // model
public function updateOrderStatus($orderId, $status) {
// Replace this with your database update logic
$this->db->where('order_id', $orderId);
$this->db->update('orders', array('order_status' => $status));
}
public function updateDeliveryId($orderId, $deliveryId) {
// Replace this with your database update logic
$this->db->where('order_id', $orderId);
$this->db->update('orders', array('delivery_id' => $deliveryId));
}