0

i've a peace of code that catch an Exception. I get the error body with $e->getMessage() and the result is the following string. Now i want to access to customer_email how can i do this?

i receive this responde from Stripe API Request

stdClass Object
(
    [error] => stdClass Object
        (
            [charge] => ch_1F1UTrAMXDCOYAqpNzJLKFff
            [code] => card_declined
            [message] => Your card was declined.
            [payment_intent] => stdClass Object
                (
                    [id] => pi_1F1IwGAMXDCOYAqpSwoFHsN1
                    [amount_capturable] => 0
                    [metadata] => stdClass Object
                        (
                            [customer_name] => C B
                            [customer_email] => pippo@gmail.com
                            [order_id] => 363
                        )
                    [payment_method_options] => stdClass Object
                        (
                            [card] => stdClass Object
                                (
                                    [request_three_d_secure] => automatic
                                )
                        )
                    [payment_method_types] => Array
                        (
                            [0] => card
                        )
                    [receipt_email] => 
                    [review] => 
                )
            [source] => stdClass Object
                (
                    [id] => src_1F1UTnAMXDCOYAqpYOtW3GyR
                    [object] => source
                    [card] => stdClass Object
                        (
                            [exp_month] => 12
                            [exp_year] => 2020
                            [last4] => 9987
                            [country] => US
                        )
                    [client_secret] => src_client_secret_FWXYzYw3vPwPe4CzyveJdVMP
                    [created] => 1564389915
                    [flow] => none
                    [metadata] => stdClass Object
                        (
                        )
                        )
                [type] => card_error
            )

    )
  • Possible duplicate of [How to access a property of an object (stdClass Object) member/element of an array?](https://stackoverflow.com/questions/21168422/how-to-access-a-property-of-an-object-stdclass-object-member-element-of-an-arr) – LLJ97 Jul 29 '19 at 09:34
  • That looks like a var_dump of an exception object or something … are you getting _all that_ as the _message_ of the exception? That would be rather weird. As if someone had “wrapped” one exception in text form into another. – misorude Jul 29 '19 at 09:35
  • are you getting all that as the message of the exception? yes i receive that from $e->getmessage() – Cesario Bortone Jul 29 '19 at 09:43
  • `->error->payment_intent->metadata->customer_email` looks like the trail of it – Jaquarh Jul 29 '19 at 09:46
  • i receive Trying to get property 'error' of non-object Trying to get property 'payment_intent' of non-object Trying to get property 'metadata' of non-object Trying to get property 'customer_email' of non-object – Cesario Bortone Jul 29 '19 at 09:50
  • They're probably protected or private properties, is there not a method you use to get the data? ie `->meta()` or similar in the docs? – Jaquarh Jul 29 '19 at 09:55
  • In the docs, it says to capture an error `catch(\Stripe\Error\Card $e)` then use `$e->getJsonBody()` which gives an array, not an Object unless you're casting it to an object `(object) $e->getJsonBody()` – Jaquarh Jul 29 '19 at 09:59

0 Answers0