Showing posts with label Braintree. Show all posts
Showing posts with label Braintree. Show all posts

Wednesday, 24 August 2016

Braintree payment with Paypal OR Credit card - Easy Payment


Braintree Payment Form

Braintree Payment Form


Pay with Credit Card

Pay with Credit Card


Pay with Paypal

Pay with Paypal


<div>
<form action="/payment.php" id="checkout" method="post">
<div id="payment-form">
</div>
<input type="submit" value="Pay $10" />
    </form>
</div>
<script src="https://js.braintreegateway.com/js/braintree-2.27.0.min.js"></script>
<script>
    var clientToken = "eyJ2ZXJzaW9uIjoyLCJhdXRob3JpemF0aW9uRmluZ2VycHJpbnQiOiJlZDMyNDY2YmY3NjEyODAxZTk1YmVkMzYyY2Y2NzQ5OThjZWJlZGU2OTgzMDI4MzY3NmJmOTZhNDI0NzI1YTJkfGNyZWF0ZWRfYXQ9MjAxNi0wOC0yNFQwNjowNzo1NS43MTUzNDUyNDIrMDAwMFx1MDAyNm1lcmNoYW50X2lkPTM0OHBrOWNnZjNiZ3l3MmJcdTAwMjZwdWJsaWNfa2V5PTJuMjQ3ZHY4OWJxOXZtcHIiLCJjb25maWdVcmwiOiJodHRwczovL2FwaS5zYW5kYm94LmJyYWludHJlZWdhdGV3YXkuY29tOjQ0My9tZXJjaGFudHMvMzQ4cGs5Y2dmM2JneXcyYi9jbGllbnRfYXBpL3YxL2NvbmZpZ3VyYXRpb24iLCJjaGFsbGVuZ2VzIjpbXSwiZW52aXJvbm1lbnQiOiJzYW5kYm94IiwiY2xpZW50QXBpVXJsIjoiaHR0cHM6Ly9hcGkuc2FuZGJveC5icmFpbnRyZWVnYXRld2F5LmNvbTo0NDMvbWVyY2hhbnRzLzM0OHBrOWNnZjNiZ3l3MmIvY2xpZW50X2FwaSIsImFzc2V0c1VybCI6Imh0dHBzOi8vYXNzZXRzLmJyYWludHJlZWdhdGV3YXkuY29tIiwiYXV0aFVybCI6Imh0dHBzOi8vYXV0aC52ZW5tby5zYW5kYm94LmJyYWludHJlZWdhdGV3YXkuY29tIiwiYW5hbHl0aWNzIjp7InVybCI6Imh0dHBzOi8vY2xpZW50LWFuYWx5dGljcy5zYW5kYm94LmJyYWludHJlZWdhdGV3YXkuY29tLzM0OHBrOWNnZjNiZ3l3MmIifSwidGhyZWVEU2VjdXJlRW5hYmxlZCI6dHJ1ZSwicGF5cGFsRW5hYmxlZCI6dHJ1ZSwicGF5cGFsIjp7ImRpc3BsYXlOYW1lIjoiQWNtZSBXaWRnZXRzLCBMdGQuIChTYW5kYm94KSIsImNsaWVudElkIjpudWxsLCJwcml2YWN5VXJsIjoiaHR0cDovL2V4YW1wbGUuY29tL3BwIiwidXNlckFncmVlbWVudFVybCI6Imh0dHA6Ly9leGFtcGxlLmNvbS90b3MiLCJiYXNlVXJsIjoiaHR0cHM6Ly9hc3NldHMuYnJhaW50cmVlZ2F0ZXdheS5jb20iLCJhc3NldHNVcmwiOiJodHRwczovL2NoZWNrb3V0LnBheXBhbC5jb20iLCJkaXJlY3RCYXNlVXJsIjpudWxsLCJhbGxvd0h0dHAiOnRydWUsImVudmlyb25tZW50Tm9OZXR3b3JrIjp0cnVlLCJlbnZpcm9ubWVudCI6Im9mZmxpbmUiLCJ1bnZldHRlZE1lcmNoYW50IjpmYWxzZSwiYnJhaW50cmVlQ2xpZW50SWQiOiJtYXN0ZXJjbGllbnQzIiwiYmlsbGluZ0FncmVlbWVudHNFbmFibGVkIjp0cnVlLCJtZXJjaGFudEFjY291bnRJZCI6ImFjbWV3aWRnZXRzbHRkc2FuZGJveCIsImN1cnJlbmN5SXNvQ29kZSI6IlVTRCJ9LCJjb2luYmFzZUVuYWJsZWQiOmZhbHNlLCJtZXJjaGFudElkIjoiMzQ4cGs5Y2dmM2JneXcyYiIsInZlbm1vIjoib2ZmIn0";

    braintree.setup(clientToken, "dropin", {
        container: "payment-form"
    });
</script>


Demo



After Successfully payment with Credit Card OR Paypal, Server will an Get Response similar to below.
Array
(
    [payment_method_nonce] => e91cdbff-d914-485f-817a-51f473b18445
)
This token is known as payment nonce. You can use this nonce once and can be used to get the payment from user account.
$paymentNonce=$POST[payment_method_nonce];//this is nonce
$result = Braintree_Transaction::sale([
  'amount' => '10.00',
  'paymentMethodNonce' => $paymentNonce,
  'options' => [
    'submitForSettlement' => True
  ]
]);

Thursday, 30 July 2015

Braintree Marketplace - Split payment between website owner and seller


Braintree Marketplace - Split payment between website owner and seller


Question: What is Braintree Marketplace?
Braintree Marketplace is platform where it enables you to split payments from customers between your marketplace and your sellers or providers.


Question: Is split payments free in Braintree Marketplace?
Yes, Braintree does not charge extra for split payment.


Question: What is Transaction cost?
2.9% + $0.30 per transaction.


Question: Is there any monthly fees?
No, There is no monthly fees. Also there is no hidden cost.


Question: In which country market place is available?
Currently Its available in USA only.


Question: What Compatibility should be for Marketplace?
Merchant accounts need to be approved by Braintree for use with Marketplace.
Master merchant and sub-merchants must be domiciled in the US and receive funding in USD.


Question: What are useful terminology for Marketplace?
Master merchant: The Marketplace owner
Sub-merchant: Sellers who will receive money along with marketplace owner.
Service fee: Amount getting by sellers.
Escrow: An option that allows you to hold funds through our banking partner until you decide to disburse them; at disbursement.
Webhooks: Notifications sent to your server that indicate whether a merchant was successfully onboarded OR there was a problem disbursing funds.


Question: What information do I need to get from Seller OR Sub-merchant?
You need to get the billing/account information along with basic details.
Following are information which you need to pass in API to create sub-merchant on the behalf of main merchant.
$result = Braintree_MerchantAccount::create(
  [
    'individual' => [
      'firstName' => 'Jane',
      'lastName' => 'Doe',
      'email' => '[email protected]',
      'phone' => '5553334444',
      'dateOfBirth' => '1981-11-19',
      'ssn' => '456-45-4567',
      'address' => [
        'streetAddress' => '111 Main St',
        'locality' => 'Chicago',
        'region' => 'IL',
        'postalCode' => '60622'
      ]
    ],
    'business' => [
      'legalName' => 'Jane Ladders',
      'dbaName' => 'Jane Ladders',
      'taxId' => '98-7654321',
      'address' => [
        'streetAddress' => '111 Main St',
        'locality' => 'Chicago',
        'region' => 'IL',
        'postalCode' => '60622'
      ]
    ],
    'funding' => [
      'descriptor' => 'Blue Ladders',
      'destination' => Braintree_MerchantAccount::FUNDING_DESTINATION_BANK,
      'email' => '[email protected]',
      'mobilePhone' => '5555555555',
      'accountNumber' => '1123581321',
      'routingNumber' => '071101307'
    ],
    'tosAccepted' => true,
    'masterMerchantAccountId' => "master_merchant_account_id",
    'id' => "blue_ladders_store"
  ]
);

