I am integrating a payment system using Stripe. In the process, I need to test the webhooks in my local dev. machine before I ship it to QA. I have tried the following,
Ultrahook: however when starting the ultrahook it said, authenticated <myaccount>, but did not give any "Forwarding activated..." message. When I tried to access the url from stripe or web, it did not work. Details below,
local url: https : //localhost/xxx/yyy/zzz
ultrahook command: ultrahook -k localhost https : //localhost.com/xxx/yyy/zzz
hook url used in stripe: http : //localhost.arivanza.ultrahook.com/xxx/yyy/zzz
I have also tried, https : //localhost.com/, but the request does not come through from the hook when tested from stripe.
LocalTunnel: I could not find the way to launch the application after downloading it from the github.
PageKite: It by default opens up localhost:80, not sure how to open up the https://localhost.com
Any help would be greatly appreciated.
Hi I have tried by self.
Please follow following steps
download ngrok and extract in any folder
run ngrok.exe and type following command ngrok http [port] -host-header="localhost:[port]"
Y0u will get a url in ngrok console "Forwording" like https://7755afd8.ngrok.io
this url is replacement of localhost:[port]
You can use no https://7755afd8.ngrok.io/index.html
Code example for stripe webhook using asp.net:
var postdata =new StreamReader(HttpContext.Request.InputStream).ReadToEnd();
var data = JObject.Parse(postdata);
var eventid = data["id"].ToString();
var eventdata = StripeHelper.GetStripeEvent(eventid);
if(eventdata!=null)
{
switch(eventdata.Type)
{
case "charge.succeeded":
//charged event
break;
case "customer.source.created":
//card added
break;
case "customer.source.deleted":
//card deleted
break;
case "customer.subscription.trial_will_end":
//trial will end
break;
}
}
If you need to receive webhooks on your local dev machine (let's say, on localhost:1234/api/url), you could use a local "mock" Stripe server, like localstripe. Once lauched, it will act like Stripe and send events if you configure it to.
Install and run localstripe:
pip3 install --user localstripe
localstripe
Configure your program to use localhost:8420 (localstripe) instead of the real Stripe (api.stripe.com). For instance with a Python program:
import stripe
stripe.api_key = 'sk_test_anythingyouwant'
stripe.api_base = 'http://localhost:8420'`
Configure localstripe to send webhook events to your program:
curl localhost:8420/_config/webhooks/mywebhook1 \
-d url=http://localhost:1234/api/url -d secret=whsec_s3cr3t
Not all events are implemented in localstripe, and it could behave slightly differently from real Stripe. But it allows you to test your application in a local sandbox, without touching actual Stripe servers.
Although the others answers work, I think they are a bit dated.
Stripe now has a CLI tool that allows you to create a connection between Stripe and your local host. Here are the steps
Create the webhook file that handles the Stripe webhook calls. Let's assume that path to this file is http://localhost/webhook.
Go to stripe.com, go to the dashboard, then click on Developers, and Webhooks, then add a new endpoint. Make sure the URL in that endpoint is the one from step 1 above (i.e., http://localhost/webhook)
Download and install the Stripe CLI locally. Then follow the instructions to login
In your Stripe CLI, run the following command:
stripe listen --forward-to http://localhost/webhooks.
This will eventually listen to Stripe for any webhooks to your local server, and forward them to your sever locally (i.e, it creates a bridge between the two)
Test your work.
The problem with the above solution is it is not going to send back the responses of the webhook back to the Stripe server (because the http://localhost/webhook is private to your network).
If you insist on having responses back to Stripe, then you should either
Map your localhost to a public domain
Use a tunnel, such as ngrok. This answer describes how to use ngrok, but for me, I make the ngrok call this way:
ngrok http -host-header=localhost 80
The above call would give me something like https://<some-random-numnber>.ngrok.io
So in stripe.com, I would have to write the endpoint as
https://<some-random-numnber>.ngrok.io/<path-to-webhook-response-page>/
Hope this helps
Although the others answers work, I think they are a bit dated.
Stripe now has a CLI tool that allows you to create a connection between Stripe and your local host. Here are the steps
Create the webhook file that handles the Stripe webhook calls. Let's
assume that path to this file is http://localhost/webhook.
Go to stripe.com, go to the dashboard, then click on Developers, and
Webhooks, then add a new endpoint. Make sure the URL in that
endpoint is the one from step 1 above (i.e.,
http://localhost/webhook)
Download and install the Stripe CLI locally. Then follow the
instructions to login
In your Stripe CLI, run the following command:
stripe listen --forward-to http://localhost/webhooks.
This will eventually listen to Stripe for any webhooks to your local
server, and forward them to your sever locally (i.e, it creates a
bridge between the two)
register url in VerifyCsrfToken[Middleware]:
class VerifyCsrfToken extends BaseVerifier
{
protected $except = [
'webhook'
];
}
Test your work
Related
I want to create a quite simple Shopify Custom App for my shop. This App should run when an order is created, so with a webhook product/change.
After creating the webhook, I receive errors in my terminal as soon as I update a product and the webhook is sent. I just have no idea how to correctly implement the webhook code and where. So this question here is a very basic question, how can I implement a Shopify webhook (webhook code from official Shopify dev page for Ruby) in my freshly Shopify CLI created app. Unfortunately, I can't find any help, it seems that there are so many different ways of creating webhooks. None of them is working for me so far, so I try to stick to the most common one described by shopify dev tutorials.
Steps so far:
I installed a custom app with Shopify CLI, using a Node template with the command "npm init #shopify/app#latest". After this, with "npm run dev" I created a tunnel with ngrok. With this, I receive a url to the app, I can access the app in my Shopify Partners and install it.There is a video tutorial of a shopify dev that I used as help, if someone is more interested Shopify dev Webhook tuorial (of 2021, so I guess a bit outdated unfortunately).
I put the following "webhook code", which uses Ruby, in a app.rb file, which I saved in my root folder of my Shopify CLI created app. The code is available in Shopify dev tutorials (Shopify dev tuorial) for Ruby (I made just very few adaptions like adding a path and adding the Shopify Secret Key:
require 'rubygems'
require 'base64'
require 'openssl'
require 'sinatra'
require 'active_support/security_utils'
# The Shopify app's API secret key, viewable from the Partner Dashboard. In a production environment, set the API secret key as an environment variable to prevent exposing it in code.
API_SECRET_KEY = 'my_api_secret_key'
helpers do
# Compare the computed HMAC digest based on the API secret key and the request contents to the reported HMAC in the headers
def verify_webhook(data, hmac_header)
calculated_hmac = Base64.strict_encode64(OpenSSL::HMAC.digest('sha256', API_SECRET_KEY, data))
ActiveSupport::SecurityUtils.secure_compare(calculated_hmac, hmac_header)
end
end
# Respond to HTTP POST requests sent to this web service
post '/webook/product_update' do
request.body.rewind
data = request.body.read
verified = verify_webhook(data, env["HTTP_X_SHOPIFY_HMAC_SHA256"])
halt 401 unless verified
# Process webhook payload
# ...
end
Next to the "app.rb" in the root folder of my App, I created a "Gemfile":
source 'https://rubygems.org'
gem 'shopify_api'
gem 'sinatra'
gem 'activesupport'
With bundle install, a Gemfile.lock is created, everything seems fine here. I created a webhook for product_change in my Shopify Partners Admin under "Notifications". As URL, I entered the ngrok URL from terminal window (from npm run dev command, the tunnel is still open), but with adding /webook/product_update, as this I used in the function path of the webhook.The webhook is sending sth to my app when I update a product, which is good at least. Unfortunately, as I update a product, my app shows errors in the terminal and crashes. The same errors are appearing even if I delete the app.rb file and the Gemlock files completely.The terminal shows these errors:
C:\ShopifyApps\test2\web\node_modules\#shopify\shopify-api\dist\error.js:13
var _this = _super.apply(this, tslib_1.__spreadArray([], tslib_1.__read(args), false)) || this;
**InvalidRequestError: Request does not contain a host query parameter**
at InvalidRequestError.ShopifyError [as constructor] (C:\ShopifyApps\test2\web\node_modules\#shopify\shopify-api\dist\error.js:13:28)
at new InvalidRequestError (C:\ShopifyApps\test2\web\node_modules\#shopify\shopify-api\dist\error.js:230:42)
at Object.getEmbeddedAppUrl (C:\ShopifyApps\test2\web\node_modules\#shopify\shopify-api\dist\utils\get-embedded-app-url.js:22:15)
at file:///C:/ShopifyApps/test2/web/index.js:187:41
I'd be very happy about any hint how to find out what is wrong. How can I connect the abb.rb file with my index.js file of my root app? I guess I need to do that. But I have no real idea unfortunately.
I have integrated Kommunicate chat bot into my website, however, a lot of traffic is generated on my website, due to which a lot more users are chatting than I have the bandwidth to support (agent wise).
I can't seem to find a way to limit the number of currently active chats one agent/human can handle at any given time. I wish to find a solution for the same.
Can this be done through the webhook integration provided? If so, how?
The solution indeed lied in adding the webhook integration.
First, I spin up a simple flask server, serving a single endpoint: /webhook.
app = Flask(__name__)
#app.route('/webhook', methods=['GET', 'POST'])
def webhook():
logger.debug('Webhook Triggered') #-> we know it's being trigerred.
resp_generated = make_response(jsonify(results()))
logger.debug(resp_generated)#-> always shows 200 anyway.
return resp_generated
if __name__ == '__main__':
app.run(host ='0.0.0.0', port = 5000, debug = True)
Then I use ngrok to create a tunnel to my local server (I plan to host it on GKE in the later stages)
ngrok http 5000
This gives me an HTTPS URL to my Flask server such as https:\\534bbe.ngrok.io
Then I go into DialogFlow -> Fulfillment -> Enter my Webhooks endpoint there:
[Note: Hit the save button at the bottom of the page]
You would have to enable webhook call for the Intents on which you are going to add your server logic, in my case it was when I wanted to transfer to a live agent while limiting the number of chats:
To ensure that the default behavior of Kommunicate is not broken when my server goes down, I have added custom payload (as shown in the image above):
{
"metadata": {
"KM_ASSIGN_TO": ""
},
"platform": "kommunicate",
"message": "---- Redact that sweet sweet company Information. Yeah!!---"
}
[Note: Make sure to hit Save on the top right, once you make your changes in the Intent.]
Then I added the Webhook URL (same as the one used in DialogFlow) in Kommunicate -> Settings -> Developer -> Webhooks
[Note: Hit the save changes button at the bottom of the page]
Once everything is set up, you will start receiving messages in the server and can add your logic as you wish. Do note that this is super tedious as you would have to read a lot of documentation and add a bunch of logic to get it to work as you want it to.
I am trying to test a stripe webhook for subscription trial ending. When I go to send the test even to my webhook receiving route I get error 302. I am using a middleware called stripe-webhook-middleware. My route looks like this:
app.post('/stripe/events',
stripeWebhook.middleware,
stripeEvents
);
I know that route goes against what they docs say but I did get it directly from the package creator. So it should work, then I have the stripe-events.js from the package. I am just adding in a console.log to the route to find the correct data I need.
I tried different webhooks and all give the same error, it has to be in how I have it set up. I hope anyways.
Edit **
I have also done a new route that is just a basic post route with a console.log and still getting the 302 error. What could possible causes be? I can't post a github because of a credential I accidentally leaked.
I am/was using cloud9.io as my development environment and had my test site as private. That was causing stripe to need to login in order to do anything. I made it public and now it works. I had completely forgotten I had to login to see the site because I always was logged in to cloud 9 when I accessed the site. If you are getting a 302 error, make sure you don't need to log in to get to that route.
Just in case anyone sees this 302 error with Codeigniter 3, my webhook route was pointing to a Subscription controller that always exits the constructor if a user isn't logged in and authorised - so I moved the method to my Home controller (used for registration, login etc) thus:
$route['webhook']['post'] = 'home/webhook';
and the 302 error went away. I hope this helps a tired CI dev down the road.
Just in case someone receives this error with dJango, my webhook route was pointing to a language redirection. You can investigate it with curl -IvL http://localhost:8000/webhooks/stripe as #duck suggested above.
Here was my output:
HTTP/1.1 302 Found
...
* Issue another request to this URL: 'http://localhost:8000/en/webhooks/stripe/'
...
You can see the redirected URL in the output.
So, when I let Stripe CLI listen to that URL, it works:
stripe listen --forward-to localhost:8000/en/webhooks/stripe/
I have successfully created bigcommerce webhooks but can't seem to get any data sending to a requestb.in
{
"id"=><webhook_id>,
"client_id"=><client_id>,
"store_hash"=><store_hash>,
"scope"=>"store/product/created",
"destination"=>"https://requestb.in/1ieyzm31",
"headers"=>{"X-ANT-SHARED-TOKEN"=>nil},
"is_active"=>true,
"created_at"=>1493173043,
"updated_at"=>1493173043
}
The docs say that the is_active flag will flip off if the webhook fails to send. Im not getting any data and the flag remains. Is there a bug BC side!?!?
UPDATE:
I tested the SSL certs of requestbin on the tool BC recommends, because big commerce said it might ignore webhooks if SSL is not set up correctly
Scored: A
I've set up the Chromecast SDK, whitelisted my device, and am running web servers at the URLs I provided in the whitelist request.
The chromecast tic tac toe app works fine with the default app id "TicTacToe", however changing it to my own: "1813060e-33c5-41dc-b356-0d2bad12497f" or "1813060e-33c5-41dc-b356-0d2bad12497f_1" does not work.
The server url is up and running at http://chromecast.clockworkmod.com/, but no requests are being made to it by Chromecast. The chromecast doesn't display anything. However I get a few errors in the log.
Here is the logcat.
W/StartSessionTask(15590): StartApplicationRequest failed with status:
-4 E/ApplicationSession(15590): StartSessionTask failed with error: failed to start application: request failed D/GameActivity(15590):
start session failed: failed to start application: request failed
I've also tried using the internal app id with the dev url I had provided, http://192.168.1.2:3000/
I found the answer here:
unable to cast to personal whitelisted receiver app
Using the Chromecast app on my Macbook, I went into Settings.
Send serial number when Checking for updates
Reboot device the device using the Mac update app
This resolved the error for me. The chromecast doesn't know if it is whitelisted unless you send the serial during update checks.
I think I see what's missing! In your receiver you gave a link to, you have:
var receiver = new cast.receiver.Receiver(
'GoogleCastSampleApp',
[cast.receiver.RemoteMedia.NAMESPACE],
"",
5);
But it should be (fill in the 'YOUR APP ID HERE' with your App ID)
var receiver = new cast.receiver.Receiver(
'YOUR APP ID HERE',
[cast.receiver.RemoteMedia.NAMESPACE],
"",
5);
I am running into the same error as well. I after setting the Chromecast to send the serial when checking for updates I was finally able to access the debugger one port 9222. Unfortunately, I don't see anything happen on the Chromecast at all when I select it from the device list on my Nexus and try sending one of the demo videos.
Something I noticed and I don't know it makes difference or not but if you whitelist a domain in the GoogleCast extension for Chrome and you include the "http://" it will cause the injection to not work. I wonder if this is the problem with the look up that the Chromecast performs as I submitted my URLs to Google with the http:// prepended. Again I am not sure this should really make a difference but I plan on trying to resubmit the URLs just to see.
Install cURL in your windows machine from here
Now make sure that your device and laptop are in same network.
Now go to command prompt, type curl -d "" http://:8008/apps/YouTube
there If it gets casted automatically to TV then instead of YouTube put your appid and try.
If not then your router is blocking some traffic.