2013-10-01 34 views
1

我有一个包含许多文件夹/子文件夹/文件的应用程序,我似乎无法让Braintree正常工作。有什么我只是在这里失踪?假设我的网站名称是DIR。Braintree API不能在PHP应用程序中工作

所有从布伦特里文件夹解压文件都在DIR/braintree_payments

然后我transaction.php文件在DIR /模板/内容/上市

所有形式的标签是在DIR /模板/内容/上市/ 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/>"); 
    } 
} 

?> 
+0

此外,包含confirm_booking.tpl.php的html页面从DIR/modules/listing/confirm_booking.php链接。所以modules/listing/confirm_booking.php位于url – pmanning

+0

嘿@pmanning,你是否在你的'require_once'中添加了'../'? 'require_once'../ braintree_payments/lib/Braintree.php';'如果这不能解决它,请更具体然后“无法正常工作”此外,我已编辑您的帖子,以删除您的私钥。即使它只是一个沙箱帐户,你应该保持私密。 – agf

+0

是的,我试过没有运气。并感谢编辑,但我只是在一些文本中涂写这些不是真正的键。它重定向到我的主页,然后在我的沙盒帐户中没有任何内容显示。 – pmanning

回答

0

我不清楚你正在经历什么,但也许这将帮助别人。

我在Braintree Sandbox中运行一个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。然后一切按预期工作。

+0

我也是这样做的,但仍然失败。我猜autoload.php有些问题 – erdomester

相关问题