【问题标题】:Braintree API not working in PHP ApplicationBraintree API 在 PHP 应用程序中不起作用
【发布时间】:2013-10-07 04:08:36
【问题描述】:

我有一个包含许多文件夹/子文件夹/文件的应用程序,但我似乎无法让 Braintree 正常运行。有什么我只是在这里想念的吗?假设我的网站名称是 DIR。

所有从braintree文件夹解压出来的文件都在DIR/braintree_payments中

那么我的transaction.php文件在DIR/templates/content/listing中

表单的所有标签都在 DIR/templates/content/listing/confirm_booking.tpl.php 中

confirm_booking.tpl.php
                <h1>Braintree Credit Card Transaction Form</h1>
                    <div style="position:relative;">
                      <form action="transaction.php" method="POST" id="braintree-payment-form">
                        <p>
                          <label>Card Number</label>
                          <input type="text" size="20" autocomplete="off" data-encrypted-name="number" />
                        </p>
                        <p>
                          <label>CVV</label>
                          <input type="text" size="4" autocomplete="off" data-encrypted-name="cvv" />
                        </p>
                        <p>
                          <label>Expiration (MM/YYYY)</label>
                          <input type="text" size="2" name="month" /> / <input type="text" size="4" name="year" />
                        </p>
                        <input type="submit" id="submit" />
                      </form>
                    </div>
                    <script type="text/javascript" src="https://js.braintreegateway.com/v1/braintree.js"></script>
                    <script type="text/javascript">
                      var braintree = Braintree.create("awefawef2oIaXiawefawefawefoP1jJ3LNuLchxfeawfawetq34tq34tq34tBtfTk6KnM0Bk3TkofNMM2CG/1ktaBDa+BEbteZjF05e5Jjfwefawfawe4t34434CVxaXNAbgZEn+ECWiZ2rynxtme5goMAhYAS+blBaVlL9+affawef aw/NLhqKmwQL7zuK3GBGiOp3ht9rL3AI1O84o1WpjVeqt8Xgg5MQe4jRTGJAfR3Rv25KPuwRaTqrevyVyRkPekcCIp1HROoZGelQyaSsPzhA0/FApbRu0Vpcx6kUwIDAQAB");
                      braintree.onSubmitEncryptForm('braintree-payment-form');
                    </script>



transaction.php

<?PHP
require_once 'braintree_payments/lib/Braintree.php';

Braintree_Configuration::environment('sandbox');
Braintree_Configuration::merchantId('389yhf9gf82gf3');
Braintree_Configuration::publicKey('r3h89h39h833');
Braintree_Configuration::privateKey('my_private_api_key');

$result = Braintree_Transaction::sale(array(
    "amount" => "1000.00",
    "creditCard" => array(
        "number" => $_POST["number"],
        "cvv" => $_POST["cvv"],
        "expirationMonth" => $_POST["month"],
        "expirationYear" => $_POST["year"]
    ),
    "options" => array(
        "submitForSettlement" => true
    )
));

if ($result->success) {
    echo("Success! Transaction ID: " . $result->transaction->id);
} else if ($result->transaction) {
    echo("Error: " . $result->message);
    echo("<br/>");
    echo("Code: " . $result->transaction->processorResponseCode);
} else {
    echo("Validation errors:<br/>");
    foreach (($result->errors->deepAll()) as $error) {
        echo("- " . $error->message . "<br/>");
    }
}

?>

【问题讨论】:

  • 包含confirm_booking.tpl.php的html的页面也是从DIR/modules/listing/confirm_booking.php链接的。所以 modules/listing/confirm_booking.php 在 url 中
  • 嘿@pmanning,您是否尝试在您的require_once 中添加../? require_once '../braintree_payments/lib/Braintree.php'; 如果这不能解决它,请更具体然后“无法正常运行”此外,我已经编辑了您的帖子以删除您的私钥。即使它只是一个沙盒帐户,您也应该保密。
  • 是的,我试过没有运气。感谢您的编辑,但我只是在一些文本中乱写了那些不是真正的键。它重定向到我的主页,然后我的沙盒帐户中什么也没有显示。
  • 控制台/日志中显示了什么?它是说“成功”还是“错误”或其他什么?
  • 我正在处理这个问题——如果你查看底部的braintree/lib/Braintree.php,你会看到它应该在哪里抛出错误,说“Briantree 需要扩展X”。我将其更改为 echo 语句,并找到了需要安装的 2 个扩展。不确定这是否能让事情顺利进行,但这就是我现在所处的位置。

标签: php payment-gateway braintree


【解决方案1】:

我不清楚你正在经历什么,但也许这会对某人有所帮助。

我在 Braintree 沙箱中运行一个 form.php 和 transaction.php 文件。在 transaction.php 中,我执行了 require_once('/lib/Braintree.php'); 并且 transaction.php 正在死去,永远不会超过 require_once 声明。

我进入 Braintree.php 文件的底部,找到throw new Braintree_Exception('The Braintree library requires the ' . $ext . ' extension.'); 这一行

无论出于何种原因,这就是我的脚本即将死去的那一行。我将 throw new 更改为 echo 并再次运行我的 transaction.php 文件 - 并收到 2 条消息说“Braintree 库需要 XXXX 扩展名”。

对我来说,它是 xml-writer 扩展。我在我的服务器上安装了 xml-writer,然后重新启动了 Apache。然后一切都按预期工作。

【讨论】:

  • 我也这样做了,但仍然失败。我猜 autoload.php 有问题
猜你喜欢
  • 1970-01-01
  • 2017-08-16
  • 2018-05-06
  • 2023-03-09
  • 2021-09-05
  • 2017-04-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多