Paypal SDK - Ajax to PHP Setup

Posting this again as have spent weeks on this now and not getting anywhere.

I cannot get paypal working on my server how I intend it to work

  1. Show payment button on page (Straight forward)
  2. Send request to php backend, post to db and take payment (Without re-direction)
  3. Recieve json response object to manipalute/feedback on payment page

I do not understand vender/autoload and every attempt to understand or locate folders etc leads to 500 errors

Simple explanation on how I can get this setup please, I do not have composer and
I do not understand composer

Thanks

So… you went to the Paypal SDK page. Downloaded the non-composer SDK, read the README inside it, and then… did what?

require __DIR__ . '/vendor/autoload.php';

Did not have this file, I tried with another sdk but classes were not found

For reference, this appears to be a continuation of Paypal SDK - Ajax/PHP Example

Search "'/vendor/autoload.php" (0 hits in 0 files of 210 searched) [Normal]

That file is not in the non-Composer SDK.

So i’m going to try that again…

you went to the Paypal (PHP) SDK page in their Getting Started section.
You downloaded the non-Composer SDK library.
You read the README file inside it.
You put the code library into your site… and…?

No, I did not download that version.
Checkout-php-sdk-develop was one of the versions I used.

Yes, correct.

Sorry, I have 6 different versions of the SDK now.
None of them make any sense.

I think I need to go back to a fresh start on this.

Yup. Go back to a fresh start with the official SDK.

Okay. So then…

Have extracted your version of the braintree app.

braintree-php-6.19.0

Will place this extracted folder to ROOT/braintree-php-6.19.0

Hold on, I thought we established you already have the autoload file and you were able to use the PayPal classes. Why are we going backwards again?

no, I could never get the classes to be found

I don’t want to derail this thread, but I’ll test something’s out when I get back home from work. I know when I was using PayPal’s SDK library, it worked for me and I was able to get sent to PayPal’s sandbox domain. Granted that was 7 months ago so I’ll see what’s wrong and get back to you.

He doesnt want to use composer. So testing the official Composer based build doesnt help the thread.

I’ll try to explain my setups. I am testing on localhost, but the files will be moved to hosting, I will keep all testing relative to the root folder for now.

Hosting account
ROOT FOLDER/htaccess (force https and remove .php extension)
ROOT FOLDER/paypal/index.php
STORAGE/VENDOR/autoload.php (so test index file I assume needs …/…/storage/vendor/autoload.php)

Wampp
ALIAS ROOT FOLDER/htaccess (remove .php extension)
ALIAS ROOT FOLDER/paypal/index.php
STORAGE/VENDOR/autoload.php (so test index file I assume needs …/…/storage/vendor/autoload.php)

require DIR . ‘…/…/storage/vendor/autoload.php’;

require(D:\Web\arcadeoperator\paypal…/…/storage/vendor/autoload.php): Failed to open stream: No such file or directory in D:\Web\arcadeoperator\paypal\index.php

That’s missing a slash and it should use 2 dots rather than an ellipsis:

require __DIR__ . '/../../storage/vendor/autoload.php';

discourse eats two dots into an ellipsis if it’s not in a codeblock.

Of course it does… sigh

However, that slash is still missing.

So looks like I might have given you just a slight bit of misinformation as the PayPal Checkout SDK uses a different namespace than the SDK that I was originally using.

The use statements you should be using are

use \PayPalCheckoutSdk\Core\PayPalHttpClient;
use \PayPalCheckoutSdk\Core\SandboxEnvironment;
use \PayPalCheckoutSdk\Core\ProductionEnvironment;

With using just this code snippet I gave you on the other thread, I was able to produce a working example. Only difference here is we’re using the correct namespace and we’re outputting the PayPalHttpClient object to make sure we’re actually getting what we are looking for. Reminder to change where the vendor/autoload.php is located.

<?php
require_once '/vendor/autoload.php';

use \PayPalCheckoutSdk\Core\PayPalHttpClient;
use \PayPalCheckoutSdk\Core\SandboxEnvironment;
use \PayPalCheckoutSdk\Core\ProductionEnvironment;

