Can I use localhost URL as Webhook URL in Instamojo? - webhooks

I am implementing instamojo payment method into my website. Can I use a localhost URL as Webhook URL in order to test the process?

I'm from Instamojo.
You can't use a local URL. This is because a webhook request is a POST request that is made from our server. Therefore, the only URLs that we can make these requests to would be URLs that are publicly available.
For testing purposes, I would recommend using RequestBin. You can create a new bin and paste the URL for that bin in the webhook URL field of your Instamojo link. This will give you a link that is accessible by our server and you can inspect the POST requests to this link by appending ?inspect at the end of the URL.

It is possible to forward Instamojo's webhooks to your local machine using tools like localtunnel.
npm is required to install localtunnel. [How to install node and npm]
Install
localtunnel
Suppose you are running your local server at port 8000, in a new terminal window, execute this:
lt --port 8000
It will show you output like:
your url is: https://whawgpctcs.localtunnel.me
This is a temporary webhook URL that will forward every HTTPS request sent to https://whawgpctcs.localtunnel.me to your local server running on port 8000.
Paste this temporary url into Instamojo's webhook field and continue testing.
Remember to remove the temporary webhook URL from Instamojo once you are done testing
The temporary webhook URL is valid as long as the lt --port 8000 command (and your Internet connection) is active.

I doubt if you can use local host URL
but instead you can create new links, as below
https://www.instamojo.com/api/1.1/links/

We can't use localhost or as Webhook URL.If it is used the following error will show "Domain name should not be "localhost" or "127.0.0.1" ". So it must be a live URL.

You cannot use the localhost URL as a webhook URL in order to test the process. But you can simply bypass it, open hosts file from C:\Windows\System32\Drivers\etc\hosts
At the end of the line write
127.0.0.1 yourname.com
And access localhost using yourname.com.
Just change localhost/your-location url with yourname.com/your-location in the PHP file.

Related

How do i edit "ngrok-skip-browser-warning" into the request sheader?

I am pretty new to ngrok and web dev but I am trying to host a apache2 server on my raspi4 and i wanted to make it public to the outside using Ngrok but whenever anyone goes on the link they are prompted with the browser warning page --browser warning. I want to remove it by setting ngrok-skip-browser-warning =1 into the request header, yet I don't now where I find that on my apache2 server. How to I edit the request header?

How to set url and callback url field for twitter app development?

I am trying to create a twitter application and got stuck on url and callback url field.
I am using it for personal project and hence I set url fields as http://127.0.0.1/ but I get Invalid website url message.
What url should I enter?
You should "real url".
URL of your server (can listen request from twitter), not http://127.0.0.1/, because it is local.
If they call to http://127.0.0.1/, just call to localhost of them, not is your computer.

Can I register a custom URL Scheme/Protocol with a Node HTTP Server?

