Reply
Member
Posts: 1
Registered: ‎03-13-2017

Fatal error: Call to a member function id() on null

[ Edited ]

Hi,

when I want to get value from response data and sometimes which field/s does not exists in response JSON, then it throws error

Fatal error: Call to a member function id() on null .....

example for getTransactionList() calls it is responding following JSON which subscription id is not exists but in others reponse exist. Because I want to show report for all batch transactions through loop I should handle this error. 

I think such type of exception should handle SDK it self.

 

HOW TO HANDLE SUCH TYPEOF ERROR IF THERE DONT HAVE ANY FIELD IN RESPONSE.

I am using php SDK.

 

        echo "    ->Transaction Id  : " . $transaction->getTransId() . "<br>"; 
        // print_r($transaction->getSubscription()->id() );
        echo "    ->Subscription Id  : " . $transaction->getSubscription()->getId() . "<br>"; 

this repsponse getting error: 

Fatal error: Call to a member function getId() on null in /Applications/XAMPP/xamppfiles/htdocs/streetreturn/system_3_0_4/libraries/Subs_auth_net.php on line 513
A PHP Error was encountered

Severity: Warning

Message: Cannot modify header information - headers already sent by (output started at /Applications/XAMPP/xamppfiles/htdocs/streetreturn/system_3_0_4/libraries/Subs_auth_net.php:500)

Filename: core/Common.php

Line Number: 573

Backtrace:

net\authorize\api\contract\v1\GetTransactionListResponse Object ( [transactions:net\authorize\api\contract\v1\GetTransactionListResponse:private] => Array ( [0] => net\authorize\api\contract\v1\TransactionSummaryType Object ( [transId:net\authorize\api\contract\v1\TransactionSummaryType:private] => 60019124427 [submitTimeUTC:net\authorize\api\contract\v1\TransactionSummaryType:private] => DateTime Object ( [date] => 2017-03-02 18:23:49.000000 [timezone_type] => 2 [timezone] => Z ) [submitTimeLocal:net\authorize\api\contract\v1\TransactionSummaryType:private] => DateTime Object ( [date] => 2017-03-02 10:23:49.000000 [timezone_type] => 3 [timezone] => UTC ) [transactionStatus:net\authorize\api\contract\v1\TransactionSummaryType:private] => settledSuccessfully [invoiceNumber:net\authorize\api\contract\v1\TransactionSummaryType:private] => [firstName:net\authorize\api\contract\v1\TransactionSummaryType:private] => [lastName:net\authorize\api\contract\v1\TransactionSummaryType:private] => [accountType:net\authorize\api\contract\v1\TransactionSummaryType:private] => Visa [accountNumber:net\authorize\api\contract\v1\TransactionSummaryType:private] => XXXX1111 [settleAmount:net\authorize\api\contract\v1\TransactionSummaryType:private] => 151.51 [marketType:net\authorize\api\contract\v1\TransactionSummaryType:private] => eCommerce [product:net\authorize\api\contract\v1\TransactionSummaryType:private] => Card Not Present [mobileDeviceId:net\authorize\api\contract\v1\TransactionSummaryType:private] => [subscription:net\authorize\api\contract\v1\TransactionSummaryType:private] => [hasReturnedItems:net\authorize\api\contract\v1\TransactionSummaryType:private] => [fraudInformation:net\authorize\api\contract\v1\TransactionSummaryType:private] => ) [1] => net\authorize\api\contract\v1\TransactionSummaryType Object ( [transId:net\authorize\api\contract\v1\TransactionSummaryType:private] => 60019123728 [submitTimeUTC:net\authorize\api\contract\v1\TransactionSummaryType:private] => DateTime Object ( [date] => 2017-03-02 18:08:27.000000 [timezone_type] => 2 [timezone] => Z ) [submitTimeLocal:net\authorize\api\contract\v1\TransactionSummaryType:private] => DateTime Object ( [date] => 2017-03-02 10:08:27.000000 [timezone_type] => 3 [timezone] => UTC ) [transactionStatus:net\authorize\api\contract\v1\TransactionSummaryType:private] => settledSuccessfully [invoiceNumber:net\authorize\api\contract\v1\TransactionSummaryType:private] => [firstName:net\authorize\api\contract\v1\TransactionSummaryType:private] => [lastName:net\authorize\api\contract\v1\TransactionSummaryType:private] => [accountType:net\authorize\api\contract\v1\TransactionSummaryType:private] => Visa [accountNumber:net\authorize\api\contract\v1\TransactionSummaryType:private] => XXXX1111 [settleAmount:net\authorize\api\contract\v1\TransactionSummaryType:private] => 151.51 [marketType:net\authorize\api\contract\v1\TransactionSummaryType:private] => eCommerce [product:net\authorize\api\contract\v1\TransactionSummaryType:private] => Card Not Present [mobileDeviceId:net\authorize\api\contract\v1\TransactionSummaryType:private] => [subscription:net\authorize\api\contract\v1\TransactionSummaryType:private] => [hasReturnedItems:net\authorize\api\contract\v1\TransactionSummaryType:private] => [fraudInformation:net\authorize\api\contract\v1\TransactionSummaryType:private] => ) ) [totalNumInResultSet:net\authorize\api\contract\v1\GetTransactionListResponse:private] => 2 [refId:net\authorize\api\contract\v1\ANetApiResponseType:private] => [messages:net\authorize\api\contract\v1\ANetApiResponseType:private] => net\authorize\api\contract\v1\MessagesType Object ( [resultCode:net\authorize\api\contract\v1\MessagesType:private] => Ok [message:net\authorize\api\contract\v1\MessagesType:private] => Array ( [0] => net\authorize\api\contract\v1\MessagesType\MessageAType Object ( [code:net\authorize\api\contract\v1\MessagesType\MessageAType:private] => I00001 [text:net\authorize\api\contract\v1\MessagesType\MessageAType:private] => Successful. ) ) ) [sessionToken:net\authorize\api\contract\v1\ANetApiResponseType:private] => ) SUCCESS: Get Transaction List for BatchID : 6910517

 

 

