从 stripe webhook 访问本地 https 服务 [英] Accessing local https service from stripe webhook
问题描述
我正在使用 Stripe 集成支付系统.在此过程中,我需要在本地开发人员中测试 webhooks.在我将其运送给 QA 之前,请先检查机器.我尝试了以下方法,
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:然而,当启动ultrahook 时,它说已验证
,但没有给出任何转发已激活..."消息.当我尝试从 Stripe 或 Web 访问 url 时,它不起作用.详情如下,
本地网址:https://localhost/xxx/yyy/zzzUltrahook 命令:ultrahook -k localhost https ://localhost.com/xxx/yyy/zzz条带中使用的钩子网址:http ://localhost.arivanza.ultraook.com/xxx/yyy/zzz
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
我也试过,https ://localhost.com/,但是当从条带测试时,请求没有通过钩子来.
I have also tried, https : //localhost.com/, but the request does not come through from the hook when tested from stripe.
LocalTunnel:从github下载应用程序后,我找不到启动应用程序的方法.
LocalTunnel: I could not find the way to launch the application after downloading it from the github.
PageKite:默认打开 localhost:80,不知道如何打开 https://localhost.com
PageKite: It by default opens up localhost:80, not sure how to open up the https://localhost.com
任何帮助将不胜感激.
推荐答案
您好,我自己试过了.请按照以下步骤操作
Hi I have tried by self. Please follow following steps
- 下载 ngrok 并解压到任意文件夹
- 运行 ngrok.exe 并输入以下命令 ngrok http [port] -host-header="localhost:[port]"
- Y0u 将在 ngrok 控制台Forwording"中获得一个 url,例如 https://7755afd8.ngrok.io这个 url 替换了 localhost:[port]
- 您不能使用 https://7755afd8.ngrok.io/index.html
- 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
使用 asp.net 的 Stripe webhook 代码示例:
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;
}
}
这篇关于从 stripe webhook 访问本地 https 服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!