简体   繁体   中英

Braintree iOS: fatal error 'Braintree_Configuration' not found

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

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

But when I run payAmountUsingBraintree.php file, I get the following error:

Fatal error: Class 'Braintree_Configuration' not found

Contents of 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 getting wrong? How do I solve this?

I know its a bit late. But let me add the solution for future readers who might be looking for similar solution while integrating the PHP technology to get the client token.

You need to setup the prerequisites first.

  • PHP version >= 5.4.0 is required.

The following PHP extensions are required:

  • curl
  • dom
  • hash
  • openssl
  • xmlwriter

Assuming that you have installed the dependencies on your server. BrainTree API expect the followings:

1) A Developer Sandbox Account – Create one here

2) BrainTree Client Framework within your application – Download from 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 require_once 'PATH_TO_BRAINTREE/lib/Braintree.php'; was missing from your code snippet.

Here are the reference links for the solution.

1) Integrating Braintree Payment Gateway with PHP

2) Github link of Braintree PHP

I also had this issue. This error rises only after Braintree.php is succesfully included. But the other file ie Braintree.php/configuration.php is not included by the autoload.php

This is a Invalid Directory path error.

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

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

to

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

i have used paypal as the directory. so change it as you want. And try to print the full $filename if you get same error and correct the directory path.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM