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' => '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 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' => 'funding@blueladders.com',
      '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@web-technology-experts-notes.in',
    '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@web-technology-experts-notes.in',
            '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 **/