Braintree iOS: fatal error "Braintree_Configuration" not found

I want to integrate Braintree payment in my iOS app. For this, I installed composer after https://getcomposer.org/doc/01-basic-usage.md .

The composer folder is created locally and I put it on my server.

But when I run the file payAmountUsingBraintree.php

, I get the following error:

Fatal error: Class 'Braintree_Configuration' not found

Contents payAmountUsingBraintree.php

:

    <?php
//include '../config.php';
include 'db_config.php';
require_once 'vendor/autoload.php';
//echo 'Current PHP version: ' . phpversion();

$PartnerId = $_POST["PartnerId"];
$nonce = $_POST["Nonce"];
$amount = $_POST["Amount"];
$fname = $_POST["fname"];
$lname = $_POST["lname"];
$SaveCard = $_POST["SaveCard"];
$number = $_POST["CardNumber"];
$postal_code = $_POST["postal_code"];
$CVV = $_POST["CVV"];
$MerchantAccountId = '';
$IsAvailable = 'no';



Braintree_Configuration::environment('sandbox'); // get error on this line
Braintree_Configuration::merchantId('2qyx6qtd9bvy82r');
Braintree_Configuration::publicKey('c9qvxk3nvhmd68b');
Braintree_Configuration::privateKey('6f8ca01bd95cc0c753e936148303de4');

      

Where am I going wrong? How to solve this?

+3


source to share


2 answers


I know him a little late. But let me add a solution for future readers who might be looking for a similar solution by integrating PHP technology to get a client token.

First you need to set up the prerequisites.

  • PHP version required> = 5.4.0.

The following PHP extensions are required:

  • curl
  • house
  • hash
  • OpenSSL
  • XmlWriter

Assuming you've installed the dependencies on your server. The BrainTree API expects the following:

1) Sandbox developer account - create here



2) BrainTree Client Framework in your application - Download here

Quick start example

<?php

require_once 'PATH_TO_BRAINTREE/lib/Braintree.php';

Braintree_Configuration::environment('sandbox');
Braintree_Configuration::merchantId('your_merchant_id');
Braintree_Configuration::publicKey('your_public_key');
Braintree_Configuration::privateKey('your_private_key');

$result = Braintree_Transaction::sale([
    'amount' => '1000.00',
    'paymentMethodNonce' => 'nonceFromTheClient',
    'options' => [ 'submitForSettlement' => true ]
]);

if ($result->success) {
    print_r("success!: " . $result->transaction->id);
} else if ($result->transaction) {
    print_r("Error processing transaction:");
    print_r("\n  code: " . $result->transaction->processorResponseCode);
    print_r("\n  text: " . $result->transaction->processorResponseText);
} else {
    print_r("Validation errors: \n");
    print_r($result->errors->deepAll());
}

      

The statement is require_once 'PATH_TO_BRAINTREE/lib/Braintree.php';

missing from the code snippet.

Here are the links for the solution.

1) Integration of Braintree payment gateway with PHP

2) Github link from Braintree PHP

+2


source


I also had this problem. This error only occurs after successfully enabling Braintree.php. But other file ie Braintree.php / configuration.php is not included autoload.php

This is an error Invalid directory path .

You want to use the exact DIRECTORY_SEPARATOR in $ file_name and change

$fileName = dirname(__DIR__) . '/lib/';



to

$fileName = dirname(__DIR__) . DIRECTORY_SEPARATOR.'paypal'.DIRECTORY_SEPARATOR;

I used paypal as a directory. so change it however you want. And try printing the full $ filename if you get the same error and fix the directory path.

+2


source







All Articles