/** * @param InvoiceFactory $InvoiceFactory */ public function processorResponse($InvoiceFactory, $response, $resp = '', $altvalidation = false) { global $aecConfig; if (!is_array($response)) { $response = array('original_response' => $response); } $this->computeAmount($InvoiceFactory); $objUsage = $this->getObjUsage(); if (is_a($objUsage, 'SubscriptionPlan')) { $plan = $objUsage; } else { $plan = $objUsage->getTopPlan(); } $response['planparams'] = $plan->getProcessorParameters($InvoiceFactory->pp); $post = aecPostParamClear($_POST); $response['userid'] = $this->userid; $InvoiceFactory->pp->exchangeSettingsByPlan($plan, $plan->params); if ($altvalidation) { $response = $InvoiceFactory->pp->instantvalidateNotification($response, $post, $this); } else { $response = $InvoiceFactory->pp->validateNotification($response, $post, $this); } if (!empty($aecConfig->cfg['invoice_cushion']) && $this->transaction_date !== '0000-00-00 00:00:00') { if (strtotime($this->transaction_date) + $aecConfig->cfg['invoice_cushion'] * 60 > (int) gmdate('U')) { if ($InvoiceFactory->pp->processor_name == 'desjardins') { // Desjardins is the only exception so far... bad bad bad } elseif ($response['valid']) { // The last notification has not been too long ago - skipping this one // But only skip actual payment notifications - errors are OK $short = JText::_('AEC_MSG_PROC_INVOICE_ACTION_SH'); $event = JText::_('AEC_MSG_PROC_INVOICE_ACTION_EV_DUPLICATE') . "\n"; $tags = 'invoice,processor,duplicate'; $level = 2; $params = array('invoice_number' => $this->invoice_number); $eventlog = new eventLog(); $eventlog->issue($short, $tags, $event, $level, $params); return $response; } } } if (isset($response['userid'])) { unset($response['userid']); } if (isset($response['planparams'])) { unset($response['planparams']); } if (isset($response['secondary_ident'])) { $this->secondary_ident = $response['secondary_ident']; $this->storeload(); unset($response['secondary_ident']); } if (isset($response['invoiceparams'])) { $this->addParams($response['invoiceparams']); $this->storeload(); unset($response['invoiceparams']); } if (isset($response['multiplicator'])) { $multiplicator = $response['multiplicator']; unset($response['multiplicator']); } else { $multiplicator = 1; } if (isset($response['fullresponse'])) { $resp = $response['fullresponse']; unset($response['fullresponse']); } if (empty($resp) && !empty($response['raw'])) { $resp = $response['raw']; } if (isset($response['break_processing'])) { unset($response['break_processing']); return $response; } $metaUser = new metaUser($this->userid); $mi_event = null; // Create history entry $history = new logHistory(); $history->entryFromInvoice($this, $resp, $InvoiceFactory->pp); $short = JText::_('AEC_MSG_PROC_INVOICE_ACTION_SH'); $event = JText::_('AEC_MSG_PROC_INVOICE_ACTION_EV') . "\n"; if (!empty($response)) { foreach ($response as $key => $value) { $event .= $key . "=" . $value . "\n"; } } $event .= JText::_('AEC_MSG_PROC_INVOICE_ACTION_EV_STATUS'); $tags = 'invoice,processor'; $level = 2; $params = array('invoice_number' => $this->invoice_number); $forcedisplay = false; $event .= ' '; $notificationerror = null; if ($response['valid']) { $break = 0; // If not in Testmode, check for amount and currency if (empty($InvoiceFactory->pp->settings['testmode'])) { if (isset($response['amount_paid'])) { // In some cases, a straight up != can still come out as an error, so forcing INT $ampaid = (int) ($response['amount_paid'] * 100); $amasked = (int) ($this->amount * 100); if ($ampaid != $amasked) { // Amount Fraud, cancel payment and create error log addition $event .= sprintf(JText::_('AEC_MSG_PROC_INVOICE_ACTION_EV_FRAUD'), $response['amount_paid'], $this->amount); $tags .= ',fraud_attempt,amount_fraud'; $break = 1; $notificationerror = 'Wrong amount for invoice. Amount provided: "' . $response['amount_paid'] . '"'; } } if (isset($response['amount_currency'])) { if ($response['amount_currency'] != $this->currency) { // Amount Fraud, cancel payment and create error log addition $event .= sprintf(JText::_('AEC_MSG_PROC_INVOICE_ACTION_EV_CURR'), $response['amount_currency'], $this->currency); $tags .= ',fraud_attempt,currency_fraud'; $break = 1; $notificationerror = 'Wrong currency for invoice. Currency provided: "' . $response['amount_currency'] . '"'; } } } if (!$break) { if ($this->pay($multiplicator) === false) { $notificationerror = 'Item Application failed. Please contact the System Administrator'; // Something went wrong $event .= JText::_('AEC_MSG_PROC_INVOICE_ACTION_EV_VALID_APPFAIL'); $tags .= ',payment,action_failed'; } else { $event .= JText::_('AEC_MSG_PROC_INVOICE_ACTION_EV_VALID'); $tags .= ',payment,action'; } } else { $level = 128; } } else { if (isset($response['pending'])) { if (strcmp($response['pending_reason'], 'signup') === 0) { if ($plan->params['trial_free'] || $this->amount == '0.00') { $this->pay($multiplicator); $this->addParams(array('free_trial' => $response['pending_reason']), 'params', true); $event .= JText::_('AEC_MSG_PROC_INVOICE_ACTION_EV_TRIAL'); $tags .= ',payment,action,trial'; } } else { $this->addParams(array('pending_reason' => $response['pending_reason']), 'params', true); $event .= sprintf(JText::_('AEC_MSG_PROC_INVOICE_ACTION_EV_PEND'), $response['pending_reason']); $tags .= ',payment,pending' . $response['pending_reason']; $mi_event = '_payment_pending'; } $this->storeload(); } elseif (isset($response['cancel'])) { $mi_event = '_payment_cancel'; $event .= JText::_('AEC_MSG_PROC_INVOICE_ACTION_EV_CANCEL'); $tags .= ',cancel'; if ($metaUser->hasSubscription) { if (!empty($this->subscr_id)) { $metaUser->moveFocus($this->subscr_id); } if (isset($response['cancel_expire'])) { $mi_event = '_payment_cancel_expire'; $metaUser->focusSubscription->expire(); $tags .= ',expire'; } else { $metaUser->focusSubscription->cancel($this); } $event .= JText::_('AEC_MSG_PROC_INVOICE_ACTION_EV_USTATUS'); } } elseif (isset($response['chargeback'])) { $mi_event = '_payment_chargeback'; $event .= JText::_('AEC_MSG_PROC_INVOICE_ACTION_EV_CHARGEBACK'); $tags .= ',chargeback'; $level = 128; if ($metaUser->hasSubscription) { if (!empty($this->subscr_id)) { $metaUser->moveFocus($this->subscr_id); } $metaUser->focusSubscription->hold($this); $event .= JText::_('AEC_MSG_PROC_INVOICE_ACTION_EV_USTATUS_HOLD'); } } elseif (isset($response['chargeback_settle'])) { $mi_event = '_payment_chargeback_settle'; $event .= JText::_('AEC_MSG_PROC_INVOICE_ACTION_EV_CHARGEBACK_SETTLE'); $tags .= ',chargeback_settle'; $level = 8; $forcedisplay = true; if ($metaUser->hasSubscription) { if (!empty($this->subscr_id)) { $metaUser->moveFocus($this->subscr_id); } $metaUser->focusSubscription->hold_settle($this); $event .= JText::_('AEC_MSG_PROC_INVOICE_ACTION_EV_USTATUS_ACTIVE'); } } elseif (isset($response['delete'])) { $mi_event = '_payment_refund'; $event .= JText::_('AEC_MSG_PROC_INVOICE_ACTION_EV_REFUND'); $tags .= ',refund'; if ($metaUser->hasSubscription) { if (!empty($this->subscr_id)) { $metaUser->moveFocus($this->subscr_id); } $usage = $this->getObjUsage(); if (is_a($usage, 'SubscriptionPlan')) { // Check whether we're really expiring the right membership, // Maybe the user was already switched to a different plan if ($metaUser->focusSubscription->plan == $usage->id) { $metaUser->focusSubscription->expire(false, 'refund'); $event .= JText::_('AEC_MSG_PROC_INVOICE_ACTION_EV_EXPIRED'); } } else { $metaUser->focusSubscription->expire(false, 'refund'); $event .= JText::_('AEC_MSG_PROC_INVOICE_ACTION_EV_EXPIRED'); } } } elseif (isset($response['eot'])) { $mi_event = '_payment_eot'; $event .= JText::_('AEC_MSG_PROC_INVOICE_ACTION_EV_EOT'); $tags .= ',eot'; } elseif (isset($response['duplicate'])) { $mi_event = '_payment_duplicate'; $event .= JText::_('AEC_MSG_PROC_INVOICE_ACTION_EV_DUPLICATE'); $tags .= ',duplicate'; } elseif (isset($response['null'])) { $mi_event = '_payment_null'; $event .= JText::_('AEC_MSG_PROC_INVOICE_ACTION_EV_NULL'); $tags .= ',null'; } elseif (isset($response['error']) && isset($response['errormsg'])) { $mi_event = '_payment_error'; $event .= 'Error:' . $response['errormsg']; $tags .= ',error'; $level = 128; $notificationerror = $response['errormsg']; } else { $event .= JText::_('AEC_MSG_PROC_INVOICE_ACTION_EV_U_ERROR'); $tags .= ',general_error'; $level = 128; $notificationerror = 'General Error. Please contact the System Administrator.'; } } if (!empty($mi_event) && !empty($this->usage)) { $objUsage = new SubscriptionPlan(); $objUsage->load($this->usage); $exchange = $silent = null; $objUsage->triggerMIs($mi_event, $metaUser, $exchange, $this, $response, $silent); } if (isset($response['explanation'])) { $event .= " (" . $response['explanation'] . ")"; } $eventlog = new eventLog(); $eventlog->issue($short, $tags, $event, $level, $params, $forcedisplay); if (!empty($notificationerror)) { $InvoiceFactory->pp->notificationError($response, $notificationerror); } else { $InvoiceFactory->pp->notificationSuccess($response); } return $response; }
public function clear($invoice_number, $applyplan, $task) { $invoiceid = aecInvoiceHelper::InvoiceIDfromNumber($invoice_number, 0, true); $userid = ''; if ($invoiceid) { $objInvoice = new Invoice(); $objInvoice->load($invoiceid); $pp = new stdClass(); $pp->id = 0; $pp->processor_name = 'none'; if ($applyplan) { $objInvoice->pay(); } else { $objInvoice->setTransactionDate(); } $history = new logHistory(); $history->entryFromInvoice($objInvoice, null, $pp); if (strcmp($task, 'editMembership') == 0) { $userid = '&userid=' . $objInvoice->userid; } } aecRedirect('index.php?option=com_acctexp&task=' . $task . $userid, JText::_('AEC_MSG_INVOICE_CLEARED')); }
public function createPayments() { if (!$_POST['create_payments']) { return; } $db = JFactory::getDBO(); $amountlist = array(); for ($i = $this->range['plans']['start']; $i <= $this->range['plans']['end']; $i++) { $amountlist[$i] = array(); $modlist[$i]['sin'] = rand(0, 360); $modlist[$i]['speed'] = rand(0, 1000) / 100; $modlist[$i]['multi'] = rand(0, 100) / 50; } $start_date = strtotime($_POST['start'] . '-01-01 00:00:00'); $years = (int) date('Y') - $_POST['start']; $days = $years * 365 + date('z') + 1; $saleslist = $this->stream_layers($amountlist, $days + 2, 1); $plandetails = array(); $query = 'SELECT MIN(id)' . ' FROM #__acctexp_log_history'; $db->setQuery($query); $this->range['payments']['start'] = $db->loadResult() + 1; for ($i = 1; $i <= $days; $i++) { $dtime = strtotime("+" . $i . " days", $start_date); foreach ($modlist as $k => $v) { $modlist[$k]['sin'] += $modlist[$k]['speed']; $modlist[$k]['sin'] = $modlist[$k] % 360; } foreach ($saleslist as $plan => $dayslist) { if (!isset($plandetails[$plan])) { $splan = new SubscriptionPlan(); $splan->load($plan); $plandetails[$plan] = array('name' => $splan->name, 'cost' => $splan->params['full_amount']); } // Add some sine modification $dsales = (int) ($dayslist[$i] * ((1 + sin($modlist[$plan]['sin'])) * $modlist[$plan]['multi'])); // Less sales on the weekends if (date('N', $dtime) > 5) { $dsales = (int) ($dsales / rand(1, 4)); } for ($j = 0; $j < $dsales; $j++) { $found = false; while (!$found) { $userid = rand($this->range['users']['start'], $this->range['users']['end']); $db->setQuery('SELECT id FROM #__users WHERE `id` = \'' . $userid . '\''); $check = $db->loadResult(); $found = !empty($check); } $invoice = new Invoice(); $invoice->userid = $userid; $invoice->usage = $plan; $invoice->method = 'none'; $invoice->invoice_number = $invoice->generateInvoiceNumber(); $invoice->storeload(); $invoice->computeAmount(); $invoice->pay(); $invoice->transaction_date = date('Y-m-d H:i:s', $dtime + rand(0, 86400)); $invoice->check(); $invoice->store(); $pp = new stdClass(); $pp->id = 0; $pp->processor_name = 'none'; $history = new logHistory(); $history->entryFromInvoice($invoice, array("dummy" => "data"), $pp); $history->transaction_date = date('Y-m-d H:i:s', $dtime + rand(0, 86400)); $history->check(); $history->store(); } } } $query = 'SELECT MAX(id)' . ' FROM #__acctexp_log_history'; $db->setQuery($query); $this->range['payments']['end'] = $db->loadResult(); }