laravel / cashier-stripe

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

Support for new usage Meters #1677

Closed obrunsmann closed 3 months ago

obrunsmann commented 3 months ago

There is a new feature called "Meters" which seems to be the new way to report usage to stripe:

https://docs.stripe.com/api/billing/meter-event

This is some sample implementation which I now use.

<?php

$payload = [
    'event_name' => 'meter_name',
    'payload' => [
        'value' => $event->count,
        'stripe_customer_id' => $event->user->stripe_id,
    ],
];

$stripe = Cashier::stripe();
$stripe->billing->meterEvents->create($payload);

Usage records seems to get deprecated. For now we could implement a method like


public function createMeterEvent(
  string $eventName,
  int $value = 1,
  string $eventPayloadKey = 'value',
  string $identifier = null,
  \DateTimeInterface|int|null $timestamp = null,
) : \Stripe\UsageRecord {}
driesvints commented 3 months ago

Yeah I'd love to see support for this in Cashier. Welcoming PR's!

jigarhalani commented 2 months ago

Is this deployed in new version of cashier?

driesvints commented 2 months ago

No, we haven't gotten a PR yet