PaynL2 SDK

paynlsdk2的Python项目详细描述


python sdk


安装

这个python2版本的sdk可以通过pip安装。

pip是python的包管理器。

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

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

$ pip install paynlsdk2

要求

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

内部API实现

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

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

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

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

快速入门和示例

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

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

from paynlsdk2.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 paynlsdk2.api.client import APIClient
APIClient.print_debug = True

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

# Import needed modulesfrompaynlsdk2.api.clientimportAPIAuthenticationfrompaynlsdk2.client.transactionimportTransactionfrompaynlsdk2.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 modulesfrompaynlsdk2.api.clientimportAPIAuthenticationfrompaynlsdk2.client.paymentmethodsimportPaymentMethodsfrompaynlsdk2.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 modulesfrompaynlsdk2.api.clientimportAPIAuthenticationfrompaynlsdk2.client.transactionimportTransactionfrompaynlsdk2.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 modulesfrompaynlsdk2.api.clientimportAPIAuthenticationfrompaynlsdk2.client.transactionimportTransactionfrompaynlsdk2.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 modulesfrompaynlsdk2.api.clientimportAPIAuthenticationfrompaynlsdk2.client.transactionimportTransactionfrompaynlsdk2.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 modulesfrompaynlsdk2.api.clientimportAPIAuthenticationfrompaynlsdk2.client.refundimportRefundfrompaynlsdk2.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 paynlsdk2
0

开始交易

$ pip install paynlsdk2
1

错误处理

您应该始终将调用包装在异常处理程序中。 sdk只包含四个internal例外情况:

  • paynlsdk2.exceptions.errorexception

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

  • paynlsdk2.exceptions.schemaexception

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

  • paynlsdk2.exceptions.transactionnotauthorizedexception

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

  • paynlsdk2.exceptions.transactionstatusexception

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

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

高级用法

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

$ pip install paynlsdk2
2

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

推荐PyPI第三方库


热门话题
java Android首选项相同getPreference()值的不同数据   字符串如何在Java中连接两个列表中的单词   安卓 Java Socket编程:检测客户端和服务器是否连接   使用JTextField的java无法将值转换为int   在java中,如何在不通过超级构造函数设置的情况下将消息设置为自定义异常类   用于标识属性值的java正则表达式模式   Android中的java不可见谷歌地图   java正确取消启动ExecutorService的JavaFX任务   在非活动java类中使用安卓的融合位置提供程序,并在主活动类中获取经度和纬度   spring为什么我的大摇大摆不能用springboot在java中工作?   java JSF(2.2)ViewScope在Weblogic 12.2.1.2和JDK 8上使用Spring 4.3.7(在Mac OS和Docker Oracle Linux环境上)   java如何用一个按钮提高计时器速度   java如何检查字符是否是元音?   注册表引用了不存在的Java运行时环境安装或运行时已损坏错误   来自ResultSet java的mysql getDateTime   maven LanguageTool Java API是否具有“无用”依赖关系?   twitter api身份验证的java Trycatch问题   java在Apache Struts 1.1中是否可以显式白名单?   安卓致命异常:主java。lang.RuntimeException:被问及未知片段