Response of above code:
Braintree_Result_Successful Object
(
    [success] => 1
    [_returnObjectNames:Braintree_Result_Successful:private] => Array
        (
            [0] => merchantAccount
        )

    [_attributes] => Array
        (
        )

    [merchantAccount] => Braintree_MerchantAccount Object
        (
            [_attributes] => Array
                (
                    [status] => pending
                    [id] => arun_kumar
                    [masterMerchantAccount] => Braintree_MerchantAccount Object
                        (
                            [_attributes] => Array
                                (
                                    [status] => active
                                    [id] => zz62xd782mdfhrzb
                                    [currencyIsoCode] => USD
                                    [subMerchantAccount] => 
                                )

                        )

                    [currencyIsoCode] => USD
                    [subMerchantAccount] => 1
                )

        )

)



Question: How to send money to sub-merchant when customer pay?
$result = Braintree_Transaction::sale([
    'merchantAccountId' => 'submerchant_account_id',
    'amount' => '10.00',
    'paymentMethodNonce' => nonceFromTheClient,
    'serviceFeeAmount' => "1.00" //this amt will be transfered to main merchnat 
]);



Question: What is maximum limit for transaction?
Its more than $80K monthly. But if you are doing much more transaction, you need to contact braintree.


Question: What is Chargeback?
Customer paid for the item and money is deduct from his bank.
After some time customer disputes a transaction to get deducted money, because he get issue is delivered product or becuase of any issue  know as chargeback.



Friday, 3 July 2015

Braintree hosted fields javascript php send nonce in ajax

Hosted Fields of Braintree are small, transparent iframes that replace the sensitive credit card inputs in your checkout flow, It helps you meet the latest data security requirements.

In this you need not to take the PCI Compliance as credit card details are in Braintree and process by Braintree. User will feel he is adding credit card details in your website and in actual its NOT.

Braintree hosted fields javascript php send nonce in ajax


After doing couples of days hard work, I am able to integrate the braintree hosted fields.
Following are HTML Form
<form action="/braintree/submitform" id="my-payment-form" method="GET">
<div class="braintreeinput">
<label for="card-number">Card Number</label>
      <br />
<div id="card-number">
</div>
</div>
<div class="braintreeinput">
<label for="cvv">CVV</label>
      <br />
<div id="cvv">
</div>
</div>
<div class="braintreeinput">
<label for="expiration-month">Expiration Month</label>
      <br />
<div id="expiration-month">
</div>
</div>
<div class="braintreeinput">
<label for="expiration-year">Expiration Year</label>
      <br />
<div id="expiration-year">
</div>
</div>
<div class="payBtnCont">
<input id="mainSubmitBtn" type="submit" value="Send Money" />
    </div>
</form>



Add Following javascript in web page
http://js.braintreegateway.com/js/beta/braintree-hosted-fields-beta.17.js



Get the Client Token from Server and set in javascript variable as below:
var clientToken = 'CLIENT_TOKEN_FROM_SERVER';



Following are javascript code:
      braintree.setup(clientToken, "custom", {
        id: "my-payment-form",
        hostedFields: {
          number: {
            selector: "#card-number"
          },
          cvv: {
            selector: "#cvv"
          },
          expirationMonth: {
            selector: "#expiration-month"
          },
          expirationYear: {
            selector: "#expiration-year"
          },
          styles:{
            ".braintreeinput": {
            "font-size": "16pt",
            "color": "#3A3A3A",
            "line-height" : "40px"
          }  
          }
        },onPaymentMethodReceived:function(nonce){
             console.log(JSON.stringify(response));
            /*Response:
{"nonce":"e1db0653-7a83-4022-8213-7e73504e7f88","details":{"lastTwo":"11","cardType":"Visa"},"type":"CreditCard"}*/


            $.ajax({
                url:'/braintree/submitform',
                data:'payment_method_nonce='+response.nonce,
                type:'POST',
                dataType:'json',
                success: function(response) {
                    //Ajax call results comes here
                }                
            });

            return false;
          
      }
        }
      
              ); 



