recurly-client-php icon indicating copy to clipboard operation
recurly-client-php copied to clipboard

Client::createSubscriptionChange() returning EmptyResource throws Fatal Exception

Open trickeyone opened this issue 2 years ago • 6 comments

Warning: Github issues are not an official support channel for Recurly. If you have an urgent request we suggest you contact us through an official channel: [email protected] or https://recurly.zendesk.com

Describe the bug

If a subscription already has a pending change, then a new change is created that matches the existing subscription, per the API docs, the change is removed and a 204 No Content is sent.

Recurly\Client::createSubscriptionChange(): Return value must be of type Recurly\Resources\SubscriptionChange, Recurly\EmptyResource returned {"exception":"[object] (TypeError(code: 0): Recurly\\Client::createSubscriptionChange(): Return value must be of type Recurly\\Resources\\SubscriptionChange, Recurly\\EmptyResource returned

To Reproduce

Have an account with an existing subscription change, then submit a change that matches the current subscription values.

Expected behavior

Recurly\Client::createSubscriptionChange() should add a union return type for PHP8+ to support returning Recurly\Resources\EmptyResource as well as the normal Recurly\Resources\SubscriptionChange

Your Environment

Recurly SDK: 4.9.0 PHP: 8.0

trickeyone avatar Nov 29 '21 19:11 trickeyone

Appears to be expected behavior per https://developers.recurly.com/api/v2021-02-25/index.html#operation/create_subscription_change

macabacus-rm avatar Jan 12 '22 04:01 macabacus-rm

Appears to be expected behavior per https://developers.recurly.com/api/v2021-02-25/index.html#operation/create_subscription_change

The issue is in the SDK, not the API. The return result from the SDK is returning a type not defined in the signature. This is causing the exception I outlined.

trickeyone avatar Jan 12 '22 05:01 trickeyone

that is a bug, It can be reproduced with stub code of that calls, like this

public function createSubscriptionChange(): \Recurly\Resources\SubscriptionChange
{
    return $this->makeRequest();
}

protected function makeRequest(): \Recurly\RecurlyResource
{
    return new \Recurly\EmptyResource(); //case when EmptyResource is returned - throws exception
    //return new \Recurly\Resources\SubscriptionChange(); //standard working behavior
}

exception is thrown because it is EmptyResource is not an instance of SubscriptionChange, this is not modeled properly

pawelbaranski avatar Feb 24 '23 09:02 pawelbaranski

We've just experienced this issue with a call to getInvoice() returning EmptyResource. It appears to affect lots of methods on the \Recurly\Client class.

Did anybody try raising a support ticket for this? As the issue template states "Github issues are not an official support channel for Recurly" I have raised a ticket through their Zendesk support portal.

Let's see if that has any effect...

willselby avatar Nov 03 '23 11:11 willselby

I can only recommend a workaround, we surrounded that call with try/catch like this

catch (\Throwable $e)
{
    if ($e->getMessage() == 'Return value of Recurly\Client::createSubscriptionChange() must be an instance of Recurly\Resources\SubscriptionChange, instance of Recurly\EmptyResource returned')
    {
        //do what is best in your case
    }
    throw $e;
}

kinda sad but works :)

pawelbaranski avatar Nov 03 '23 11:11 pawelbaranski

Thanks for the suggestion Paweł. I've implemented something similar as a workaround, was hoping they could resolve the issue. The only response I've had to my support ticket is an acknowledgement.

willselby avatar Nov 08 '23 17:11 willselby