paypal订单捕获java,paypal获取交易订单信息api(python实现)

薛烈
2023-12-01

获取access_token,需要ClientId和ClientSecret

https://developer.paypal.com/docs/api/overview/#make-your-first-call

curl -v https://api.sandbox.paypal.com/v1/oauth2/token \

-H "Accept: application/json" \

-H "Accept-Language: en_US" \

-u "client_id:secret" \

-d "grant_type=client_credentials" /v1/oauth2/tokenThe get access token endpoint.

client_idYour client ID.

secretYour secret.

grant_typeThe grant type. Set to client_credentials.

返回: {

"scope": "https://uri.paypal.com/services/subscriptions https://api.paypal.com/v1/payments/.* https://api.paypal.com/v1/vault/credit-card https://uri.paypal.com/services/applications/webhooks openid https://uri.paypal.com/payments/payouts https://api.paypal.com/v1/vault/credit-card/.*",

"nonce": "2017-06-08T18:30:28ZCl54Q_OlDqP6-4D03sDT8wRiHjKrYlb5EH7Di0gRrds",

"access_token": "Access-Token",

"token_type": "Bearer",

"app_id": "APP-80W284485P519543T",

"expires_in": 32398

} postman操作测试

1、Download the latest version of Postman for your environment, and open Postman.

2、Select the POST method.

3、Enter the https://api.sandbox.paypal.com/v1/oauth2/token request URL.

4、On the Authorization tab, select the Basic Auth type and enter this information:

UsernameYour client ID.

PasswordYour secret.

5、On the Body tab, select x-www-form-urlencoded and enter this information:

keygrant_type

valueclient_credentials

6、Click Send.

python sdk获取access_token方法: api = Api({

"mode": "live", # sandbox or live

"client_id": client_id,

"client_secret": client_secret})

access_token = api.get_access_token()

print('access_token:' + access_token)

-------------------------------------------------------------------------------------------

2、通过tocken获取账单数据,返回账单和账单里的商品

接口地址:https://developer.paypal.com/docs/api/sync/v1/#transactions_get

url = 'https://api.paypal.com/v1/reporting/transactions?start_date=2018-12-16T00:00:00%2B0800&end_date=2018-12-30T00:00:00%2B0800&page_size=500&page=1&fields=all'

headers = {"Authorization": "bearer " + access_token, 'Content-Type': 'application/json'}

# headers = {"Authorization": "bearer " + access_token['access_token'],'Content-Type': 'application/json'}

# params = {'key1': 'value1', 'key2': ['value2', 'value3']}

r = requests.get(url, headers=headers)

with open('text.txt', 'w') as f:

f.write(r.text)

 类似资料: