我想在我的iOS应用中集成Braintree付款。为此,我在https://getcomposer.org/doc/01-basic-usage.md之后安装了作曲家。
composer文件夹是在本地创建的,我把它放在我的服务器上。
但是当我运行payAmountUsingBraintree.php
文件时,我收到以下错误:
Fatal error: Class 'Braintree_Configuration' not found
payAmountUsingBraintree.php
的内容:
<?php
//include '../config.php';
include 'db_config.php';
require_once 'vendor/autoload.php';
//echo 'Current PHP version: ' . phpversion();
$PartnerId = $_POST["PartnerId"];
$nonce = $_POST["Nonce"];
$amount = $_POST["Amount"];
$fname = $_POST["fname"];
$lname = $_POST["lname"];
$SaveCard = $_POST["SaveCard"];
$number = $_POST["CardNumber"];
$postal_code = $_POST["postal_code"];
$CVV = $_POST["CVV"];
$MerchantAccountId = '';
$IsAvailable = 'no';
Braintree_Configuration::environment('sandbox'); // get error on this line
Braintree_Configuration::merchantId('2qyx6qtd9bvy82r');
Braintree_Configuration::publicKey('c9qvxk3nvhmd68b');
Braintree_Configuration::privateKey('6f8ca01bd95cc0c753e936148303de4');
我哪里出错了?我该如何解决这个问题?
答案 0 :(得分:2)
我知道它有点晚了。但是,让我为未来的读者添加解决方案,他们可能正在寻找类似的解决方案,同时集成 PHP 技术来获取客户端令牌。
您需要先设置先决条件。
需要以下PHP扩展:
假设您已在服务器上安装了依赖项。 BrainTree API期望以下内容:
1)开发人员沙盒帐户 - 创建一个here
2)应用程序中的BrainTree Client Framework - 从here下载
快速入门示例
<?php
require_once 'PATH_TO_BRAINTREE/lib/Braintree.php';
Braintree_Configuration::environment('sandbox');
Braintree_Configuration::merchantId('your_merchant_id');
Braintree_Configuration::publicKey('your_public_key');
Braintree_Configuration::privateKey('your_private_key');
$result = Braintree_Transaction::sale([
'amount' => '1000.00',
'paymentMethodNonce' => 'nonceFromTheClient',
'options' => [ 'submitForSettlement' => true ]
]);
if ($result->success) {
print_r("success!: " . $result->transaction->id);
} else if ($result->transaction) {
print_r("Error processing transaction:");
print_r("\n code: " . $result->transaction->processorResponseCode);
print_r("\n text: " . $result->transaction->processorResponseText);
} else {
print_r("Validation errors: \n");
print_r($result->errors->deepAll());
}
您的代码段中缺少require_once 'PATH_TO_BRAINTREE/lib/Braintree.php';
声明。
以下是解决方案的参考链接。
答案 1 :(得分:2)
我也遇到过这个问题。只有在成功包含Braintree.php之后,此错误才会上升。但另一个文件,即Braintree.php / configuration.php不包含在 autoload.php
中这是无效的目录路径错误。
您想在 $ file_name 中使用完全 DIRECTORY_SEPARATOR 并更改
$fileName = dirname(__DIR__) . '/lib/';
到
$fileName = dirname(__DIR__) . DIRECTORY_SEPARATOR.'paypal'.DIRECTORY_SEPARATOR;
我用paypal作为目录。所以根据需要改变它。如果出现相同的错误并更正目录路径,请尝试打印完整的 $ filename 。