Reputation: 45
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!
Upvotes: 2
Views: 2874
Reputation: 644
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!
Upvotes: 5