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

前端 未结 2 1192
我在风中等你
我在风中等你 2021-01-23 09:19

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 <

2条回答
  •  北荒
    北荒 (楼主)
    2021-01-23 09:49

    It seems like you're not using the most upto date version of Laravel Cashier. In older versions, if you follow the code through, you'll see that Laravel Cashier is trying to format a property that Stripe no longer returns.

    cashier\src\Invoice.php, line 48

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

    As per the Stripe "API Upgrade Guide", you can see on 2019-03-14, they announced the following change;

    "The date property has been renamed to created." (Source: https://stripe.com/docs/upgrades#2019-03-14)

    The latest version of Cashier has addressed this issue by checking for the existance of the created property first.

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

    EDIT: If you can't upgrade for whatever reason, instead of:

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

    You can try something like:

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

提交回复
热议问题