I would like to be able to handle a custom URL scheme with the Node HTTP API. I would like to write links inside web pages like this: app://foo/bar. I would like to have the Node HTTP Request Handler receive this kind of URL.
When I try this kind of custom protocol in my URL, it looks like Chrome is not sending out the request because it is malformed. So nothing gets to my HTTP server in Node.
Is it possible to bind your HTTP server to a custom URL Scheme or Protocol like app://foo/bar?
Only certain protocols such as http:// and https:// will be sent to your nodejs http server. That's the issue. Your node.js server is an http server. The chrome browser will only send it URLs with the http protocol that it knows belong to an http server.
A custom protocol has to be first handled in the browser with a browser add-on that can then decide what to do with it.
Perhaps what you want to do is a custom HTTP URL such as:
http://yourserver.com/foo/bar
Then, your node.js http server will get the /foo/bar part of the request and you can write custom handlers for that.
To recap, the first part of the URL the part before the :// is the protocol. That tells the browser what protocol this URL is supposed to be used with. Without a browser add-on, a browser only comes with support for some built-in protocols such as http, https, ws, wss, mailto and some others.
An http server will only be able to respond to the http protocol so it will only work with URLs that expect to use the http protocol and that the browser knows use the http protocol. Thus your own protocol that the browser does not know about is not something the browser knows what to do with. It would take a browser add-on to tell the browser what to do for a custom URL.
When I try this kind of url, it almost looks like Chrome is batting it down before it can get to my HTTP server in Node.
Yes, it's not a recognizable protocol built into the browser so the browser doesn't know what to do with it or how to speak that protocol.
Is it possible to bind your HTTP server to a custom URL Scheme like this?
Only with a browser add-on that registers and implements support for the custom URL protocol.
I have made an npm module for this purpose.
link :https://www.npmjs.com/package/protocol-registry
So to do this in nodejs you just need to run the code below:
First Install it
npm i protocol-registry
Then use the code below to register you entry file.
const path = require('path');
const ProtocolRegistry = require('protocol-registry');
console.log('Registering...');
// Registers the Protocol
ProtocolRegistry.register({
protocol: 'testproto', // sets protocol for your command , testproto://**
command: `node ${path.join(__dirname, './index.js')} $_URL_`, // $_URL_ will the replaces by the url used to initiate it
override: true, // Use this with caution as it will destroy all previous Registrations on this protocol
terminal: true, // Use this to run your command inside a terminal
script: false
}).then(async () => {
console.log('Successfully registered');
});
Then suppose someone opens testproto://test
then a new terminal will be launched executing :
node yourapp/index.js testproto://test
Based on the comment thread on the other answer, I think I understand what you're trying to do.
I hear that you want to serve some files off localhost but not at all pollute the namespace of an existing webserver.
I have several weird alternative solutions:
Just pick a namespace that's unlikely to be used by a user. You can start with an underscore or a dollar sign? Or you can just a very random number.
You can serve your files, but only if a URI parameter exists with a very random string. PHP does this to serve the PHP logo for example.
You can't really change the scheme without creating browser add-ons, but you do have control over the TCP port. You can start a second webserver on a second port.
You can use a second domain. Just register a domain and point an A record to 127.0.0.1. Now your webserver running on localhost can check out the Host: header and serve your files if it matches your special hostname.

Messenger bot - Sample code

I am trying to create a bot. Using this project. My setup is as follows:
Amazon EC2 instance. I created a sub-domain.domain.com I have added the ssl certifications. I have pointed the sub-domain to the /var/www/sub-domain/
I have installed the unzip and installed the project in /var/www/sub-domain/project/ I have configured the project and correctly run it:
Node app is running on port 5000
If I access http://sub-domain.domain.com:5000 I access to the projects public index. I understand that means the port is open and the node app works.
Now when I am trying to configure in facebook my webhook I dont understand what url callbak to use. From what I understand in the configuration the server url whould be https://sub-domain.domain.com and the configuration should work. but it doesnt.
What url should I use?
Your callback URL should be your actual file where facebook would send user data. Like if you were using PHP, you'd say: http://yourhost/chatbot.php. Currently, webhook would be the URL on which your node app is listening.
Your webhook needs to an accessible URL. I don't know which sample code you used, but my guess is that with your current set up you should use http://sub-domain.domain.com:5000/webhook.
You can use Apache or Nginx to make it accessible on http://sub-domain.domain.com/webhook (port 80) with ProxyPass/proxy_pass directives.
I have installed the unzip and installed the project in /var/www/sub-domain/project/ [...] I access to the projects public index
The Javascript files of your project don't need to and should not be accessible to the public, as they may contain your application's secret IDs and tokens.

Using 3xx codes to perform redirect for directory level resources

I have hosted a local server on my system on port 80. And I have few other local servers running on port 8080/8081/8082.. And I want to redirect by requests from port 80 to these ports based on the directory they access.
So for example if request is like http:// 127.0.0.1/test1/... I want request to be redirected to http:// 127.0.0.1:8080/test1/....
Is there a way in which I can just return 301 once and then browser understands that all the requests with http:// 127.0.0.1/test1/ prefix all automatically should be redirected to new URL. I do not want to send redirect call for every resource within test1 folder.
There is no way to do what you are describing using 3xx HTTP response codes. You do however, have several options:
Use a rewrite module
Create a relay, to simply connect the client to the correct server
Setup your server to send a 301 code for every url that starts with a certain path (test1, for example).
You'll need to provide more information about what type of servers you're using to get a more specific answer.

Resources