Once you get the nonce in API call "/braintree/submitform", you can charge from customer using below code.
$result = Braintree_Transaction::sale([
  'amount' => '10.00',
  'paymentMethodNonce' => nonceFromTheClient,
  'options' => [
    'submitForSettlement' => True
  ]
]);


Thursday, 25 June 2015

Braintree Questions and Answers - Javascript+PHP

Braintree Questions and Answers - Javascript+PHP


Question: What is use of custom fields? How to use custom fields to save the customer details?
When we create/update the customer details, you might need to add extra fields which are not supported by braintree APIs. In that case, you can use braintree custom fields, with use of custom fields you can save extra customer details like nick name, personal meeting date etc.
When you start save custom fields you will get following error:
Customer ID has already been taken.

Then means, you must have to set the custom fields name in cpanel of your account.
Following are simple instruction to set the custom fields in cpanel of merchant account.
01) Log into the Control Panel in braintree.
02) Go to Settings > Processing > Custom Fields.
03) Click on "New".
04) Fill the form. (Use API Name variable in custom field ).
05) Click Save.


Question: How to get the client token?
"Client token" are generated by Server, use following function to do the same.
$clientToken = Braintree_ClientToken::generate();
This token is used by braintree js and compulsory to process the transaction.
   braintree.setup(clientToken, "custom", {
        . 
        .
        .
      });



Question: How to get "noune payment method"?
When customer fill the credit card details and submit the form, Request goes to "Braintree".
All details are saved in "Braintree" Server.
and you get an unique string that is know as "noune payment method".
With use of this "noune payment method", you can charge the customer.

$result = Braintree_Transaction::sale(array(
    'amount' => '1.00',
    'paymentMethodNonce' => '699dc252-6388-464a-9712-5dd8fa2bb656',
    'options' => array(
      'submitForSettlement' => True
    )
  ));
$transactionId = $result->transaction->id;

 noune payment method will expired in 24 Hours.


Question: I am getting error "Unknown payment_method_nonce.". Why?
If you are getting above error message, It might have any of below Reason.
a) paymentMethodNonce is invalid.
b) paymentMethodNonce is already expired OR used.


Question: Give some test credit card numbers for braintree?
378282246310005
371449635398431
6011111111111117
3530111333300000
4111111111111111
4500600000000061

Use any CVV Number and Expiry date (Must future date)


Question: How to get Client Token from server using for Customer.
/** Include Library and set configuration**/
require_once '/braintree-php301/lib/Braintree.php';
Braintree_Configuration::environment('sandbox');
Braintree_Configuration::merchantId('xxxxxxxx');//update merchantId
Braintree_Configuration::publicKey('xxxxxxxxxx');//update public key
Braintree_Configuration::privateKey('xxxxxxxxxxxxxxxxxxxxxx'); //Private key
 
//Get the Client Token
$clientToken = Braintree_ClientToken::generate();

//Get the Client Token for Customer 
$clientToken = Braintree_ClientToken::generate(array('customerId'=>464654654));



Question: How to get Custom details using customerId?
/** Include Library and set configuration**/
.
.
.       
/** Include Library and set configuration**/
$customerId = 67222186;  
   try{
       $result = Braintree_Customer::find($customerId); 
      echo $result->id; echo "\n";
      echo $result->firstName; echo "\n";
      echo $result->lastName; echo "\n";
      echo $result->email; echo "\n";
      echo $result->phone; echo "\n";
   }  catch (Exception $e){
    echo $e->getMessage();die;
  }


Question: How to connect a customer with nonce (payment method)?
$customer = 66082493; //CustomerId of customer
$result = Braintree_PaymentMethod::create(array(
    'customerId' => $customer,
    'paymentMethodNonce' => 'be2d6271-c71f-46ae-96c4-3b1e471cc575'
));


