Example #1
0
 public function getMetaField(MetaModel $meta)
 {
     Model::register('user');
     $field = $this->decorationFactory($meta);
     $field->setType('fk');
     $field->setModelName('user');
     return $field;
 }
Example #2
0
 public function updatePayment()
 {
     $request = Ajde::app()->getRequest();
     $username = $request->getParam('Username');
     $password = $request->getParam('Password');
     $id = $request->getParam('ID');
     $secret = $request->getParam('Reference');
     $paymentMethod = $request->getParam('PaymentMethod');
     $state = $request->getParam('PaymentState');
     $description = $request->getParam('Description');
     if ($username != Config::get('shopWedealCallbackUsername')) {
         Log::log('Invalid username for callback of transaction ' . $secret);
         return false;
     }
     if ($password != Config::get('shopWedealCallbackPassword')) {
         Log::log('Invalid password for callback of transaction ' . $secret);
         return false;
     }
     Model::register('shop');
     $transaction = new TransactionModel();
     if (!$transaction->loadByField('secret', $secret)) {
         Log::log('Could not find transaction for PayPal payment with txn id ' . $txn_id . ' and transaction secret ' . $secret);
     }
     $request = array("type" => 'query', "merchant" => array("username" => Config::get('shopWedealUsername'), "password" => Config::get('shopWedealPassword'), "reference" => $secret));
     // Pause a little before request is made to allow for processing on provider
     // as this request will be made synchronously after payment
     sleep(3);
     $res = $this->sendRequest($request);
     if ($res['success'] === true) {
         $response = $res['response']->paymentinfo;
         $count = (int) $res['response']->count;
         // get transaction details
         if ($count == 0) {
             $transaction->payment_status = 'refused';
             $transaction->save();
             Log::log('iDeal callback didn\'t return any transaction for ' . $secret);
         } elseif (self::isPaid((string) $response->state)) {
             if ((string) $response->id != $id) {
                 Log::log('IDs don\'t match for iDeal callback of transaction ' . $secret);
             } else {
                 $details = 'AMOUNT: ' . (string) $response->amount . PHP_EOL . 'PAYER_NAME: ' . (string) $response->consumername . PHP_EOL . 'PAYER_ACCOUNT: ' . (string) $response->consumeraccount . PHP_EOL . 'PAYER_CITY: ' . (string) $response->consumercity . PHP_EOL . 'PAYER_COUNTRY: ' . (string) $response->consumercountry . PHP_EOL . 'WEDEAL_ID: ' . (string) $response->id;
                 $transaction->payment_details = $details;
                 $transaction->payment_status = 'completed';
                 $transaction->save();
                 return array('success' => true, 'transaction' => $transaction);
             }
         } elseif (self::isRefused((string) $response->state)) {
             $transaction->payment_status = 'refused';
             $transaction->save();
             Log::log("iDeal payment refused with state " . (string) $response->state);
         } else {
             Log::log("iDeal payment callback called with state " . (string) $response->state . " but no status change for transaction " . $secret . " detected");
         }
     } else {
         Log::log("Wedeal::updatePayment() failed because: " . $res['response']);
     }
     return array('success' => false, 'transaction' => $transaction);
 }
Example #3
0
 /**
  *
  * @return UserModel
  */
 protected function getLoggedInUser()
 {
     if (!isset($this->_user)) {
         foreach ($this->_registerUserModels as $model) {
             Model::register($model);
         }
         $this->_user = UserModel::getLoggedIn();
     }
     return $this->_user;
 }
Example #4
0
 public static function __bootstrap()
 {
     Model::register('user');
     if (User::getLoggedIn()) {
         return true;
     }
     $user = new UserModel();
     $user->verifyCookie(false);
     return true;
 }
Example #5
0
 public static function _($message, $channel = Log::CHANNEL_INFO, $level = Log::LEVEL_INFORMATIONAL, $description = '', $code = '', $trace = '')
 {
     // don't use db writer on db error
     if (substr_count($message, 'SQLSTATE')) {
         return false;
     }
     Model::register('admin');
     $log = new LogModel();
     $log->populate(array('message' => $message, 'channel' => $channel, 'level' => $level, 'description' => $description, 'code' => $code, 'trace' => $trace, 'request' => self::getRequest(), 'user_agent' => self::getUserAgent(), 'referer' => self::getReferer(), 'ip' => self::getIP()));
     return $log->insert();
 }
Example #6
0
 public static function __bootstrap()
 {
     Model::register('user');
     if (($user = User::getLoggedIn()) && $user->getDebug()) {
         $config = Config::getInstance();
         $config->debug = true;
         if (!in_array('Debugger', $config->documentProcessors['html'])) {
             $config->documentProcessors['html'][] = 'Debugger';
         }
     }
     return true;
 }
