首页 > 解决方案 > 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
  // --------------------------------------------------------------------------

标签: phpxero-api

解决方案


我有同样的问题,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}" : ''),

这有点骇人听闻,但它确实有效。


推荐阅读