braintree / braintree_php_example

An example Braintree integration for PHP
MIT License
127 stars 94 forks source link

Hello it's not showing google pay and apple button what's the process for that #52

Closed atta1234 closed 4 years ago

atta1234 commented 4 years ago

as title~

crookedneighbor commented 4 years ago

ApplePay: https://developers.braintreepayments.com/guides/drop-in/setup-and-integration/javascript/v3#apple-pay GooglePay: https://developers.braintreepayments.com/guides/drop-in/setup-and-integration/javascript/v3#google-pay

If you need additional help, contact our support team: https://help.braintreepayments.com/

atta1234 commented 4 years ago

that's confused me,,,, currently i have on front end,,,so what's the next step, to include that button same ui,,, and secondly when i use crdit card 42424 4242 etc the transaction working , but when i select paypal , then it show this error "PayPal pending payments are not supported"

<script src="https://js.braintreegateway.com/web/dropin/1.13.0/js/dropin.min.js"></script>
    <script>
        var form = document.querySelector('#payment-form');
        var client_token = "{{ $token }}";
        braintree.dropin.create({
          authorization: client_token,
          selector: '#bt-dropin',
          paypal: {
            flow: 'vault'
          }
        }, function (createErr, instance) {
          if (createErr) {
            console.log('Create Error', createErr);
            return;
          }
          form.addEventListener('submit', function (event) {
            event.preventDefault();
            instance.requestPaymentMethod(function (err, payload) {
              if (err) {
                console.log('Request Payment Method Error', err);
                return;
              }
              // Add the nonce to the form and submit
              document.querySelector('#nonce').value = payload.nonce;
              form.submit();
            });
          });
        });
    </script>
atta1234 commented 4 years ago

sir can you please help, i have added the google code above that one like this but not showing,,, and the token will be same for all,? or i have to do seprate back end for google pay? very confused please help,,,

@csrf
    </div>

  </div>
 <!--  <div class="phonnumber">
      <p class="number">Need assistance? Call 1-800-669-4268</p>
  </div> -->
</div>

@endsection @section('page-js')


<script src="https://js.braintreegateway.com/web/dropin/1.13.0/js/dropin.min.js"></script>
    <script>
        var form = document.querySelector('#payment-form');
        var client_token = "{{ $token }}";

      braintree.dropin.create({
          authorization: client_token,
  container: '#bt-dropin',
  googlePay: {
    googlePayVersion: 2,
    merchantId: 'merchant-id-from-google',
    transactionInfo: {
      totalPriceStatus: 'FINAL',
      totalPrice: '123.45',
      currencyCode: 'USD'
    },
    cardRequirements: {
      // We recommend collecting and passing billing address information with all Google Pay transactions as a best practice.
      billingAddressRequired: true
    }
  }
});

        braintree.dropin.create({
          authorization: client_token,
          selector: '#bt-dropin',
          paypal: {
            flow: 'vault'
          }
        },

         function (createErr, instance) {
          if (createErr) {
            console.log('Create Error', createErr);
            return;
          }
          form.addEventListener('submit', function (event) {
            event.preventDefault();
            instance.requestPaymentMethod(function (err, payload) {
              if (err) {
                console.log('Request Payment Method Error', err);
                return;
              }
              // Add the nonce to the form and submit
              document.querySelector('#nonce').value = payload.nonce;
              form.submit();
            });
          });
        });
    </script>

my backend function

public function index()
       {

     $gateway = new Braintree\Gateway([
         'environment' => 'sandbox',
         'merchantId' => 'tq7vsrgd2zjczk2t',
         'publicKey' => '',
         'privateKey' => ''
        ]);
    $token = $gateway->ClientToken()->generate();
        $title="Home Page";
        return view('index',compact('title','token'));
        }
    public function checkout(Request $request){
       $gateway = new Braintree\Gateway([
         'environment' => 'sandbox',
         'merchantId' => 'tq7vsrgd2zjczk2t',
         'publicKey' => '',
         'privateKey' => ''
       ]);

        $amount = $request->amount;
        $nonce = $request->payment_method_nonce;
        $result = $gateway->transaction()->sale([
        'amount' => $amount,
        'paymentMethodNonce' => $nonce,
        'customer' => [
            'firstName' => 'Tony',
            'lastName' => 'Stark',
            'email' => 'tony@avengers.com',
        ],
        'options' => [
            'submitForSettlement' => true
        ]
    ]);

       // echo '<pre>';
       //  print_r($result);
       //  exit();

    if ($result->success) {
        $transaction = $result->transaction;
        // header("Location: transaction.php?id=" . $transaction->id);

        return back()->with('success_message', 'Transaction successful. The ID is:'. $transaction->id);
    } else {
        $errorString = "";

        foreach ($result->errors->deepAll() as $error) {
            $errorString .= 'Error: ' . $error->code . ": " . $error->message . "\n";
        }

        // $_SESSION["errors"] = $errorString;
        // header("Location: index.php");
        return back()->withErrors('An error occurred with the message: '.$result->message);
    }
  }
hollabaq86 commented 4 years ago

I'm locking this issue - please contact Braintree Support for assistance. Also, it is good security practice to never publicly share private keys (even for a sandbox account). You should rotate the API keys for your account.