Getting Braintree client token using PHP? - php

I'm following Braintree's instructions to create a client token using this page.
I made a Sandbox Account. Then, I downloaded the PHP library. The file downloaded as braintree-php-2.37.0.tgz, which I unzipped.
Then, using Eclipse for PHP Developers and following these directions, I:
went to Eclipse, then Preferences..., then PHP, then Libraries, then New...
made a new library called braintree
chose Add External folder... and added the braintree-php-2.37.0 folder which I had earlier unzipped.
went to the Properties of the app I'm working on
went to PHP, then Include Path, then Libraries, then Add Library...
then chose User Library and clicked Next >, then selected braintree (which I had just made) and clicked Finish
finalized by clicking OK
After I've done all of the above, I see that within the project's PHP Include Path folder, braintree is present with Braintree.php and all.
I then continued with the first set of instructions and my PHP file basically looks like this:
Braintree_Configuration::environment('sandbox');
Braintree_Configuration::merchantId('<my_merchant_id>');
Braintree_Configuration::publicKey('<my_public_key>');
Braintree_Configuration::privateKey('<my_private_key>');
$clientToken = Braintree_ClientToken::generate();
But nothing happens. It seems like the code won't even get past Braintree_Configuration::environment('sandbox');.
I see in many places that require_once 'PATH_TO_BRAINTREE/lib/Braintree.php'; is included but I don't know how to write the path to the Braintree.php file. I added the actual path which leads to where I downloaded the Braintree folder, but that didn't help at all. And I'm also further confused because I figured that Braintree.php is already added as a library.
I'm also using Google App Engine and uploading my PHP code to their server. I'm not sure if this is part of the problem or not.
EDIT:
I took the unzipped folder (braintree-php-2.37.0) and copied it into the PHP folder so it could be uploaded to Google App Engine as well.
I then edited my PHP code to be this:
<?php
require_once('./braintree-php-2.37.0/lib/Braintree.php');
Braintree_Configuration::environment('sandbox');
Braintree_Configuration::merchantId('<my_merchant_id>');
Braintree_Configuration::publicKey('<my_public_key>');
Braintree_Configuration::privateKey('<my_private_key>');
$clientToken = Braintree_ClientToken::generate();
?>
The code now won't get past require_once('./braintree-php-2.37.0/lib/Braintree.php');.

After discussing the details over with the staff from Braintree, we've come to the conclusion that, at the present moment, Google App Engine using PHP will not play nicely with Braintree's setup.
Hopefully there will be an answer to this problem in the future.

Related

PHP script not looking in includes folder

I have a new install. Ubuntu 22.04, Apache2, PHP 8.1 and I'm trying to use PHPMailer. My test page with phpinfo all looks good and shows the includes directory /usr/share/php. My form and script are in a subfolder of my document root and it loads fine. But when I fill out the form and the script starts it errors out unable to find PHPMailer. It's only looking in the subfolder the script is in, not the global includes directory. I don't want to put the mod in every form folder and I know it's supposed to work from the includes folder. Is this an Apache or php config issue? Or something I have to specify in the vhost?
Just verifying and closing out with the answer
I found the issue early today. Thanks to bad/tired eyes, I wasn't seeing the leading dot so it was looking for ./usr... Once i fixed that i was able to sort out the Ubuntu method of calling it from the libphp-phpmailer pkg autoload.php. I was able to get the script working with a few code corrections. The only thing I didn't sort out was PHPMailer:ParseAdresses but i only had a few recipients for this form so it wasn't that big an issue. My form is back online and my managers are happy 😊

My PHP page refer to Error:Missing controller

