문제

I'm working with SOAP to communicate with a payment platform, I'm nearly there, the only problem remaining is that i can't seem to translate the answer from the server into an action

I need to check if the 'payment' method exists

i've tried using method_exists as follows

if(property_exists($response, 'payment')){
    echo 'PAYMENT EXISTS';
} else {
    echo 'PAYMENT doesnt exist';
}

but it's always returning payment doesn't exist, Am i doing something wrong to check that? Thanks!

Here's a print_r of the $response object

stdClass Object
(
[statusSuccess] => stdClass Object
    (
        [success] => stdClass Object
            (
                [_] => Operation successful.
                [code] => SUCCESS
            )

        [report] => stdClass Object
            (
                [approximateTotals] => stdClass Object
                    (
                        [totalRegistered] => 1500
                        [totalShopperPending] => 0
                        [totalAcquirerPending] => 0
                        [totalAcquirerApproved] => 1500
                        [totalCaptured] => 0
                        [totalRefunded] => 0
                        [totalChargedback] => 0
                        [exchangedTo] => EUR
                        [exchangeRateDate] => 2014-04-01 13:02:30
                    )

                [payment] => stdClass Object
                    (
                        [id] => 4906949180
                        [paymentMethod] => MASTERCARD
                        [authorization] => stdClass Object
                            (
                                [status] => AUTHORIZED
                                [amount] => stdClass Object
                                    (
                                        [_] => 1500
                                        [currency] => EUR
                                    )

                                [confidenceLevel] => ACQUIRER_APPROVED
                                [capture] => stdClass Object
                                    (
                                        [status] => NEW
                                        [amount] => stdClass Object
                                            (
                                                [_] => 1500
                                                [currency] => EUR
                                            )

                                    )

                            )

                    )

            )

    )

)
도움이 되었습니까?

해결책

Try this:

if (
   property_exists($response, 'statusSuccess')
   && property_exists($response->statusSuccess, 'report')
   && property_exists($response->statusSuccess->report, 'payment')
) {
    echo 'payment method exists';
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top