Search code examples
phpdrupalpaypaldrupal-7composer-php

Autoload a Paypal PHP SDK in Drupal 7


I am new in creating a custom module in drupal 7 and basically I want to include the paypal PHP SDK library into my custom module.

This is my example path of my custom module

drupal/sites/all/modules/custom/custom_paypal

I've created the necessary files like .info and .module file for it my problem is when I am including the autoload.php from the composer install in my custom module that creates the directories and file

vendor->autoload.php, vendor->composer, and vendor->paypal

The vendor paypal where the library is found is autoloaded by the autoload.php. I've tried using this one into my .info file:

files[] = vendor/autoload.php

but it didn't work I've also tried this one

function custom_paypal_init() {
  require __DIR__ . '/vendor/autoload.php';
}

now I am instantiating a new class in the custom form I've made but it prompts an error:

Fatal error: Class 'Payment' not found

Which is in the Paypal SDK,

Can anyone help me how to properly include the classes of this API? Thanks!


Solution

  • I've fix the problem by using require_once method on the very first line of my custom module:

    require_once (__DIR__ . '/vendor/autoload.php');