Paynl SDK

paynlsdk的Python项目详细描述


python sdk


安装

这个sdk可以通过pip安装。

pip是python的包管理器。

有关如何使用/安装PIP的更多信息,请访问:https://pypi.org/project/pip/

要在项目中安装pay.nl python sdk,只需

$ pip install paynlsdk

要求

pay.nl python sdk在python 3.7上工作,依赖于requests包和marshmallow包(仅限于v2.x) 通过PIP安装时,将自动检测并安装这些依赖项

内部API实现

并非所有函数参数都会针对每个情况进行完整描述。 当使用实用程序/快速启动类时,所有参数都可用,因此请查看那里的方法参数以获取更多选项。 它们基本上是不言而喻的

每个api实现都有自己的请求和响应类,可以在各种paynlsdk.api.xxx.yyy模块中找到。 每个模块至少包含一个请求和一个响应类。 例如,transaction.info api可以位于paynlsdk.api.transaction.info模块中,并且将包含 paynlsdk.api.transaction.info.request和一个paynlsdk.api.transaction.info.response类 通常,这些模块还将包含一个特定的(棉花糖)模式实现,该实现定义来自json的响应映射。

对于每个调用,都将返回一个响应对象。 使用print(result)语句,或者通过研究paynlsdk.objects模块,您可以找到可用的属性。 每个结果都将包含一个请求对象,它本质上提供了有关请求成功或失败的信息。 此对象还用于在请求失败时抛出paynlsk.exceptions.errorexception。 其余的响应对象将包含payl api返回的信息

同样,请参考paynlsdk.objects模块来研究响应中包含的各种对象。 响应对象本身的确切内容在所有paynlsdk.api.xxx.yyy.response类中定义

快速入门和示例

请注意,此快速启动仅使用快速调用实用程序方法。 如果您更熟悉python,则可以使用paynlsdk.api名称空间中的完整api请求/响应实现。

设置配置(这是必须的,而且应该在使用sdk之前完成)

from paynlsdk.api.client import APIAuthentication
APIAuthentication.service_id = 'SL-xxxx-xxxx'
APIAuthentication.api_token = '<yourtokenhere>'
APIAuthentication.token_code = 'AT-xxxx-xxxx'

打开api客户端的调试输出 注意:这将使用"print",并将相关信息转储到控制台,如端点, http方法、请求参数、http头和api调用的原始响应

from paynlsdk.api.client import APIClient
APIClient.print_debug = True

获得银行(仅限理想银行)

# Import needed modulesfrompaynlsdk.api.clientimportAPIAuthenticationfrompaynlsdk.client.transactionimportTransactionfrompaynlsdk.exceptionsimport*# Set mandatory basicsAPIAuthentication.service_id='SL-xxxx-xxxx'APIAuthentication.api_token='<yourtokenhere>'APIAuthentication.token_code='AT-xxxx-xxxx'# Perform requesttry:result=Transaction.get_banks()forbankinresult:print('{id}: {name}'.format(id=bank.id,name=bank.name))exceptSchemaExceptionasse:print('SCHEMA ERROR:\n\t'+str(se))print('\nSCHEMA ERRORS:\n\t'+str(se.errors))exceptErrorExceptionasee:print('API ERROR:\n'+str(ee))exceptExceptionase:print('GENERIC EXCEPTION:\n'+str(e))

获取付款方式列表

# Import needed modulesfrompaynlsdk.api.clientimportAPIAuthenticationfrompaynlsdk.client.paymentmethodsimportPaymentMethodsfrompaynlsdk.exceptionsimport*# Set mandatory basicsAPIAuthentication.service_id='SL-xxxx-xxxx'APIAuthentication.api_token='<yourtokenhere>'APIAuthentication.token_code='AT-xxxx-xxxx'# Perform requesttry:result=PaymentMethods.get_list()forpayment_methodinresult.values():print('{id}: {name} ({visible_name})'.format(id=payment_method.id,name=payment_method.name,visible_name=payment_method.visible_name))exceptSchemaExceptionasse:print('SCHEMA ERROR:\n\t'+str(se))print('\nSCHEMA ERRORS:\n\t'+str(se.errors))exceptErrorExceptionasee:print('API ERROR:\n'+str(ee))exceptExceptionase:print('GENERIC EXCEPTION:\n'+str(e))

检索交易信息

# Import needed modulesfrompaynlsdk.api.clientimportAPIAuthenticationfrompaynlsdk.client.transactionimportTransactionfrompaynlsdk.exceptionsimport*# Set mandatory basicsAPIAuthentication.service_id='SL-xxxx-xxxx'APIAuthentication.api_token='<yourtokenhere>'APIAuthentication.token_code='AT-xxxx-xxxx'# Perform requesttry:result=Transaction.info(transaction_id='1234567890X1a2b3')print(result)exceptSchemaExceptionasse:print('SCHEMA ERROR:\n\t'+str(se))print('\nSCHEMA ERRORS:\n\t'+str(se.errors))exceptErrorExceptionasee:print('API ERROR:\n'+str(ee))exceptExceptionase:print('GENERIC EXCEPTION:\n'+str(e))

正在检索事务状态

