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

Hydrate class from PushNotification #303

Closed
NicholasJohn16 opened this issue Feb 12, 2017 · 2 comments
Closed

Hydrate class from PushNotification #303

NicholasJohn16 opened this issue Feb 12, 2017 · 2 comments
Assignees
Labels
V2 V2 Client

Comments

@NicholasJohn16
Copy link

Is there an easy way to hydrate, say an Recurly_Subscription object, from a Recurly_PushNotification object?

When I try to access a date property from the subscription attribute on a notification, instead of getting a DateTime object as I would expect and would get from Recurly_Subscription object, I get an SimpleXMLElement.

@bhelx bhelx self-assigned this Feb 12, 2017
@bhelx
Copy link
Contributor

bhelx commented Feb 13, 2017

@NicholasJohn16 If you are referring to taking a push notification object and turning it into a Recurly_Subscription, then no we don't directly support that. Part of the problem is that we don't guarantee a 1:1 mapping of these objects to the resource objects. Also, you could maybe get away with constructing the Subscription from xml and it would be accurate 95% of the time, but the xml parsing code is protected and we don't recommend relying on the webhook mappings.

For now, I'd say your best option is to use the uuid to fetch the subscription:

$pn = new Recurly_PushNotification($xml);
$subscription = Recurly_Subscription::get($pn->subscription->uuid);

Considering that webhooks may be stale when they arrive, you'll get more reliable data this way too. I hope this answers your question. If you think we should make some changes to this library to help I'd be happy to consider it.

@bhelx bhelx closed this as completed Feb 13, 2017
@NicholasJohn16
Copy link
Author

It would be nice if the properties of push notification were instances of their object counterparts, like the account property is an instance of Recurly_Account and the subscription property is a property of Recurly_Subscription. It could just be understood that if you're getting the info from a notification object, it's just not going to be fully loaded or possibly outdated.

But I get that it doesn't work that way. Thanks for the info.

@bhelx bhelx added the V2 V2 Client label Mar 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
V2 V2 Client
Projects
None yet
Development

No branches or pull requests

2 participants