/** * Generate the module * @return void */ protected function compile() { $objOrder = new IsotopeOrder(); if (!$objOrder->findBy('uniqid', $this->Input->get('uid'))) { $this->Template = new FrontendTemplate('mod_message'); $this->Template->type = 'error'; $this->Template->message = $GLOBALS['TL_LANG']['ERR']['orderNotFound']; return; } $arrOrder = $objOrder->getData(); $this->Template->setData($arrOrder); $this->import('Isotope'); $this->Isotope->overrideConfig($objOrder->config_id); // Article reader $arrPage = $this->Database->prepare("SELECT * FROM tl_page WHERE id=?")->limit(1)->execute($this->jumpTo)->fetchAssoc(); $arrAllDownloads = array(); $arrItems = array(); $arrProducts = $objOrder->getProducts(); foreach ($arrProducts as $i => $objProduct) { $arrDownloads = array(); $objDownloads = $this->Database->prepare("SELECT p.*, o.* FROM tl_iso_order_downloads o LEFT OUTER JOIN tl_iso_downloads p ON o.download_id=p.id WHERE o.pid=?")->execute($objProduct->cart_id); while ($objDownloads->next()) { $blnDownloadable = ($objOrder->status == 'complete' || intval($objOrder->date_paid) > 0 && intval($objOrder->date_paid) <= time()) && ($objDownloads->downloads_remaining === '' || $objDownloads->downloads_remaining > 0) ? true : false; // Send file to the browser if (strlen($this->Input->get('file')) && $this->Input->get('file') == $objDownloads->id && $blnDownloadable) { if (!$this->backend && $objDownloads->downloads_remaining !== '') { $this->Database->prepare("UPDATE tl_iso_order_downloads SET downloads_remaining=? WHERE id=?")->execute($objDownloads->downloads_remaining - 1, $objDownloads->id); } $this->sendFileToBrowser($objDownloads->singleSRC); } $arrDownload = array('raw' => $objDownloads->row(), 'title' => $objDownloads->title, 'href' => TL_MODE == 'FE' ? IsotopeFrontend::addQueryStringToUrl('file=' . $objDownloads->id) : '', 'remaining' => $objDownloads->downloads_allowed > 0 ? sprintf($GLOBALS['TL_LANG']['MSC']['downloadsRemaining'], intval($objDownloads->downloads_remaining)) : '', 'downloadable' => $blnDownloadable); $arrDownloads[] = $arrDownload; $arrAllDownloads[] = $arrDownload; } $arrItems[] = array('raw' => $objProduct->getData(), 'sku' => $objProduct->sku, 'name' => $objProduct->name, 'image' => $objProduct->images->main_image, 'product_options' => $objProduct->getOptions(), 'quantity' => $objProduct->quantity_requested, 'price' => $this->Isotope->formatPriceWithCurrency($objProduct->price), 'total' => $this->Isotope->formatPriceWithCurrency($objProduct->total_price), 'href' => $this->jumpTo ? $this->generateFrontendUrl($arrPage, '/product/' . $objProduct->alias) : '', 'tax_id' => $objProduct->tax_id, 'downloads' => $arrDownloads); } $this->Template->info = deserialize($objOrder->checkout_info, true); $this->Template->items = IsotopeFrontend::generateRowClass($arrItems, 'row', 'rowClass', 0, ISO_CLASS_COUNT | ISO_CLASS_FIRSTLAST | ISO_CLASS_EVENODD); $this->Template->downloads = $arrAllDownloads; $this->Template->downloadsLabel = $GLOBALS['TL_LANG']['MSC']['downloadsLabel']; $this->Template->raw = $arrOrder; $this->Template->date = $this->parseDate($GLOBALS['TL_CONFIG']['dateFormat'], $objOrder->date); $this->Template->time = $this->parseDate($GLOBALS['TL_CONFIG']['timeFormat'], $objOrder->date); $this->Template->datim = $this->parseDate($GLOBALS['TL_CONFIG']['datimFormat'], $objOrder->date); $this->Template->orderDetailsHeadline = sprintf($GLOBALS['TL_LANG']['MSC']['orderDetailsHeadline'], $objOrder->order_id, $this->Template->datim); $this->Template->orderStatus = sprintf($GLOBALS['TL_LANG']['MSC']['orderStatusHeadline'], $GLOBALS['TL_LANG']['ORDER'][$objOrder->status]); $this->Template->orderStatusKey = $objOrder->status; $this->Template->subTotalPrice = $this->Isotope->formatPriceWithCurrency($objOrder->subTotal); $this->Template->grandTotal = $this->Isotope->formatPriceWithCurrency($objOrder->grandTotal); $this->Template->subTotalLabel = $GLOBALS['TL_LANG']['MSC']['subTotalLabel']; $this->Template->grandTotalLabel = $GLOBALS['TL_LANG']['MSC']['grandTotalLabel']; $this->Template->surcharges = IsotopeFrontend::formatSurcharges($objOrder->getSurcharges()); $this->Template->billing_label = $GLOBALS['TL_LANG']['ISO']['billing_address']; $this->Template->billing_address = $this->Isotope->generateAddressString($objOrder->billing_address, $this->Isotope->Config->billing_fields); if (strlen($objOrder->shipping_method)) { $arrShippingAddress = $objOrder->shipping_address; if (!is_array($arrShippingAddress) || $arrShippingAddress['id'] == -1) { $this->Template->has_shipping = false; $this->Template->billing_label = $GLOBALS['TL_LANG']['ISO']['billing_shipping_address']; } else { $this->Template->has_shipping = true; $this->Template->shipping_label = $GLOBALS['TL_LANG']['ISO']['shipping_address']; $this->Template->shipping_address = $this->Isotope->generateAddressString($arrShippingAddress, $this->Isotope->Config->shipping_fields); } } }
/** * Authorize or capture the payment * * @param int * @param float * @param array * @param bool * @access public * @return bool */ public function authCapturePayment($intOrderId, $fltOrderTotal, $blnCapture = false) { //Gather Order data and set IsotopeOrder object $objOrder = new IsotopeOrder(); if (!$objOrder->findBy('id', $intOrderId)) { $objOrder->uniqid = uniqid($this->Isotope->Config->orderPrefix, true); $objOrder->cart_id = $this->Isotope->Cart->id; $objOrder->findBy('id', $objOrder->save()); } $strLineItems = ''; $arrBilling = array(); $arrShipping = array(); $arrProducts = array(); $arrPaymentInfo = array(); //grab any existing payment data. If this is an order where a prior auth was made and a new total greater than the original exists, //we need to re-auth. Otherwise we simply use the old auth with the <= order total. $arrOrderPaymentData = deserialize($objOrder->payment_data, true); //Gather product and address data depending on FE(Cart) or BE(Order) if (TL_MODE == 'FE') { $arrBilling = $this->Isotope->Cart->billingAddress; $arrShipping = $this->Isotope->Cart->shippingAddress; $arrProducts = $this->Isotope->Cart->getProducts(); } else { $arrBilling = $objOrder->billingAddress; $arrShipping = $objOrder->shippingAddress; $arrProducts = $objOrder->getProducts(); } if (count($arrProducts)) { foreach ($arrProducts as $objProduct) { $arrItemData = array(); $arrItemData = array($objProduct->id, $objProduct->name, substr($objProduct->description, 0, 100), $objProduct->quantity_requested, $objProduct->price, $objProduct->tax_class ? 'Y' : 'N'); $arrLineItems[] = implode('<|>', $arrItemData); } $strLineItems .= implode('&', $arrLineItems); } //Authorization type $strAuthType = $blnCapture ? 'PRIOR_AUTH_CAPTURE' : 'AUTH_ONLY'; //Get Address Data $arrBillingSubdivision = explode('-', $arrBilling['subdivision']); $arrShippingSubdivision = explode('-', $arrShipping['subdivision']); //Set up basic request fields required by all transactions $authnet_values_default = array("x_version" => '3.1', "x_login" => $this->authorize_login, "x_tran_key" => $this->authorize_trans_key, "x_type" => $strAuthType, "x_delim_char" => $this->authorize_delimiter, "x_delim_data" => "TRUE", "x_relay_response" => "FALSE", "x_amount" => $fltOrderTotal, "x_test_request" => $this->debug ? "TRUE" : "FALSE"); switch ($strAuthType) { case 'AUTH_ONLY': $authnet_values_authonly = array("x_url" => "FALSE", "x_description" => "Order Number " . $this->Isotope->Config->orderPrefix . $objOrder->order_id, "x_invoice_num" => $objOrder->order_id, "x_first_name" => $arrBilling['firstname'], "x_last_name" => $arrBilling['lastname'], "x_company" => $arrBilling['company'], "x_address" => $arrBilling['street_1'] . "\n" . $arrBilling['street_2'] . "\n" . $arrBilling['street_3'], "x_city" => $arrBilling['city'], "x_state" => $arrBillingSubdivision[1], "x_zip" => $arrBilling['postal'], "x_email_customer" => "FALSE", "x_email" => $arrBilling['email'], "x_country" => $arrBilling['country'], "x_phone" => $arrBilling['phone'], "x_ship_to_first_name" => $arrShipping['firstname'], "x_ship_to_last_name" => $arrShipping['lastname'], "x_ship_to_company" => $arrShipping['company'], "x_ship_to_address" => $arrShipping['street_1'] . "\n" . $arrShipping['street_2'] . "\n" . $arrShipping['street_3'], "x_ship_to_city" => $arrShipping['city'], "x_ship_to_state" => $arrShippingSubdivision[1], "x_ship_to_zip" => $arrShipping['postal'], "x_ship_to_country" => $arrShipping['country']); $authnet_values = array_merge($authnet_values_default, $authnet_values_authonly); break; case 'PRIOR_AUTH_CAPTURE': $arrTransactionData = deserialize($objOrder->payment_data, true); $authnet_values = array_merge($authnet_values_default, array("x_trans_id" => $arrTransactionData['transaction-id'])); break; default: break; } if (!$blnCapture) { $arrPaymentInput = $this->Input->post('payment'); unset($_POST['payment']); $authnet_values["x_method"] = "CC"; $authnet_values["x_card_num"] = $arrPaymentInput['card_accountNumber']; $authnet_values["x_exp_date"] = $arrPaymentInput['card_expirationMonth'] . substr($arrPaymentInput['card_expirationYear'], 2, 2); if ($this->requireCCV) { $authnet_values["x_card_code"] = $arrPaymentInput['card_cvNumber']; } $arrPaymentInfo["x_card_num"] = $this->maskCC($arrData['card_accountNumber']); //PCI COMPLIANCE - MASK THE CC DATA $arrPaymentInfo["x_card_type"] = $GLOBALS['ISO_LANG']['CCT'][$arrData['card_cardType']]; } foreach ($authnet_values as $key => $value) { $fields .= "{$key}=" . urlencode($value) . "&"; } $fieldsFinal = rtrim($fields, '&'); //new auth required if one has been sent and the value of that was less than our new value. if (!count($arrOrderPaymentData) || $arrOrderPaymentData['transaction-status'] != 'Approved' || $blnCapture || !$blnCapture && count($arrOrderPaymentData) && $fltOrderTotal > $arrOrderPaymentData['grand-total']) { $objRequest = new Request(); $objRequest->send('https://' . ($this->debug ? 'test' : 'secure') . '.authorize.net/gateway/transact.dll', $fieldsFinal, 'post'); $arrResponses = $this->handleResponse($objRequest->response); $arrResponseCodes = $this->getResponseCodes($objRequest->response); unset($arrPaymentInput); //clear all cc input foreach (array_keys($arrResponses) as $key) { $arrReponseLabels[standardize($key)] = $key; } $this->loadLanguageFile('payment'); $this->strStatus = $arrResponses['transaction-status']; $this->strReason = $GLOBALS['TL_LANG']['MSG']['authorizedotnet'][$arrResponseCodes['response_type']][$arrResponseCodes['response_code']]; } else { //otherwise, if this isn't a capture, simply bypass/return true. If it is, we need to do some additional work below. if (!$blnCapture) { return true; } } if (!$blnCapture) { switch ($arrResponses['transaction-status']) { case 'Approved': $objOrder->status = $this->new_order_status; $blnFail = false; break; default: $objOrder->status = 'on_hold'; $blnFail = true; break; } } //Update payment data AKA Response Data. Transaction ID will not be saved during test mode. $arrPaymentInfo = count($arrOrderPaymentData) ? array_merge($arrOrderPaymentData, $arrResponses) : $arrResponses; $objOrder->payment_data = serialize($arrPaymentInfo); $objOrder->save(); //unlock the payment submit $_SESSION['CHECKOUT_DATA']['payment']['request_lockout'] = false; if ($blnFail) { $this->log(sprintf("Transaction failure. Transaction Status: %s, Reason: %s", $this->strStatus, $this->strReason), 'PaymentAuthorizeDotNet capturePayment()', TL_ERROR); return false; } return true; }
/** * Button Callback for the MultipleShipping backend interface for label generation * * @access public * @param int * @return string */ public function backendInterfaceMultiple($intOrderId, $intPackageId = 0) { $objOrder = new IsotopeOrder(); $strFormId = 'ups_backend_interface'; //Check for valid order if (!$objOrder->findBy('id', $intOrderId)) { $this->log('Invalid order id.', __METHOD__, TL_ERROR); $this->redirect('contao/main.php?act=error'); } //Get the order's products $arrProducts = $objOrder->getProducts(); //Get the package data $objPackage = $this->Database->execute("SELECT * FROM tl_iso_packages WHERE id={$intPackageId}"); if (!$objPackage->numRows) { return '<p class="tl_gerror">' . $GLOBALS['TL_LANG']['ISO']['backendShippingNotFound'] . '</p>'; } //Build the initial compiled package data array $arrPackage = array('id' => $objPackage->id, 'address' => deserialize($objPackage->order_address, true), 'formattedaddress' => $this->Isotope->generateAddressString(deserialize($objPackage->order_address, true), $this->Isotope->Config->shipping_fields), 'status' => $GLOBALS['TL_LANG']['ISO']['multipleshipping'][$objPackage->status], 'formid' => $strFormId . '_' . $objPackage->id); //Check for an existing label thumbnail and create one if it has not been created if ($objPackage->ups_label) { //Set a cache name $strCacheName = 'system/html/ups_label_' . $objOrder->order_id . '_' . $objPackage->id . substr(md5($arrPackage['formattedaddress']), 0, 8) . '.gif'; $arrPackage['label'] = $this->getShippingLabelImage($objPackage->ups_label, $strCacheName, 75, 75, 'exact'); $arrPackage['labelLink'] = $this->Environment->request . '&printLabel=' . $arrPackage['formid']; //Now that we have the label created check for request to output to PDF if ($this->Input->get('printLabel') == $arrPackage['formid']) { $this->printShippingLabel($strCacheName, 'order_' . $objOrder->order_id . '_' . $intPackageId, true); } } //Add tracking number if (strlen($objPackage->ups_tracking_number)) { $arrPackage['tracking'] = $objPackage->ups_tracking_number; } //Add package products $arrShipmentProducts = $this->Database->execute("SELECT product_id FROM tl_iso_order_items WHERE package_id={$objPackage->id}")->fetchEach('product_id'); foreach ($arrProducts as $objProduct) { if (in_array($objProduct->id, $arrShipmentProducts)) { $arrPackage['products'][] = $objProduct; } } //Data has been submitted. Send request for tracking numbers and label if ($this->Input->post('FORM_SUBMIT') == $arrPackage['formid']) { $this->Shipment = $arrPackage; list($arrOrigin, $arrDestination, $arrShipment) = $this->buildShipment(); if ($this->isValidDestination($arrDestination)) { $objUPSAPI = new UpsAPIShipping($arrShipment, $arrOrigin, $arrOrigin, $arrDestination); $xmlShip = $objUPSAPI->buildRequest(); $arrResponse = $objUPSAPI->sendRequest($xmlShip); } //Request was successful - add the new data to the package if ((int) $arrResponse['ShipmentAcceptResponse']['Response']['ResponseStatusCode'] == 1) { $objOrder->ups_tracking_number = $arrResponse['ShipmentAcceptResponse']['ShipmentResults']['ShipmentIdentificationNumber']; $objOrder->ups_label = $arrResponse['ShipmentAcceptResponse']['ShipmentResults']['PackageResults']['LabelImage']['GraphicImage']; $objOrder->save(); if ($this->Database->tableExists('tl_iso_packages') && $arrPackage['formid'] != $strFormId . '_' . 'order') { $this->Database->prepare("UPDATE tl_iso_packages SET ups_tracking_number=?, ups_label=?, status='shipped' WHERE id=?")->execute($objOrder->ups_tracking_number, $objOrder->ups_label, $arrPackage['id']); } $strCacheName = 'system/html/ups_label_' . $objOrder->order_id . '_' . $objPackage->id . substr(md5($arrPackage['formattedaddress']), 0, 8) . '.gif'; $arrPackage['label'] = $this->getShippingLabelImage($objOrder->ups_label, $strCacheName); $arrPackage['tracking'] = $objOrder->ups_tracking_number; } elseif ($this->isValidDestination($arrDestination) == false) { } else { //Request returned an error $strDescription = $arrResponse['ShipmentAcceptResponse']["Response"]["ResponseStatusDescription"]; $strError = $arrResponse['ShipmentAcceptResponse']["Response"]["Error"]["ErrorDescription"]; $_SESSION['TL_ERROR'][] = $strDescription . ' - ' . $strError; $this->log(sprintf('Error in shipping digest: %s - %s', $strDescription, $strError), __METHOD__, TL_ERROR); $this->redirect('contao/main.php?act=error'); } } //Set template data $objTemplate = new IsotopeTemplate('be_iso_ups'); $objTemplate->setData($arrPackage); $objTemplate->labelHeader = $GLOBALS['TL_LANG']['MSC']['labelLabel']; $objTemplate->trackingHeader = $GLOBALS['TL_LANG']['MSC']['trackingNumberLabel']; $objTemplate->addressHeader = $GLOBALS['TL_LANG']['MSC']['shippingAddress']; $objTemplate->statusHeader = $GLOBALS['TL_LANG']['MSC']['shippingStatus']; $objTemplate->submitLabel = $objPackage->status != 'not_shipped' ? $GLOBALS['TL_LANG']['MSC']['re-ship'] : $GLOBALS['TL_LANG']['MSC']['ship']; return $objTemplate->parse(); }