/** * 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 !'); }
/** * Gets payment for current operation * * @return mixed RApi object with information on success, boolean false on failure. */ public function getPayment() { if (!empty($this->paymentObject)) { return $this->paymentObject; } if (!empty($this->paymentId)) { $this->paymentObject = RApiPaymentHelper::getPaymentById($this->paymentId); } if (empty($this->paymentObject) && (!empty($this->orderId) && !empty($this->extensionName))) { $this->paymentObject = RApiPaymentHelper::getPaymentByExtensionId($this->extensionName, $this->orderId); } // Set up default variables if not set if ($this->paymentObject) { if (empty($this->paymentName)) { $this->paymentName = $this->paymentObject->payment_name; } $this->extensionName = $this->paymentObject->extension_name; $this->ownerName = $this->paymentObject->owner_name; $this->orderId = $this->paymentObject->order_id; $this->paymentId = $this->paymentObject->id; } return $this->paymentObject; }
/** * Check for notifications from Payment Gateway * * @param string $paymentName Name of the extension * @param int $paymentId Payment id to check * @param array &$status Payment check status * * @return mixed */ public function onRedpaymentCheckPayment($paymentName, $paymentId, &$status) { if ($paymentName != $this->paymentName) { return null; } $payment = RApiPaymentHelper::getPaymentById($paymentId); $this->setRedpaymentOptions($payment->extension_name, $payment->owner_name); // Plugin is disabled (optionally for this extension) if (!$this->paymentHelper->pluginEnabled) { return null; } // Check for new status $this->paymentHelper->handleCheckPayment($paymentId, $status); // We call extension helper file to trigger afterHandleCheckPayment method if needed RApiPaymentHelper::triggerExtensionHelperMethod($payment->extension_name, 'afterHandleCheckPayment', $payment->owner_name, $paymentName, $payment, $status); }