Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Client::createSubscriptionChange() returning EmptyResource throws Fatal Exception #648

Open
trickeyone opened this issue Nov 29, 2021 · 6 comments
Labels

Comments

@trickeyone
Copy link

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: support@recurly.com 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

@macabacus-rm
Copy link

@trickeyone
Copy link
Author

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.

@pawelbaranski
Copy link

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

@willselby
Copy link

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...

@pawelbaranski
Copy link

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 :)

@willselby
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants