Integrating Stripe PHP library into a custom WordPress Plugin

Check out this article. It’s kind of old, but still quite relevant – I used it to build my own Stripe integration plugin for WordPress.

Note that including the line:

require_once('vendor/autoload.php');

should load the Stripe libraries for you. Depending on how you have your plugin folders set up, the plugin might not be finding the autoload.php file. It’s best to set a base directory in your plugin’s primary php file as such:

if ( ! defined( 'PLUGINNAME_BASE_DIR' )) 
    define( 'PLUGINNAME_BASE_DIR', dirname( __FILE__ ) );

Then, your require statement would look like:

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

Even better, put the Stripe library in a /lib folder in your plugin, so your include would be:

require_once( PLUGINNAME_BASE_DIR . '/lib/stripe-php/vendor/autoload.php' );

There is also an init.php file in the library that does the same thing and is what I used since I didn’t use Composer to pull it in. You can use this by downloading the source for the stripe-php library and putting the raw source in your plugin directory inside a /lib directory.

require_once( PLUGINNAME_BASE_DIR . '/lib/stripe-php/init.php' );