我正在尝试在laravel中安装一个php包。安装后用编写器获取问题特征类找不到。
第一步:
{
"require": {
"avalara/avataxclient": "*"
}
}删除这行require __DIR__ . '/vendor/autoload.php';之后,我的控制器脚本是
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class AvaController extends Controller
{
// Include the AvaTaxClient library
use Avalara\AvaTaxClient;
// Create a new client
public function avatax(){
$client = new Avalara\AvaTaxClient('phpTestApp', '1.0', 'localhost', 'sandbox');
$client->withSecurity('', '');
// If I am debugging, I can call 'Ping' to see if I am connected to the server
$p = $client->ping();
echo('<h2>Ping</h2>');
echo('<pre>' . json_encode($p, JSON_PRETTY_PRINT) . '</pre>');
if ($p->authenticated == true) {
echo '<p>Authenticated!</p>';
}
// Create a simple transaction for $100 using the fluent transaction builder
$tb = new Avalara\TransactionBuilder($client, "DEFAULT", Avalara\DocumentType::C_SALESINVOICE, 'ABC');
$t = $tb->withAddress('SingleLocation', '123 Main Street', null, null, 'Irvine', 'CA', '92615', 'US')
->withLine(100.0, 1, null, "P0000000")
->create();
echo('<h2>Transaction #1</h2>');
echo('<pre>' . json_encode($t, JSON_PRETTY_PRINT) . '</pre>');
// Now, let's create a more complex transaction!
$tb = new Avalara\TransactionBuilder($client, "DEFAULT", Avalara\DocumentType::C_SALESINVOICE, 'ABC');
$t = $tb->withAddress('ShipFrom', '123 Main Street', null, null, 'Irvine', 'CA', '92615', 'US')
->withAddress('ShipTo', '100 Ravine Lane', null, null, 'Bainbridge Island', 'WA', '98110', 'US')
->withLine(100.0, 1, null, "P0000000")
->withLine(1234.56, 1, null, "P0000000")
->withExemptLine(50.0, null, "NT")
->withLine(2000.0, 1, null, "P0000000")
->withLineAddress(Avalara\TransactionAddressType::C_SHIPFROM, "123 Main Street", null, null, "Irvine", "CA", "92615", "US")
->withLineAddress(Avalara\TransactionAddressType::C_SHIPTO, "1500 Broadway", null, null, "New York", "NY", "10019", "US")
->withLine(50.0, 1, null, "FR010000")
->create();
echo('<h2>Transaction #2</h2>');
echo('<pre>' . json_encode($t, JSON_PRETTY_PRINT) . '</pre>');
}
}当我试图运行这个脚本时,我会得到以下错误:
(1/1) FatalErrorException特性‘App\Http\Controller\Avalara\AvaTaxClient’未找到
在AvaController.php第8行
如果我遗漏了什么,请告诉我。谢谢
发布于 2021-08-13 02:22:26
您需要用\反斜杠设置每个"Avalara“关键字
$client = new \Avalara\AvaTaxClient('phpTestApp', '1.0', 'localhost', 'sandbox');
$tb = new \Avalara\TransactionBuilder($client, "DEFAULT", \Avalara\DocumentType::C_SALESINVOICE, 'ABC');
->withLineAddress(\Avalara\TransactionAddressType::C_SHIPFROM, "123 Main Street", null, null, "Irvine", "CA", "92615", "US")
->withLineAddress(\Avalara\TransactionAddressType::C_SHIPTO, "1500 Broadway", null, null, "New York", "NY", "10019", "US")https://stackoverflow.com/questions/58623974
复制相似问题