Ejemplo n.º 1
0
    public function declinedAction()
    {
        $producturrency = new Admin_Model_DbTable_Countries();
        $modelAuthor = new Publisher_Model_DbTable_Publishers();
        $tempObj = new Model_DbTable_Checkout();
        $creditHistoryObj = new User_Model_DbTable_Chistory();
        $transactionHistoryObj = new User_Model_DbTable_Transactionhistory();
        $productPrice = new Publisher_Model_DbTable_BookPrices();
        $modelImage = new Publisher_Model_DbTable_BookImages();
        $modelStore = new Admin_Model_DbTable_Countries();
        $productPrice = new Publisher_Model_DbTable_BookPrices();
        $this->modelBooks = new Publisher_Model_DbTable_Books();
        $response = $_POST['xmlmsg'];
        $xml_string = $_POST['xmlmsg'];
        $parsedxml = simplexml_load_string(stripslashes($response));
        $formDataTransDeclined = array();
        foreach ($parsedxml as $RESPONSENODE) {
            if ($RESPONSENODE->getName() == 'OrderID') {
                $orderId = $RESPONSENODE;
                $orderIdForPurchase = $RESPONSENODE;
            }
            if ($RESPONSENODE->getName() == 'TransactionType') {
                $transactionType = $RESPONSENODE;
            }
            if ($RESPONSENODE->getName() == 'PAN') {
                $pan = $RESPONSENODE;
            }
            if ($RESPONSENODE->getName() == 'PurchaseAmountScr') {
                $purchaseAmount = $RESPONSENODE;
            }
            if ($RESPONSENODE->getName() == 'TranDateTime') {
                $tranDateTime = $RESPONSENODE;
            }
            if ($RESPONSENODE->getName() == 'ResponseCode') {
                $responseCode = $RESPONSENODE;
            }
            if ($RESPONSENODE->getName() == 'ResponseDescription') {
                $responseDescription = $RESPONSENODE;
            }
            if ($RESPONSENODE->getName() == 'OrderStatusScr') {
                $orderStatus = $RESPONSENODE;
            }
            if ($RESPONSENODE->getName() == 'ApprovalCode') {
                $approvalCode = $RESPONSENODE;
            }
            if ($RESPONSENODE->getName() == 'MerchantTranID') {
                $merchantTranId = $RESPONSENODE;
            }
            if ($RESPONSENODE->getName() == 'OrderDescription') {
                $orderDescription = $RESPONSENODE;
            }
            if ($RESPONSENODE->getName() == 'ApprovalCodeScr') {
                $approvalCodeScr = $RESPONSENODE;
            }
            if ($RESPONSENODE->getName() == 'CurrencyScr') {
                $currency = $RESPONSENODE;
            }
            if ($RESPONSENODE->getName() == 'ThreeDSVerificaion') {
                $threeDsVerification = $RESPONSENODE;
            }
            if ($RESPONSENODE->getName() == 'Brand') {
                $brandname = $RESPONSENODE;
            }
            if ($RESPONSENODE->getName() == 'Name') {
                $card_holder_name = $RESPONSENODE;
            }
            if ($RESPONSENODE->getName() == 'ThreeDSStatus') {
                $ThreeDSStatus = $RESPONSENODE;
            }
            if ($RESPONSENODE->getName() == 'MerchantTranID') {
                $MerchantTranID = $RESPONSENODE;
            }
        }
        $formDataTransDeclined = array("orderId" => $orderId, "transactionType" => $transactionType, "pan" => $pan, "purchaseAmount" => $purchaseAmount, "tranDateTime" => $tranDateTime, "responseCode" => $responseCode, "responseDescription" => $responseDescription, "orderStatus" => $orderStatus, "approvalCode" => $approvalCode, "approvalCode" => $approvalCode, "merchantTranId" => $merchantTranId, "orderDescription" => $orderDescription, "approvalCodeScr" => $approvalCodeScr, "currency" => $currency, "brand" => $brandname, "card_holder_name" => $card_holder_name, "ThreeDSStatus" => $ThreeDSStatus, "threeDsVerification" => $threeDsVerification, "transaction_xml" => $xml_string);
        //$dataTrans = array("orderId"=>)
        $inserted_id = $transactionHistoryObj->insert($formDataTransDeclined);
        ##############  update table ###########################
        if ($orderStatus == 'DECLINED') {
            $orderSt = 2;
        } else {
            $orderSt = 0;
        }
        $tempTransactionUpdate = array("payment_status" => $orderSt, "transaction_id" => $inserted_id);
        //$tempObj->update($tempTransactionUpdate,'user_id="'.$user_id.'"');
        $creditHistoryObj->update($tempTransactionUpdate, "order_id='" . $orderId . "'");
        $modelSubscription = new Publisher_Model_DbTable_Subscriptions();
        ##########################################################
        $tempData = $tempObj->fetchAll("order_id='" . $orderIdForPurchase . "' and is_purchase!='1'");
        $order_details = "<table cellpadding='1'><tr><td colspan='3'>Your reference Id</td></tr><tr><td colspan='3'>Order Id:" . $orderId . "</td></tr><tr><td colspan='3'>Transaction ID:" . $inserted_id . "</td></tr><tr><td>Item</td><td>Price</td><td>Subscription Details</td><td>Subscription Details</td><td>Number of Issues</td><td>Start Date</td><td>End Date</td><td>Quantity</td></tr>";
        $modelSubscription = new Publisher_Model_DbTable_Subscriptions();
        foreach ($tempData as $dataDet) {
            $productPriceInfo = $productPrice->getPriceByStoreId($dataDet['product_id'], $dataDet['store_id']);
            $subscription_data = $modelSubscription->fetchAll('id="' . $dataDet['subscription_type'] . '"');
            if ($dataDet['group_id'] > 0) {
                $price = $productPriceInfo['group_price'];
            } else {
                $price = $productPriceInfo['price'];
            }
            $getCurrencyName = $producturrency->getCurrencyCode($dataDet['store_id']);
            $product_details = $this->modelBooks->fetchRow("id='" . $dataDet['product_id'] . "'");
            $getBrandInfo = $this->modelBooks->getBrandInfo($product_details['title']);
            if (!empty($getBrandInfo) && is_numeric($this->{$product_details}['title'])) {
                $titleBrand = $getBrandInfo['brand'];
            } else {
                $titleBrand = $product_details['title'];
            }
            if (!empty($product_details['parent_brand_id']) && $product_details['cat_id'] != '3') {
                $productInfo = $this->modelBooks->fetchRow('id="' . $product_details['parent_brand_id'] . '"');
                $getParentBrandInfo = $this->modelBooks->getBrandInfo($productInfo->title);
                if (!empty($getParentBrandInfo)) {
                    $titleBrand = $getParentBrandInfo['brand'] . " - " . $titleBrand;
                } else {
                }
            }
            $subscription_data = $modelSubscription->fetchAll('id="' . $dataDet['subscription_type'] . '"');
            $todaysdate = date('Y-m-d H:i:s');
            if ($dataDet['subscription_name'] == 'Weekly') {
                $date = new DateTime($todaysdate);
                $date->modify("+7 day");
                $end_date = $date->format("Y-m-d H:i:s");
            } else {
                if ($dataDet['subscription_name'] == 'Monthly') {
                    $date = new DateTime($todaysdate);
                    $date->modify("+30 day");
                    $end_date = $date->format("Y-m-d H:i:s");
                } else {
                    if ($dataDet['subscription_name'] == 'Quarterly') {
                        $date = new DateTime($todaysdate);
                        $date->modify("+90 day");
                        $end_date = $date->format("Y-m-d H:i:s");
                    } else {
                        if ($dataDet['subscription_name'] == 'Half Yearly') {
                            $date = new DateTime($todaysdate);
                            $date->modify("+182 day");
                            $end_date = $date->format("Y-m-d H:i:s");
                        } else {
                            if ($dataDet['subscription_name'] == 'Yearly') {
                                $date = new DateTime($todaysdate);
                                $date->modify("+365 day");
                                $end_date = $date->format("Y-m-d H:i:s");
                            }
                        }
                    }
                }
            }
            if (count($subscription_data) > 0) {
                /*if($dataDet['group_id']!='' && $dataDet['group_id']!=0)
                		{
                			$price_to_show = $subscription_data[0]->group_price_sub;
                		}
                		else
                		{
                			$price_to_show = $subscription_data[0]->individual_price;
                		}*/
                $price_to_show = $dataDet['subscription_price'];
                $subtype = $dataDet['subscription_name'];
                $subscription_issues = $dataDet['subscription_issues'];
                $todaysdate = $todaysdate;
                $end_date = $end_date;
            } else {
                $price_to_show = $price;
                $subtype = "N/A";
                $subscription_issues = "N/A";
                $todaysdate = "N/A";
                $end_date = "N/A";
            }
            if ($dataDet['user_type'] == "1") {
                $finalsubprice = $price_to_show * $dataDet['quntity'];
            } else {
                $finalsubprice = $price_to_show;
            }
            $quntity_price = $dataDet['quntity'] * $price_to_show;
            $price_quan = $producturrency->currencyconverter($getCurrencyName, "NGN", $quntity_price);
            $price_in = $producturrency->currencyconverter($getCurrencyName, "NGN", $price_to_show);
            $total_price = $total_price + $price_quan;
            //if($dataDet['is_purchase']!='1')
            //{
            $order_details .= "<tr>\n\t\t\t\t\t\t\t\t\t<td>" . $titleBrand . "</td>\n\t\t\t\t\t\t\t\t\t<td>" . $price_in . "</td>\n\t\t\t\t\t\t\t\t\t<td>" . $subtype . "</td>\n\t\t\t\t\t\t\t\t\t<td>" . $subscription_issues . "</td>\n\t\t\t\t\t\t\t\t\t<td>" . $todaysdate . "</td>\n\t\t\t\t\t\t\t\t\t<td>" . $end_date . "</td>\n\t\t\t\t\t\t\t\t\t<td>" . $dataDet['quntity'] . "</td>\n\t\t\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t\t<td colspan='3' align='left'>Sub Total: &#x20a6;" . $price_quan . "</td></tr>";
            //}
            //if($dataDet['is_purchase']!='1')
            //{
            //$quntity_price = $dataDet['quntity']*$price;
            //$order_details.= "<tr><td>".$titleBrand."</td><td>".$producturrency->currencyconverter($getCurrencyName,"NGN",$price)."</td><td>".$dataDet['quntity']."</td></tr><tr><td colspan='3' align='left'>Sub Total: &#x20a6;".@mumber_format($producturrency->currencyconverter($getCurrencyName,"NGN",$quntity_price),2)."</td></tr>";
            //}
        }
        $order_details .= "<tr><td colspan='3'>Total Price:" . @number_format($producturrency->currencyconverter($getCurrencyName, "NGN", $total_price), 2) . "</td>";
        $order_details .= "</table>";
        ###########################################  mail action ############################
        $userCompanyObj = new Company_Model_DbTable_Companies();
        $storage_company = new Zend_Auth_Storage_Session('company_type');
        $company_data = $storage_company->read();
        $storage = new Zend_Auth_Storage_Session('account_type');
        $data = $storage->read();
        if ($data->id) {
            $user_id = $data->id;
        } elseif ($company_data->id) {
            $user_id = $company_data->id;
        }
        $user_details = $userCompanyObj->fetchRow("id='" . $user_id . "'");
        $mailhost = SMTP_SERVER;
        $mailconfig = array('ssl' => SMTP_SSL, 'port' => SMTP_PORT, 'auth' => SMTP_AUTH, 'username' => SMTP_USERNAME, 'password' => SMTP_PASSWORD);
        $transport = new Zend_Mail_Transport_Smtp($mailhost, $mailconfig);
        Zend_Mail::setDefaultTransport($transport);
        $message = '<!DOCTYPE html>
				<html>
				<head>
				<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
				<meta charset="utf-8">
				<meta name="viewport" content="width=device-width,initial-scale=1.0">
				<title>Evendor</title>
				</head>
				<body style="font-family: \'Calibri\', arial;">
				<div id="container" style="width:80%; margin:0 auto;">
				<header id="heder">
				<div style="padding:15px 0px; background:#000000;"><a href="' . $this->view->serverUrl() . $this->view->baseUrl() . '/" target="_blank"><img src="' . $this->view->serverUrl() . $this->view->baseUrl() . '/public/css/default/images/logo.png" style="border:none;" alt="E-Vendor"></a></div>
				</header>
				<div style="background:#656565; padding:15px; min-height:200px;">
					<aside> 
						Hi ' . $user_details['first_name'] . ' ' . $user_details['last_name'] . ',<br/>
						Your order has been Declined.Please check your order details.<br/><br/>
						' . $order_details . '<br/>Transaction message:' . $responseDescription . '
						<br/>Masked PAN:' . $pan . '<br/>Card Holder Name:' . $card_holder_name . '						
						<br/>Transaction Date & Time:' . $tranDateTime . '<br/>
						<br/>Transactions reference number(MerchantTranID):' . $MerchantTranID . '<br/>
						<br/>Transaction Amount:&#x20a6;' . $purchaseAmount . '<br/>
						<br/>Transaction Currency:' . $currency . '<br/>
						<br/>Authorization Code:' . $approvalCodeScr . '<br/>
						<br/>Merchant Name:Evendor<br/>
						<br/>Site Url:' . $this->view->serverUrl() . $this->view->baseUrl() . '<br/>
						<br/><br/><br/>
						Thank You<br/>
						Evendor 
					</aside>
				</div>

				<div style="background:#000000;  text-align:center; color:#FFFFFF; font-size:14px; padding:15px;">
				<br>
				&copy; Copyright ' . date("Y") . ' All Rights Reserved By Electronic Vendor Ltd.
				</div>

				</div>
				</body>
				</html>';
        $mail = new Zend_Mail();
        $mail->addTo($user_details['user_email']);
        $mail->setSubject("Order Declined message");
        $mail->setBodyHtml($message);
        $mail->setFrom(SETFROM, SETNAME);
        $mail->send();
        $tempObj->delete('order_id="' . $orderIdForPurchase . '"');
        $this->_redirect('/checkout/displayorder/orderid/' . $orderIdForPurchase);
    }