stripe / stripe-php

PHP library for the Stripe API.
https://stripe.com
MIT License
3.75k stars 848 forks source link

Fixed empty response from v2 meter event stream endpoint #1755

Closed prathmesh-stripe closed 2 months ago

prathmesh-stripe commented 2 months ago

MeterEventStream returns a void response. As part of request handling we setLastResponse on the returned object from \Stripe\Util\Util::convertToStripeObject. Empty response meant we were getting back an array.

Fix

If the returned object is an array, we create a new empty StripeObject and set the response on it.

Another option would've been to skip setting the response itself. Open to hearing your opinions based on how this is handled in other languages.

Sample code that caused this issue.

$meterClient = new \Stripe\StripeClient([
        'api_key' => $meterEventSession->authentication_token,
    ]);

    $meterEvent = [
        'event_name' => 'new_meter',
        'payload'    => [
            'stripe_customer_id' => 'cus_Qv....,
            'value'              => '25',
        ],
    ];
    $createMeterEventResponse = $meterClient->v2->billing->meterEventStream->create([
            'events' => [$meterEvent],
        ]
    );
    print_r($createMeterEventResponse);