GoCardless Pro API的客户端库。
gocardless-pro的Python项目详细描述
用于与gocardless pro api交互的python客户端。
测试了Python2.7、3.3、3.4、3.5、3.6和3.7。
- “Getting Started” guide带有复制和粘贴python代码示例
- API reference
从pypi安装:
$ pip install gocardless_pro
用法
创建一个Client实例,提供访问令牌和环境 您想使用:
importgocardless_protoken=os.environ['ACCESS_TOKEN']client=gocardless_pro.Client(access_token=token,environment='live')
使用客户端对象上的相应方法访问API终结点:
# Create a new customer. We automatically add idempotency keys to requests to create# resources, stopping duplicates accidentally getting created if something goes wrong# with the API (e.g. networking problems) - see https://developer.gocardless.com/api# -reference/#making-requests-idempotency-keys for detailscustomer=client.customers.create(params={'email':'jane@example.com'})# Fetch a payment by its IDpayment=client.payments.get("PA123")# Loop through a page of payments, printing each payment's amountforpaymentinclient.payments.list().records:decimal_amount=decimal.Decimal(payment.amount)/100print('Payment for £{0}'.format(decimal_amount))# Create a mandate PDF in a specific languageclient.mandate_pdfs.create(params={'links':{'mandate':'MD00001234XYZ'}},headers={'Accept-Language':'fr'})
有关完整文档,请参阅我们的API reference。
可用资源
银行详细信息查询
# Perform a bank details lookupclient.bank_details_lookups.create(params={...})
债权人
# Create a creditorclient.creditors.create(params={...})# List creditorsclient.creditors.list(params={...})# Iterate through all creditorsclient.creditors.all(params={...})# Get a single creditorclient.creditors.get('CR123',params={...})# Update a creditorclient.creditors.update('CR123',params={...})
债权人银行账户
# Create a creditor bank accountclient.creditor_bank_accounts.create(params={...})# List creditor bank accountsclient.creditor_bank_accounts.list(params={...})# Iterate through all creditor_bank_accountsclient.creditor_bank_accounts.all(params={...})# Get a single creditor bank accountclient.creditor_bank_accounts.get('BA123',params={...})# Disable a creditor bank accountclient.creditor_bank_accounts.disable('BA123',params={...})
客户
# Create a customerclient.customers.create(params={...})# List customersclient.customers.list(params={...})# Iterate through all customersclient.customers.all(params={...})# Get a single customerclient.customers.get('CU123',params={...})# Update a customerclient.customers.update('CU123',params={...})# Remove a customerclient.customers.remove('CU123',params={...})
客户银行账户
# Create a customer bank accountclient.customer_bank_accounts.create(params={...})# List customer bank accountsclient.customer_bank_accounts.list(params={...})# Iterate through all customer_bank_accountsclient.customer_bank_accounts.all(params={...})# Get a single customer bank accountclient.customer_bank_accounts.get('BA123',params={...})# Update a customer bank accountclient.customer_bank_accounts.update('BA123',params={...})# Disable a customer bank accountclient.customer_bank_accounts.disable('BA123',params={...})
客户通知
# Handle a notificationclient.customer_notifications.handle('PCN123',params={...})
事件
# List eventsclient.events.list(params={...})# Iterate through all eventsclient.events.all(params={...})# Get a single eventclient.events.get('EV123',params={...})
授权
# Create a mandateclient.mandates.create(params={...})# List mandatesclient.mandates.list(params={...})# Iterate through all mandatesclient.mandates.all(params={...})# Get a single mandateclient.mandates.get('MD123',params={...})# Update a mandateclient.mandates.update('MD123',params={...})# Cancel a mandateclient.mandates.cancel('MD123',params={...})# Reinstate a mandateclient.mandates.reinstate('MD123',params={...})
指令导入
# Create a new mandate importclient.mandate_imports.create(params={...})# Get a mandate importclient.mandate_imports.get('IM000010790WX1',params={...})# Submit a mandate importclient.mandate_imports.submit('IM000010790WX1',params={...})# Cancel a mandate importclient.mandate_imports.cancel('IM000010790WX1',params={...})
委托进口分录
# Add a mandate import entryclient.mandate_import_entries.create(params={...})# List all mandate import entriesclient.mandate_import_entries.list(params={...})# Iterate through all mandate_import_entriesclient.mandate_import_entries.all(params={...})
授权PDF
# Create a mandate PDFclient.mandate_pdfs.create(params={...})
付款
# Create a paymentclient.payments.create(params={...})# List paymentsclient.payments.list(params={...})# Iterate through all paymentsclient.payments.all(params={...})# Get a single paymentclient.payments.get('PM123',params={...})# Update a paymentclient.payments.update('PM123',params={...})# Cancel a paymentclient.payments.cancel('PM123',params={...})# Retry a paymentclient.payments.retry('PM123',params={...})
支出
# List payoutsclient.payouts.list(params={...})# Iterate through all payoutsclient.payouts.all(params={...})# Get a single payoutclient.payouts.get('PO123',params={...})
付款项目
# Get all payout items in a single payoutclient.payout_items.list(params={...})# Iterate through all payout_itemsclient.payout_items.all(params={...})
重定向流
# Create a redirect flowclient.redirect_flows.create(params={...})# Get a single redirect flowclient.redirect_flows.get('RE123456',params={...})# Complete a redirect flowclient.redirect_flows.complete('RE123456',params={...})
退款
# Create a refundclient.refunds.create(params={...})# List refundsclient.refunds.list(params={...})# Iterate through all refundsclient.refunds.all(params={...})# Get a single refundclient.refunds.get('RF123',params={...})# Update a refundclient.refunds.update('RF123',params={...})
订阅
# Create a subscriptionclient.subscriptions.create(params={...})# List subscriptionsclient.subscriptions.list(params={...})# Iterate through all subscriptionsclient.subscriptions.all(params={...})# Get a single subscriptionclient.subscriptions.get('SB123',params={...})# Update a subscriptionclient.subscriptions.update('SB123',params={...})# Cancel a subscriptionclient.subscriptions.cancel('SB123',params={...})
运行测试
首先,安装开发依赖项:
$ pip install -r requirements-dev.txt
要针对当前python版本运行测试套件,请运行nosetests。
要针对多个python版本运行测试套件,请运行tox。
如果没有安装所有版本的python,可以在 运行make的Docker容器。