Dr.Knowitall
Dr.Knowitall

Reputation: 10498

How to include stripe client api with symfony2. How to include files with no classes in symfony2

I'm trying to include this file in my symfony2 project which is a file with a bunch of require statements. Unfortunately this, file doesn't contain a class. I don't want to manually write namespaces for all the included file that do contain the classes that I need so I was wondering how I can include this file in a way that it will also include the other files that I need. The file that I'm trying to include into symfony2 looks like this :

<?php

// Tested on PHP 5.2, 5.3

// This snippet (and some of the curl code) due to the Facebook SDK.
if (!function_exists('curl_init')) {
  throw new Exception('Stripe needs the CURL PHP extension.');
}
if (!function_exists('json_decode')) {
  throw new Exception('Stripe needs the JSON PHP extension.');
}
if (!function_exists('mb_detect_encoding')) {
  throw new Exception('Stripe needs the Multibyte String PHP extension.');
}

// Stripe singleton
require(dirname(__FILE__) . '/Stripe/Stripe.php');

// Utilities
require(dirname(__FILE__) . '/Stripe/Util.php');
require(dirname(__FILE__) . '/Stripe/Util/Set.php');

// Errors
require(dirname(__FILE__) . '/Stripe/Error.php');
require(dirname(__FILE__) . '/Stripe/ApiError.php');
require(dirname(__FILE__) . '/Stripe/ApiConnectionError.php');
require(dirname(__FILE__) . '/Stripe/AuthenticationError.php');
require(dirname(__FILE__) . '/Stripe/CardError.php');
require(dirname(__FILE__) . '/Stripe/InvalidRequestError.php');

// Plumbing
require(dirname(__FILE__) . '/Stripe/Object.php');
require(dirname(__FILE__) . '/Stripe/ApiRequestor.php');
require(dirname(__FILE__) . '/Stripe/ApiResource.php');
require(dirname(__FILE__) . '/Stripe/SingletonApiResource.php');
require(dirname(__FILE__) . '/Stripe/List.php');

// Stripe API Resources
require(dirname(__FILE__) . '/Stripe/Account.php');
require(dirname(__FILE__) . '/Stripe/Card.php');
require(dirname(__FILE__) . '/Stripe/Charge.php');
require(dirname(__FILE__) . '/Stripe/Customer.php');
require(dirname(__FILE__) . '/Stripe/Invoice.php');
require(dirname(__FILE__) . '/Stripe/InvoiceItem.php');
require(dirname(__FILE__) . '/Stripe/Plan.php');
require(dirname(__FILE__) . '/Stripe/Token.php');
require(dirname(__FILE__) . '/Stripe/Coupon.php');
require(dirname(__FILE__) . '/Stripe/Event.php');
require(dirname(__FILE__) . '/Stripe/Transfer.php');
require(dirname(__FILE__) . '/Stripe/Recipient.php');

Upvotes: 2

Views: 2953

Answers (2)

Jaime Ni&#241;oles
Jaime Ni&#241;oles

Reputation: 44

Yes! With composer, and you can call Stripe functions where you want like this:

\Stripe::setApiKey("sk_test_yourkey");

$charge = \Stripe_Charge::create(array(...

I think it would be better creating a service and use it from there. Hope it helps. Regards.

Upvotes: 3

Emii Khaos
Emii Khaos

Reputation: 10085

I found stripe finally on packagist :)

{
    "require": {
        "stripe/stripe-php": "1.8.*"
    }
}

Upvotes: 7

Related Questions