/**
  * update registration REG_paid field after refund and link registration with payment
  *
  * @param EE_Registration $registration
  * @param EE_Payment      $payment
  * @param float           $available_refund_amount - IMPORTANT !!! SEND AVAILABLE REFUND AMOUNT AS A POSITIVE NUMBER
  * @return float
  * @throws \EE_Error
  */
 public function process_registration_refund(EE_Registration $registration, EE_Payment $payment, $available_refund_amount = 0.0)
 {
     //EEH_Debug_Tools::printr( $payment->amount(), '$payment->amount()', __FILE__, __LINE__ );
     if ($registration->paid() > 0) {
         // ensure $available_refund_amount is NOT negative
         $available_refund_amount = (double) abs($available_refund_amount);
         // don't allow refund amount to exceed the available payment amount, OR the amount paid
         $refund_amount = min($available_refund_amount, (double) $registration->paid());
         // update $available_payment_amount
         $available_refund_amount -= $refund_amount;
         //calculate and set new REG_paid
         $registration->set_paid($registration->paid() - $refund_amount);
         // convert payment amount back to a negative value for storage in the db
         $refund_amount = (double) abs($refund_amount) * -1;
         // now save it
         $this->_apply_registration_payment($registration, $payment, $refund_amount);
     }
     return $available_refund_amount;
 }