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

  1. 获取access_token,需要ClientId和ClientSecret
  2. 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/token	The get access token endpoint.
    client_id	Your client ID.
    secret	Your secret.
    grant_type	The 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:
    
    Username	Your client ID.
    Password	Your secret.
    5、On the Body tab, select x-www-form-urlencoded and enter this information:
    
    key	grant_type
    value	client_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)

 

 

 

 

 

 

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值