如何捕获paypal webhook?
How to capture paypal webhook?
我在我的网站上集成了 PayPal 智能按钮,createOrder
和 Capture
都在服务器端处理,当付款完成后,交易可以在商业沙盒帐户上使用,并且webhook
事件已在 Webhooks 事件页面中注册。
webhook
POST
url 在仪表板中订阅了所有事件并在 localhost
中测试它我使用 webhookrelay.
问题是只有当事件来自 Webhook 模拟器而不是来自 Smart Button 的实际付款时,我才会调用 webhook
。
因此我的服务器仅接收来自模拟器的 webhook 调用,并且 未从 Smart Button 支付中触发。
我处于沙盒模式,所有支付和智能按钮都处于沙盒模式。
这是我的智能按钮代码:
paypal
.Buttons({
style: {
shape: "rect",
color: "gold",
layout: "horizontal",
label: "paypal",
tagline: false,
height: 52,
},
createOrder: async function () {
const res = await fetch(
"https://www.example.it/payment/paypal/order/create/" + orderID,
{
method: "post",
headers: {
"content-type": "application/json",
},
credentials: "include",
}
);
const data = await res.json();
return data.id;
},
onApprove: async function (data) {
const res = await fetch(
"https://www.example.it/payment/paypal/" +
data.orderID +
"/capture/",
{
method: "post",
headers: {
"content-type": "application/json",
},
credentials: "include",
}
);
const details = await res.json();
if (localStorage.STBOrder) {
localStorage.removeItem("STBOrder");
}
$("#modalPayments").modal("hide");
$("#modalSuccess").modal("show");
},
onCancel: function (data) {},
})
.render("#paypal-button-container");
- 由于您是在服务器端进行捕获,因此没有使用 webhook 的真正动机。您的 API 调用进行捕获的响应已经是权威的; webhook 没有提供有用的附加信息
- 如果你因为某些原因坚持要实现webhooks,你需要为你想要接收的事件注册一个监听器。有一个 API 用于管理 webhook 注册:https://developer.paypal.com/docs/api/webhooks/v1/#webhooks_post , or you can try the steps in this guide https://developer.paypal.com/docs/api-basics/notifications/webhooks/rest/#subscribe-to-events
- 同样,当您已经在服务器上实现同步捕获 API 调用时,完全没有必要实现异步 webhook。
我在我的网站上集成了 PayPal 智能按钮,createOrder
和 Capture
都在服务器端处理,当付款完成后,交易可以在商业沙盒帐户上使用,并且webhook
事件已在 Webhooks 事件页面中注册。
webhook
POST
url 在仪表板中订阅了所有事件并在 localhost
中测试它我使用 webhookrelay.
问题是只有当事件来自 Webhook 模拟器而不是来自 Smart Button 的实际付款时,我才会调用 webhook
。
因此我的服务器仅接收来自模拟器的 webhook 调用,并且 未从 Smart Button 支付中触发。
我处于沙盒模式,所有支付和智能按钮都处于沙盒模式。
这是我的智能按钮代码:
paypal
.Buttons({
style: {
shape: "rect",
color: "gold",
layout: "horizontal",
label: "paypal",
tagline: false,
height: 52,
},
createOrder: async function () {
const res = await fetch(
"https://www.example.it/payment/paypal/order/create/" + orderID,
{
method: "post",
headers: {
"content-type": "application/json",
},
credentials: "include",
}
);
const data = await res.json();
return data.id;
},
onApprove: async function (data) {
const res = await fetch(
"https://www.example.it/payment/paypal/" +
data.orderID +
"/capture/",
{
method: "post",
headers: {
"content-type": "application/json",
},
credentials: "include",
}
);
const details = await res.json();
if (localStorage.STBOrder) {
localStorage.removeItem("STBOrder");
}
$("#modalPayments").modal("hide");
$("#modalSuccess").modal("show");
},
onCancel: function (data) {},
})
.render("#paypal-button-container");
- 由于您是在服务器端进行捕获,因此没有使用 webhook 的真正动机。您的 API 调用进行捕获的响应已经是权威的; webhook 没有提供有用的附加信息
- 如果你因为某些原因坚持要实现webhooks,你需要为你想要接收的事件注册一个监听器。有一个 API 用于管理 webhook 注册:https://developer.paypal.com/docs/api/webhooks/v1/#webhooks_post , or you can try the steps in this guide https://developer.paypal.com/docs/api-basics/notifications/webhooks/rest/#subscribe-to-events
- 同样,当您已经在服务器上实现同步捕获 API 调用时,完全没有必要实现异步 webhook。