/** * 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 !'); }
/** * Update payment status * * @param mixed $paymentData Payment data * * @return bool */ public static function updatePaymentData($paymentData) { if (is_object($paymentData)) { $paymentData = JArrayHelper::fromObject($paymentData); } // If there is no payment Id, we are checking if that payment data is saved under another row if (empty($paymentData['id'])) { $oldPayment = self::getPaymentByExtensionId($paymentData['extension_name'], $paymentData['order_id']); // We add all relevant data to the object if ($oldPayment) { $paymentData['id'] = $oldPayment->id; } } else { $oldPayment = self::getPaymentById($paymentData['id']); } if ($oldPayment) { // We are in different payment if (isset($paymentData['payment_name']) && !empty($oldPayment->payment_name) && $oldPayment->payment_name != $paymentData['payment_name']) { // We check for status in old Payment data, if it is confirmed, then this order is already processed and should not be processed again if (in_array($oldPayment->status, array(RApiPaymentStatus::getStatusCompleted(), RApiPaymentStatus::getStatusCanceled_Reversal()))) { return false; } } } // Set status to created if not set if (empty($paymentData['status'])) { $paymentData['status'] = RApiPaymentStatus::getStatusCreated(); } /** @var RedcoreModelPayment $model */ $model = RModelAdmin::getAdminInstance('Payment', array(), 'com_redcore'); if (!$model->save($paymentData)) { return false; } $paymentId = isset($paymentData['id']) ? $paymentData['id'] : (int) $model->getState('payment.id'); if (!empty($paymentData['id'])) { // We unset the object so we can load a fresh one on next request unset(self::$payments[$paymentData['id']]); } return $paymentId; }