Example #7
0
 public function beforeInvoke($allowed = array())
 {
     foreach ($this->_registerAclModels as $model) {
         Model::register($model);
     }
     if (!in_array($this->getAction(), array_merge($this->_allowedActions, $allowed)) && $this->hasAccess() === false) {
         Log::_('ACL firewall hit', Log::CHANNEL_SECURITY, Log::LEVEL_INFORMATIONAL, implode(PHP_EOL, Ajde_Acl::$log));
         Ajde::app()->getRequest()->set('message', __('You may not have the required permission to view this page'));
         Ajde::app()->getResponse()->dieOnCode(Response::RESPONSE_TYPE_UNAUTHORIZED);
     } else {
         return true;
     }
 }
Example #8
0
 public function getMetaField(MetaModel $meta)
 {
     $field = $this->decorationFactory($meta);
     $field->setType('spatial');
     if ($meta->getOption('spatialtype') === 'Image') {
         Model::register('media');
         $media = new MediaModel();
         $media->loadByPK($meta->getOption('media'));
         $field->setUseImage(true);
         $field->setLayerImage($this->_uploaddir . $media->get('thumbnail'));
     }
     return $field;
 }
Example #9
0
 public function beforeInvoke($allowed = array())
 {
     $token = Ajde::app()->getRequest()->getParam('token', false);
     if ($token) {
         Model::register('user');
         $user = new UserModel();
         list($uid, $hash) = explode(':', $token);
         if ($user->loadByPK($uid)) {
             if ($user->getCookieHash(false) === $hash) {
                 $user->login();
             }
         }
     }
     $user = UserModel::getLoggedIn();
     if ($user) {
         return parent::beforeInvoke($allowed);
     }
     Ajde::app()->getRequest()->set('message', __('You may not have the required permission to view this page'));
     Ajde::app()->getResponse()->dieOnCode(Response::RESPONSE_TYPE_UNAUTHORIZED);
 }
Example #10
0
 public function getMetaField(MetaModel $meta)
 {
     Model::register('media');
     $field = $this->decorationFactory($meta);
     $field->setType('fk');
     $field->setModelName('media');
     if ($meta->getOption('usemediatype')) {
         $field->setAdvancedFilter(array(new Where('mediatype', Filter::FILTER_EQUALS, $meta->getOption('usemediatype'))));
     }
     if ($meta->getOption('popup')) {
         $field->setListRoute('admin/media:view.crud');
         $field->setUsePopupSelector(true);
         $field->setUseImage(true);
         $field->addTableFileField('thumbnail', UPLOAD_DIR);
         $field->setThumbDim(600, 200);
     }
     //		$field->setUseImage(true);
     //		$field->addTableFileField('thumbnail', UPLOAD_DIR);
     //		$field->setThumbDim(300, 20);
     return $field;
 }
Example #11
0
 public static function mergeUserToClient()
 {
     Model::register('user');
     Model::register('shop');
     if ($user = User::getLoggedIn()) {
         // Do we have a saved cart for logged in user?
         $userCart = new CartModel();
         if ($userCart->loadByUser($user)) {
             // Do we have a saved cart for client?
             $clientCart = new CartModel();
             if ($clientCart->loadByClient() === false) {
                 $clientCart->client = md5($_SERVER['REMOTE_ADDR'] . $_SERVER['HTTP_USER_AGENT']);
                 $clientCart->insert();
             }
             foreach ($userCart->getItems() as $item) {
                 /* @var $item Ajde_Shop_Cart_Item */
                 $clientCart->addItem($item->getEntity(), null, $item->getQty());
             }
             $userCart->delete();
         }
     }
 }
