Search code examples
phplaravellaravel-5payment-gatewaybraintree

Where to set require once include in laravel?


My requirement is to include the braintree into my laravel application. The first step I have copied the whole sdk into the my laravel app folder and the folder is named braintree-php. Next I go into my C:\xampp\htdocs\cserver\resources\views\layouts and in my app.blade.php below is part of my code.

<!DOCTYPE html>
@section('includebt')

@show
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <!-- CSRF Token -->
    <meta name="csrf-token" content="{{ csrf_token() }}">

    <title>My system @yield ('role-heading')</title>

Then I have my actual blade page where I extend from the above app layout.This is just part of the codes there is more in detail below but my focus is on the library include.

@extends('layouts.app')


@section('includebt')
include(app_path().'/braintree-php/lib/Braintree.php');
Braintree_Configuration::environment('sandbox');
Braintree_Configuration::merchantId('**');
Braintree_Configuration::publicKey('***');
Braintree_Configuration::privateKey('***');

@endsection

I am getting this error Class 'Braintree\ClientToken' not found (View:


Solution

  • You should do it through composer like

    open composer.json file there only one requre make it

    "require": { 
    "laravel/framework": "5.0.*", 
    "illuminate/html": "^5.0", 
    "braintree/braintree_php" : "3.20.0" 
    },
    

    and use composer update from artisian

    composer update

    after that you need to setup your environment and generate client token and follow documentation . you may also think to go packagist .