I have a payment system in place and working, and I'm trying to implement a log of the responses from the processor API, in the database.
If payments are successful the code works and a new entry in the database is created, however if the payment fails, the entry in the database isn't created.
The thrown exception for failed payment is handled by the calling function, but something is happening to cause the create action for the log to not only fail but pretend to succeed. No exception for the database is thrown and the next lines are run. When testing the result of the create it returns true.
$charge = $this->chargeUser($user, $price, $nonce);
TransactionApiLog::create([
'user_id' => $user->id,
'transaction_id' => $transaction->id,
'success' => $charge->success,
'message' => $charge->message,
'api_response' => serialize($charge)
])->save();
if (!$charge->success) {
throw new Exception('Unable to process a charge: ' . $charge->message);
}
I would rather not remove the payment failed exception as that would require some extensive changes in the handling system, but from what i can tell that is the cause of the failed insert to the database.
I tried also tried using DB:table and it results in the same situation.
Another interesting thing is this error only occurs when i deploy to a staging site, (obvs cant test this on live) the code works as expected within a development environment.
Edit Using Laravel 5.3