簡體   English   中英

Braintree與Paypal自定義集成

[英]braintree custom integration with paypal

我是Braintree付款網關的新手。 即時通訊使用自定義集成進行付款。我使用信用卡成功完成了付款。但是我有兩個問題,我也想在表格中添加我選擇的金額。

1)我想在表單中添加更多字段,例如客戶名,地址,電話號碼,電子郵件我不知道如何在托管字段中添加更多字段。

2)老實說,我不知道如何在braintree中配置貝寶。即使braintree說“默認情況下,沙箱中啟用了PayPal”。 當我單擊貝寶按鈕時,它顯示類似“抱歉,我們無法連接到貝寶。請在幾分鍾后重試。”

我在印度創建了我的沙盒帳戶。也許Paypal不允許來自印度的Paypal付款。

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

這是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
  ]);

  ?>

全面披露:我在Braintree工作。 如果您還有其他疑問,請隨時與支持小組聯系

1)要添加其他字段,您需要做的就是將輸入字段添加到表單中,並以與托管字段輸入相同的方式對它們進行樣式設置。 提交表單時,您可以將這些值捕獲為普通表單輸入。

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

這是服務器代碼

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

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

2)根據給定的信息,我不確定您的PayPal配置出了什么問題。 我建議聯系Braintree支持,以便他們可以幫助您解決問題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM