-2

How can I access the TXN_ID in the following object with PHP? Below is a print_r of the object:

$txn_object = $txn_params[last_payment];
error_log( print_r($txn_object,true) );

I get this in the error log:

EE_Payment Object
(
    [_props_n_values_provided_in_constructor:protected] => Array(
        [PAY_ID] => 4168
        [TXN_ID] => 746919
        [STS_ID] => PAP
        [PAY_timestamp] => 2017-08-29 14:06:26
        [PAY_source] => CART
        [PAY_amount] => 24.000
        [PMD_ID] => 11
        [PAY_gateway_response] => submitted_for_settlement
        [PAY_txn_id_chq_nmbr] => 96g71gxv
        [PAY_po_number] => 
        [PAY_extra_accntng] => 
        [PAY_details] => 
    )
)

I've tried a few things, but can't seem to get that value but comes back blank:

$txn_object->_props_n_values_provided_in_constructor[0]->TXN_ID
rwfitzy
  • 413
  • 5
  • 16

2 Answers2

3

You can't access to TXN_ID element from outside of the Object (class), because the _props_n_values_provided_in_constructor property is protected.

  • public scope to make that variable/function available from anywhere, other classes and instances of the object.
  • private scope when you want your variable/function to be visible in its own class only.
  • protected scope when you want to make your variable/function visible in all classes that extend current class including the parent class.

https://stackoverflow.com/a/4361582/5465663

Take a look into into PHP documentation.

Neodan
  • 5,154
  • 2
  • 27
  • 38
2

Stop using print_r to reverse-engineer objects and read the documentation/source.

You've got an EE_Payment object, which is part of the Event Espresso library. The source of this class is available here, and shows a method called TXN_ID to return the transaction ID.

$id = $txn_object->TXN_ID();

will get you what you need.

iainn
  • 16,826
  • 9
  • 33
  • 40