Laravel Cashier DateTime::__construct(): Failed to parse time string (@) at position 0 (@):

时间:2019-04-17 00:42:19

标签: laravel php-carbon laravel-cashier

I have this code when displaying list of invoices, this is similar or maybe exactly the same to the ones in the official Laravel Cashier documentation. I am getting this weird DateTime::__construct(): Failed to parse time string (@) at position 0 (@): Unexpected character error and I'm not sure what's the @ character doing in replace of a supposed to be date.

@foreach (Auth::user()->invoices() as $invoice)
    <tr>
        <td>{{ $invoice->date()->toFormattedDateString() }}</td>
        <td>{{ $invoice->total() }}</td>
        <td>
            <a href="/user/invoice/{{ $invoice->id }}">Download</a>
        </td>
    </tr>
@endforeach

Does anyone have a similar experience? I have also tried to just var_dump each $invoice->date() in the controller but the error is still the same.

2 个答案:

答案 0 :(得分:0)

似乎您没有使用最新版本的Laravel Cashier。在较旧的版本中,如果您遵循该代码,将会看到Laravel Cashier试图格式化Stripe不再返回的属性。

cashier \ src \ Invoice.php,第48行

$carbon = Carbon::createFromTimestampUTC($this->invoice->date);

根据Stripe的“ API升级指南”,您可以在2019-03-14上看到他们宣布了以下更改;

“日期属性已重命名为创建。” (来源:https://stripe.com/docs/upgrades#2019-03-14

最新版本的Cashier通过首先检查created属性的存在来解决此问题。

https://github.com/laravel/cashier/blob/9.0/src/Invoice.php#L48

编辑:如果由于某种原因而无法升级,则代替:

$invoice->date()->toFormattedDateString()

您可以尝试以下操作:

Carbon::createFromTimestamp($invoice->asStripeInvoice()->created)->toFormattedDateString();

答案 1 :(得分:0)

最近我遇到了同样的错误。标签上的日期为null

我正在阅读Stripe's docs,自2019年3月14日以来,他们进行了一些更改。

Laravel Cashier将停止获取发票日期,因为Stripe将不再提供该日期。

  

发票对象有一些更改:

  • status_transitions哈希现在包含发票的时间戳记 已完成,付款,标记为无法收藏或作废。
  • date属性已重命名为created。
  • finalized_at属性已移到status_transitions哈希中。

现在,我该如何解决?

  1. 我在9.3文件中通过composer.json更改了Laravel Cashier的版本。
  2. 我打开终端并运行composer update

我希望我的解决方案对您有用。问候!