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

register Webhook shrows an exception when processing returned data #21

Closed
wwalex opened this issue Nov 12, 2020 · 0 comments
Closed

register Webhook shrows an exception when processing returned data #21

wwalex opened this issue Nov 12, 2020 · 0 comments
Assignees

Comments

@wwalex
Copy link

wwalex commented Nov 12, 2020

Description
When registereing a Webhook, the returned data is passed to a new instance of Webhook class, which uses
function applyV1() to add the json data to the object.
This results in the following error:
Fatal error: Uncaught TypeError: Argument 1 passed to Trunkrs\SDK\Util\JsonDateTime::from() must be of the type string, null given

Looking at the returned data, it has the field
'created_at' => '.....',
While the code has
$webhook->createdAt = JsonDateTime::from($json->createdAt);

How to reproduce
$webhook = new \Trunkrs\SDK\Webhook();
$webhook->callbackUrl = "https://domain.name/";
$webhook->sessionHeaderName = 'XXXX';
$webhook->sessionToken = "yyyy";

$result = \Trunkrs\SDK\Webhook::register($webhook);

Possible Solution
Either have the API return createdAt or change the code to
$webhook->createdAt = JsonDateTime::from($json->created_at);

Additional context
Have only tested on staging, not sure if it also happens on live

fean pushed a commit that referenced this issue Nov 27, 2020
* Prevent Undefined Properties

This solves two problems.
1. The json result of the listing of webhooks, doesn't containt an url property. See https://docs.trunkrs.nl/docs/v1-api-documentation/reference/Trunkrs-Client-API.v1.yaml/paths/~1webhooks/get. If no url property is set, a default empty string will be used.
2. The json result doesn't containt a createdAt property. It's created_at poperty. This should solve issue #21 

With these fixes i was able to create, list and delete webhooks (live environment)

* Set $webhook->callbackUrl to null

Set $webhook->callbackUrl to null instead of empty string if $json->url is not set

* Fake webhook body response

Webhook body response didn't match actual response.
See: https://docs.trunkrs.nl/docs/v1-api-documentation/reference/Trunkrs-Client-API.v1.yaml/components/schemas/Webhook
@fean fean closed this as completed Nov 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants