1

我正在尝试通过 Sage Accounting API 调用创建销售发票(其文档可在此处找到:https ://developer.sage.com/api/accounting/api/ )

为了使我的代码更清晰,我创建了一个类来帮助我相应地进行这些调用。

这是我用来进行这些调用的方法:

public function postRequest()
{
    $url = $this->baseEndpoint . $this->request;
    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    if (isset($this->params)) {
        curl_setopt($ch, CURLOPT_POSTFIELDS, $this->params);
    }

    curl_setopt($ch, CURLOPT_HTTPHEADER, array(
        "Authorization: Bearer $this->token",
        "Host: api.accounting.sage.com",
        "Content-Type: application/json"
    ));
    $response = json_decode(curl_exec($ch), true);
    curl_close($ch);
    return $response;
}

我如何调用此方法:

$params = array(
"sales_invoice" => array(
    "contact_id" => "485fdfe0be154f9c9af44351de16e5be",
    "date" => "2019-06-13",
    "invoice_lines" => array(
        array(
            "description" => "description",
            "ledger_account_id" => "f04157c90ff0496ab3a22f2558e46010",
            "unit_price" => 10   ,
            "quantity" => 1,
            "tax_rate_id" => "ES_RE_STANDARD",
            "tax_rate" => 0.1
        )
    )
)
);

$params = json_encode($params);
$request = "v3.1/sales_invoices";
$sageRequest = new SageRequest($token, $request, $params);
$sageRequest->postRequest();

根据 API 文档,这应该可以,但我仍然收到此错误:

[$severity] => error
[$dataCode] => UnexpectedError
[$message] => An unexpected error occurred.
[$source] => 

如果有人对 Sage Accounting API 有一些经验,我会非常感激知道我做错了什么。

4

1 回答 1

0

这个例子适用于我的西班牙企业:

{
  "sales_invoice": {
    "contact_id": "22b609fba11642238f2ecd0f5fe3e0b5",
    "date": "2019-06-12",
    "invoice_lines": [
      {
        "description": "Description",
        "ledger_account_id": "829739738de811e996c90122ae3d08ca",
        "quantity": 1,
        "unit_price": 100,
        "tax_rate_id": "ES_STANDARD"
      }
    ],
    "main_address": {
      "city": "Madrid"
    }
  }
}

确保您的联系人列在联系人端点中。用于GET https://api.accounting.sage.com/v3.1/ledger_accounts?visible_in=sales获取销售对象的所有有效分类帐帐户的列表。

我看到你的问题ES_RE_STANDARD用作税率。我将很快用一个“recargo de equivalencia”税率的例子来更新这个答案。

于 2019-06-13T15:06:56.483 回答