脑树透明重定向方法中PayPal的集成.


Integration of Paypal in transparent redirect method of 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>

完全披露:我在Braintree工作。如果您有任何其他问题,请随时联系支持人员。

透明重定向是与 Braintree 集成的一种已弃用的方法;您不能将其与PayPal集成一起使用。

我建议使用插入式。

具有 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

如果您需要更好地控制表单的外观,我建议使用托管字段。

如果必须使用透明重定向,则可以创建独立的PayPal集成,但这将是与透明重定向表单完全分开的表单。