This response working fine, when subscription information exists.

 

net\authorize\api\contract\v1\GetTransactionListResponse Object ( [transactions:net\authorize\api\contract\v1\GetTransactionListResponse:private] => Array ( [0] => net\authorize\api\contract\v1\TransactionSummaryType Object ( [transId:net\authorize\api\contract\v1\TransactionSummaryType:private] => 60019302518 [submitTimeUTC:net\authorize\api\contract\v1\TransactionSummaryType:private] => DateTime Object ( [date] => 2017-03-07 08:50:17.000000 [timezone_type] => 2 [timezone] => Z ) [submitTimeLocal:net\authorize\api\contract\v1\TransactionSummaryType:private] => DateTime Object ( [date] => 2017-03-07 00:50:17.000000 [timezone_type] => 3 [timezone] => UTC ) [transactionStatus:net\authorize\api\contract\v1\TransactionSummaryType:private] => settledSuccessfully [invoiceNumber:net\authorize\api\contract\v1\TransactionSummaryType:private] => ref1488868094 [firstName:net\authorize\api\contract\v1\TransactionSummaryType:private] => 8694 [lastName:net\authorize\api\contract\v1\TransactionSummaryType:private] => Hossain Inc. [accountType:net\authorize\api\contract\v1\TransactionSummaryType:private] => AmericanExpress [accountNumber:net\authorize\api\contract\v1\TransactionSummaryType:private] => XXXX0002 [settleAmount:net\authorize\api\contract\v1\TransactionSummaryType:private] => 100 [marketType:net\authorize\api\contract\v1\TransactionSummaryType:private] => eCommerce [product:net\authorize\api\contract\v1\TransactionSummaryType:private] => Card Not Present [mobileDeviceId:net\authorize\api\contract\v1\TransactionSummaryType:private] => [subscription:net\authorize\api\contract\v1\TransactionSummaryType:private] => net\authorize\api\contract\v1\SubscriptionPaymentType Object ( [id:net\authorize\api\contract\v1\SubscriptionPaymentType:private] => 4382565 [payNum:net\authorize\api\contract\v1\SubscriptionPaymentType:private] => 1 ) [hasReturnedItems:net\authorize\api\contract\v1\TransactionSummaryType:private] => [fraudInformation:net\authorize\api\contract\v1\TransactionSummaryType:private] => ) [1] => net\authorize\api\contract\v1\TransactionSummaryType Object ( [transId:net\authorize\api\contract\v1\TransactionSummaryType:private] => 60019302381 [submitTimeUTC:net\authorize\api\contract\v1\TransactionSummaryType:private] => DateTime Object ( [date] => 2017-03-07 08:50:12.000000 [timezone_type] => 2 [timezone] => Z ) [submitTimeLocal:net\authorize\api\contract\v1\TransactionSummaryType:private] => DateTime Object ( [date] => 2017-03-07 00:50:12.000000 [timezone_type] => 3 [timezone] => UTC ) [transactionStatus:net\authorize\api\contract\v1\TransactionSummaryType:private] => settledSuccessfully [invoiceNumber:net\authorize\api\contract\v1\TransactionSummaryType:private] => ref1488826501 [firstName:net\authorize\api\contract\v1\TransactionSummaryType:private] => 7890 [lastName:net\authorize\api\contract\v1\TransactionSummaryType:private] => Zakir [accountType:net\authorize\api\contract\v1\TransactionSummaryType:private] => Discover [accountNumber:net\authorize\api\contract\v1\TransactionSummaryType:private] => XXXX0012 [settleAmount:net\authorize\api\contract\v1\TransactionSummaryType:private] => 100 [marketType:net\authorize\api\contract\v1\TransactionSummaryType:private] => eCommerce [product:net\authorize\api\contract\v1\TransactionSummaryType:private] => Card Not Present [mobileDeviceId:net\authorize\api\contract\v1\TransactionSummaryType:private] => [subscription:net\authorize\api\contract\v1\TransactionSummaryType:private] => net\authorize\api\contract\v1\SubscriptionPaymentType Object ( [id:net\authorize\api\contract\v1\SubscriptionPaymentType:private] => 4382053 [payNum:net\authorize\api\contract\v1\SubscriptionPaymentType:private] => 1 ) [hasReturnedItems:net\authorize\api\contract\v1\TransactionSummaryType:private] => [fraudInformation:net\authorize\api\contract\v1\TransactionSummaryType:private] => ) ) [totalNumInResultSet:net\authorize\api\contract\v1\GetTransactionListResponse:private] => 2 [refId:net\authorize\api\contract\v1\ANetApiResponseType:private] => [messages:net\authorize\api\contract\v1\ANetApiResponseType:private] => net\authorize\api\contract\v1\MessagesType Object ( [resultCode:net\authorize\api\contract\v1\MessagesType:private] => Ok [message:net\authorize\api\contract\v1\MessagesType:private] => Array ( [0] => net\authorize\api\contract\v1\MessagesType\MessageAType Object ( [code:net\authorize\api\contract\v1\MessagesType\MessageAType:private] => I00001 [text:net\authorize\api\contract\v1\MessagesType\MessageAType:private] => Successful. ) ) ) [sessionToken:net\authorize\api\contract\v1\ANetApiResponseType:private] => ) SUCCESS: Get Transaction List for BatchID : 6921564

->Transaction Id : 60019302518
->Subscription Id : 4382565
Submitted on (Local) : 2017-03-07 00:50:17
Status : settledSuccessfully Settle amount : 100.00
->Transaction Id : 60019302381
->Subscription Id : 4382053
Submitted on (Local) : 2017-03-07 00:50:12
Status : settledSuccessfully Settle amount : 100.00

 

 

All Star
Posts: 699
Registered: ‎11-03-2016

Re: Fatal error: Call to a member function id() on null

Hi @zakir,

 

The SDK provides the response, but it's up to your code to determine what to look for in the response and how to look for it.

 

 

If you'd like the SDK to provide more of this parsing logic for you, I can see how that might be useful.

 

I'd encourage you to post this onto our Ideas Forum where others can take a look, contribute feedback, and vote for new features.