Exemplo n.º 1
0
 /**
  * Attached event for anytime a new customer is created
  * @param $event
  * @return bool
  */
 public function onCreateOrder($event)
 {
     $this->init();
     $topicArn = $this->getTopicArn();
     //don't run this unless we actually have a cloud acct
     if (Yii::app()->params['LIGHTSPEED_CLOUD'] == '0' || empty($topicArn)) {
         return true;
     }
     $objCart = Cart::LoadByIdStr($event->order_id);
     $strSignal = $this->buildOrderSignal($objCart);
     $this->sendSignal($strSignal, $topicArn);
     return true;
 }
Exemplo n.º 2
0
 private static function generateErrorResponse($trnOrderNumber, $messageText)
 {
     $objCart = Cart::LoadByIdStr($trnOrderNumber);
     $url = Yii::app()->controller->createAbsoluteUrl('cart/restoredeclined', array('getuid' => $objCart->linkid, 'reason' => $messageText));
     $arrReturn = array('order_id' => $trnOrderNumber, 'output' => "<html><head><meta http-equiv=\"refresh\" content=\"1;url={$url}\"></head><body><a href=\"{$url}\">Verifying order, please wait...</a></body></html>", 'success' => false);
     return $arrReturn;
 }
 public function actionConfirmation()
 {
     // We should only be in here if someone has chosen a SIM.
     $this->checkoutForm = MultiCheckoutForm::loadFromSessionOrNew();
     $this->layout = '/layouts/checkout-confirmation';
     $objCart = Yii::app()->shoppingcart;
     $error = null;
     if (isset($_POST['MultiCheckoutForm'])) {
         $this->checkoutForm->attributes = $_POST['MultiCheckoutForm'];
         if ($objCart->shipping->isStorePickup) {
             $this->checkoutForm->setScenario('ConfirmationStorePickup');
         } else {
             $this->checkoutForm->setScenario('ConfirmationSim');
         }
         $isFormValid = $this->checkoutForm->updateCartCustomerId() && $this->checkoutForm->validate();
         if ($isFormValid && Yii::app()->shoppingcart->wasCartModified === false) {
             // our form is valid and the cart items are as we expect, continue
             self::executeCheckoutProcessInit();
             $this->runPaymentSim();
         } else {
             $this->layout = '/layouts/checkout-confirmation';
             $this->render('confirmation', array('model' => $this->checkoutForm, 'cart' => $objCart, 'error' => $this->formatErrors(), 'shippingEstimatorOptions' => $this->_getShippingEstimatorOptions(), 'recalculateShippingOnLoad' => Yii::app()->shoppingcart->wasCartModified));
         }
     } else {
         $orderId = Yii::app()->getRequest()->getQuery('orderId');
         $errorNote = Yii::app()->getRequest()->getQuery('errorNote');
         if (isset($errorNote) && isset($orderId)) {
             // Cancelled/Declined simple integration transaction.
             $objCart = Cart::LoadByIdStr($orderId);
             if (stripos($errorNote, 'cancel') !== false) {
                 // Cancelled.
                 $translatedErrorNote = Yii::t('checkout', 'You <strong>cancelled</strong> your payment.');
             } else {
                 // Declined.
                 $translatedErrorNote = Yii::t('checkout', 'There was an issue with your payment.') . '<br><br><strong>' . $errorNote . '</strong><br><br>';
                 $translatedErrorNote .= Yii::t('checkout', 'Try re-entering your payment details or contact us at {email} or {phone}', array('{email}' => _xls_get_conf('EMAIL_FROM'), '{phone}' => _xls_get_conf('STORE_PHONE')));
             }
             $this->checkoutForm->addErrors(array('note' => $translatedErrorNote));
         }
         $this->render('confirmation', array('model' => $this->checkoutForm, 'cart' => $objCart, 'shippingEstimatorOptions' => $this->_getShippingEstimatorOptions(), 'error' => $this->formatErrors()));
     }
 }
 /**
  * Add an order for display
  *
  * @param string $passkey
  * @param string $strId
  * @param int $intDttDate
  * @param int $intDttDue
  * @param string $strPrintedNotes
  * @param string $strStatus
  * @param string $strEmail
  * @param string $strPhone
  * @param string $strZipcode
  * @param int $intTaxcode
  * @param float $fltShippingSell
  * @param float $fltShippingCost
  * @return string
  */
 public function add_order($passkey, $strId, $intDttDate, $intDttDue, $strPrintedNotes, $strStatus, $strEmail, $strPhone, $strZipcode, $intTaxcode, $fltShippingSell, $fltShippingCost)
 {
     if (!$this->check_passkey($passkey)) {
         return self::FAIL_AUTH;
     }
     $objDocument = Document::LoadByIdStr($strId);
     if (!$objDocument instanceof Document) {
         $objDocument = new Document();
     } else {
         // if cart already exists then delete the items
         foreach ($objDocument->documentItems as $item) {
             $item->qty = 0;
             $item->save();
             $item->product->SetAvailableInventory();
             $item->delete();
         }
     }
     $objDocument->order_type = CartType::order;
     $objDocument->order_str = $strId;
     $objDocument->printed_notes = $strPrintedNotes;
     $objDocument->datetime_cre = date("Y-m-d H:i:s", trim($intDttDate));
     $objDocument->datetime_due = date("Y-m-d H:i:s", trim($intDttDue));
     $objDocument->fk_tax_code_id = $intTaxcode ? $intTaxcode : 0;
     $objDocument->status = $strStatus;
     $objCustomer = Customer::LoadByEmail($strEmail);
     if ($objCustomer instanceof Customer) {
         $objDocument->customer_id = $objCustomer->id;
     }
     $objCart = Cart::LoadByIdStr($strId);
     if ($objCart instanceof Cart) {
         $objDocument->cart_id = $objCart->id;
     }
     $objDocument->status = $strStatus;
     if (!$objDocument->save()) {
         Yii::log("SOAP ERROR : add_order " . print_r($objDocument->getErrors(), true), 'error', 'application.' . __CLASS__ . "." . __FUNCTION__);
         return self::UNKNOWN_ERROR;
     }
     if ($objCart instanceof Cart) {
         $objCart->document_id = $objDocument->id;
         $objCart->save();
     }
     if (substr($strId, 0, 3) == "WO-") {
         Configuration::SetHighestWO();
     }
     return self::OK;
 }
