/**
  * test_build_payment_json_response_for_payment
  * @since    4.8
  * @group    8620
  */
 public function test_build_payment_json_response_for_payment()
 {
     $this->_admin_page = new Transactions_Admin_Page_Mock();
     $this->_setup_standard_transaction_and_payment(40.0, 4, 15.0);
     // need to make sure relation is set between payment and payment method
     $this->_payment->_add_relation_to($this->_payment_method(), 'Payment_Method');
     $registrations = $this->_get_x_number_of_registrations_from_transaction($this->_transaction, 1);
     $this->_apply_payment_to_registrations($registrations);
     $json_response_data = $this->_admin_page->build_payment_json_response($this->_payment);
     $pay_status = EEM_Payment::instance()->status_array(true);
     $this->assertEquals(15.0, $json_response_data['amount']);
     // total paid is still zero, because we haven't actually updated the TXN with the payment info
     $this->assertEquals(0, $json_response_data['total_paid']);
     $this->assertEquals(EEM_Transaction::incomplete_status_code, $json_response_data['txn_status']);
     $this->assertEquals(EEM_Payment::status_id_approved, $json_response_data['pay_status']);
     $this->assertEquals(EEM_Payment::status_id_approved, $json_response_data['STS_ID']);
     $this->assertEquals($pay_status[EEM_Payment::status_id_approved], $json_response_data['status']);
     $this->assertEquals($this->_payment->ID(), $json_response_data['PAY_ID']);
     $this->assertEquals($this->_payment->timestamp('Y-m-d', 'h:i a'), $json_response_data['date']);
     $this->assertEquals(strtoupper($this->_payment->source()), $json_response_data['method']);
     $this->assertEquals($this->_payment_method()->ID(), $json_response_data['PM_ID']);
     $this->assertEquals($this->_payment_method()->admin_name(), $json_response_data['gateway']);
     $this->assertEquals($this->_payment->gateway_response(), $json_response_data['gateway_response']);
     $this->assertEquals($this->_payment->txn_id_chq_nmbr(), $json_response_data['txn_id_chq_nmbr']);
     $this->assertEquals($this->_payment->po_number(), $json_response_data['po_number']);
     $this->assertEquals($this->_payment->extra_accntng(), $json_response_data['extra_accntng']);
     $this->assertEquals($this->_payment->extra_accntng(), $json_response_data['extra_accntng']);
     // will validate $json_response_data[ 'registrations' ] in test_registration_payment_data_array()
 }
 /**
  * _build_payment_json_response
  *
  * @access public
  * @param \EE_Payment $payment
  * @param array       $REG_IDs
  * @param bool | null        $delete_txn_reg_status_change
  * @return array
  */
 protected function _build_payment_json_response(EE_Payment $payment, $REG_IDs = array(), $delete_txn_reg_status_change = null)
 {
     // was the payment deleted ?
     if (is_bool($delete_txn_reg_status_change)) {
         return array('PAY_ID' => $payment->ID(), 'amount' => $payment->amount(), 'total_paid' => $payment->transaction()->paid(), 'txn_status' => $payment->transaction()->status_ID(), 'pay_status' => $payment->STS_ID(), 'registrations' => $this->_registration_payment_data_array($REG_IDs), 'delete_txn_reg_status_change' => $delete_txn_reg_status_change);
     } else {
         $this->_get_payment_status_array();
         return array('amount' => $payment->amount(), 'total_paid' => $payment->transaction()->paid(), 'txn_status' => $payment->transaction()->status_ID(), 'pay_status' => $payment->STS_ID(), 'PAY_ID' => $payment->ID(), 'STS_ID' => $payment->STS_ID(), 'status' => self::$_pay_status[$payment->STS_ID()], 'date' => $payment->timestamp('Y-m-d', 'h:i a'), 'method' => strtoupper($payment->source()), 'PM_ID' => $payment->payment_method() ? $payment->payment_method()->ID() : 1, 'gateway' => $payment->payment_method() ? $payment->payment_method()->admin_name() : __("Unknown", 'event_espresso'), 'gateway_response' => $payment->gateway_response(), 'txn_id_chq_nmbr' => $payment->txn_id_chq_nmbr(), 'po_number' => $payment->po_number(), 'extra_accntng' => $payment->extra_accntng(), 'registrations' => $this->_registration_payment_data_array($REG_IDs));
     }
 }