I have to check the InAppPurchases receipts with my PHP server.
I would use this script in order to achieve my goal.
I'm running on a shared hosting server, so I'm not able to install or use composer. How can I still use and include the above mentioned PHP script?
I already included the following lines:
require '../lib/validate_inapp_purchase/iTunes/PurchaseItem.php';
require '../lib/validate_inapp_purchase/iTunes/Response.php';
require '../lib/validate_inapp_purchase/iTunes/Validator.php';
use ReceiptValidator\iTunes\Validator as iTunesValidator;
But the script throws the following error:
Fatal error: Class 'GuzzleHttp\Client' not found in /homepages/11/htdocs/app/lib/validate_inapp_purchase/iTunes/Validator.php on line 130
Use composer locally (on your machine) and then upload everything (including vendor folder) to the hosting server.
Related
I am new to php and have just installed my first package via composer. I'm now trying to call a function from the package I installed as follows:
<?php
require_once 'vendor/autoload.php';
$value = 1;
$aws = AmazonGiftCode::make()->buyGiftCard($value);
echo $aws;
?>
But I get the following error:
PHP Fatal error: Uncaught Error: Class 'AmazonGiftCode' not found in
/public_html/php/test.php:4 Stack trace:
#0 {main} thrown in /public_html/php/test.php on line 4
Based on my (albeit limited) experience with other languages, I'm guessing I have to load the package that contains the class first. The package folder is in the same directory as the test.php file, in the subfolder vendor/kamerk22/AmazonGiftCode/. But I think this is where I don't know enough to troubleshoot it based on the information I could find.
Your directory structure should look like this.
test.php
composer.json
vendor
└───autoload.php
└───kamerk22
└───AmazonGiftCode
Make sure you installed the package using composer, and not by downloading it.
I'm guessing I have to load the package that contains the class first.
Unlike what you would normally expect when importing stuff, when using composer you only have to import the autoload.php file, and composer will take care of loading other packages as needed. By as needed what I mean is that as soon as composer sees you use the AmazonGiftCode class it will import the AmazonGiftCode package, but if one of your REST endpoints doesn't use anything from the AmazonGiftCode package it won't ever load it. This allows you to not have to worry about slowing down the entire application when you want to use a composer package for only a few endpoints. At least that's the way I understand how composer works.
Just run composer dump-autoload once and the class should known then.
You could also get verbose and use kamerk22\AmazonGiftCode\AmazonGiftCode;
But that AmazonGiftCode looks quite Laravel specific... that's why it may still fail, even if it may be found by auto-load. One needs to setup Laravel framework in the first place; just see this query (just in case if you may wonder where all these missing classes may come from).
I'm trying to use the Mailgun API SDK to send emails from my test server. I downloaded the SDK itself as I am not currently using Composer.
However, when I try to instantiate a Mailgun object, I get this error:
Fatal error: Class 'Mailgun\Connection\RestClient' not found in /var/www/mysite.xyz/www/inc/libs/Mailgun/Mailgun.php on line 38
Which I fixed by adding require "Connection/RestClient.php"; to the Mailgun.php file. However, this in turn caused its own error.
Fatal error: Class 'GuzzleHttp\Client' not found in /var/www/mysite.xyz/www/inc/libs/Mailgun/Connection/RestClient.php on line 41
This is included in my includes.php, so for all pages.
#Mailgun php functions
require_once "libs/Mailgun/Mailgun.php";
use Mailgun\Mailgun;
Then, when I try to use this;
# First, instantiate the SDK with your API credentials and define your domain.
$mg = new Mailgun\Mailgun("key-myactualkey");
$domain = "myactualdomain.xyz";
print "Email to send is ".$welcomeemail; #Never gets reached
It causes those fatal errors and the program grinds to a halt.
Why is this happening and how do I fix it?
I had the same problem and fixed it by using composer which is easier then you might think. Just follow these instructions (locally, on your computer, where PHP should be installed):
https://github.com/mailgun/mailgun-php/blob/master/SharedHostInstall.md
Then upload all files generated to your server in a separate directory.
Then include the following lines to your script:
require 'your/path/to/these/files/vendor/autoload.php';
use Mailgun\Mailgun;
Create a new Mailgun object like this:
$mg = new Mailgun("your-secret-key");
Im kind of new with Travis, and I am expreimenting with it right now. I uploaded have my PHP Project on Github and when I let it test via Travis it fails and gives me this error.
PHP Fatal error: Class 'controllers\Welcome' not found in /home/travis/build/ezylot/PHPSkeleton/tests/controllers/welcomeTest.php on line 4
I use a autoloader to load the classes, and it is no problem on my local machine. I include the autoloader in bootsrap.php with the bootstrap in the PHPUnit Konfiguration-XML File.
<?php
if (!#include __DIR__ . '/../vendor/autoload.php') {
die('You must set up the project dependencies, run the following commands:
wget http://getcomposer.org/composer.phar
php composer.phar install');
}
?>
You are most likely developing on OSX which has case insensitive filesystem and tests pass. Travis uses case sensitive file system. Try renaming app/controllers/welcome.php to app/controllers/Welcome.php.
In general it is good idea to follow PSR-1 standard to avoid autoloading issues.
I had a short php open tag at the top of the class file.
<?
as opposed to
<?php
This broke it on the remote, but not on my local. Which is weird, because I would've expected it to break locally too.
Putting this out there in case someone else is in the same odd situation.
I'm trying to send an email using PHP from Google App Engine. To send an email, Require Once must include the php file Message.php: See: Code example here at Google
require_once 'google\appengine\api\mail\Message.php';
The Message.php file includes:
require_once 'google/appengine/api/mail/BaseMessage.php';
The BaseMessage.php file in turn requires three other PHP files:
require_once 'google/appengine/api/mail_service_pb.php';
require_once 'google/appengine/runtime/ApiProxy.php';
require_once 'google/appengine/runtime/ApplicationError.php';
So, to recap, Message.php requires BaseMessage.php and BaseMessage.php requires 3 more php files.
Everything works fine until that last PHP file that is required:
require_once 'google/appengine/runtime/ApplicationError.php';
Then a fatal error happens:
Fatal error: Class 'google\appengine\runtime\Error' not found in
C:\Users\UserName\Dropbox\ApplicationName\google\appengine\runtime\
ApplicationError.php on line 22
This is line 22:
class ApplicationError extends Error {
This is code that is provided by Google: the latest PHP SDK for App Engine
It's not code that I wrote. The path to the required files seems to be working, or else I'd get an error msg on the first required file. I've tested require_once lines of code that reference other PHP files in the same directories with no errors. So the issue isn't a problem with the relative path or the PHP.ini file.
My PHP version is Current PHP version: 5.4.22
Windows 7
XAMPP with Netbeans, Apache
How do I fix this problem?
I got the PHP email code to work. I still don't know what the exact problem was to begin with, but it must have something to do with how my Netbeans IDE is currently configured to PHP. The Google App Engine SDK has PHP built into it's installation, but I wasn't running my app from the Google App Engine Launcher. When I ran my app directly from the Google App Engine Launcher, the code worked. I'm guessing that the Netbeans version of PHP was a little different than the Google App Engine SDK version of PHP. And that caused an error in one of the files. In any case, I got the PHP code that sends a email to work. So, the code will run. That tells me that my configuration to PHP in Netbeans probably isn't the same as the configuration to PHP in the version of PHP in the Google App Engine SDK. I might try tweaking the PHP.ini file in netbeans to see if I can link directly to the Google App Engine SDK verion of PHP.
I'm running ArchLinux 64bit, I'm trying to create a Clickstack to run Symfony on Cloudbees.
I've created a Clickstack that extends PHP-ClickStack
When trying to test the bundled PHP I get the following error:
php: error while loading shared libraries: libpng15.so.15: cannot open shared object file: No such file or directory
I've downloaded and installed LibPng15 to /usr/local/.
I've also copied that file to: /path/to/php/lib/, /path/to/php/include/, and /path/to/php/bin/. It hasn't fixed the error.
I've also downloaded tried downloading the source for PHP-5.4.24 and 5.5.8 but, when I compile them they both some of the Intl tests.
So how can I get a working binary version of PHP that I can upload to Cloudbees?
The solution was to create LD_LIBRARY_PATH as an environment variable in script.
Apparently it didn't exist.
LD_LIBRARY_PATH=/usr/lib:/usr/local/lib/:/path/to/libpng/
NOTE: adding the normal directories prevents other tools/apps from breaking.