phppdopaypalmailguneasypost

PHP Custom Class, PayPal API, Mailgun API, Easypost API. Can they work together


I have an ecommerce site that i am building for a client. This site had previously worked perfectly fine using procedural functions and curl to make the calls to Paypal. I download the Mailgun and Easypost API manual and installed manually. DOwn the road, I wanted to update the site to utilize PDO & OOP. I have done a fair job at getting the foundation laid. Now it is time to start making calls to the various API's.I installed everything using composer and currently run a dual autoloader. The composer autoload and then beneath it a custom autoload to load my classes. Now, when I call on the PayPal API, I get the following error:

Fatal error: Class 'Paypal\Rest\ApiContext' not found in /var/www/html/myla-dev/shoppingCartFinalize.php on line 18 

I think what is happening is my autoloader is trying to load this rather than the composers autoloader. Here is where the autoloading is occurring:

init.php

require __DIR__.'/core/functions/general.php';
function autoLoader ($class) {
  if (file_exists(__DIR__.'/core/classes/'.$class.'.php')) {
    require __DIR__.'/core/classes/'.$class.'.php';
  }
}
spl_autoload_register('autoLoader');
require __DIR__.'/vendor/autoload.php';

This file sits in project root directory and is then required at the top of every file.

File Structure

core
--classes
----Alert.php
----....
--functions
----general.php
vendor
--composer
--easypost
--guzzle
--mailgun
--symfony
--paypal
--autoload.php
index.php
init.php
...

composer.json

{
  "repositories": [
    {
      "type": "vcs",
      "url": "https://github.com/EasyPost/easypost-php"
    }
  ],
  "require": {
    "php": ">=5.3.0",
    "easypost/easypost-php": "dev-master",
    "ext-curl": "*",
    "ext-json": "*",
    "paypal/rest-api-sdk-php":"*",
    "mailgun/mailgun-php": "dev-master"
  }
}

Any and all assistance is appreciated. If you feel like writing code, GREAT, but that is not what I am asking for. That is my job, but help with reworking to make it work would be awesome.

Thanks


Solution

  • It ended up being a simple syntax error. After I dumped and updated composer it still failed to work, so I just copied the code from the installation wiki. It worked so I composer their code to mine and I was missing a backslash in my call to the wiki. Thank you for your assistance though.