【问题标题】:PayPal Webhook cannot be validated无法验证 PayPal Webhook
【发布时间】:2020-05-25 10:16:01
【问题描述】:

这似乎是一个重复的问题,但如果任何建议的解决方案确实有效,我就不会在这里。我一直在尝试根据他们的docs 和 Github 代码示例在我的服务器端集成 PayPal IPN https://github.com/paypal/ipn-code-samples/blob/master/python/paypal_ipn.py

我已根据此答案 Paypal sandbox IPN return INVALID 将我的沙盒业务帐户的编码更改为 UTF-8,但我一直收到相同的 INVALID 响应。

我正在将 python 与 Django REST 框架一起使用。这是我的代码。

class PaypalWebhookAPIView(APIView):
    permission_classes = (AllowAny,)

    def post(self, request, *args, **kwargs):
        VERIFY_URL_PROD = 'https://ipnpb.paypal.com/cgi-bin/webscr'
        VERIFY_URL_TEST = 'https://ipnpb.sandbox.paypal.com/cgi-bin/webscr'
        # Switch as appropriate
        VERIFY_URL = VERIFY_URL_TEST
        data = {
            'cmd': '_notify-validate',
            **request.data
        }
        # Post back to PayPal for validation
        headers = {'content-type': 'application/x-www-form-urlencoded',
                   'user-agent': 'Python-IPN-Verification-Script'}
        response = requests.post(VERIFY_URL, data=data,
                                 headers=headers)
        response.raise_for_status()
        import pdb
        pdb.set_trace()

        # Check return message and take action as needed
        if response.text == 'VERIFIED':
            pass
        elif response.text == 'INVALID':
            pass
        else:
            pass

这是我收到的 IPN 消息。您会注意到在结帐时我添加了一个custom_id 字段。

{'id': 'WH-8VT506292F0529107-6AL76556YR820754B', 'event_version': '1.0', 'create_time': '2020-02-10T05:44:14.774Z', 'resource_type': 'capture', 'resource_version': '2.0', 'event_type': 'PAYMENT.CAPTURE.COMPLETED', 'summary': 'Payment completed for $ 30.0 USD', 'resource': {'id': '5YA69751S2248772K', 'amount': {'currency_code': 'USD', 'value': '30.00'}, 'final_capture': True, 'seller_protection': {'status': 'ELIGIBLE', 'dispute_categories': ['ITEM_NOT_RECEIVED', 'UNAUTHORIZED_TRANSACTION']}, 'seller_receivable_breakdown': {'gross_amount': {'currency_code': 'USD', 'value': '30.00'}, 'paypal_fee': {'currency_code': 'USD', 'value': '1.32'}, 'net_amount': {'currency_code': 'USD', 'value': '28.68'}}, 'custom_id': 'RO8ZXX20', 'status': 'COMPLETED', 'create_time': '2020-02-10T05:44:10Z', 'update_time': '2020-02-10T05:44:10Z', 'links': [{'href': 'https://api.sandbox.paypal.com/v2/payments/captures/5YA69751S2248772K', 'rel': 'self', 'method': 'GET'}, {'href': 'https://api.sandbox.paypal.com/v2/payments/captures/5YA69751S2248772K/refund', 'rel': 'refund', 'method': 'POST'}, {'href': 'https://api.sandbox.paypal.com/v2/checkout/orders/5GN0468041100792N', 'rel': 'up', 'method': 'GET'}]}, 'links': [{'href': 'https://api.sandbox.paypal.com/v1/notifications/webhooks-events/WH-8VT506292F0529107-6AL76556YR820754B', 'rel': 'self', 'method': 'GET'}, {'href': 'https://api.sandbox.paypal.com/v1/notifications/webhooks-events/WH-8VT506292F0529107-6AL76556YR820754B/resend', 'rel': 'resend', 'method': 'POST'}]}

这是我要发回的数据。

{'cmd': '_notify-validate', 'id': 'WH-8VT506292F0529107-6AL76556YR820754B', 'event_version': '1.0', 'create_time': '2020-02-10T05:44:14.774Z', 'resource_type': 'capture', 'resource_version': '2.0', 'event_type': 'PAYMENT.CAPTURE.COMPLETED', 'summary': 'Payment completed for $ 30.0 USD', 'resource': {'id': '5YA69751S2248772K', 'amount': {'currency_code': 'USD', 'value': '30.00'}, 'final_capture': True, 'seller_protection': {'status': 'ELIGIBLE', 'dispute_categories': ['ITEM_NOT_RECEIVED', 'UNAUTHORIZED_TRANSACTION']}, 'seller_receivable_breakdown': {'gross_amount': {'currency_code': 'USD', 'value': '30.00'}, 'paypal_fee': {'currency_code': 'USD', 'value': '1.32'}, 'net_amount': {'currency_code': 'USD', 'value': '28.68'}}, 'custom_id': 'RO8ZXX20', 'status': 'COMPLETED', 'create_time': '2020-02-10T05:44:10Z', 'update_time': '2020-02-10T05:44:10Z', 'links': [{'href': 'https://api.sandbox.paypal.com/v2/payments/captures/5YA69751S2248772K', 'rel': 'self', 'method': 'GET'}, {'href': 'https://api.sandbox.paypal.com/v2/payments/captures/5YA69751S2248772K/refund', 'rel': 'refund', 'method': 'POST'}, {'href': 'https://api.sandbox.paypal.com/v2/checkout/orders/5GN0468041100792N', 'rel': 'up', 'method': 'GET'}]}, 'links': [{'href': 'https://api.sandbox.paypal.com/v1/notifications/webhooks-events/WH-8VT506292F0529107-6AL76556YR820754B', 'rel': 'self', 'method': 'GET'}, {'href': 'https://api.sandbox.paypal.com/v1/notifications/webhooks-events/WH-8VT506292F0529107-6AL76556YR820754B/resend', 'rel': 'resend', 'method': 'POST'}]}

【问题讨论】:

    标签: paypal paypal-ipn


    【解决方案1】:

    这是我收到的 IPN 消息

    您没有收到 IPN。您收到了 Webhook 事件通知。 Webhook 不使用回发进行验证,而是使用 a signature in the event's header.


    即时付款通知 (IPN) - 使用回传到带有 &cmd=_notify-validate 的 ipnpb 主机进行验证 - 是一种比 Webhooks 更早的服务。

    【讨论】:

      猜你喜欢
      • 2020-08-07
      • 1970-01-01
      • 2020-09-19
      • 1970-01-01
      • 2020-07-17
      • 1970-01-01
      • 1970-01-01
      • 2020-08-22
      • 2021-06-30
      相关资源
      最近更新 更多