Question: How to charge from Customer with customer_id?
$result = Braintree_Transaction::sale(
  array(
    'customerId' => 'the_customer_id',
    'amount' => '100.00'
  )
);

Question: How to charge from Customer with nonce token?
$result = Braintree_Transaction::sale(array(
  'amount' => '100.00',
  'paymentMethodNonce' => nonceFromTheClient
]));





Wednesday, 24 June 2015

Manage Customer Details in Braintree




Following are code snippet that are useful to mange the customer details in braintree. you must have an account in braintree to use below code.


Add Customer
You can ADD customer details in braintree server, after saving the customer detail you will get customerId which can use latter on.  You can also add custom fields.

Note: Each customer is bound to specific merchant.

/** Include Library and set configuration**/
require_once '/braintree-php301/lib/Braintree.php';
Braintree_Configuration::environment('sandbox');
Braintree_Configuration::merchantId('xxxxxxxxxxxxxxxx');
Braintree_Configuration::publicKey('xxxxxxxxxxxxxxxxx');
Braintree_Configuration::privateKey('xxxxxxxxxxxxxxxxxxxxxxxxxxxx');
/** Include Library and set configuration**/

$result = Braintree_Customer::create(array(
    'firstName' => 'Ram   ',
    'lastName' => 'Kumar',
    'company' => 'web-technology-experts-notes',
    'email' => '[email protected]',
    'phone' => '281.330.8004',
    'fax' => '419.555.1235',
    'website' => 'http://www.web-technology-experts-notes.in',
    'customFields' => array(
            'custom_field_one' => 'custom value',
            'custom_field_two' => 'another custom value'
        )
));

if($result->success){
    $customerId = $result->customer->id; //New Customer Id
}



Update Customer
Using the customerId, You can UPDATE customer details in braintree server.

/** Include Library and set configuration**/
.
.
.
/** Include Library and set configuration**/


$customerId = 14983213;
$result = Braintree_Customer::update($customerId,array(
            'firstName' => 'Ram   ',
            'lastName' => 'Singh',
            'company' => 'web-technology-experts-notes',
            'email' => '[email protected]',
            'phone' => '281.330.8004',
            'fax' => '419.555.1235',
            'website' => 'http://www.web-technology-experts-notes.in'
));  
if($result->success){
    die("Customer Detail Updated Successfuly");
}



Find Customer
Using the customerId, You can SEARCH the customer detail from braintree server.

/** Include Library and set configuration**/
.
.
.
/** Include Library and set configuration**/

/** find customer detail **/
$customerId = 14983213;
try{
      $result = Braintree_Customer::find($customerId); 
     echo $result->id; echo "\n";
     echo $result->firstName; echo "\n";
     echo $result->lastName; echo "\n";
     echo $result->email; echo "\n";
     echo $result->phone; echo "\n";
  }  catch (Exception $e){

      echo $e->getMessage();die;
  }
/** find customer detail **/


Delete Customer
Using the customerId, You can DELETE customer detail from braintree server.

/** Include Library and set configuration**/
.
.
.
/** Include Library and set configuration**/

/** Delete a customer **/
$customerId = 14983213;
try{
      $result = Braintree_Customer::delete($customerId); 
      if($result->success){
        echo "Customer deleted successfully";
        }
      
  }  catch (Exception $e){

      echo $e->getMessage();die;
  }
/** Delete a customer **/



Tuesday, 23 June 2015

Hosted Field Integration - Braintree

Hosted Field Integration - Braintree


Question:What is Hosted Field in Braintree?
Hosted Fields are fields which are in another websites but displaying on your own website. It gives such a look, Customer will think its on your website but in actual its on braintree website. Payment Form files are in Iframe.
Following are the fields which can display in your website.
Credit card Number
Expiry Date
CVV Number



