public function customerAction() { $this->getResponse()->setHeader('Content-type', 'application/json'); $route = $this->resolver->process(preg_replace('/.*(expressly\\/.*)/i', '/${1}', $_SERVER['REQUEST_URI'])); if ($route instanceof Route) { $json = file_get_contents('php://input'); $json = json_decode($json); $existing = array(); $pending = array(); try { if (!property_exists($json, 'emails')) { throw new GenericException('Invalid JSON input'); } $customerModel = Mage::getModel('customer/customer'); foreach ($json->emails as $email) { $customerModel->setWebsiteId(Mage::app()->getWebsite()->getId()); $customerModel->loadByEmail($email); if ($customerModel->getId()) { if ($customerModel->getData('is_active')) { $existing[] = $email; continue; } $pending[] = $email; } } } catch (\Exception $e) { $this->logger->error(ExceptionFormatter::format($e)); } $presenter = new BatchCustomerPresenter($existing, array(), $pending); $this->getResponse()->setBody(json_encode($presenter->toArray())); } else { $this->getResponse()->setHttpResponseCode(401); } }
public function testOtherExceptionFormatted() { $exception = new Exception('not a defined exception'); $formatted = ExceptionFormatter::format($exception); $this->assertContains('Exception-not a defined exception', $formatted); $this->assertContains('ExceptionFormatterTest.php::19)', $formatted); }
/** * */ public function register() { // Check for request forgeries JSession::checkToken() or jexit(JText::_('JInvalid_Token')); $merchant = $this->app['merchant.provider']->getMerchant(true); $event = new PasswordedEvent($merchant); try { $this->app['dispatcher']->dispatch(MerchantSubscriber::MERCHANT_REGISTER, $event); if (!$event->isSuccessful()) { throw new \Expressly\Exception\InvalidAPIKeyException($this->error_formatter($event)); } } catch (\Exception $e) { $this->app['logger']->error(\Expressly\Exception\ExceptionFormatter::format($e)); JFactory::getApplication()->enqueueMessage(sprintf('<div id="message" class="error"><p><strong>%s</strong></p></div>', $e->getMessage()), 'error'); } $this->setRedirect('index.php?option=com_expressly'); }
public function registerUpdateMerchant($observer) { $helper = new Expressly_Expressly_Helper_Client(); $provider = $helper->getMerchantProvider(); $merchant = $provider->getMerchant(); $event = new PasswordedEvent($merchant); try { $provider->setMerchant($merchant); $helper->getDispatcher()->dispatch(MerchantSubscriber::MERCHANT_REGISTER, $event); if (!$event->isSuccessful()) { throw new InvalidAPIKeyException(); } } catch (\Exception $e) { $helper->getLogger()->error(ExceptionFormatter::format($e)); $response = array('error' => -1, 'message' => $helper->__('Your values could not be transmitted to the server. Please try resubmitting, or contacting info@buyexpressly.com')); \Mage::app()->getResponse()->setBody(Mage::helper('core')->jsonEncode($response)); } }
/** * @return void */ public function afterSave() { $app = $this->getApplication()->getApp(); $provider = $app['merchant.provider']; $dispatcher = $app['dispatcher']; $merchant = $provider->getMerchant(); $event = new PasswordedEvent($merchant); try { $dispatcher->dispatch(MerchantSubscriber::MERCHANT_REGISTER, $event); if (!$event->isSuccessful()) { throw new InvalidAPIKeyException(); } $this->getMessageManager()->addSuccess('MERCHANT_REGISTER'); } catch (\Exception $e) { $app['logger']->error(ExceptionFormatter::format($e)); $this->getMessageManager()->addError(__('Your values could not be transmitted to the server. Please try resubmitting, or contacting info@buyexpressly.com')); } }
public function popupAction() { $uuid = $this->getRequest()->getParam('uuid'); $merchant = $this->merchantProvider->getMerchant(); $event = new CustomerMigrateEvent($merchant, $uuid); try { $this->dispatcher->dispatch(CustomerMigrationSubscriber::CUSTOMER_MIGRATE_POPUP, $event); if (!$event->isSuccessful()) { throw new GenericException($this->processError($event)); } $this->mimicFrontPage(); $this->getResponse()->appendBody($event->getContent()); } catch (\Exception $e) { $this->logger->error(ExceptionFormatter::format($e)); $this->getResponse()->setRedirect('https://prod.expresslyapp.com/api/redirect/migration/' . $uuid . '/failed'); } }
public function register_uninstall_hook() { $merchant = $this->merchantProvider->getMerchant(); try { $event = new PasswordedEvent($merchant); $this->dispatcher->dispatch('merchant.delete', $event); } catch (\Exception $e) { $this->app['logger']->error(ExceptionFormatter::format($e)); } delete_option(WC_Expressly_MerchantProvider::HOST); delete_option(WC_Expressly_MerchantProvider::PATH); delete_option(WC_Expressly_MerchantProvider::DESTINATION); delete_option(WC_Expressly_MerchantProvider::OFFER); delete_option(WC_Expressly_MerchantProvider::PASSWORD); delete_option(WC_Expressly_MerchantProvider::UUID); delete_option(WC_Expressly_MerchantProvider::IMAGE); delete_option(WC_Expressly_MerchantProvider::TERMS); delete_option(WC_Expressly_MerchantProvider::POLICY); }
/** * */ private function migratecomplete($uuid) { if (empty($uuid)) { JFactory::getApplication()->redirect('/'); } $exists = false; $merchant = $this->app['merchant.provider']->getMerchant(); $event = new Expressly\Event\CustomerMigrateEvent($merchant, $uuid); try { $this->app['dispatcher']->dispatch(\Expressly\Subscriber\CustomerMigrationSubscriber::CUSTOMER_MIGRATE_DATA, $event); $json = $event->getContent(); if (!$event->isSuccessful()) { if (!empty($json['code']) && $json['code'] == 'USER_ALREADY_MIGRATED') { $exists = true; } throw new \Expressly\Exception\UserExistsException(ExpresslyHelper::error_formatter($event)); } $email = $json['migration']['data']['email']; $user = ExpresslyHelper::get_user_by_email($email); if (null === $user) { $customer = $json['migration']['data']['customerData']; $model = JModelLegacy::getInstance('Registration', 'UsersModel', array('ignore_request' => true)); $user_id = $model->register(['name' => $customer['firstName'] . ' ' . $customer['lastName'], 'username' => 'user' . time() . rand(1000, 9999), 'email1' => $email, 'password1' => JUserHelper::genRandomPassword()]); if (isset($customer['billingAddress'])) { $userInfo = VmTable::getInstance('userinfos', 'Table', array('dbo' => JFactory::getDbo())); $userInfo->bindChecknStore(array_merge(array('virtuemart_userinfo_id' => 0, 'virtuemart_user_id' => $user_id, 'address_type' => 'BT'), $this->parse_address($customer['addresses'][$customer['billingAddress']], $customer))); } if (isset($customer['shippingAddress'])) { $userInfo = VmTable::getInstance('userinfos', 'Table', array('dbo' => JFactory::getDbo())); $userInfo->bindChecknStore(array_merge(array('virtuemart_userinfo_id' => 0, 'virtuemart_user_id' => $user_id, 'address_type' => 'ST'), $this->parse_address($customer['addresses'][$customer['shippingAddress']], $customer))); } // TODO: Need to do programmatically authorize here (if some way exists for Joomla!) } else { $exists = true; $event = new \Expressly\Event\CustomerMigrateEvent($merchant, $uuid, \Expressly\Event\CustomerMigrateEvent::EXISTING_CUSTOMER); } // ************************************* // * Add items (product/coupon) to cart // ************************************* if (!empty($json['cart'])) { if (!class_exists('VirtueMartCart')) { require_once JPATH_VM_SITE . DS . 'helpers' . DS . 'cart.php'; } $cart = VirtueMartCart::getCart(); if (!empty($json['cart']['productId'])) { $cartProductsData = array(); $cartProductsData[intval($json['cart']['productId'])] = array('virtuemart_product_id' => intval($json['cart']['productId']), 'quantity' => 1); $cart->cartProductsData = $cartProductsData; } if (!empty($json['cart']['couponCode'])) { $cart->setCouponCode(strval($json['cart']['couponCode'])); } $cart->setCartIntoSession(); } $this->app['dispatcher']->dispatch(\Expressly\Subscriber\CustomerMigrationSubscriber::CUSTOMER_MIGRATE_SUCCESS, $event); } catch (\Exception $e) { $this->app['logger']->error(\Expressly\Exception\ExceptionFormatter::format($e)); } if ($exists) { $session = JFactory::getSession(); $session->set('__xly', array('action' => 'exists')); } JFactory::getApplication()->redirect('/'); }