php - XERO PHP API 将文件附加到发票 - 发送时不包含文件
问题描述
我正在将自定义 PHP 系统与 XERO 集成,我可以创建发票等。现在我们需要将一些文件附加到发票上。
PHP API 示例没有这个函数,只有一个将文件附加到帐户的函数,所以我以此为基础,查看了 createInvoiceAttachmentByFileName() 函数的在线文档,它类似于 createAccountAttachmentByFileName( ),除了它有一个额外的参数 ($include_online)。
该函数成功并返回正确的结果,但它似乎忽略了 $include_online 参数。我将它设置为什么并不重要,它永远不会被包括在内。
下面是我的函数代码。
有没有人这样做过,也许可以告诉我我做错了什么?
我正在使用 XERO PHP API 的 v 1.4.0
谢谢
安德烈
public function addInvoiceAttachment($invoice_xero_id, $file_path)
{
$res = "OK";
// Get the file name
$sep_pos = strrpos($file_path, '/');
$filename = substr($file_path, $sep_pos+1);
$handle = fopen($file_path, "r");
$contents = fread($handle, filesize($file_path));
fclose($handle);
$include_online = True;
try
{
$result = $this->apiInstance->createInvoiceAttachmentByFileName($this->xeroTenantId, $invoice_xero_id, $filename, $include_online, $contents);
trigger_error("addInvoiceAttachment: result = ".print_r($result, true));
}
catch (Exception $e)
{
trigger_error('Exception when calling AccountingApi->createInvoiceAttachmentByFileName: '.$e->getMessage());
$res = $e->getMessage();
}
return $res;
} // addInvoiceAttachment
// --------------------------------------------------------------------------
解决方案
我有同样的问题,Xero API 中有一个错误,这个参数被忽略了。lib/api/AccountingApi.php
解决方案是在文件中更改以下内容
createInvoiceAttachmentByFileNameRequest
在在线函数中8203
(至少在我的文件中)更改:
从:
$this->config->getHost() . $resourcePath . ($query ? "?{$query}" : ''),
至:
$this->config->getHost() . $resourcePath . "?IncludeOnline=" . ($include_online ? "true" : "false") . ($query ? "&{$query}" : ''),
这有点骇人听闻,但它确实有效。
推荐阅读
- python - python中多列的层次映射
- java - 尝试使用 ElasticSearch 存储和获取一些数据
- dataweave - JSON 对象忽略 null
- c# - 实现自定义两因素身份验证,为什么 GetTwoFactorAuthenticationUserAsync() 返回一个空用户?
- c++ - 从负 int 静态转换为 uint
- c++ - C ++指针的指针是否自动访问新值?
- asp.net-core - 如何在 Asp .Net Core SignalR Hub 中获取不记名令牌?
- reactjs - 如何从 react-scripts 中删除未使用的依赖项?
- ansible - 在一组主机上运行 ansible 任务,每个主机也作为参数传递给任务
- firebase - Firebase Auth SendEmailVerificationAsync 在收件人电子邮件上失败