这似乎是一个重复的问题,但是如果有任何建议的解决方案能够奏效,我就不会在这里。我一直在尝试根据他们的docs和此处https://github.com/paypal/ipn-code-samples/blob/master/python/paypal_ipn.py的Github代码示例在我的服务器端集成PayPal IPN。
我已根据此答案Paypal sandbox IPN return INVALID将我的沙盒企业帐户的编码更改为UTF-8,但始终收到相同的INVALID响应。
我在Django REST框架中使用python。这是我的代码。
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'}]}
答案 0 :(得分:0)
这是我收到的IPN消息
您没有收到IPN。您收到了Webhook事件通知。 Webhooks不使用回发进行验证,而是使用a signature in the event's header.
即时付款通知(IPN)(它使用回退到&cmd=_notify-validate
的ipnpb主机进行验证)是一种比Webhooks早得多的古老服务。