Search code examples
symfonybraintree

Attempted to load class "Braintree_MerchantAccount" from namespace


I am trying to implement braintree merchant payment in Symfony2 project. I have added below bundle

"require" : {
    "braintree/braintree_php" : "3.17.0"
}

to project

This is the action to create merchant with example from documentation:

public function createMerchantAction(Request $request){

    $response = new JsonResponse();

    $merchantAccountParams = [
        'individual' => [
            'firstName' => 'Jane',
            'lastName' => 'Doe',
            'email' => 'jane@14ladders.com',
            'phone' => '5553334444',
            'dateOfBirth' => '1981-11-19',
            'ssn' => '456-45-4567',
            'address' => [
                'streetAddress' => '111 Main St',
                'locality' => 'Chicago',
                'region' => 'IL',
                'postalCode' => '60622'
            ]
        ],
        'business' => [
            'legalName' => 'Jane\'s Ladders',
            'dbaName' => 'Jane\'s Ladders',
            'taxId' => '98-7654321',
            'address' => [
                'streetAddress' => '111 Main St',
                'locality' => 'Chicago',
                'region' => 'IL',
                'postalCode' => '60622'
            ]
        ],
        'funding' => [
            'descriptor' => 'Blue Ladders',
            'destination' => 'bank',
            'email' => 'funding@blueladders.com',
            'mobilePhone' => '5555555555',
            'accountNumber' => '1123581321',
            'routingNumber' => '071101307'
        ],
        'tosAccepted' => true,
        'masterMerchantAccountId' => 'asdasd'
    ];

    $result = Braintree_MerchantAccount::create($merchantAccountParams);

    $response->setData([
        "success" => $result->success
    ]);

    return $response;
  }

Why do I keep getting following error?

'Attempted to load class "Braintree_MerchantAccount" from namespace "AppBundle\Controller". Did you forget a "use" statement for another namespace? (500 Internal Server Error)'


Solution

  • I think you have not declared namespace for Braintree_MerchantAccount.

    Please replace $result = Braintree_MerchantAccount::create($merchantAccountParams);

    with

    $result = \Braintree_MerchantAccount::create($merchantAccountParams);