使用Python验证Payone上的信用卡(creditcardcheck)

2024-10-03 21:32:12 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在验证PayOnehttps://www.payone.de/en/)上的信用卡。在

我从PAYONE平台客户端API文档的According to 3.4.1 Verifying credit cards (creditcardcheck)3.1.2 Standard parameter部分获得的参数列表_英语.pdf(您可以在此处请求https://www.payone.de/en/contact/)。在

  1. 我计算(aid,apivversion,mid,mode,portalid,responsetype,request,storecarddata)(Python)的散列值并将其传递给客户端。在
# build hash on server side: 
import hmac
import hashlib

params = {
    'aid': '123456', 
    'api_version': '3.12', 
    'mid': '123456', 
    'mode': 'test', 
    'portalid': '1234567', 
    'responsetype': 'JSON', 
    'request': 'creditcardcheck', 
    'storecarddata': 'yes'
}
message = ''.join([params[k] for k in sorted(params)])
return hmac.new(b'some-secret-key!', msg=message.encode('utf-8'), digestmod=hashlib.sha384).hexdigest()
  1. 然后做JSONP(为什么这里没有CORS和restfulapi?)使用我从服务器端获得的附加参数(cardcvc2、cardexpiredate、cardpan、cardtype)和哈希向请求:

https://secure.pay1.de/client-api/?aid=123456&api_version=3.10&cardcvc2=123&cardexpiredate=1801&cardpan=012344567890123&cardtype=M&mid=12345&mode=test&portalid=1234567&responsetype=JSON&request=creditcardcheck&storecarddata=yes&hash=c6a8fe28e6d4cc63139aae5eba41bdb74f877f364a444745f4083a22db0f9861247cd4a0dfa82bd42df1ff7724754ea6&callback_method=ng_jsonp.__req0.finished

  1. 获取结果:

{ "customermessage": "An error occured while processing this transaction (wrong parameters).", "errorcode": "2007", "errormessage": "Hash incorrect", "status": "ERROR" }

我使用的是python3.5和angular2。在

我做错什么了?在

附言:

  • 您可以找到示例php代码here,但没有python代码

PPS:

哈希方法已在web界面中选择:https://pmi.pay1.de/merchants/?navi=portal&rc=1Method hash calculation*: SHA2-384 (recommended method)

{1美元^


Tags: httpsapimoderequestwwwdehashparams
2条回答

默认情况下,付款人商户账户使用md5而不是sha384

# build hash on server side: 
import hmac
import md5
import hashlib

params = {
        'request': 'creditcardcheck', 
        'responsetype': 'JSON',       
        'mode': 'test',               
        'mid': '12345',                                
        'aid': '54321',                                
        'portalid': '2222222',                         
        'encoding': 'UTF-8',                           
        'storecarddata': 'yes', 
}
message = ''.join([params[k] for k in sorted(params)])
print message

m = hashlib.md5()
m.update(message)
m.update("secretkey")
print m.hexdigest()

该输出:

^{pr2}$

然后,打开URL并确保除了在URL中传递的信用卡参数(和回调方法)之外的所有参数都在散列中。在本例中:

https://secure.pay1.de/client-api/?aid=54321&cardcvc2=123&cardexpiredate=1801&cardpan=4111111111111111&cardtype=V&mid=12345&mode=test&portalid=2222222&responsetype=JSON&encoding=UTF-8&request=creditcardcheck&storecarddata=yes&hash=a435bff18234ec02a2dffa4d4850a08f

解决方案是不带api_version参数的调用端点:

# build hash on server side: 
import hmac
import hashlib

params = {
    'aid': '123456', 
#    'api_version': '3.12', 
    'mid': '123456', 
    'mode': 'test', 
    'portalid': '1234567', 
    'responsetype': 'JSON', 
    'request': 'creditcardcheck', 
    'storecarddata': 'yes'
}
message = ''.join([params[k] for k in sorted(params)])
return hmac.new(b'some-secret-key!', msg=message.encode('utf-8'), digestmod=hashlib.sha384).hexdigest()

PS公司

同时,api_version是第3.1.2 Standard parameter节的必需参数,也是在3.1.4 Calculation of the HASH value节进行散列处理的参数。所以它看起来像是输入文档。在

相关问题 更多 >