Exemplo n.º 1
0
 public function pay($multiplicator = 1, $noclear = false)
 {
     $metaUser = false;
     $new_plan = false;
     $plans = array();
     if (!empty($this->userid)) {
         $metaUser = new metaUser($this->userid);
     }
     if (!empty($this->params['target_user'])) {
         $targetUser = new metaUser($this->params['target_user']);
     } else {
         $targetUser =& $metaUser;
     }
     if (!empty($this->params['aec_pickup'])) {
         if (is_array($this->params['aec_pickup'])) {
             foreach ($this->params['aec_pickup'] as $key) {
                 if (isset($this->params[$key])) {
                     unset($this->params[$key]);
                 }
             }
         }
         unset($this->params['aec_pickup']);
     }
     $override_permissioncheck = $this->isRecurring() && $this->counter > 1;
     if (!empty($this->usage)) {
         $usage = explode('.', $this->usage);
         // Update old notation
         if (!isset($usage[1])) {
             $temp = $usage[0];
             $usage[0] = 'p';
             $usage[1] = $temp;
         }
         switch (strtolower($usage[0])) {
             case 'c':
             case 'cart':
                 if (empty($this->params['cart']->content)) {
                     $this->params['cart'] = new aecCart();
                     $this->params['cart']->load($usage[1]);
                     if (!empty($this->params['cart']->content)) {
                         foreach ($this->params['cart']->content as $c) {
                             $new_plan = new SubscriptionPlan();
                             $new_plan->load($c['id']);
                             for ($i = 0; $i < $c['quantity']; $i++) {
                                 $plans[] = $new_plan;
                             }
                         }
                     }
                     $this->params['cart']->clear();
                     $this->storeload();
                     // Load and delete original entry
                     $cart = new aecCart();
                     $cart->load($usage[1]);
                     if ($cart->id) {
                         $cart->delete();
                     }
                 } else {
                     foreach ($this->params['cart']->content as $c) {
                         $new_plan = new SubscriptionPlan();
                         $new_plan->load($c['id']);
                         if (!$override_permissioncheck) {
                             if ($new_plan->checkPermission($metaUser) === false) {
                                 return false;
                             }
                         }
                         for ($i = 0; $i < $c['quantity']; $i++) {
                             $plans[] = $new_plan;
                         }
                     }
                 }
                 break;
             case 'p':
             case 'plan':
             default:
                 $new_plan = new SubscriptionPlan();
                 $new_plan->load($this->usage);
                 if (!$override_permissioncheck) {
                     if ($new_plan->checkPermission($metaUser) === false) {
                         return false;
                     }
                 }
                 $plans[] = $new_plan;
                 break;
         }
     }
     if (is_object($metaUser)) {
         if (!empty($this->params['userMIParams'])) {
             foreach ($this->params['userMIParams'] as $plan => $mis) {
                 foreach ($mis as $mi_id => $content) {
                     $metaUser->meta->setMIParams($mi_id, $plan, $content);
                     if ($metaUser->userid !== $targetUser->userid) {
                         $targetUser->meta->setMIParams($mi_id, $plan, $content);
                     }
                 }
             }
             $metaUser->meta->storeload();
             if ($metaUser->userid !== $targetUser->userid) {
                 $targetUser->meta->storeload();
             }
         }
     }
     foreach ($plans as $plan) {
         if (is_object($targetUser) && is_object($plan)) {
             if ($targetUser->userid) {
                 if (!empty($this->subscr_id)) {
                     $targetUser->establishFocus($plan, $this->method, false, $this->subscr_id);
                 } else {
                     $targetUser->establishFocus($plan, $this->method);
                 }
                 $this->subscr_id = $targetUser->focusSubscription->id;
                 // Apply the Plan
                 $application = $targetUser->focusSubscription->applyUsage($plan->id, $this->method, 0, $multiplicator, $this);
             } else {
                 $application = $plan->applyPlan(0, $this->method, 0, $multiplicator, $this);
             }
         }
     }
     $micro_integrations = false;
     if (!empty($this->conditions)) {
         if (strpos($this->conditions, 'mi_attendevents')) {
             $start_position = strpos($this->conditions, '<registration_id>') + strlen('<registration_id>');
             $end_position = strpos($this->conditions, '</registration_id>');
             $micro_integration['name'] = 'mi_attendevents';
             $micro_integration['parameters'] = array('registration_id' => substr($this->conditions, $start_position, $end_position - $start_position));
             $micro_integrations = array();
             $micro_integrations[] = $micro_integration;
         }
     }
     // Reload the meta- & targetUser since they have been updated
     if (!empty($this->userid)) {
         $metaUser = new metaUser($this->userid);
     }
     if (!empty($this->params['target_user'])) {
         $targetUser = new metaUser($this->params['target_user']);
     } else {
         $targetUser =& $metaUser;
     }
     if (!empty($micro_integrations)) {
         if (is_array($micro_integrations)) {
             foreach ($micro_integrations as $micro_int) {
                 $mi = new microIntegration();
                 if (isset($micro_integration['parameters'])) {
                     $exchange = $micro_integration['parameters'];
                 } else {
                     $exchange = null;
                 }
                 if (isset($micro_int['name'])) {
                     if ($mi->callDry($micro_int['name'])) {
                         if (is_object($targetUser)) {
                             $mi->action($targetUser, $exchange, $this, $new_plan);
                         } else {
                             $mi->action($targetUser, $exchange, $this, $new_plan);
                         }
                     }
                 } elseif (isset($micro_int['id'])) {
                     if ($mi->mi_exists($micro_int['id'])) {
                         $mi->load($micro_int['id']);
                         if ($mi->callIntegration()) {
                             if (is_object($metaUser)) {
                                 $mi->action($targetUser, $exchange, $this, $new_plan);
                             } else {
                                 $mi->action($targetUser, $exchange, $this, $new_plan);
                             }
                         }
                     }
                 }
                 unset($mi);
             }
         }
     }
     if ($this->coupons) {
         foreach ($this->coupons as $coupon_code) {
             $cph = new couponHandler();
             $cph->load($coupon_code);
             $cph->triggerMIs($targetUser, $this, $plans[0]);
         }
     }
     // We need to at least warn the admin if there is an invoice with nothing to do
     if (empty($this->usage) && empty($this->conditions) && empty($this->coupons)) {
         $short = 'Nothing to do';
         $event = JText::_('AEC_MSG_PROC_INVOICE_ACTION_EV_VALID_APPFAIL');
         $tags = 'invoice,application,payment,action_failed';
         $params = array('invoice_number' => $this->invoice_number);
         $eventlog = new eventLog();
         $eventlog->issue($short, $tags, $event, 32, $params);
     }
     if (!$noclear) {
         $this->setTransactionDate();
     }
     return true;
 }
