Retrieving all Payment info from PayPal App

北战南征 提交于 2019-12-22 12:15:41

问题


I've recently been trying to write a Python script to automatically fetch all the payments made or received by a PayPal app, tied to a facilitator account. I'm using the client_id and client_secret from the app, and the official Python API library.

import paypalrestsdk
import logging
logging.basicConfig(level=logging.INFO)

paypalrestsdk.configure({
    "mode": "sandbox",
    "client_id": CLIENT_ID,
    "client_secret": CLIENT_SECRET})

payment_history = paypalrestsdk.Payment.all({"count": 10})
print(payment_history.payments)

Unfortunately, None is printed (payment_history returns a NoneType). The logging prints

INFO:root:Request[POST]: https://api.sandbox.paypal.com/v1/oauth2/token
INFO:requests.packages.urllib3.connectionpool:Starting new HTTPS connection (1):  api.sandbox.paypal.com
INFO:root:Response[200]: OK, Duration: 0.937975s.
INFO:root:Request[GET]: https://api.sandbox.paypal.com/v1/payments/payment?count=10
INFO:requests.packages.urllib3.connectionpool:Starting new HTTPS connection (1): api.sandbox.paypal.com
INFO:root:Response[200]: OK, Duration: 1.19636s.
None

so the client_id and client_secret are probably fine for logging in. On the sandbox account for PayPal, I've both received and sent payments from the facilitator, none of which are output.

That being said, is there anything I'm doing incorrectly? This is the first time I'm using the PayPal API, so any help would be great!


回答1:


I haven't seen this documented anywhere, but it looks to me like the REST API only returns payments that were created via the new API.

You may have to use the much uglier Classic API, which has a decent Python client at https://github.com/duointeractive/paypal-python, which you can use like:

from paypal import PayPalInterface
paypal_api = PayPalInterface(API_USERNAME="xxx_xxx_apix.xxx.com",
                             API_PASSWORD="xxxxxxxxxx",
                             API_SIGNATURE="xxxxxxxxxxxxxxxxxxxxxxxx",
                             DEBUG_LEVEL=0,
                             HTTP_TIMEOUT=30)

transactions = paypal_api._call('TransactionSearch',
                                STARTDATE='2014-01-01T00:00:00Z',
                                STATUS="Success")

I'm working on a fork that wraps TransactionSearch in a shortcut method and also parses the NVP response into a list of python dictionaries. Still in progress, but you can check it out at https://github.com/jlev/paypal-python. Patches and pull-requests welcome!



来源:https://stackoverflow.com/questions/23050232/retrieving-all-payment-info-from-paypal-app

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!