简体   繁体   中英

braintree custom integration with paypal

i am new at braintree payment gateway. im using custom integration to make payment.i complete successfully my payment by using credit cards.but i have two issues and i also want to add amount of my choice in form.

1)i want to add more fields in my form like customername,address,phone number,email i dont have any idea how to add more fields in hosted fields.

2)honestly i don't have any idea how to configure paypal in braintree.even braintree says "PayPal is enabled by default in the Sandbox." when i click on paypal button it shows error like " Sorry we cannot connect to PayPal. Please try again in a few minutes."

i created my sandbox account in india.maybe paypal doesn't allow paypal payment from india.

    <?php 
require ('vendor/autoload.php');
$clientToken = Braintree_ClientToken::generate();
?>
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8">
    <title>Checkout</title>
  </head>
  <body>
    <form action="#" id="my-sample-form">
    <div id="paypal-container"></div>
      <label for="card-number">Card Number</label>
      <div id="card-number"></div>

      <label for="cvv">CVV</label>
      <div id="cvv"></div>

      <label for="expiration-date">Expiration Date</label>
      <div id="expiration-date"></div>

      <input type="submit" value="Pay" />
    </form>

    <script src="https://js.braintreegateway.com/v2/braintree.js"></script>
    <script>
      braintree.setup("<?php echo   $clientToken; ?>", "custom", {
        id: "my-sample-form",
        hostedFields: {
          number: {
            selector: "#card-number"
          },
          cvv: {
            selector: "#cvv"
          },
          expirationDate: {
            selector: "#expiration-date"
          }
        },
        paypal: {
      container: "paypal-container",
    },
    onPaymentMethodReceived: function (obj) {
      window.location.href = 'http://localhost/braintreecustom/payment.php?payment_method_nonce='+obj.nonce;
    },
    onError: function (){

        alert('wrong details');
    }
      });
    </script>
  </body>
</html>

and here is the code of payment.php

<?php
require ('vendor/autoload.php');


  $nonce = $_GET["payment_method_nonce"];


  $result = Braintree_Transaction::sale([
    'amount' => '700.00', // Your amount goes here
    'paymentMethodNonce' => $nonce
  ]);

  ?>

Full disclosure: I work at Braintree. If you have any further questions, feel free to contact support .

1) To add additional fields, all you need to do is add input fields to your form and style them the same way as your hosted fields inputs. When submitting your form, you can capture those values as normal form inputs.

<form action="#" id="my-sample-form">
  <div id="paypal-container"></div>
  <label for="card-number">Card Number</label>
  <div id="card-number"></div>

  <label for="cvv">CVV</label>
  <div id="cvv"></div>

  <label for="expiration-date">Expiration Date</label>
  <div id="expiration-date"></div>

  <label for="another-field">Another Field</label>
  <input type="text" id="another-field" name="another-field" />

  <input type="submit" value="Pay" />
</form>

And here's the server code

<?php
require('vendor/autoload.php');

$nonce = $_GET["payment_method_nonce"];
$anotherField = $_GET["another-fild"];
// do something with fields

2) With the given information, I'm not sure what's wrong with your PayPal configuration. I'd recommend reaching out to Braintree support so they can help you troubleshoot it.

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