Exemplo n.º 5
0
 public function gateway_response_process()
 {
     $status = Yii::app()->getRequest()->getQuery('Status');
     $authCode = Yii::app()->getRequest()->getQuery('AuthCode');
     $orderId = Yii::app()->getRequest()->getQuery('TransactionID');
     $objCart = Cart::LoadByIdStr($orderId);
     if (strtolower($status) != 'approved') {
         $url = Yii::app()->controller->createAbsoluteUrl('cart/restoredeclined', array('getuid' => $objCart->linkid, 'reason' => $status));
         return array('success' => false, 'order_id' => $objCart->id_str, 'output' => "<html><head><meta http-equiv=\"refresh\" content=\"1;url={$url}\"></head><body><a href=\"{$url}\">Verifying order, please wait...</a></body></html>");
     }
     return array('success' => true, 'data' => $authCode, 'order_id' => $objCart->id_str, 'amount' => $objCart->total);
 }
Exemplo n.º 6
0
 public function onActionListOrderDetails($event)
 {
     Yii::log("Running event " . print_r($event, true), 'info', 'application.' . __CLASS__ . "." . __FUNCTION__);
     $data_id = $event->data_id;
     $arrData = explode(",", $data_id);
     $cartId = $arrData[0];
     $checkDate = $arrData[1];
     $config = array('ServiceURL' => $this->getMWSUrl() . "/Orders/" . $checkDate, 'ProxyHost' => null, 'ProxyPort' => -1, 'MaxErrorRetry' => 3);
     $service = new MarketplaceWebServiceOrders_Client($this->MWS_ACCESS_KEY_ID, $this->MWS_SECRET_ACCESS_KEY, $this->APPLICATION_NAME, $this->APPLICATION_VERSION, $config);
     $request = new MarketplaceWebServiceOrders_Model_ListOrderItemsRequest();
     $request->setSellerId($this->MerchantID);
     $request->setAmazonOrderId($cartId);
     // object or array of parameters
     $response = $this->invokeListOrderItems($service, $request);
     $listOrderItemsResult = $response->getListOrderItemsResult();
     if ($listOrderItemsResult->isSetOrderItems()) {
         $objCart = Cart::LoadByIdStr($cartId);
         if ($objCart->cart_type == CartType::cart) {
             $orderItems = $listOrderItemsResult->getOrderItems();
             $orderItemList = $orderItems->getOrderItem();
             $shippingCost = 0;
             foreach ($orderItemList as $orderItem) {
                 $strCode = $orderItem->getSellerSKU();
                 Yii::log("Amazon " . $cartId . " item on order " . $strCode, 'info', 'application.' . __CLASS__ . "." . __FUNCTION__);
                 Yii::log("Order item information " . print_r($orderItem, true), 'info', 'application.' . __CLASS__ . "." . __FUNCTION__);
                 $intQty = $orderItem->getQuantityOrdered();
                 $objPrice = $orderItem->getItemPrice();
                 $fltPrice = $objPrice->getAmount();
                 $strCurrency = $objPrice->getCurrencyCode();
                 //Amazon provides price as total for line item, but our AddToCart expects per item
                 //so we divide
                 if ($intQty > 1) {
                     $fltPrice = $fltPrice / $intQty;
                 }
                 if ($orderItem->isSetShippingPrice()) {
                     $objShippingPrice = $orderItem->getShippingPrice();
                     if ($objShippingPrice->isSetAmount()) {
                         $shippingCost += $objShippingPrice->getAmount();
                     }
                 }
                 if ($orderItem->isSetPromotionDiscount()) {
                     $promotionDiscount = $orderItem->getPromotionDiscount();
                     $fltDiscount = $promotionDiscount->getAmount();
                 } else {
                     $fltDiscount = 0;
                 }
                 $objProduct = Product::LoadByCode($strCode);
                 if (is_null($objProduct)) {
                     $objCart->printed_notes .= "ERROR MISSING PRODUCT - " . "Attempted to download a product from Amazon " . $strCode . " that doesn't exist in Web Store\n";
                     Yii::log("Attempted to download a product from Amazon " . $strCode . " that doesn't exist in Web Store", 'error', 'application.' . __CLASS__ . "." . __FUNCTION__);
                 } else {
                     $objCart->AddProduct($objProduct, $intQty, CartType::order, null, $orderItem->getTitle(), $fltPrice, $fltDiscount);
                 }
                 $objCart->currency = $strCurrency;
                 if (!$objCart->save()) {
                     Yii::log("Error saving cart " . print_r($objCart->getErrors(), true), 'error', 'application.' . __CLASS__ . "." . __FUNCTION__);
                 }
             }
             $objCart->cart_type = CartType::order;
             if (!$objCart->save()) {
                 Yii::log("Error saving cart " . print_r($objCart->getErrors(), true), 'error', 'application.' . __CLASS__ . "." . __FUNCTION__);
             }
             $objShipping = $objCart->shipping;
             $objShipping->shipping_cost = $shippingCost;
             $objShipping->shipping_sell = $shippingCost;
             $objShipping->save();
             $objCart->recalculateAndSave();
             $objCart->RecalculateInventoryOnCartItems();
             //A new order has been created, so run signal
             $objEvent = new CEventOrder('wsamazon', 'onCreateOrder', $objCart->id_str);
             _xls_raise_events('CEventOrder', $objEvent);
         }
     }
     return self::SUCCESS;
 }
