Metered billing plan

Metered billing is useful in cases where you want to charge your customers a granular amount based on their consumption of your service during the billing cycle, instead of explicitly setting quantities. For example, if you are running an email SaaS business, you can track your customers’ API calls, then bill them for the total number used at the end of each month.

When the customer subscribes to the plan, Stripe Payments will save the subscription item (opens new window) id, this id is used for usage reporting. You can grab manually this id from the view order page or from the subscription model.

Stripe Payments Metered Subscription

# Reporting usage

To report the usage you can use the next examples:

use Craft;
use enupal\stripe\Stripe;


$currentUser = Craft::$app->getUser()->getIdentity();
$orders = Stripe::$app->subscriptions->getSubscriptionsByUser($currentUser->id);
// $orders = Stripe::$app->subscriptions->getSubscriptionsByEmail($currentUser->email);

foreach ($orders as $order) {
    $subscription = $order->getSubscription();
    if ($subscription->status == 'active' && $subscription->meteredId){