简体   繁体   English

Braintree与Paypal自定义集成

[英]braintree custom integration with paypal

i am new at braintree payment gateway. 我是Braintree付款网关的新手。 im using custom integration to make payment.i complete successfully my payment by using credit cards.but i have two issues and i also want to add amount of my choice in form. 即时通讯使用自定义集成进行付款。我使用信用卡成功完成了付款。但是我有两个问题,我也想在表格中添加我选择的金额。

1)i want to add more fields in my form like customername,address,phone number,email i dont have any idea how to add more fields in hosted fields. 1)我想在表单中添加更多字段,例如客户名,地址,电话号码,电子邮件我不知道如何在托管字段中添加更多字段。

2)honestly i don't have any idea how to configure paypal in braintree.even braintree says "PayPal is enabled by default in the Sandbox." 2)老实说,我不知道如何在braintree中配置贝宝。即使braintree说“默认情况下,沙箱中启用了PayPal”。 when i click on paypal button it shows error like " Sorry we cannot connect to PayPal. Please try again in a few minutes." 当我单击贝宝按钮时,它显示类似“抱歉,我们无法连接到贝宝。请在几分钟后重试。”

i created my sandbox account in india.maybe paypal doesn't allow paypal payment from india. 我在印度创建了我的沙盒帐户。也许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>

and here is the code of payment.php 这是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
  ]);

  ?>

Full disclosure: I work at Braintree. 全面披露:我在Braintree工作。 If you have any further questions, feel free to contact support . 如果您还有其他疑问,请随时与支持小组联系

1) To add additional fields, all you need to do is add input fields to your form and style them the same way as your hosted fields inputs. 1)要添加其他字段,您需要做的就是将输入字段添加到表单中,并以与托管字段输入相同的方式对它们进行样式设置。 When submitting your form, you can capture those values as normal form inputs. 提交表单时,您可以将这些值捕获为普通表单输入。

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

And here's the server code 这是服务器代码

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

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

2) With the given information, I'm not sure what's wrong with your PayPal configuration. 2)根据给定的信息,我不确定您的PayPal配置出了什么问题。 I'd recommend reaching out to Braintree support so they can help you troubleshoot it. 我建议联系Braintree支持,以便他们可以帮助您解决问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM