I am trying to create a webhook for Braintree for the Disbursements. I am using WordPress and below is the code I am using but getting the following error:
“Fatal error: Class ‘Braintree_Configuration’ not found in /public_html/domain name/Braintree.php on line 4”
$fileName = 'Braintree.php';
if ( file_exists($fileName) ) {
require_once $fileName;
|else{
echo 'Yes we have no ' .$fileName;
exit; // no point in continuing
}
$fileName = 'Braintree.php';
if ( file_exists($fileName) ) {
require_once $fileName;
else{
echo 'Yes we have no ' .$fileName;
exit; // no point in continuing
}
I did fix that but I am still getting the error: “Parse error: syntax error, unexpected ‘else’ (T_ELSE) in /#/public_html/#/Braintree.php on line 7”
$fileName = 'Braintree.php';
if ( file_exists($fileName) ) {
require_once $fileName;
}
|else{
echo 'Yes we have no ' .$fileName;
exit; // no point in continuing.
}
Yes, as I pointed out in post # 4, there is no such thing as a Braintree_Configuration class.
“Braintree” is the namespace needed for the autoloader and the class is “Configuration”
I’m not sure how you are getting that when I’m trying to debug what you have and I just got a fresh clean copy from https://github.com/braintree/braintree_php. I’m getting a different message which is
PHP Fatal error: Uncaught Braintree\\Exception\\InvalidChallenge: challenge contains non-hex characters in
My question to you is, did you modify any part of the source code at all? If you have, please change it back because this could be the problem. If not, check where Braintree.php is located. Mine from the github repository is in lib. So you do require_once 'lib/Braintree.php; and it should work.
Also, Braintree_WebhookNotification should be Braintree\WebhookNotification. You need to get a grasp of how namespaces work in order to complete this sample snippet of yours.
Did doing what I suggested work? If not, post the updated snippet here.
Also, to make it easier for you to understand namespaces and classes, you are using what is called a static call which isn’t preferred, but can still be used.
In static calls, the best and easiest way to remember what each segment means is by doing a small comment and telling yourself how it’s setup. Like so.