Question: What is purpose of hosted Fields?
If you want to accept the credit card/debit card in your website to charge from customer. You have to take the PCI compliance.
With using hosted field of braintree, you need not to worry about PCI Compliance.
Basically, Hosted Fields are developed to Solved the PCI 3.0..


Question: How hosted fields helps to solve the issue PCI Compliance?
Suppose you have payment page, where customer can fill credit card information.

Braintree create a payment-form dynamically in your website with use of java-script. This form is in iframe but and you can do lot of styling customization.

In this way, customer add the credit card info in your website but in actual its on braintree. that's why you need not to worry about PCI Compliance. Also when user submit the form, credit card information goes on braintree and use them & you will get a "nonce" variable.


Question:Explain Hosted Field in single line?
Hosted Fields are small, transparent iframes that replace the sensitive credit card inputs in your checkout flow/payment-form.


Question: What are two different ways to integrate the Hosted Fields?
Following are two different way.
1) Drop-in: It is quick way to integrate with braintree, In this payment form is pre-formated.
2) Custom with Hosted Fields: In this, you can do lot of styling customization.



Question: Which browser support the Hosted fields of braintree?
On web, Hosted Fields supports IE 8+ and Safari (OS X and iOS), Firefox, and Chrome (desktop, Android, and iOS).


Question: What is YOUR_CLIENT_TOKEN?
To process anything in client side like create transaction, create customer, update details etc you need a new YOUR_CLIENT_TOKEN.
YOUR_CLIENT_TOKEN is unique random token created from server side(in your application). Following function generate the token?
Braintree_ClientToken::generate();






Wednesday, 17 June 2015

Braintree payment gateway integration

Braintree payment gateway integration


Braintree is an American company which helps online business by processing credit card for merchants. They have payment gateway which support normal payment, recurring billing and credit card storage. It is a Level 1 PCI-DSS(Payment Card Industry Data Security Standard) compliant service provider. Braintree was founded in 2007 by Bryan Johnson. Latter on it was acquired by eBay.

  Following are characteristics of Braintree.
01. Online payment with Web AND mobile application.
02. Streamlining the onboarding process for US merchants.
03. Venmo Touch which checkout with one touch across multiple mobile applications.
04. Marketplace product which manages the payouts, taxes, compliance and chargebacks.
05. Credit Card Data Portability.
06. Fast deposits to bank account.
07. Support over 40 countries and 130 currencies.
08. Sophisticated sales analytics.
09. No fees for failed transactions.
10. No inactivity fees.
11. Consistent pricing for all card brands.
12. 2.9% + $.30 per transaction.


What is Braintree Marketplace
Braintree Marketplace is part of Braintree that enable to split payment between seller and marketplace.

Following are characteristics of Braintree Marketplace.
01. Easy Compliance.
02. No Extra Fees.
03. Flexibility.
04. Splitting payments.
05. Works for both Web and Mobile.
06. No escrow is required, charge when you need.
07. Its free for merchants and charge only on transactions i.e (2.9% + $.30).
08. Braintree generate 1099-K tax forms required by the IRS.


How Braintree works? 
01. Your web requests a "client token" from your server in order to initialize the JS SDK.
02. Your server generates a token and sends back to your client.
03. Once the JS SDK is initialized, it communicates with Braintree, which returns a "payment method nonce" to your client code.
04. You then send the payment nonce to your server.
05. Your server code receives the "payment method nonce" from your client and then uses the PHP SDK to create a transaction.


Question: What are Payment Methods available in Braintree?
01. Paypal
02.Credit Cards
03. Venmo (With on touch)
04. Apple Pay


Question: What is Payment method nonce?
Payment method nonce: It is string returned by the client SDK (javascript) to represent a payment method.
It is reference to the customer payment method details that were provided in your payment form and used by PHP Server.
Note: Expired in 24 Hour


Question: How to get paymentMethodNonce?
1. Create an account in braintree.
2. Get the merchantId, PublicKey and private Key.
3. Update the merchantId, PublicKey and private Key in following code snippet.
4. Run the code.