Exemplo n.º 2
0
 public function action($request)
 {
     $location = $this->getLocation($request);
     if (empty($location['mi'])) {
         return true;
     }
     $db = JFactory::getDBO();
     $mi = new microIntegration();
     if (!$mi->mi_exists($location['mi'])) {
         return true;
     }
     $mi->load($location['mi']);
     if (!$mi->callIntegration()) {
         return null;
     }
     global $aecConfig;
     $action = 'action';
     $exchange = null;
     if ($mi->relayAction($request->metaUser, $exchange, $request->invoice, null, $action, $request->add) === false) {
         if ($aecConfig->cfg['breakon_mi_error']) {
             return false;
         }
     }
     return true;
 }
 /**
  * @param string $action
  */
 public function triggerMIs($action, &$metaUser, &$exchange, &$invoice, &$add, &$silent)
 {
     global $aecConfig;
     $micro_integrations = $this->getMicroIntegrations();
     if (!is_array($micro_integrations)) {
         return null;
     }
     foreach ($micro_integrations as $mi_id) {
         $mi = new microIntegration();
         if (!$mi->mi_exists($mi_id)) {
             continue;
         }
         $mi->load($mi_id);
         if (!$mi->callIntegration()) {
             continue;
         }
         // TODO: Only trigger if this is not email or made not silent
         if (method_exists($metaUser, $action)) {
             if ($mi->{$action}($metaUser, $exchange, $invoice, $this) === false) {
                 if ($aecConfig->cfg['breakon_mi_error']) {
                     return false;
                 }
             }
         } else {
             $params = array();
             if (isset($invoice->params['userMIParams'])) {
                 if (is_array($invoice->params['userMIParams'])) {
                     if (isset($invoice->params['userMIParams'][$this->id][$mi->id])) {
                         $params = $invoice->params['userMIParams'][$this->id][$mi->id];
                     }
                 }
             }
             if ($mi->relayAction($metaUser, $exchange, $invoice, $this, $action, $add, $params) === false) {
                 if ($aecConfig->cfg['breakon_mi_error']) {
                     return false;
                 }
             }
         }
     }
     return true;
 }
