コード例 #1
0
 /**
  * This should be called each time there may have been an update to a
  * payment on a transaction (ie, we asked for a payment to process a
  * payment for a transaction, or we told a payment method about an IPN, or
  * we told a payment method to
  * "finalize_payment_for" (a transaction), or we told a payment method to
  * process a refund. This should handle firing the correct hooks to
  * indicate
  * what exactly happened and updating the transaction appropriately). This
  * could be integrated directly into EE_Transaction upon save, but we want
  * this logic to be separate from 'normal' plain-jane saving and updating
  * of transactions and payments, and to be tied to payment processing.
  * Note: this method DOES NOT save the payment passed into it. It is the responsibility
  * of previous code to decide whether or not to save (because the payment passed into
  * this method might be a temporary, never-to-be-saved payment from an offline gateway,
  * in which case we only want that payment object for some temporary usage during this request,
  * but we don't want it to be saved).
  *
  * @param EE_Transaction|int $transaction
  * @param EE_Payment     $payment
  * @param boolean        $update_txn
  *                        whether or not to call
  *                        EE_Transaction_Processor::
  *                        update_transaction_and_registrations_after_checkout_or_payment()
  *                        (you can save 1 DB query if you know you're going
  *                        to save it later instead)
  * @param bool           $IPN
  *                        if processing IPNs or other similar payment
  *                        related activities that occur in alternate
  *                        requests than the main one that is processing the
  *                        TXN, then set this to true to check whether the
  *                        TXN is locked before updating
  * @throws \EE_Error
  */
 public function update_txn_based_on_payment($transaction, $payment, $update_txn = true, $IPN = false)
 {
     $do_action = 'AHEE__EE_Payment_Processor__update_txn_based_on_payment__not_successful';
     /** @type EE_Transaction $transaction */
     $transaction = EEM_Transaction::instance()->ensure_is_obj($transaction);
     // can we freely update the TXN at this moment?
     if ($IPN && $transaction->is_locked()) {
         // don't update the transaction at this exact moment
         // because the TXN is active in another request
         EE_Cron_Tasks::schedule_update_transaction_with_payment(time(), $transaction->ID(), $payment->ID());
     } else {
         // verify payment and that it has been saved
         if ($payment instanceof EE_Payment && $payment->ID()) {
             if ($payment->payment_method() instanceof EE_Payment_Method && $payment->payment_method()->type_obj() instanceof EE_PMT_Base) {
                 $payment->payment_method()->type_obj()->update_txn_based_on_payment($payment);
                 // update TXN registrations with payment info
                 $this->process_registration_payments($transaction, $payment);
             }
             $do_action = $payment->just_approved() ? 'AHEE__EE_Payment_Processor__update_txn_based_on_payment__successful' : $do_action;
         } else {
             // send out notifications
             add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true');
             $do_action = 'AHEE__EE_Payment_Processor__update_txn_based_on_payment__no_payment_made';
         }
         // if this is an IPN, then we want to know the initial TXN status prior to updating the TXN
         // so that we know whether the status has changed and notifications should be triggered
         if ($IPN) {
             /** @type EE_Transaction_Processor $transaction_processor */
             $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor');
             $transaction_processor->set_old_txn_status($transaction->status_ID());
         }
         if ($payment->status() !== EEM_Payment::status_id_failed) {
             /** @type EE_Transaction_Payments $transaction_payments */
             $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments');
             // set new value for total paid
             $transaction_payments->calculate_total_payments_and_update_status($transaction);
             // call EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment() ???
             if ($update_txn) {
                 $this->_post_payment_processing($transaction, $payment, $IPN);
             }
         }
         // granular hook for others to use.
         do_action($do_action, $transaction, $payment);
         do_action('AHEE_log', __CLASS__, __FUNCTION__, $do_action, '$do_action');
         //global hook for others to use.
         do_action('AHEE__EE_Payment_Processor__update_txn_based_on_payment', $transaction, $payment);
     }
 }
コード例 #2
0
 /**
  * update_transaction_with_payment
  *
  * loops through the self::$_abandoned_transactions array
  * and attempts to finalize any TXNs that have not been completed
  * but have had their sessions expired, most likely due to a user not
  * returning from an off-site payment gateway
  */
 public static function update_transaction_with_payment()
 {
     // are there any TXNs that need cleaning up ?
     if (!empty(self::$_update_transactions_with_payment)) {
         /** @type EE_Payment_Processor $payment_processor */
         $payment_processor = EE_Registry::instance()->load_core('Payment_Processor');
         // set revisit flag for payment processor
         $payment_processor->set_revisit(false);
         // load EEM_Transaction
         EE_Registry::instance()->load_model('Transaction');
         foreach (self::$_update_transactions_with_payment as $TXN_ID => $payment) {
             // reschedule the cron if we can't hit the db right now
             if (!EE_Maintenance_Mode::instance()->models_can_query()) {
                 // reset cron job for updating the TXN
                 EE_Cron_Tasks::schedule_update_transaction_with_payment(time() + 10 * MINUTE_IN_SECONDS + 1, $TXN_ID, $payment);
                 continue;
             }
             $transaction = EEM_Transaction::instance()->get_one_by_ID($TXN_ID);
             // verify transaction
             if ($transaction instanceof EE_Transaction) {
                 // now try to update the TXN with any payments
                 $payment_processor->update_txn_based_on_payment($transaction, $payment, true, true);
             }
             unset(self::$_update_transactions_with_payment[$TXN_ID]);
         }
     }
 }