# Import needed modulesfrompaynlsdk.api.clientimportAPIAuthenticationfrompaynlsdk.client.transactionimportTransactionfrompaynlsdk.exceptionsimport*# Set mandatory basicsAPIAuthentication.service_id='SL-xxxx-xxxx'APIAuthentication.api_token='<yourtokenhere>'APIAuthentication.token_code='AT-xxxx-xxxx'# Perform requesttry:result=Transaction.status(transaction_id='1234567890X1a2b3')print(result)exceptSchemaExceptionasse:print('SCHEMA ERROR:\n\t'+str(se))print('\nSCHEMA ERRORS:\n\t'+str(se.errors))exceptErrorExceptionasee:print('API ERROR:\n'+str(ee))exceptExceptionase:print('GENERIC EXCEPTION:\n'+str(e))

退还(部分)交易

# Import needed modulesfrompaynlsdk.api.clientimportAPIAuthenticationfrompaynlsdk.client.transactionimportTransactionfrompaynlsdk.exceptionsimport*# Set mandatory basicsAPIAuthentication.service_id='SL-xxxx-xxxx'APIAuthentication.api_token='<yourtokenhere>'APIAuthentication.token_code='AT-xxxx-xxxx'# Perform requesttry:result=Transaction.refund(transaction_id='1234567890X1a2b3')# Whenever you want to partially refund use e.g. (note: amounts are in cents)# result = Refund.transaction(transaction_id='1234567890X1a2b3', amount=500, description='partial refund')# PLEASE NOTE the refund_id is NOT guaranteed, it will only be returned when the refund is done through IBAN.# This is a known flaw, so please do not rely on the refund ID to be part of the response by defaultprint('Refund ID: {refund_id}'.format(refund_id=result.refund_id))exceptSchemaExceptionasse:print('SCHEMA ERROR:\n\t'+str(se))print('\nSCHEMA ERRORS:\n\t'+str(se.errors))exceptErrorExceptionasee:print('API ERROR:\n'+str(ee))exceptExceptionase:print('GENERIC EXCEPTION:\n'+str(e))

退回(部分)交易(可选方法:此API中提供更多请求选项)。

# Import needed modulesfrompaynlsdk.api.clientimportAPIAuthenticationfrompaynlsdk.client.refundimportRefundfrompaynlsdk.exceptionsimport*# Set mandatory basicsAPIAuthentication.service_id='SL-xxxx-xxxx'APIAuthentication.api_token='<yourtokenhere>'APIAuthentication.token_code='AT-xxxx-xxxx'# Perform requesttry:result=Refund.transaction(transaction_id='1234567890X1a2b3')# Whenever you want to partially refund use e.g. (note: amounts are in cents)# result = Refund.transaction(transaction_id='1234567890X1a2b3', amount=500, description='partial refund')# PLEASE NOTE the refund_id is NOT guaranteed, it will only be returned when the refund is done through IBAN.# This is a known flaw, so please do not rely on the refund ID to be part of the response by defaultprint('Refund ID: {refund_id}'.format(refund_id=result.refund_id))exceptSchemaExceptionasse:print('SCHEMA ERROR:\n\t'+str(se))print('\nSCHEMA ERRORS:\n\t'+str(se.errors))exceptErrorExceptionasee:print('API ERROR:\n'+str(ee))exceptExceptionase:print('GENERIC EXCEPTION:\n'+str(e))

正在检索退款信息 注意:退款ID以"RF xxxx xxxx"的形式出现。

$ pip install paynlsdk
0

开始交易

$ pip install paynlsdk
1

错误处理

您应该始终将调用包装在异常处理程序中。 sdk只包含四个内部异常:

  • <P>paynlsdk.exceptions.errorexception

    如果由于任何原因,在通信或API内部出现错误,将引发此异常

  • paynlsdk.exceptions.schemaexception

    如果由于任何原因架构映射(使用棉花糖)失败,则引发此异常

  • paynlsdk.exceptions.transactionnotauthorizedexception异常

    只有当您尝试使用响应实例作为 调用transaction.info()的结果

  • paynlsdk.exceptions.transactionStatusException

    只有当您尝试使用响应实例作为 调用transaction.info()的结果

注意:总是会抛出任何其他标准异常。 这些最有可能发生在sdk之外,但也应该进行处理。

高级用法

无论何时您想将请求和响应对象用于任何目的,都可以选择 为任何api调用创建请求对象。这些可以在任何paynlsdk.api.xxx.yyy模块中找到。 这使您能够获得原始请求参数和原始响应 由pay.nl返回。 尽管您通常不需要这样做,但下面是一个完整的示例

$ pip install paynlsdk
2

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
具有x86javapath的x64机器上x86java上的java JNI未满足链接错误   java将Pixmap的一部分上传到GPU   图像Java位图RLE8格式   java Android studio谷歌广告崩溃应用程序   java如何创建包含未知数量对象的变量?   Java计算给定int数组的所有可能组合   java JDBC classnotfound异常   httpclient中的java将HttpEntity转换为字符串的最优雅/正确的方法是什么?   如何从Java程序运行nano?   java在安卓中调用自定义类/方法   调用方法和JOptionPane后,允许代码继续执行所需的java计时器或其他想法   关于侦听器的向量Java并发问题   线程池执行器Java线程池   java配置DTO上的Swagger javax验证约束   Java中用于按钮功能的swing操作命令   ServletOutputStream中的java设置状态代码   java打印输入数组的平均值