I am not sure how to include the PHP stripe api library into my php file in order to get a list of transactions from my stripe account. I have downloaded the lib source and extracted the contents to a folder into which I saved a file called getStripeTransList.php with the following code inside:-
The error I get is
Class Stripe not found
I have adjusted the code as follows:-
<?php
require "Stripe.php";
require "Charge.php";
Stripe\Stripe::setApiKey("sk_test_...");
$transList = Stripe\Charge::all(array("limit" => 3));
var_dump($transList);
The error I now get is 'Stripe\ApiResource' not found in Charge.php.
Charge.php looks like this:-
<?php
namespace Stripe;
class Charge extends ApiResource
{
/**
* #param string $id The ID of the charge to retrieve.
with class APIResource declared in APIResource.php. I get the feeling that I have not installed or configured the stripe PHP API library correctly with all these dependencies appearing? How should the library be installed. I try not to use Composer, but will if that is the only way.
You're not including the Stripe PHP bindings correctly.
If you're using Composer, you'd simply include Composer's autoload.php file:
require_once("vendor/autoload.php");
If you installed the library manually, you'd need to include the init.php file:
require_once("/path/to/stripe-php/init.php");
Once the library has been included, you will be able to list all charges like this:
$charges = \Stripe\Charge::all();
foreach ($charges->data as $charge) {
// Do something with $charge
}
Note that all "list" API calls only return a finite number of resources. To retrieve the entire list, you might need to issue several API calls with pagination parameters to pick up where the previous call left off.
If you're using the latest versions of the bindings (3.9.0), you can also use the new auto-pagination feature:
$charges = \Stripe\Charge::all();
foreach ($charges->autoPagingIterator() as $charge) {
// Do something with $charge
}
This will automatically iterate over all charges, querying new pages as needed.
Related
I have used composer to download the Angell EYE PayPal library into my vendor directory. Now I'm trying to call the class within a controller.
I've tried various methods:
Use \angelleye\PayPal;
at the top of page. I've tried using the require() method.
Within the controller I have used
$paypal = PayPal::PayPal($payment);
And a few other ways, but I just get the error Class not found at line 179 and I'm not sure why.
You just need to load a config file (depending on your framework) and the autoloader.
require_once('includes/config.php');
require_once('vendor/angelleye/paypal-php-library/autoload.php');
Of course, adjust the paths to suit where you have those saved, but the autoloader is what makes the classes available to you.
If you want more direct help you can submit a ticket here.
Thanks for response.
I actually managed to get it working on the framework.
I did nt have to load anything or require the class as the composer autoload must do it for me in the framework.
I simply added :
$PayPal = new \angelleye\PayPal\PayPal($PayPalConfig);
and it started to work.
Im guessing if i want to use the PayFlow i would call using:
$PayPal = new \angelleye\PayPal\PayFlow($PayPalConfig);
I will definately post back if the rest of the proccess fails to work.
I am trying to use the Parse.com SDK with PHP. I have downloaded and installed the SDK and I have successfully created a test object.
However, when trying to retrieve an object with a basic query using the sample code provided in the Parse docs and when I try to run it I get:
Fatal Error: Class 'ParseQuery' not found in /home/jameshilton/public_html/index.php on line 109
I would have guessed that it is not linking to the SDK properly but everything else is working fine.
Any ideas what I'm doing wrong?
By looking at the code of the class ParseClient in on GitHub I can see that the classes are declared in the namespace parse. So when you need an object from the Parse library you need to select the namespace. This can be done in two ways.
At the top of your file write:
use \parse;
or when instantiating the class:
$query = new \parse\ParseQuery
And remember to make sure the files are included either through an autoloader (composer?) or manually using include or require.
Regards.
I am using the google api php client.
Howewer, when I'm trying to include the three following libraries:
require_once app_path().'/library/googleapi/contrib/Google_PlusService.php';
require_once app_path().'/library/googleapi/contrib/Google_TasksService.php';
require_once app_path().'/library/googleapi/contrib/Google_CalendarService.php';
I get : Cannot redeclare class Google_Acl on line 784 of Google_CalendarService.php.
I know I could modify Google_CalendarService.php so that the class is only created if it doesn't exist, but this is kind of messy.
I need to load both libraries at the same time to create a valid AuthURL to authorize requests on google plus (to get the profile image) and the calendar (to get the calendar).
What's the best workaround for this ?
Seems that it is not possible to use these 3 libraries together
Reply from google code.google-api-php-client
Unfortunately its not the same object - there is name collision in
this version of the library. The alpha version 1.0.0 includes better
name generation that avoids this:
http://github.com/google/google-api-php-client/
The workaround at the moment is not to include both at the same time
unfortunately.
https://code.google.com/p/google-api-php-client/issues/detail?id=439
I built a PHP application that uses namespaces and PSR-0 autoloading. In trying to implement the Stripe library, I've found that it can't seem to load the classes because they aren't namespaced. Is there a way to not autoload if I have manually included the files?
// Get Stripe Library
require_once(App\App::$APP_PATH . "/Extensions/Stripe.php");
// Set Key
Stripe::setApiKey($stripe['secret_key']);
Setting the key in the example fails with a fatal error because it thinks a Stripe class exists in my namespace of the current file.
I found that if I add a use Stripe; line below my namespace declaration, it will work, but then fails on the next class in the Stripe library.
Am I really going to have to add a Use Stripe, Stripe_Customer, Stripe_xyz...; line to let it load the files correctly (which there are over 25 files) or is there a better way?
[EDIT]
Until I hear whether there is a better way, I've done this:
// Import Non-Namespaced Stripe Library
use Stripe, Stripe_Account, Stripe_ApiConnectionError, Stripe_ApiError, Stripe_ApiRequestor, Stripe_ApiResource, Stripe_AuthenticationError;
use Stripe_Card, Stripe_CardError, Stripe_Charge, Stripe_Coupon, Stripe_Customer, Stripe_Error, Stripe_Event, Stripe_InvalidRequestError;
use Stripe_Invoice, Stripe_InvoiceItem, Stripe_List, Stripe_Object, Stripe_Plan, Stripe_Recipient, Stripe_SingletonApiResource;
use Stripe_Stripe, Stripe_Token, Stripe_Transfer, Stripe_Util;
Using composer is the easiest way (I promise!)
Just install composer and then install stripe. Once you have those installed just browse to your project's folder and run composer install. This will install the needed dependencies and will put composer in a folder called vendor.
Then you simple require the autoload.php file which will load up stripe, without bothering to use a namespace. Here's a full example block that I grabbed from here.
<?php
require_once('vendor/autoload.php');
$stripe = array(
"secret_key" => "sk_test_BQokikJOvBiI2HlWgH4olfQ2",
"publishable_key" => "pk_test_6pRNASCoBOKtIshFeQd4XMUh"
);
\Stripe\Stripe::setApiKey($stripe['secret_key']);
?>
You can use \ to specify that the class name you're specifying is a fully qualified namespace (FQNS), for example:
<?php
use \Stripe, \Stripe_Account;
$stripe = new Stripe();
$stripe_account = new Stripe_Account();
or without use statements:
<?php
$stripe = new \Stripe();
$stripe_account = new \Stripe_Account();
I'm using Stripe's php library. DL link: https://code.stripe.com/stripe-php-latest.zip
I've included the library like so inside of a view:
require_once(APPPATH.'libraries/stripe/lib/stripe.php');
Everything works fine when I do this in a view, but if I attempt to do it in a controller I get a server error. Why?
I have tried codeigniters load library method, but still a server error. I've change all capitals to lowercases, still the error.
Loading Packages:
$this->load->add_package_path(APPPATH.'third_party/stripe/');
$this->load->library('stripe');
Documentation: Application "Packages" section
http://ellislab.com/codeigniter/user-guide/libraries/loader.html
If you use third_party libraries, like for example the Facebook PHP SDK, use the following code:
$this->_obj->load->add_package_path(APPPATH.'third_party/facebook/');
$this->_obj->load->library('facebook', $config);
$this->_obj->load->remove_package_path(APPPATH.'third_party/facebook/');
And place the files for this library in the /third_party/facebook/libraries/ folder.
Note: It's a common mistake to place the files directly in '/facebook/' instead of in '/libraries/' (and also not mentioned in the documentation, too bad).
You can use the stripe native library by adding as codeigniter helper.
step 1: put the stripe package into helper directory
step 2: rename the init.php to init_helper.php
step 3: load the helper into your controller
$this->load->helper('stripe/init');
step 4: call stripe library
try
{
// set api key
\Stripe\Stripe::setApiKey('YOUR_SECRET_STRIPE_API_KEY');
// create customer
$customer_detail = \Stripe\customer::create(array(
'email' => 'customer_email#testdomain.com'
));
echo $customer_detail->id;
}
catch (Exception $e)
{
$error = $e->getMessage();
echo $error;
}
Try putting your library on application/libraries and then load your librarie with
$this->load->libraries('Stripe.php');