Exemplo n.º 7
0
 /**
  * Update an individual order as downloaded
  * @param string $passkey
  * @param string $strId
  * @param int $intDownloaded
  * @return string
  * @throws SoapFault
  * @soap
  */
 public function update_order_downloaded_status_by_id($passkey, $strId, $intDownloaded)
 {
     self::check_passkey($passkey);
     try {
         $objCart = Cart::LoadByIdStr($strId);
         if ($objCart === null) {
             throw new WsSoapException("Cart with ID '" . $strId . "' was not found");
         }
         Cart::model()->updateByPk($objCart->id, array('downloaded' => $intDownloaded, 'status' => OrderStatus::Downloaded));
     } catch (WsSoapException $wsse) {
         $strMsg = "update_order_downloaded_status_by_id " . $wsse;
         Yii::log("SOAP ERROR : {$strMsg}", CLogger::LEVEL_ERROR, 'application.' . __CLASS__ . "." . __FUNCTION__);
         throw new SoapFault($strMsg, WsSoapException::ERROR_UNKNOWN);
     } catch (Exception $ex) {
         $strMsg = "Unknown error while trying to update downloaded status for the cart with ID '" . $strId . "'";
         Yii::log("SOAP ERROR : {$strMsg}", CLogger::LEVEL_ERROR, 'application.' . __CLASS__ . "." . __FUNCTION__);
         throw new SoapFault($strMsg, WsSoapException::ERROR_UNKNOWN);
     }
     return self::OK;
 }
 /**
  * gateway_response_process
  *
  * Processes processor gateway response
  * Processes returned $_GET or $_POST variables from the third party website
  */
 public function gateway_response_process()
 {
     Yii::log("Response Transaction " . print_r($_POST, true), $this->logLevel, 'application.' . __CLASS__ . "." . __FUNCTION__);
     $x_response_code = Yii::app()->getRequest()->getPost('x_response_code');
     $x_invoice_num = Yii::app()->getRequest()->getPost('x_invoice_num');
     $x_MD5_Hash = Yii::app()->getRequest()->getPost('x_MD5_Hash');
     $x_amount = Yii::app()->getRequest()->getPost('x_amount');
     $x_trans_id = Yii::app()->getRequest()->getPost('x_trans_id');
     if (empty($x_response_code) || empty($x_invoice_num)) {
         return false;
     }
     if ($x_response_code != 1) {
         // failed order
         Yii::log(__CLASS__ . " failed order payment received " . print_r($_POST, true), 'error', 'application.' . __CLASS__ . "." . __FUNCTION__);
         return false;
     }
     if (isset($this->config['md5hash']) && $this->config['md5hash'] && !empty($x_MD5_Hash)) {
         $md5 = strtolower(md5($this->config['md5hash'] . $this->config['login'] . Yii::app()->getRequest()->getPost('x_trans_id') . $x_amount));
         if (strtolower($x_MD5_Hash) != $md5) {
             Yii::log("authorize.net.sim failed md5 hash", 'error', 'application.' . __CLASS__ . "." . __FUNCTION__);
             return false;
         }
     }
     $objCart = Cart::LoadByIdStr($x_invoice_num);
     $url = Yii::app()->createAbsoluteUrl('cart/receipt', array('getuid' => $objCart->linkid));
     return array('order_id' => $x_invoice_num, 'amount' => !empty($x_amount) ? $x_amount : 0, 'success' => true, 'data' => !empty($x_trans_id) ? $x_trans_id : '', 'output' => "<html><head><meta http-equiv=\"refresh\" content=\"0;url={$url}\"></head><body><a href=\"{$url}\">" . Yii::t('global', 'Redirecting to your receipt') . "...</a></body></html>");
 }
