How do I detect failed transaction coming in from invoice.payment.add?

A failed transaction - It is showing as failed on our end/in InfusionSoft - but in the API that sent this data to our webhook (invoice.payment.add), it’s shown as PAID - There’s no indication of this being a failed transaction.
How do I detect a failed transaction ?

[id] => xxx
    [test] => 
    [amount] => 397
    [currency] => 
    [gateway] => AUTHORIZE
    [type] => CAPTURE
    [status] => Successful Transaction
    [errors] => 
    [orders] => Array
        (
            [0] => stdClass Object
                (
                    [id] => xxx
                    [title] => DFYMR Upsell
                    [status] => PAID
                    [recurring] => 
                    [total] => 397
                    [contact] => stdClass Object
                        (
                            [id] => 2772201
                            [email] => xxx@xxx.com
                            [first_name] => xxx
                            [last_name] => xxx
                            [company_name] => 
                            [job_title] => 
                        )

                    [notes] => 
                    [terms] => 
                    [creation_date] => 2019-03-27T16:41:07.000Z
                    [modification_date] => 2019-03-27T19:13:47.000Z
                    [order_date] => 2019-03-27T16:41:07.000Z
                    [lead_affiliate_id] => 0
                    [sales_affiliate_id] => 0
                    [total_paid] => 397
                    [total_due] => 397
                    [shipping_information] => stdClass Object
                        (
                            [id] => xxx
                            [first_name] => xxx
                            [middle_name] => 
                            [last_name] => xxx
                            [company] => 
                            [phone] => xxx
                            [street1] => null
                            [street2] => null
                            [city] => null
                            [state] => null
                            [zip] => null
                            [country] => null
                        )

                    [refund_total] => 0
                    [allow_payment] => 
                    [order_items] => Array
                        (
                            [0] => stdClass Object
                                (
                                    [id] => 497113
                                    [name] => xxx
                                    [description] => xxx
                                    [type] => Product
                                    [notes] => 
                                    [quantity] => 1
                                    [cost] => 0
                                    [price] => 397
                                    [discount] => 
                                    [product] => stdClass Object
                                        (
                                            [id] => 370
                                            [name] => xxx
                                            [sku] => 
                                            [description] => 
                                            [shippable] => 
                                            [taxable] => 
                                        )

                                )

                        )

                )

        )

    [contact_id] => xxx
    [transaction_date] => 2019-03-27T12:36:11.000-04:00
    [gateway_account_name] => xxx
    [order_ids] => 488683
    [collection_method] => PAYMENT_GATEWAY
    [payment_id] => 5127385

I believe you would have to take the payment_id and read the payment table for the pay status? Obviously, I’m not 100% on that but from what I’ve coded in the past that seems to be the case.

I have something like this

$transaction_id = $json->object_keys[$i]->id;
$url = "https://api.infusionsoft.com/crm/rest/v1/transactions/{$transaction_id}?access_token={$token}";
$data_transactions = file_get_contents($url);
$json_transactions = json_decode($data_transactions);

It depends on how much of the Payment table is included in the transactions call with REST. I’m just suggesting that it might show more information to use the XML-RPC to directly read the payment record using the id from the Payment table, because I know that table has a status field that reports things like failures.

If you head to https://developer.infusionsoft.com/docs/rest/#!/E-Commerce/listTransactionsForOrderUsingGET and try it using the OrderId in question, does the status show correctly for the Transaction/Order?

Which API are you hitting (REST or XML-RPC), and are you using a SDK or raw models? Resthooks only give the Id of the affected objects, so I assume you’re making a follow-up call.

I’m using resthooks. So far I’m logging the data to a log file but will filter out paid ones to be entered into our database.

$id = $json->object_keys[$i]->id;
$url = "https://api.infusionsoft.com/crm/rest/v1/transactions/{$id}?access_token={$token}";
$data_transactions = file_get_contents($url);
$json_transactions = json_decode($data_transactions);

When I called https://api.infusionsoft.com/crm/rest/v1/orders/{$id}/transactions?access_token={$token}
I can see : [status] => UNPAID

and also [status] => UNPAID when I called https://api.infusionsoft.com/crm/rest/v1/transactions/{$id}?access_token={$token}

So I guess this is what I have to be looking out for ?