paypal - 如何捕获paypal webhook?
问题描述
我已经在我的网站中集成了 PayPal 智能按钮,两者createOrder
都Capture
在服务器端进行处理,当支付完成后,可以在商业沙盒帐户上进行交易,并且该webhook
事件已在 Webhooks 事件页面中注册。
该webhook
POST
url 在仪表板中订阅了所有事件并在localhost
我使用webhookrelay中对其进行测试。
问题是我webhook
只有在事件来自 Webhook Simulator 而不是来自 Smart Button 的实际付款时才会被调用。
所以我的服务器只接收来自模拟器的 webhook 调用,而不是由智能按钮支付触发。
我处于沙盒模式,所有付款和智能按钮都处于沙盒模式。
这是我的智能按钮代码:
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 没有提供有用的附加信息
- 如果您出于某种原因坚持实施 webhook,则需要为要接收的事件注册一个侦听器。有一个用于管理 webhook 注册的 API:https ://developer.paypal.com/docs/api/webhooks/v1/#webhooks_post ,或者您可以尝试本指南中的步骤https://developer.paypal.com/docs /api-basics/notifications/webhooks/rest/#subscribe-to-events
- 同样,当您已经在服务器上实现了同步捕获 API 调用时,完全没有必要实现异步 webhook。
推荐阅读
- ios - Places SDK for iOS 和 Places API 在限制选项下有什么区别?
- vb.net - 如何在vb中检测多个kye press
- python - Python:如何使用带有 scipy.optimize.minimize 的元组
- angular - ng-reflect-model 显示不正确的值,但输入是正确的
- azure - Powershell Azure New-AzVirtualNetworkSubnetConfig 重大更改?
- mysql - mysql 查询慢,可能是由于 find_in_set 函数
- single-sign-on - 如何使用 AWS amplify 将电子邮件地址传递给 Auth.federatedSignIn
- python - 当 LIKE 变量/模式可以更改时如何向 SQL 查询(?,'%?%',...)
- c - 将 12 位数字转换为 2 个 8 位字节
- javascript - Moment JS 设置日期格式