invoiceninja / sdk-php

PHP wrapper for Invoice Ninja's REST API
https://www.invoiceninja.com
83 stars 41 forks source link

Accessing POST data #7

Closed hjone72 closed 7 years ago

hjone72 commented 7 years ago

Hi,

I am having trouble accessing the POST data from a new payment subscription call. Do you have any examples of what InvoiceNinja sends with the webhook?

Thanks,

hillelcoren commented 7 years ago

You can use the API to request a record to see what's sent with the subscription.

hjone72 commented 7 years ago

So as an example if I had a subscription for a payment, the same information that is returned by looking up that payment using the API is sent with the subscription?

hillelcoren commented 7 years ago

That's correct.

hjone72 commented 7 years ago

I am not finding that to be the case.

I am calling a simple PHP script that is outputting the json_encode($_POST) to a file. After triggering the subscription the file only has [].

Hoping you might be able to point me in a direction to start debugging this.

hillelcoren commented 7 years ago

Here's where we get the data ready to send in the app:

https://github.com/invoiceninja/invoiceninja/blob/master/app/Listeners/SubscriptionListener.php#L143

We use transformers to map the data, for example:

https://github.com/invoiceninja/invoiceninja/blob/master/app/Ninja/Transformers/PaymentTransformer.php

hjone72 commented 7 years ago

I've added a bit of code to the SubscriptionListener.php writing the $data array to a file and that works. But I can't seem to access the data at the target_url.

My target URL is the following: http://localhost:8080/in_sdk/processpayment.php

Are there any issues with the URL?

Thank you for your assistance!

hillelcoren commented 7 years ago

Looks ok to me. Is the app on the same port, maybe a firewall/proxy/etc is stripping the post data?

hjone72 commented 7 years ago

Executing a curl to the same URL with some random post data works fine. Does InvoiceNinja log what data is sent to the subscription?

hillelcoren commented 7 years ago

It doesn't but you could add \Log::info(...)

hjone72 commented 7 years ago

Thanks for your help. I'll keep looking

hjone72 commented 7 years ago

So as it turns out... If you send application/json to PHP it won't convert it to POST. You can access it using the following file_get_contents("php://input");

Here is a link with some more details. https://stackoverflow.com/questions/13050716/receiving-a-json-post

hillelcoren commented 7 years ago

Thanks for sharing the solution!