if(PAYPAL_MODE == 'sandbox') {
	$environment = new SandboxEnvironment(PAYPAL_CLIENT_ID, PAYPAL_SECRET, PAYPAL_MODE);
} elseif(PAYPAL_MODE == 'live') {
	$environment = new ProductionEnvironment(PAYPAL_CLIENT_ID, PAYPAL_SECRET, PAYPAL_MODE);
} else {
	throw new Exception('Unknown Paypal mode');
}

// Instantiate PayPal's entrypoint
$client = new PayPalHttpClient($environment);
print_r($client);

Here’s the output I get when I run that PHP code snippet from above.

# php index.php
PayPalCheckoutSdk\Core\PayPalHttpClient Object
(
    [environment] => PayPalCheckoutSdk\Core\SandboxEnvironment Object
        (
            [clientId:PayPalCheckoutSdk\Core\PayPalEnvironment:private] => {REDACTED}
            [clientSecret:PayPalCheckoutSdk\Core\PayPalEnvironment:private] => {REDACTED}
        )

    [injectors] => Array
        (
            [0] => PayPalCheckoutSdk\Core\AuthorizationInjector Object
                (
                    [client:PayPalCheckoutSdk\Core\AuthorizationInjector:private] => PayPalCheckoutSdk\Core\PayPalHttpClient Object
 *RECURSION*
                    [environment:PayPalCheckoutSdk\Core\AuthorizationInjector:private] => PayPalCheckoutSdk\Core\SandboxEnvironment Object
                        (
                            [clientId:PayPalCheckoutSdk\Core\PayPalEnvironment:private] => {REDACTED}
                            [clientSecret:PayPalCheckoutSdk\Core\PayPalEnvironment:private] => {REDACTED}
                        )

                    [refreshToken:PayPalCheckoutSdk\Core\AuthorizationInjector:private] => 
                    [accessToken] => 
                )

            [1] => PayPalCheckoutSdk\Core\GzipInjector Object
                (
                )

            [2] => PayPalCheckoutSdk\Core\FPTIInstrumentationInjector Object
                (
                )

        )

    [encoder] => PayPalHttp\Encoder Object
        (
            [serializers:PayPalHttp\Encoder:private] => Array
                (
                    [0] => PayPalHttp\Serializer\Json Object
                        (
                        )

                    [1] => PayPalHttp\Serializer\Text Object
                        (
                        )

                    [2] => PayPalHttp\Serializer\Multipart Object
                        (
                        )

                    [3] => PayPalHttp\Serializer\Form Object
                        (
                        )

                )

        )

    [refreshToken:PayPalCheckoutSdk\Core\PayPalHttpClient:private] => 
    [authInjector] => PayPalCheckoutSdk\Core\AuthorizationInjector Object
        (
            [client:PayPalCheckoutSdk\Core\AuthorizationInjector:private] => PayPalCheckoutSdk\Core\PayPalHttpClient Object
 *RECURSION*
            [environment:PayPalCheckoutSdk\Core\AuthorizationInjector:private] => PayPalCheckoutSdk\Core\SandboxEnvironment Object
                (
                    [clientId:PayPalCheckoutSdk\Core\PayPalEnvironment:private] => {REDACTED}
                    [clientSecret:PayPalCheckoutSdk\Core\PayPalEnvironment:private] => {REDACTED}
                )

            [refreshToken:PayPalCheckoutSdk\Core\AuthorizationInjector:private] => 
            [accessToken] => 
        )

    [curlCls] => PayPalHttp\Curl
)
#

Here’s the Composer command I used to get download the PayPal Checkout SDK. All I did was since I’m using Linux, I just went to the base root of the system and then used that command. Composer then auto generates a vendor folder for me to use. Hence why I didn’t need to change much in the code snippet I gave you. / refers to the base root of the system and then the vendor folder is automatically created from Composer so for me, /vendor is a legitimate folder location.

composer require paypal/paypal-checkout-sdk

Sorry I have never used composer, so do not understand how it is used.

I have the SDK and have placed it here.
(I can now use the vendor as that error has gone again now, but still cannot find that class.