laravel / cashier-stripe

Laravel Cashier provides an expressive, fluent interface to Stripe's subscription billing services.
https://laravel.com/docs/billing
MIT License
2.39k stars 680 forks source link

Metered Billing does not support their new API #1709

Closed timwrb closed 3 months ago

timwrb commented 3 months ago

Cashier Stripe Version

15.0

Laravel Version

11.21.0

PHP Version

8.2

Database Driver & Version

No response

Description

When dealing with metered billing, either with recieving usage records or reporting usage to a metered subscription, stripe tells me this:

Error: Cannot create a usage record for SUBSCRIPTION_ITEM because it is not on the legacy metered billing system. Call /v1/billing/meter_events instead.

Here are the docs: https://docs.stripe.com/api/billing/meter-event/create

This code worked for me then:

$stripe = new StripeClient(config('services.stripe.secret')); $stripe->billing->meterEvents->create([ 'event_name' => 'EVENT_NAMEr', 'payload' => [ 'value' => '1', 'stripe_customer_id' => $company_stripe_id, ], 'identifier' => 'identifier_123', ]);

Steps To Reproduce

$company->subscription('default')->reportUsageFor('PRICE_ID', 1);

driesvints commented 3 months ago

There was an attempt here but was reverted because of failing tests. We'd still very much appreciate PR's for this with passing tests. https://github.com/laravel/cashier-stripe/pull/1698