Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PayPal Checkout : LiveEnvironment class not found

Tags:

php

paypal

I am making a website with PayPal integration and I'm looking at the tutorial ... In sandbox everything works fine, but in Live it's not working...

The point is, the payment is well executed, but then I try to retrieve the order informations and I get :

<br />
<b>Fatal error</b>:  Uncaught Error: Class 'PayPalCheckoutSdk\Core\LiveEnvironment' not found in /api/sources/Classes/PaypalClient.php:25
Stack trace:
#0 /api/sources/Classes/PaypalClient.php(16): PayPalClient::environment()
#1 /api/sources/Controllers/PaymentController.php(116): PayPalClient::client()
#2 [internal function]: PaymentController-&gt;update()
#3 /api/vendor/pecee/simple-router/src/Pecee/SimpleRouter/Route/Route.php(119): call_user_func_array(Array, Array)
#4 /api/vendor/pecee/simple-router/src/Pecee/SimpleRouter/Router.php(286): Pecee\SimpleRouter\Route\Route-&gt;renderRoute(Object(Pecee\Http\Request))
#5 /api/vendor/pecee/simple-router/src/Pecee/SimpleRouter/SimpleRouter.php(52): Pecee\SimpleRouter\Router-&gt;routeRequest()
#6 /api/sources/autoload.php(23): Pecee\SimpleRouter\SimpleRouter::start()
#7 /api/autoloader.php(7): require_once('/home/soinsdesz...')
#8 /api/public/index.php in <b>/api/sources/Classes/PaypalClient.php</b> on line <b>25</b><br />

This is my PaypalClient.php class :

<?php

use PayPalCheckoutSdk\Core\PayPalHttpClient;
use PayPalCheckoutSdk\Core\SandboxEnvironment;
use PayPalCheckoutSdk\Core\LiveEnvironment;

class PayPalClient
{
    /**
     * Returns PayPal HTTP client instance with environment that has access
     * credentials context. Use this instance to invoke PayPal APIs, provided the
     * credentials have access.
     */
    public static function client()
    {
        return new PayPalHttpClient(self::environment());
    }

    /**
     * Set up and return PayPal PHP SDK environment with PayPal access credentials.
     * This sample uses SandboxEnvironment. In production, use LiveEnvironment.
     */
    public static function environment()
    {
        return (ENV === "prod") ? new LiveEnvironment(PAYPAL_CLIENT_ID, PAYPAL_PRIVATE_KEY) : new SandboxEnvironment(PAYPAL_CLIENT_ID, PAYPAL_PRIVATE_KEY);
    }
}

Can anyone help me please?

like image 563
Simon Trichereau Avatar asked Nov 20 '19 21:11

Simon Trichereau


1 Answers

Ok ... I found the solution ... So ...

In the tutorial it's said : "use LiveEnvironment instead" ... It's WRONG (thanks PayPal!!! Really) the correct class name is ProductionEnvironment !

Can PayPal modify his tutorial please : https://developer.paypal.com/docs/checkout/reference/server-integration/setup-sdk/

like image 117
Simon Trichereau Avatar answered Oct 25 '22 07:10

Simon Trichereau