1

I'm using Omnipay Paypal Rest api for Laravel and getting this: "Authentication failed due to invalid authentication credentials or a missing Authorization header." here is my code :

public function PayWithPaypal(Request $request)
    {
        // Initialize the Omnipay PayPal_Rest gateway
        $gateway = Omnipay::create('PayPal_Rest');
        $gateway->setClientId(env('PAYPAL_SANDBOX_CLIENT_ID'));
        $gateway->setSecret(env('PAYPAL_SANDBOX_CLIENT_SECRET'));
        $gateway->setTestMode(true);

        // Prepare the payment request
        $request = $gateway->purchase([
            'amount' => 1,
            'returnUrl' => route('payment.success'),
            'cancelUrl' => route('payment.cancel'),
        ]);

        // Send the payment request
        $response = $request->send();

        // Process the payment response
        if ($response->isRedirect()) {
            // Redirect the customer to the payment gateway
            $response->redirect();
        } else {
            // Payment failed, display an error message to the customer
            Log::alert($response->getMessage());
            return redirect()->route('payment.error')->with('error', $response->getMessage());
        }
    }

Any way to solve this error ?

Nelixus
  • 31
  • 9

0 Answers0