0

Hello I've a respone object from outsource and I need to reach sub elements of the object.

Here is response I have :

object(Iyzipay\Model\Payment)#13 (32) {
  ["price":"Iyzipay\Model\PaymentResource":private]=>
  NULL
  ["paidPrice":"Iyzipay\Model\PaymentResource":private]=>
  NULL
  ["locale":"Iyzipay\IyzipayResource":private]=>
  string(2) "tr"
  ["systemTime":"Iyzipay\IyzipayResource":private]=>
  int(1568548407994)
  ["conversationId":"Iyzipay\IyzipayResource":private]=>
  string(13) "***_46_25"
  ["rawResult":"Iyzipay\ApiResource":private]=>
  string(156) "{"status":"failure","errorCode":"12","errorMessage":"Kart numarası geçersizdir","locale":"tr","systemTime":1568548407994,"conversationId":"***_46_25"}"
}

Here is php code :

$payment = \Iyzipay\Model\Payment::create($request, Config::options());

I have to reach elements like $payment->rawResult or $payment->price etc.

However I try lots of things to reach it but there is no way. Probably I don't know the reaching issue about object. Is there anyone know ?

I will interpret the response with make subobject as variable. Also I tried to make array from this object but there is no way too.

furkeen
  • 411
  • 5
  • 11

1 Answers1

1

Those properties are private, so they can't be accessed directly from outside the class. Howwever, the class Iyzipay\Model\Payment extends other classes that extends even more classes. After following the code, I found that there are getters for most properties.

To get the two properties you mentioned, use:

$price     = $payment->getPrice();
$rawResult = $payment->getRawResult();

You can read more about property- and method visibility in the manual: https://www.php.net/manual/en/language.oop5.visibility.php

M. Eriksson
  • 13,450
  • 4
  • 29
  • 40