"Still having an issue. When you click the Pay with PayPal button on the checkout page it still takes you to the failure page even after I put that code in and then reloaded the page."
yes, that code was not intended to fix that issue, it was intended to give information to help fix the issue.
that code should write the session contents to the page
it will include the response from the gateway, i need to know the response from the gateway yo tell why the transaction is failing.