I am working on an integration with Commerce Stripe and the new Connect functionality. This however requires the 2.0 version of the library which can be found here https://github.com/stripe/stripe-php/releases.

I have downloaded the source code for this and put this in my stripe-php directory. The stripe-php library has a namespace of Stripe. I have defined my hook_libraries_info as follows

function bh_test_namespace_libraries_info() {
  return array(
    'stripe-php' => array(
      'name' => 'Stripe API Client Library for PHP',
      'vendor url' => 'https://stripe.com/',
      'download url' => 'https://github.com/stripe/stripe-php',
      'dependencies' => array(),
      'version arguments' => array(
        'file' => 'VERSION',
        'pattern' => '/(2.\d+(\.\d+)?)/',
      'files' => array(
        'php' => array(
    'xautoload' => function($api) {
        $api->namespaceRoot('Stripe', 'lib');


I have installed the xautoload module. However, the classes are still not loaded. Does anyone have an idea as to what I am doing wrong?


Download the 2.x uc_stripe version of the gateway for Stripe - it has code that works (https://www.drupal.org/project/uc_stripe) as you are seeking - the version 2.0 library uses \Stripe\Action-to-Take:: instead of Stripe_Action-to-Take:: Stripe Connect however is a whole other issue requiring a OAuth2 flow and JSON working with the Stripe Webhooks to get it working initially and THEN one can use the API for the rest of the issues for nmaintainance

  • Woohoo. Your suggestion gave me a clue. My code for loading the library works. I needed to access the Stripe classes using \Stripe\Stripe::Action-to-Take. I am loading it using namespaces. I will make this suggestion to ubercart and to the commerce_stripe project
    – angms.bh
    Aug 15 '15 at 17:34
  • I have implemented that OAuth2 flow already for Connect. I am not sure which project I should submit my code to for review. Any ideas?
    – angms.bh
    Aug 15 '15 at 17:56
  • Also - if you use the uc-stripe code - you should be aware a better way is to use the Stripe init.php and not their individual calls to the class files BECAUSE when the library is updated with another file the init.php file will have it - while the include format of the uc-stripe version setup WILL NOT - one would need to add it manually or use require_once('./sites/all/libraries/stripe-php/init.php'); in the code. I'd would like to see how you got the Oauth2 flow working - I am not sure why you would submit it to either (assume Drupal) project - but the code should work for Commerce or UC Aug 15 '15 at 20:24
  • I have uploaded my code for OAuth flow implementation at github.com/angms-bh/bh_c_stripe_oauth It is not abstracted out at all, just my implementation. Be sure to read how that OAuth flow works at stripe.com/docs/connect/standalone-accounts. The install module within the code needs to be enabled first. I separate out my installation into another module for easier testing. Once you have the stripe_user_id, you use this in the 'destination' parameter of a charge. If you need to send me a message, use drupal.org. My user id is angms-bh
    – angms.bh
    Aug 18 '15 at 14:49
  • The new github reference is github.com/angms-bh/bh_commerce_stripe_oauth. You will need to define your client url and secret key at the top
    – angms.bh
    Aug 18 '15 at 18:49

My code works above. However, when you access the classes, it must be in the form of \Stripe\Stripe class::method, not Stripe_Stripeclass::method. This code uses the init.php that is mentioned in stackin_hackin's comment above.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.