/** * Message triggers for manual payment applied by admin * @param EE_Payment $payment EE_payment object * @return bool success/fail */ public static function process_admin_payment(EE_Payment $payment) { EE_Registry::instance()->load_helper('MSG_Template'); //we need to get the transaction object $transaction = $payment->transaction(); if ($transaction instanceof EE_Transaction) { $data = array($transaction, $payment); $message_type = EEH_MSG_Template::convert_payment_status_to_message_type($payment->STS_ID()); //if payment amount is less than 0 then switch to payment_refund message type. $message_type = $payment->amount() < 0 ? 'payment_refund' : $message_type; //if payment_refund is selected, but the status is NOT accepted. Then change message type to false so NO message notification goes out. $message_type = $message_type == 'payment_refund' && $payment->STS_ID() != EEM_Payment::status_id_approved ? false : $message_type; self::_load_controller(); self::$_MSG_PROCESSOR->generate_for_all_active_messengers($message_type, $data); //get count of queued for generation $count_to_generate = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(array(EEM_Message::status_incomplete, EEM_Message::status_idle)); if ($count_to_generate > 0 && self::$_MSG_PROCESSOR->get_queue()->get_message_repository()->count() !== 0) { add_filter('FHEE__EE_Admin_Page___process_admin_payment_notification__success', '__return_true'); return true; } else { $count_failed = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::instance()->stati_indicating_failed_sending()); /** * Verify that there are actually errors. If not then we return a success message because the queue might have been emptied due to successful * IMMEDIATE generation. */ if ($count_failed > 0) { EE_Error::add_error(sprintf(_n('The payment notification generation failed.', '%d payment notifications failed being sent.', $count_failed, 'event_espresso'), $count_failed), __FILE__, __FUNCTION__, __LINE__); return false; } else { add_filter('FHEE__EE_Admin_Page___process_admin_payment_notification__success', '__return_true'); return true; } } } else { EE_Error::add_error('Unable to generate the payment notification because the given value for the transaction is invalid.', 'event_espresso'); return false; } }