Exemplo n.º 9
0
 /**
  * Process payments coming in from third party systems, such as Paypal IPN and other SIM integrations
  */
 public function actionPayment()
 {
     $strModule = Yii::app()->getRequest()->getQuery('id');
     Yii::log("Incoming message for " . $strModule, 'info', 'application.' . __CLASS__ . "." . __FUNCTION__);
     try {
         $retVal = Yii::app()->getComponent($strModule)->gateway_response_process();
         Yii::log("Gateway response {$strModule}:\n" . print_r($retVal, true), 'info', 'application.' . __CLASS__ . '.' . __FUNCTION__);
         if (is_array($retVal)) {
             if ($retVal['success']) {
                 $objCart = Cart::model()->findByAttributes(array('id_str' => $retVal['order_id']));
                 if (is_null($objCart)) {
                     Yii::log($retVal['order_id'] . " is not our order, ignoring", 'info', 'application.' . __CLASS__ . "." . __FUNCTION__);
                 }
                 if ($objCart instanceof Cart && $objCart->cart_type == CartType::awaitpayment) {
                     $objPayment = CartPayment::model()->findByPk($objCart->payment_id);
                     $objPayment->payment_amount = isset($retVal['amount']) ? $retVal['amount'] : 0;
                     $objPayment->payment_data = $retVal['data'];
                     $objPayment->datetime_posted = isset($retVal['payment_date']) ? date("Y-m-d H:i:s", strtotime($retVal['payment_date'])) : new CDbExpression('NOW()');
                     $objPayment->save();
                     self::EmailReceipts($objCart);
                     Yii::log('Receipt e-mails added to the queue', 'info', __CLASS__ . '.' . __FUNCTION__);
                     self::FinalizeCheckout($objCart, Yii::app()->getComponent($strModule)->performInternalFinalizeSteps);
                     Yii::log('Checkout Finalized', 'info', __CLASS__ . '.' . __FUNCTION__);
                     if (!isset($retVal['output'])) {
                         Yii::app()->controller->redirect(Yii::app()->controller->createAbsoluteUrl('cart/receipt', array('getuid' => $objCart->linkid), 'http'));
                     }
                 }
             }
             if (isset($retVal['output'])) {
                 echo $retVal['output'];
             } else {
                 $objCart = Cart::LoadByIdStr($retVal['order_id']);
                 if ($objCart instanceof Cart) {
                     Yii::app()->controller->redirect(Yii::app()->controller->createAbsoluteUrl('cart/restore', array('getuid' => $objCart->linkid)));
                 }
                 echo Yii::t('global', 'Payment Error: Was not successful, and payment attempt did not return a proper error message');
             }
         }
     } catch (Exception $e) {
         //Can't find module. if $val=="fancyshipping" then filename must be "FancyshippingModule.php" (case sensitive)
         Yii::log("Received payment but could not process {$e}", 'error', 'application.' . __CLASS__ . "." . __FUNCTION__);
     }
 }