简体   繁体   中英

Integration of Paypal in transparent redirect method of braintree

im new at braintree.I am using braintree transparent redirect(php SDK) method for making payments.In this method i can successfully make payment by using credit cards.now i want to add paypal payment in transparent redirect.i can show my code if anyone wanna have look.Any help will be appreciated.sorry for bad english.

<?php

    require ('vendor/autoload.php');
    require ('settings.php');

    $settings['redirectUrl'] .= $_SERVER['SCRIPT_NAME'];

    /*
     * replace the following with the configuration code from the Braintree Control Panel, which
     * will contain your unique API keys
     */
    Braintree_Configuration::environment($settings['environment']);
    Braintree_Configuration::merchantId($settings['merchantId']);
    Braintree_Configuration::publicKey($settings['publicKey']);
    Braintree_Configuration::privateKey($settings['privateKey']);


$status = '';

    if(isset($_GET['http_status']) && $_GET['http_status'] == '200') {

        try {
            $result = Braintree_TransparentRedirect::confirm($_SERVER['QUERY_STRING']);
            if ($result->success) {
                $status = 'Your transaction was processed successfully.';
            } else {
                $status = $result->message;
            }
        } catch (Braintree_Exception_NotFound $e) {
            $status = 'Due to security reasons, the reload button has been disabled on this page.';
        }

    }

    $tr_data = Braintree_TransparentRedirect::transactionData([
         'transaction' => [
            'type' => Braintree_Transaction::SALE,
            'options' => [
                'submitForSettlement' => true
            ]
        ],
        'redirectUrl' => $settings['redirectUrl']
    ]);

?>

<body>
    <div id="wrap">
        <?php if ($status):?>
            <div class="status"><?= $status?></div>
        <?php endif;?>
        <form method="post" action="<?= Braintree_TransparentRedirect::url()?>" autocomplete="off">
        <label>Amount: <input type="text" name="transaction[amount]" /></label>
            <label>First Name: <input type="text" name="transaction[customer][first_name]"></label>
            <label>Last Name: <input type="text" name="transaction[customer][last_name]"></label>
            <label>Email: <input type="text" name="transaction[customer][email]"></label>
            <label>Phone No.: <input type="text" name="transaction[customer][phone]"></label>
            <label>Card Number: <input type="text" name="transaction[credit_card][number]"></label>
            <label>CVV: <input type="text" name="transaction[credit_card][cvv]" class="short"></label>
            <label>Expiration Date (MM/YYYY): <input type="text" name="transaction[credit_card][expiration_date]" class="short"></label>
            <p>----------------------------------------Billing Address------------------------------------</p>
            <label>Billing First Name: <input type="text" name="transaction[billing][first_name]"></label>
            <label>Billing Last Name: <input type="text" name="transaction[billing][last_name]"></label>
            <label>Billing Street Address: <input type="text" name="transaction[billing][street_address]"></label>
            <label>Postal Code: <input type="text" name="transaction[billing][postal_code]"></label>
            <input type="submit" value="submit payment">

            <input type="hidden" name="tr_data" value="<?=$tr_data?>">
        </form>
    </div>
</body>

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

Transparent Redirect is a deprecated method for integrating with Braintree; you cannot use it with the PayPal integration.

I recommend using Drop-In .

The page with the Braintree form:

<?php
  Braintree_Configuration::environment($settings['environment']);
  Braintree_Configuration::merchantId($settings['merchantId']);
  Braintree_Configuration::publicKey($settings['publicKey']);
  Braintree_Configuration::privateKey($settings['privateKey']);

  $clientToken = Braintree_ClientToken::generate();
?>

<form action="/endpoint_to_submit_transaction.php" method="post">
  <div id="dropin-container"></div>
</form>

<script src="https://js.braintreegateway.com/v2/braintree.js"></script>
<script>
  var clientToken = "<?php echo $clientToken; ?>";

  // If you have PayPal configured in your Braintree control panel, it'll appear automatically
  braintree.setup(clientToken, "dropin", {
    container: "dropin-container"
  });
</script>

And here's a sample endpoint to process the transaction

<!-- endpoint_to_submit_transaction.php -->
<?php
  $nonce = $_POST["payment_method_nonce"];
  $result = Braintree_Transaction::sale([
    'amount' => '100.00', // Your amount goes here
    'paymentMethodNonce' => $nonce
  ]);

  // Do something with the resulting transaction (save to your db, redirect to a confirmation page with the transaction details, etc)
  // https://developers.braintreepayments.com/reference/response/transaction/php

If you need more control over the look of the form, I'd recommend using Hosted Fields .

If you must use Transparent Redirect, you can create a standalone PayPal integration , but this will be a completely separate form from your Transparent Redirect form.

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