Example #12
0
 public function updatePayment()
 {
     // PHP 4.1
     // read the post from PayPal system and add 'cmd'
     $req = 'cmd=_notify-validate';
     foreach ($_POST as $key => $value) {
         $value = urlencode(stripslashes($value));
         $req .= "&{$key}={$value}";
     }
     // post back to PayPal system to validate
     $header = '';
     $header .= "POST /cgi-bin/webscr HTTP/1.0\r\n";
     $header .= "Content-Type: application/x-www-form-urlencoded\r\n";
     $header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
     $fp = fsockopen($this->isSandbox() ? 'ssl://www.sandbox.paypal.com' : 'ssl://www.paypal.com', 443, $errno, $errstr, 30);
     // assign posted variables to local variables
     $item_name = issetor($_POST['item_name']);
     $item_number = issetor($_POST['item_number']);
     $payment_status = issetor($_POST['payment_status']);
     $payment_amount = issetor($_POST['mc_gross']);
     $payment_currency = issetor($_POST['mc_currency']);
     $txn_id = issetor($_POST['txn_id']);
     $receiver_email = issetor($_POST['receiver_email']);
     $payer_email = issetor($_POST['payer_email']);
     Model::register('shop');
     $secret = issetor($_POST['custom']);
     $transaction = new TransactionModel();
     $changed = false;
     if (!$fp) {
         // HTTP ERROR
     } else {
         fputs($fp, $header . $req);
         while (!feof($fp)) {
             $res = fgets($fp, 1024);
             if (strcmp($res, "VERIFIED") == 0) {
                 if (!$transaction->loadByField('secret', $secret)) {
                     Log::log('Could not find transaction for PayPal payment with txn id ' . $txn_id . ' and transaction secret ' . $secret);
                     return array('success' => false, 'transaction' => null);
                 }
                 // check the payment_status is Completed
                 // accept Pending from PayPal (eChecks?)
                 $acceptPending = true;
                 if ($payment_status == 'Completed' || $acceptPending && $payment_status == 'Pending') {
                     $details = 'AMOUNT: ' . $payment_amount . PHP_EOL . 'CURRENCY: ' . $payment_currency . PHP_EOL . 'PAYER_EMAIL: ' . $payer_email . PHP_EOL . 'RECEIVER_EMAIL: ' . $receiver_email . PHP_EOL . 'TXN_ID: ' . $txn_id . PHP_EOL;
                     // update transaction only once
                     if ($transaction->payment_status != 'completed') {
                         $transaction->payment_details = $details;
                         $transaction->payment_status = 'completed';
                         $transaction->save();
                         $changed = true;
                     }
                     // Write pending to Log
                     if ($payment_status == 'Pending') {
                         Log::log('Status is Pending but accepting now. PayPal payment with txn id ' . $txn_id . ' and transaction secret ' . $secret);
                     }
                     return array('success' => true, 'changed' => $changed, 'transaction' => $transaction);
                 } else {
                     if ($transaction->payment_status != 'refused') {
                         $transaction->payment_status = 'refused';
                         $transaction->save();
                         $changed = true;
                     }
                     Log::log('Status is not Completed but ' . $payment_status . ' for PayPal payment with txn id ' . $txn_id . ' and transaction secret ' . $secret);
                 }
                 // check that txn_id has not been previously processed
                 // check that receiver_email is your Primary PayPal email
                 // check that payment_amount/payment_currency are correct
                 // process payment
             } else {
                 if (strcmp($res, "INVALID") == 0) {
                     if (!$transaction->loadByField('secret', $secret)) {
                         // secret not found anyway
                         $transaction = null;
                         Log::log('Could not find transaction for PayPal payment with txn id ' . $txn_id . ' and transaction secret ' . $secret);
                     } else {
                         // log for manual investigation
                         if ($transaction->payment_status != 'refused') {
                             $transaction->payment_status = 'refused';
                             $transaction->save();
                             $changed = true;
                         }
                         Log::log('Validation failed for PayPal payment with txn id ' . $txn_id);
                     }
                 }
             }
         }
         fclose($fp);
     }
     return array('success' => false, 'changed' => $changed, 'transaction' => $transaction);
 }
Example #13
0
 public function getMetaFields($crossReferenceTable, $crossReferenceField, $sortField, $parentField, $filters = array())
 {
     $allFields = array();
     Model::register('admin');
     $metas = new MetaCollection();
     $metas->concatCrossReference($crossReferenceTable, $crossReferenceField);
     $metas->concatField($crossReferenceTable, $sortField);
     if (!empty($filters)) {
         $group = new WhereGroup();
         foreach ($filters as $filter) {
             if ($filter instanceof Where) {
                 $group->addFilter($filter);
             } else {
                 $metas->addFilter($filter);
             }
         }
         $metas->addFilter($group);
     }
     foreach ($metas as $meta) {
         $metaField = $this->getType($meta->get('type'));
         $fieldOptions = $metaField->getMetaField($meta);
         // add show only when
         foreach (explode(',', $meta->get($crossReferenceField)) as $parentValue) {
             $fieldOptions->addShowOnlyWhen($parentField, $parentValue);
         }
         // add sorting
         foreach (explode(',', $meta->get($sortField)) as $parentValue) {
             $fieldOptions->addDynamicSort($parentField, $parentValue);
         }
         $allFields['meta_' . $meta->getPK()] = $fieldOptions;
     }
     return $allFields;
 }