Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exception Attempt to read property "percentage" on string #1475

Merged
merged 2 commits into from
Nov 17, 2022

Conversation

padre
Copy link
Contributor

@padre padre commented Nov 17, 2022

When i try:

$user->downloadInvoice($invoiceId);

I receive the following exception:

production.ERROR: Attempt to read property "percentage" on string (View: /var/app/current/vendor/laravel/cashier/resources/views/receipt.blade.php) {"exception":"[object] (Illuminate\\View\\ViewException(code: 0): Attempt to read property \"percentage\" on string (View: /var/app/current/vendor/laravel/cashier/resources/views/receipt.blade.php) at /var/app/current/vendor/laravel/cashier/src/InvoiceLineItem.php:146)
[stacktrace]
#0 /var/app/current/vendor/livewire/livewire/src/ComponentConcerns/RendersLivewireComponents.php(106): Illuminate\\View\\Engines\\CompilerEngine->handleViewException(Object(ErrorException), 1)
#1 /var/app/current/vendor/laravel/framework/src/Illuminate/View/Engines/PhpEngine.php(60): Livewire\\LivewireViewCompilerEngine->handleViewException(Object(ErrorException), 1)
#2 /var/app/current/vendor/livewire/livewire/src/ComponentConcerns/RendersLivewireComponents.php(69): Illuminate\\View\\Engines\\PhpEngine->evaluatePath('/var/app/curren...', Array)
#3 /var/app/current/vendor/laravel/framework/src/Illuminate/View/Engines/CompilerEngine.php(70): Livewire\\LivewireViewCompilerEngine->evaluatePath('/var/app/curren...', Array)
#4 /var/app/current/vendor/livewire/livewire/src/ComponentConcerns/RendersLivewireComponents.php(35): Illuminate\\View\\Engines\\CompilerEngine->get('/var/app/curren...', Array)
#5 /var/app/current/vendor/laravel/framework/src/Illuminate/View/View.php(152): Livewire\\LivewireViewCompilerEngine->get('/var/app/curren...', Array)
#6 /var/app/current/vendor/laravel/framework/src/Illuminate/View/View.php(135): Illuminate\\View\\View->getContents()
#7 /var/app/current/vendor/laravel/framework/src/Illuminate/View/View.php(104): Illuminate\\View\\View->renderContents()
#8 /var/app/current/vendor/laravel/cashier/src/Invoices/DompdfInvoiceRenderer.php(26): Illuminate\\View\\View->render()
#9 /var/app/current/vendor/laravel/cashier/src/Invoice.php(787): Laravel\\Cashier\\Invoices\\DompdfInvoiceRenderer->render(Object(Laravel\\Cashier\\Invoice), Array, Array)
#10 /var/app/current/vendor/laravel/cashier/src/Invoice.php(813): Laravel\\Cashier\\Invoice->pdf(Array)
#11 /var/app/current/vendor/laravel/cashier/src/Concerns/ManagesInvoices.php(255): Laravel\\Cashier\\Invoice->downloadAs('9B35A9EA-0057', Array)

Because $taxAmount can be:

Stripe\StripeObject JSON: {
"amount": 41,
"inclusive": false,
"tax_rate": {
"id": "txr_1KxZESCelkdgTLAvmlfA4gHl",
"object": "tax_rate",
"active": false,
"country": "ES",
"created": 1652112888,
"description": null,
"display_name": "VAT",
"inclusive": false,
"jurisdiction": "Spain",
"livemode": false,
"metadata": [],
"percentage": 21,
"state": null,
"tax_type": "vat"
}

or

Stripe\StripeObject JSON: {
"amount": 41,
"inclusive": false,
"tax_rate": "txr_1KxZESCelkdgTLAvmlfA4gHl"
}

@padre padre changed the title Attempt to read property "percentage" on string Exception Attempt to read property "percentage" on string Nov 17, 2022
@taylorotwell taylorotwell merged commit a4477c7 into laravel:14.x Nov 17, 2022
@driesvints
Copy link
Member

This cannot be an issue. All lines on an invoice are expanded, including the tax rate for a tax amount:

https://github.com/laravel/cashier-stripe/blob/14.x/src/Invoice.php#L567

I'm going to revert this for now. @padre can you please open an issue with full steps to reproduce? I have a feeling we're missing something here. Did you maybe adjust the receipt.blade.php file?

@padre
Copy link
Contributor Author

padre commented Nov 18, 2022

@driesvints I din't adjust the receipt.blade.php file.

I did some more research and found that if the invoice has more than 10 items, from item number 11 tax_amounts does not include expanded tax_rate.

@driesvints
Copy link
Member

That would seem like a bug in stripe tbh. Can you contact stripe support?

@padre
Copy link
Contributor Author

padre commented Nov 18, 2022

Ok, I'll report back if there is any news.

@padre
Copy link
Contributor Author

padre commented Nov 18, 2022

@driesvints could you help me, please?

stripe/stripe-php#1400 (comment)

Thank you.

@padre
Copy link
Contributor Author

padre commented Dec 7, 2022

@driesvints until there is a better solution, could you accept the pull request?

Right now, when executing the instruction $user->downloadInvoice($invoiceId); with an invoice with more than 10 items an exception is generated.

@driesvints
Copy link
Member

No sorry, this PR would add an extra load to large invoices doing a stripe call per line item which is just too much.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants