在braintree的透明重定向方法中集成Paypal

时间:2016-01-20 10:43:08

标签: php braintree

我正在使用braintree透明重定向(php SDK)方法进行付款。在这种方法中,我可以使用信用卡成功付款。现在我想在透明重定向中添加paypal付款。我可以显示我的代码,如果有人想看。任何帮助将被赞赏。对于糟糕的英语。

<?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>

1 个答案:

答案 0 :(得分:0)

完全披露:我在Braintree工作。如果您还有其他问题,请随时contact support

透明重定向是一种不推荐使用的方法,可与Braintree集成;你不能在PayPal集成中使用它。

我建议使用Drop-In

具有Braintree形式的页面:

<?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>

这是处理交易的样本端点

<!-- 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

如果您需要更多地控制表单的外观,我建议您使用Hosted Fields

如果您必须使用透明重定向,则可以create a standalone PayPal integration,但这与透明重定向表单完全不同。