Exemplo n.º 4
0
 public function triggerPreExpiration($metaUser, $mi_pexp)
 {
     // No actions on expired, trial or recurring
     if ($this->isExpired() || $this->isTrial() || $this->recurring) {
         return false;
     }
     $plan = $this->getPlan();
     $micro_integrations = $plan->getMicroIntegrations();
     $actions = 0;
     if (empty($micro_integrations)) {
         return $actions;
     }
     foreach ($micro_integrations as $mi_id) {
         if (!in_array($mi_id, $mi_pexp)) {
             continue;
         }
         $mi = new microIntegration();
         if (!$mi->mi_exists($mi_id)) {
             continue;
         }
         $mi->load($mi_id);
         if (!$mi->callIntegration()) {
             continue;
         }
         // Do the actual pre expiration check on this MI
         if ($this->isExpired($mi->pre_exp_check)) {
             $result = $mi->pre_expiration_action($metaUser, $plan);
             if ($result) {
                 $actions++;
             }
         }
         unset($mi);
     }
     return $actions;
 }
Exemplo n.º 5
0
 public function cmdApply($metaUser, $params)
 {
     global $aecConfig;
     $db = JFactory::getDBO();
     switch (strtolower($params[0])) {
         case 'plan':
             $plans = explode(',', $params[1]);
             foreach ($plans as $planid) {
                 $plan = new SubscriptionPlan();
                 $plan->load($planid);
                 $metaUser->establishFocus($plan);
                 $metaUser->focusSubscription->applyUsage($planid, 'none', 1);
             }
             break;
         case 'mi':
             $micro_integrations = explode(',', $params[1]);
             if (is_array($micro_integrations)) {
                 foreach ($micro_integrations as $mi_id) {
                     $mi = new microIntegration();
                     if (!$mi->mi_exists($mi_id)) {
                         continue;
                     }
                     $mi->load($mi_id);
                     if (!$mi->callIntegration()) {
                         continue;
                     }
                     if (isset($params[2])) {
                         $action = $params[2];
                     } else {
                         $action = 'action';
                     }
                     $invoice = $exchange = $add = null;
                     if ($mi->relayAction($metaUser, $exchange, $invoice, null, $action, $add) === false) {
                         if ($aecConfig->cfg['breakon_mi_error']) {
                             return false;
                         }
                     }
                     unset($mi);
                 }
             }
             break;
     }
 }
Exemplo n.º 6
0
 /**
  * @param Invoice $invoice
  */
 public function triggerMIs($metaUser, $invoice, $new_plan)
 {
     global $aecConfig;
     // See whether this coupon has micro integrations
     if (empty($this->coupon->micro_integrations)) {
         return null;
     }
     foreach ($this->coupon->micro_integrations as $mi_id) {
         $mi = new microIntegration();
         // Only call if it exists
         if (!$mi->mi_exists($mi_id)) {
             continue;
         }
         $mi->load($mi_id);
         // Check whether we can really call
         if (!$mi->callIntegration()) {
             continue;
         }
         $add = $params = false;
         if (is_object($metaUser)) {
             if ($mi->action($metaUser, null, $invoice, $new_plan) === false) {
                 if ($aecConfig->cfg['breakon_mi_error']) {
                     return false;
                 }
             }
             if ($mi->relayAction($metaUser, null, $invoice, $this, 'afteraction', $add, $params) === false) {
                 if ($aecConfig->cfg['breakon_mi_error']) {
                     return false;
                 }
             }
         } else {
             $metaUser = false;
             if ($mi->action($metaUser, null, $invoice, $new_plan) === false) {
                 if ($aecConfig->cfg['breakon_mi_error']) {
                     return false;
                 }
             }
             if ($mi->relayAction($metaUser, null, $invoice, $this, 'afteraction', $add, $params) === false) {
                 if ($aecConfig->cfg['breakon_mi_error']) {
                     return false;
                 }
             }
         }
     }
 }
Exemplo n.º 7
0
 public function relayAction($request)
 {
     if (!($request->area == 'afteraction')) {
         return null;
     }
     $options = $this->getOption($request);
     foreach ($options as $option) {
         if (empty($option['mi'])) {
             continue;
         }
         $mi = new microIntegration();
         if (!$mi->mi_exists($option['mi'])) {
             return true;
         }
         $mi->load($option['mi']);
         if ($mi->callIntegration()) {
             $exchange = $params = null;
             if ($mi->relayAction($request->metaUser, $exchange, $request->invoice, null, 'action', $request->add, $params) === false) {
                 global $aecConfig;
                 if ($aecConfig->cfg['breakon_mi_error']) {
                     return false;
                 }
             }
             if ($mi->relayAction($request->metaUser, $exchange, $request->invoice, null, 'afteraction', $request->add, $params) === false) {
                 global $aecConfig;
                 if ($aecConfig->cfg['breakon_mi_error']) {
                     return false;
                 }
             }
         }
     }
     return true;
 }