/** * Entry point for the script * * @return void * * @since 2.5 */ public function doExecute() { JFactory::getApplication('site'); JPluginHelper::importPlugin('redcore'); JPluginHelper::importPlugin('redpayment'); // Set up statuses that are in their final stage $this->finalStatuses = array(RApiPaymentStatus::getStatusCompleted(), RApiPaymentStatus::getStatusCanceled_Reversal(), RApiPaymentStatus::getStatusDenied(), RApiPaymentStatus::getStatusExpired(), RApiPaymentStatus::getStatusRefunded(), RApiPaymentStatus::getStatusReversed()); $this->out('============================'); $this->out('Check Payments status change'); $this->out('============================'); $payments = $this->getPaymentsForChecking(); $this->out('Number of payments for checking:' . count($payments)); $this->out('============================'); if (!empty($payments)) { foreach ($payments as $payment) { // Print out payment info $this->out('============================'); $this->out(sprintf('Check for order name "%s" for extension "%s" using "%s" payment plugin:', $payment->order_name, $payment->extension_name, $payment->payment_name)); $this->out('============================'); // Preform check $status = RApiPaymentHelper::checkPayment($payment->id); // Print out status result foreach ($status as $statusKey => $message) { if (is_array($message)) { foreach ($status as $key => $value) { $this->out($key . ': ' . $value); } } else { $this->out($statusKey . ': ' . $message); } } // Subtract retry count or reset it $paymentNew = RApiPaymentHelper::getPaymentById($payment->id); if (!in_array($paymentNew->status, $this->finalStatuses)) { // We are still not done, we will subtract retry counter for this payment $paymentNew->retry_counter -= 1; RApiPaymentHelper::updatePaymentCounter($paymentNew->id, $paymentNew->retry_counter); $this->out('Retry checks left: ' . $paymentNew->retry_counter); } $this->out('============================'); } } $this->out('============================'); $this->out('Done !'); }