您好我以这种方式使用express.js设置我的webhook构建(webhook托管在Parse.com上):
var Stripe = require('stripe');
Stripe.initialize('sk_test_...');
...
app.post("/stripe", function(request, response) {
console.log("Type: "+request.body.type);
console.log("Event id: "+ request.body.id);
// Retrieve the request's body and parse it as JSON
// Verify the event by fetching it from Stripe
Stripe.Events.retrieve(request.body.id, function(err, event) {
console.log("This string is not printed on the logs");
response.send(200);
});
});
然后测试请求就是这样,通过更改仪表板中的测试用户订阅生成:
{
"id": "evt_16oKcXAEHouDaR4rj8m5AtcC",
"created": 1443043065,
"livemode": false,
"type": "customer.subscription.updated",
"data": {
"object": {
"id": "sub_71zTKb8dLfo3RX",
...
"start": 1443042949
}
},
"object": "event",
"pending_webhooks": 3,
"request": "req_72PRYW2FrgFkDr",
"api_version": "2015-04-07"
}
这是我的webhook日志:
E2015-09-23T22:36:40.864Z]v342 Ran custom endpoint with:
Input: {"method":"POST","url":"/stripe","headers":{"accept":"*/*; q=0.5, application/xml","cache-control":"no-cache","content- length":"1358","content-type":"application/json; charset=utf- 8","host":"sceglime.parseapp.com","user-agent":"Stripe/1.0 (+https://stripe.com/docs/webhooks)","version":"HTTP/1.1","x-forwarded-for":"54.241.31.102, 10.252.11.20","x-forwarded-port":"80","x-forwarded- proto":"http"}}
Result: success/error was not called
I2015-09-23T22:36:40.974Z]Type: customer.subscription.updated
I2015-09-23T22:36:40.975Z]Event id: evt_16oLqrAEHouDaR4rpAi8FWt2
E2015-09-23T22:36:43.246Z]v342 Ran custom endpoint with:
Input: {"method":"POST","url":"/stripe","headers":{"accept":"*/*; q=0.5, application/xml","cache-control":"no-cache","content-length":"1160","content-type":"application/json; charset=utf-8","host":"sceglime.parseapp.com","user-agent":"Stripe/1.0 (+https://stripe.com/docs/webhooks)","version":"HTTP/1.1","x-forwarded-for":"54.241.34.107, 10.252.7.139","x-forwarded-port":"80","x-forwarded-proto":"http"}}
Result: success/error was not called
I2015-09-23T22:36:43.332Z]Type: invoiceitem.created
I2015-09-23T22:36:43.333Z]Event id: evt_16oLqrAEHouDaR4rcj0syMGn
在条带日志上,我收到错误“500 pending”。为什么webhook没有正确响应?
由于