简体   繁体   English

使用Paypal进行Braintree付款与我的Paypal帐户没有关联

[英]Braintree payment with Paypal doesn't connect with my Paypal account

I have been working with the implementation of Braintree payment gateway and now i am stuck with its Paypal method. 我一直在与Braintree付款网关的实现一起工作,现在我坚持使用其Paypal方法。 The issue is describe below. 问题描述如下。

I have integrated the necessary code for for this and when selection the Paypal method and trying to login to Paypal, it always shows the error like below screenshot. 我已经为此集成了必要的代码,当选择Paypal方法并尝试登录Paypal时,它始终显示如下屏幕截图所示的错误。 [![error screen while login in to paypal][1]][1] [![登录Paypal时出现错误屏幕] [1]] [1]

I think this is happening because of the client token is wrong. 我认为这是由于客户端令牌错误而发生的。 but i have creating the token using the php method: $clientToken = Braintree_ClientToken::generate(). 但是我已经使用php方法创建了令牌:$ clientToken = Braintree_ClientToken :: generate()。

(It will currently login when i give the demo client token provided by Braintree demo code). (当我提供Braintree演示代码提供的演示客户端令牌时,它将当前登录)。

Here below i mentioned my code . 在下面,我提到了我的代码。 Please check and hope anyone can trigger the issue. 请检查并希望任何人都可以触发此问题。

<?php
require_once '_environment.php';

function braintree_text_field($label, $name, $result) {
    echo('<div>' . $label . '</div>');
    $fieldValue = isset($result) ? $result->valueForHtmlField($name) : '';
    echo('<div><input type="text" name="' . $name .'" value="' . $fieldValue . '" /></div>');
    $errors = isset($result) ? $result->errors->onHtmlField($name) : array();
    foreach($errors as $error) {
        echo('<div style="color: red;">' . $error->message . '</div>');
    }
    echo("\n");
}

// CLIENT TOKEN
$clientToken = Braintree_ClientToken::generate();

if(isset($_POST['payment_method_nonce'])){   
    $nonce  = $_POST['payment_method_nonce'];
    $result = Braintree_Transaction::sale(array(
      'amount' => '91.00',
      'paymentMethodNonce' => $nonce
    ));
    if ($result->success) {
        echo($result->customer->id);
        echo($result->customer->creditCards[0]->token);
        echo 'success';
    } else {
        foreach($result->errors->deepAll() AS $error) {
          echo($error->code . ": " . $error->message . "\n");
        }
    }    
}

?>
<form id="checkout" method="post" action="">
  <div id="payment-form"></div>
  <input type="submit" value="Pay $10">
</form>

<script src="https://js.braintreegateway.com/v2/braintree.js"></script>
<script>
    var clientToken = '<?php echo trim($clientToken);?>';
    braintree.setup(clientToken, "dropin", {
        container: "payment-form"
        });
</script>

To create a PayPal transaction, you will need a customer id, the following sample works for me. 要创建PayPal交易,您需要一个客户ID,以下示例适用于我。

index.php index.php

<?php
require("config.php"); //config.php contains Braintree_Configuration object.

$aCustomerId = '39538986'; // can be generated from braintreegateway.com vault->New Customer
$clientToken = Braintree_ClientToken::generate(array(
    "customerId" => $aCustomerId
));
;
?>




<script src="https://js.braintreegateway.com/v2/braintree.js"></script>
<script>
var clientToken = "<?php echo $clientToken ?>";
braintree.setup(clientToken, "dropin", {
  container: "payment-form"
});
</script>

<form>
    <div id="paypal-container"></div>
</form>
<script type="text/javascript">
braintree.setup(clientToken, "paypal", {
  container: "paypal-container",

  onPaymentMethodReceived: function (obj) {
   window.location.href = 'http://localhost/braintree/checkout_paypal.php?nounce='+obj.nonce;
  }
});
</script>

checkout_paypal.php checkout_paypal.php

<?php
require("config.php");
$nonce = $_GET["nounce"];
$result = Braintree_Transaction::sale(array(
  'amount' => '100.00',
  'paymentMethodNonce' => $nonce,
  'options' => array(
    'submitForSettlement' => True
  )
));

?>

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

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