[英]Braintree iOS: fatal error 'Braintree_Configuration' not found
我想在我的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');
我哪里出错了? 我该如何解决这个问题?
我知道它有点晚了。 但是,让我为未来的读者添加解决方案,他们可能正在寻找类似的解决方案,同时集成PHP技术以获取客户端令牌。
您需要先设置先决条件。
需要以下PHP扩展:
假设您已在服务器上安装了依赖项。 BrainTree API期望以下内容:
1)开发人员沙盒帐户 - 在此处创建一个帐户
2)您的应用程序中的BrainTree客户端框架 - 从此处下载
快速入门示例
<?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';
您的代码段中缺少。
以下是解决方案的参考链接。
我也有这个问题。 只有在成功包含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 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.