I´m new in PHP and creating dynamic webpages and after I installed Apache and my PHP IDE(codelobster) I face a serious problem.I really don´t know what I´m doing wrong but when I create new PHP project and I try to open it via my browser through localhost/...it always return me back a error page with this description:
Error:Missing controller
Cake\Routing\Exception\MissingControllerException
My php file is called oneironaut.php so it gives me also:
Oneironaut.phpController could not be found.
In the case you tried to access a plugin controller make sure you added it to your composer file or you use the autoload option for the plugin.
Error: Create the class Oneironaut.phpController below in file:
src\Controller\Oneironaut.phpController.php
I tried to create different projects like with different names and there was always this bug diference only with name of my .php webpage.So I think this must be some system error and something in my xampp/php or Apache settings must change.Maybe there could be some connection with my unfunctional debugger , I tried to download Xdebug from https://xdebug.org/wizard.php and even though I follow instructions on this website and another websites too I can´t successfully get xdebug extensions into my computer.So in this some help will be highly appreciated too.
So give me someone please help what to do with these problems? Thank You so much.
This seems to be happening because the server is loading files in "case-sensitive" mode.
You call your PHP file "oneironaut.php", however, the page is looking for "Oneironaut.php"
A similar question has been answered here, please try:
Missing Controller Error on remote server using Beta 3

PHP MySQL database connection using x10hosting

I am currently working on my database to keep my customer's name,birthday,email. In order to send email two weeks prior to customer's birthday.
I have followed "Derek Banas" youtube tutorial but when I tried to access to my code there were several errors.
http://i.imgur.com/djGeBd0.png
I realized there were path error when I use this code
require_once('http://grillontherock.x10host.com/CustomerInfo/mysqli_connect.php');
I put my files in the necessary location(I think)
http://i.imgur.com/TdQIEk3.png
Some guy told me to use x10host but I really do not know main purpose of this hosting website.
Thanks for any help you can provide :)
Assuming that require_once is used in one of the other files shown in that second picture, you shouldn't use the whole URL like that. require_once takes a file path, and a path relative to the file doing the requiring will work. Since the file your including is in the same directory, you should be able to just use
require_once 'mysqli_connect.php';
First, I strongly recommended against including remote PHP files in your code. You don't have control over the contents which could change without warning. This is especially dangerous when databases are involved.
I recommended getting the PHP source of that mysqli_connect.php file, adding it to your project, and then requiring it from there.
On a related note, you would need to set allow_url_include to true in your php.ini file per the documentation in order to successfully require remote scripts by URL. But again, please do not do this.

Google calendar php API gives file not found errors

I don't know if this has been asked before, but I'm trying to set up a simple call to the google API to retrieve events from a calendar (eventually i want to do more than this, but this is a test project to try to get up and running)
I have set up the project in the google developer pages and got the keys and secret etc, and enabled the calendar API
I have a folder on localhost, inside which is a single php file and the folder containing the library.
What I am currently getting is file not found errors, such as
failed to open stream: No such file or directory in ... google-api\src\Google\Client.php on line 18
What I don't understand is that this is one file in the library (Client.php) referencing another file (Google/Auth/AssertionCredentials.php) in the same library, so do I need to go through the entire library, editing all of the paths, or am i missing something? (or doing something really wrong?)
Many thanks,
John
As described in the installation documentation, you need to ensure that the /src folder is in your include_path. Alternatively, as you've found, you can just copy the /src/Google directory into the root of your application.

Installing JPGraph with Hostgator website

I've been trying to install jpgraph to my hostgator website but there's a problem somewhere which I can't figure out. There's a few things which are causing me to think the problem could be in several places;
first, when unpacking the file to my desktop ready to put into the server I get an error of 'The destination folder is a subfolder of the source folder', for this I just click continue and it seems to be OK.
This unpacks the folders which I rename to jpgraph as per the example FAQ on http://jpgraph.net/download/manuals/chunkhtml/ch02.html#id2475509
second, when I look at the examples the original code is [code]require_once ('jpgraph/jpgraph.php'); though the file structure is such that it should be jpgraph/src/jpgraph.php though even when I update the file structre the file doesn't work.
Third, I noticed when looking at different files some of the file structures reference jpgraph 3.xxx(version)/jpgraph.php but others use the short form jpgraph/jpgraph.php
I can't find any reasonable installation (see:Any) installation tutorials from youtube and the other thread on SO wasn't very helpful as it was solved in the background.
From your comment it looks like your php script just cannot find the jpgraph scripts, p.e. wrong path.
Try something like this, if you're using jpgraph as the graph lib of your choice:
$jpgraph_dir = '/your/path/to/your/jpgraph/';
require_once($jpgraph_dir . 'src/jpgraph.php');
If you still receive this error message, your path is just wrong.

Categories