A. First get the clientToken from your server
/** Include Library and set configuration**/
require_once '/braintree-php301/lib/Braintree.php';
Braintree_Configuration::environment('sandbox');
Braintree_Configuration::merchantId('xxxxxxxx');//update merchantId
Braintree_Configuration::publicKey('xxxxxxxxxx');//update public key
Braintree_Configuration::privateKey('xxxxxxxxxxxxxxxxxxxxxx'); //Private key

//Get the Client Token
$clientToken = Braintree_ClientToken::generate();

B. Add following following HTML Code.
<script src="https://js.braintreegateway.com/js/beta/braintree-hosted-fields-beta.17.js"></script>
<form action="/payment.php" id="my-sample-form" method="POST">
<label for="card-number">Card Number</label>
      <br />
<div id="card-number">
</div>
<label for="cvv">CVV</label>
      <br />
<div id="cvv">
</div>
<label for="expiration-date">Expiration Date</label>
      <br />
<div id="expiration-date">
</div>
<input type="submit" value="Pay" />
</form>


C. Update the clientToken in following javascript code.
braintree.setup(clientToken, "custom", {
        id: "my-sample-form",
        hostedFields: {
          number: {
            selector: "#card-number"
          },
          cvv: {
            selector: "#cvv"
          },
          expirationDate: {
            selector: "#expiration-date"
          }
        }
      });


OR - Custom Form with Custom URL to get payments
braintree.setup(clientToken, "custom", {
        id: "my-sample-form",
        hostedFields: {
          number: {
            selector: "#card-number",
            placeholder: "Card Number"
          },
          cvv: {
            selector: "#cvv",
            placeholder: "CVV"
          },
          expirationMonth: {
            selector: "#expiration-month",
            placeholder: "Expiration Month"
          },
          expirationYear: {
            selector: "#expiration-year",
            placeholder: "Expiration Year"
          }
        },onPaymentMethodReceived:function(response){
             $.ajax({
                url:'/ajax/braintree-nonce',
                data:'payment_method_nonce='+response.nonce+'&card_digits='+response.details.lastTwo+'&card_type='+response.details.cardType+'&user_id=',
                type:'POST',
                dataType:'json',
                success: function(response) {
                    
                    if(response.success == 1){
                        //write here Code
                    }else{
                       $('#mainSubmitBtn-help').html('Some payment method input fields are invalid. Please try again.').show();
                    }
                },
                error: function(xhr, ajaxOptions, thrownError) {
                    //Error Handling
                }
            });
            return false;
            
        },onError:function(response){
              //Error Handling
            
        }
        }); 



Collect above code (A,B and C), In single page and click on "Pay" after filling the cc details

When customer add the credit card detail and submit the form, First request goes to braintree server they do the process and return an unique string with name "payment_method_nonce" to payment.php.
Once get the "payment_method_nonce" from payment.php. Use this token to charge the customer. It is valid upto 24 Hour


Question: How to charge the customer with use of payment_method_nonce token?
/** Include Library and set configuration**/
require_once '/braintree-php301/lib/Braintree.php';
Braintree_Configuration::environment('sandbox');
Braintree_Configuration::merchantId('xxxxxxxxxxxxxxxx');
Braintree_Configuration::publicKey('xxxxxxxxxxxxxxxxx');
Braintree_Configuration::privateKey('xxxxxxxxxxxxxxxxxxxxxxxxxxxx');
/** Include Library and set configuration**/


$paymentMethodNonce ='699dc252-6388-464a-9712-5dd8fa2bb656';
try{ 
          $result = Braintree_Transaction::sale(array(
               'amount' => '1.00',
               'paymentMethodNonce' => paymentMethodNonce,
               'options' => array(
                 'submitForSettlement' => True
               )
             ));
          $transactionId = $result->transaction->id;
          echo "Transaction Id".$transactionId;die;

       }  catch (Exception $e){
           echo $e->getMessage();die;

       }