recurly-client-php
recurly-client-php copied to clipboard
Client::createSubscriptionChange() returning EmptyResource throws Fatal Exception
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
Appears to be expected behavior per https://developers.recurly.com/api/v2021-02-25/index.html#operation/create_subscription_change
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.
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
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...
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 :)
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.