Xero testing webhooks on localhost - php

So I am running a PHP application on localhost and I want to test an incoming web hook. Is there a recommended way to test the local development for this?
Is there an example web hook invoice-paid POST request I could just test with something like postman on my localhost?

You can use a tool like ngrok or Pagekite to expose your local server. You download and run a program on your machine and provide it the port of a network service, usually a web server.
It connects to the ngrok cloud service which accepts traffic on a public address and relays that traffic through to the ngrok process running on your machine and then on to the local address you specified.

I wrote a blog post on the topic
https://devblog.xero.com/lets-play-web-hooky-with-php-34a141dcac0a

You can use ngrok for test webhook in your local machine. Here is an additional detail to #sidney.maestre answer,
You only have to use Xero demo company in developer console for once,
then you can use the "Replay" button to use exact request every time in ngrok's dashboard.

Related

Not able to run local site and api at the same time laravel

I am not able to run local site and api at the same time laravel i am running the local site in port: 8000
and i am also using same port for api but its not working. I am using Xampp on windows.
Api url : http://localhost:8000/api/v1/login in postman works. But when in try in website with http client its not working
The same port can be used only if you use a different domain for the API. For example, you can use webapp.com for the frontend and use api.webapp.com for the API.

How to test integrations between local environment and external services (webhooks)

since i started to develop web applications i always found very annoying to inspect external services requests and test my application with "realistic" scenarios. What's the solutions we've got to expose my local development environment to external services?
I am using Laravel Homestead and/or PHP Development Server
Before some time searching for the definitive answer i found a solution that solves all these problems in an efficient, free way, this is Ngrok, a product created by Alan Shreve -- which has worked on giants like Microsoft and Twilio. Alan wrote about the creation of Ngrok and an article on his blog he describes the product as:
"Ngrok is a tunneling, reverse proxy that establishes secure tunnels from a public endpoint to a locally running network service while capturing all traffic for inspection and replay. It is an open-source project on GitHub."
Let's get started:
Well, now that you know a little bit about the tool and why i found it let's demonstrate how to expose a local environment to allow third-party services to submit requests to local environments via Webhook is very simple and the two solutions that I'm going to present have been tested and work with the following scenarios :
Scenario 1: A PHP project using PHP 7.2.6 Development Server
Scenario 2: A Laravel (PHP) project using Laravel Development Server (php artisan serve)
Scenario 3: A Laravel (PHP) project using Laravel Homestead
To do this just follow the steps:
Access the Ngrok website
Register or Login
Download the client based on your OS
Authenticate the client downloaded following the instructions that appear on the same page you've downloaded it.
For the first two scenarios just run the following command
ngrok http <host>:<port>
ex: ngrok http 127.0.0.0.1:666
For the third scenario (if you are using a domain to access the homestead Ex: homestead.test you must rewrite the host-header. But don't worry, to achieve it just increment the command above to something like)
ngrok http <homestead_host_ip>:<port> -host-header=<homestead_domain>
example: ngrok http 192.168.10.10:80 -host-header=homestead.test
VoilĂ , now just point the URL generated by Ngrok in Webhook that you want to test and enjoy this wonderful solution.

How to execute a shell_exec command from the cloud to my localhost

i am making a SMS sending website and im using Gammu as my local sms gateway, it is working fine in my localhost base on the php code i am using which is:
echo shell_exec('"C:\Gammu\bin\gammu.exe" --sendsms TEXT +'.$row["mobilenum"].' -text '.$message.'');
Now how i can execute this when i start putting the website on the cloud? I am using a window based for my SMS server.
Is there other way i can link the cloud and the localhost to just execute the gammu command?
Calling shell_exec() to gammu.exe on a cloud server won'r work as you don't have the phone connection.
Instead of calling shell_exec() from your cloud hosted website, you will need to make a request via HTTP to a service which can do this.
The easiest would be to use something like Twillio.com
Or, you can also expose a simple HTTP API on your local network that is accesible for the cloud server to POST to.
You would need a static IP on your local Gammu server, and the corresponding port opened in the firewall.
So for example:
POST http://100.22.33.11/sms?number=82736164617&text=Hello%20World
or in JS
$.post('http://100.22.33.11/sms',{
number: '82736164617',
text: 'Hello World'
})
Of course, you would also want to add some authentication (over SSL), to avoid being an open SMS proxy :)

Testing PHP Web Service locally by using android app

I am new to web services and planning to design a php webservice for my android app on my local machine which will send some user informations to database and generate some JSON data. But the problem is i am little confused about how to test it.
For example lets say that my webservice will locate on my local machine like below http://localhost:80/webservice/register.php
And my ip address is 192.168.1.X
Than is it possible for my android app to use this web service by using this url http://192.168.1.X:80/webservice/register.php
Normally since webservices are on the internet any program can access them. But i thought that i can test my webservice with my android app since both my pc and android device are on the same subnet.
If someone make things clear and tell me a way for testing a web service locally i appreciated
This is possible to call the web service in the local network also from the android app. But Your device and Your server on which Web Service running must have on the same network and Your firewall or any proxy server must be off on the server.

Instagram redirect-uri fails for localhost

I am writing a PHP app to fetch all my photos with Instagram using their API. However, what puzzles me is, I run the app on my hosted server it works perfectly fine and the same app running locally does not work.
Here are some points on the app workflow:
The user sees the homepage and he will be prompted with 'sign-in with Instagram'
User signs in with Instagram and authorizes the app.
Instagram redirects the user.
The app then makes a request for access_token and receives it.
Using the access_token, the app will send further requests for user media
The response is parsed and the links to the images are now provided to the user.
All the above mentioned process works fine on my hosted server but fails at 'Step 3.' and redirects user to home page of my app.
The problem is localhost being the redirect_uri. Does anyone have a solution to this problem to use the app locally?
P.S: I have registered two separate clients on Instagram: one for locally hosted development and the other on a web server.
Also, I have tried localtunnel. Did not help either.
I know its a very very very old Question. but for those who get to this page hoping a solution:
instagram currently does not allow to use something like localhost or myvhost.test in redirection url, whats more it requires the url to be certified (https).
so the only working solution I could find is using ngrok. you should download it from the url, open it and type a localhost virtual domain name along with a specific port number like ngrok http myLocalUrl.test/app 80, hit enter and it will gives you two temporary public links.
it will remain valid until you close the ngrok command line. you can direct the link to a specific port number and direct the port number to specific folder path of the application in your localhost.
the tutorials provided by ngrok is simple enough if you did not understand my hints.
I was dealing with this issue trying to develop an Instagram App using NodeJS/Express.
I got around this by using my computer's external local IP rather than localhost, which you can grep for. I assume you're on a *nix machine, so do a very simple (and crude)
$ ifconfig | grep inet
which will return you a few ip and MAC addresses, one of them being your external IP. However this is lousy because it means every time you switch IPs you'll have to update your application's redirect_url with Instagram as well as update any code that relies on it.
Thankfully, there exists services like no-ip that will basically provide free DDNS service to you, so you need simply register a hostname with them and then drop that into your DEV env code as well as your development client's redirect url and you're set to go!

Categories