How can I get customer payment method ids from AuthorizeNetCIM_Response object?

There's a method in AuthorizeNetCIM_Response which is supposed to return payment method ids

public function getCustomerPaymentProfileIds()
{
    $ids = (array)$this->xml->customerPaymentProfileIdList;
    return $ids["numericString"];
}

but calling this function results in error

Notice: Undefined index: numericString

The response object outputs as:

AuthorizeNet_AuthorizeNetCIMResponse Object
(
    [xml] => SimpleXMLElement Object
        (
            [messages] => SimpleXMLElement Object
                (
                    [resultCode] => Ok
                    [message] => SimpleXMLElement Object
                        (
                            [code] => I00001
                            [text] => Successful.
                        )
                )
            [profile] => SimpleXMLElement Object
                (
                    [merchantCustomerId] => 10
                    [email] => user@nine.com
                    [customerProfileId] => 25441529
                    [paymentProfiles] => Array
                        (
                            [0] => SimpleXMLElement Object
                                (
                                    [billTo] => SimpleXMLElement Object
                                        (
                                            [firstName] => 
                                            [lastName] => 
                                            [address] => 
                                            [city] => 
                                            [zip] => 
                                            [country] => 
                                            [phoneNumber] => 
                                        )
                                    [customerPaymentProfileId] => 23298664
                                    [payment] => SimpleXMLElement Object
                                        (
                                            [creditCard] => SimpleXMLElement Object
                                                (
                                                    [cardNumber] => XXXX2224
                                                    [expirationDate] => XXXX
                                                )
                                        )
                                )
                            [1] => SimpleXMLElement Object
                                (
                                    [customerType] => individual
                                    [billTo] => SimpleXMLElement Object
                                        (
                                            [firstName] => Test
                                            [lastName] => Individual
                                            [company] => SimpleXMLElement Object
                                                (
                                                )

                                            [address] => 
                                            [city] => 
                                            [state] => 
                                            [zip] => 
                                            [country] => 
                                            [phoneNumber] => SimpleXMLElement Object
                                                (
                                                )

                                            [faxNumber] => SimpleXMLElement Object
                                                (
                                                )
                                        )
                                    [customerPaymentProfileId] => 23299421
                                    [payment] => SimpleXMLElement Object
                                        (
                                            [creditCard] => SimpleXMLElement Object
                                                (
                                                    [cardNumber] => XXXX0027
                                                    [expirationDate] => XXXX
                                                )
                                        )
                                )
                        )
                )
        )

and I supposed to get the array of paymentProfiles as

$response->xml->profile->paymentProfiles;

but it only returning the first element of paymentProfiles not an array.

有帮助吗?

解决方案

Since there can be more then one, as per your example, you need to loop through each profile to get that information:

$paymentProfileIds = array();
foreach ($response->xml->profile->paymentProfiles AS $profile) {
    $paymentProfileIds[] = (string) $profile->customerPaymentProfileId;
}

print_r($paymentProfileIds);
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top