使用 Python 在 Payone 上验证信用卡 (creditcardcheck)
Verifying credit cards (creditcardcheck) on Payone with Python
我正在尝试在 PayOne (https://www.payone.de/en/) 上验证信用卡。
我从文档 According to 3.4.1 Verifying credit cards (creditcardcheck)
和 3.1.2 Standard parameter
部分获得的参数列表 PAYONE_Platform_Client_API_EN.pdf(您可以在此处请求 https://www.payone.de/en/contact/)。
- 我计算了(aid, api_version, 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()
- 然后执行 JSONP(为什么这里没有 CORS 和 RESTful API?)请求附加参数(cardcvc2、cardexpiredate、cardpan、cardtype) 和我从服务器端获得的哈希:
- 得到结果:
{
"customermessage": "An error occured while processing this transaction (wrong parameters).",
"errorcode": "2007",
"errormessage": "Hash incorrect",
"status": "ERROR" }
我正在使用 python 3.5 和 angular2。
我哪里做错了?
PS:
- 您可以找到示例 php 代码 here,但找不到 python 代码
PPS:
已在网络界面中选择哈希方法:https://pmi.pay1.de/merchants/?navi=portal&rc=1 (Method hash calculation*: SHA2-384 (recommended method)
)
默认情况下,payone 商家帐户使用 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()
这输出:
54321UTF-812345test2222222creditcardcheckJSONyes
a435bff18234ec02a2dffa4d4850a08f
然后,打开 URL 并确保在 URL 中传递的除信用卡参数(和回调方法)之外的所有参数也在散列中。在这个例子中是:
解决方案是不带 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
部分被标记为应该散列的参数。所以它看起来像输入文档。
我正在尝试在 PayOne (https://www.payone.de/en/) 上验证信用卡。
我从文档 According to 3.4.1 Verifying credit cards (creditcardcheck)
和 3.1.2 Standard parameter
部分获得的参数列表 PAYONE_Platform_Client_API_EN.pdf(您可以在此处请求 https://www.payone.de/en/contact/)。
- 我计算了(aid, api_version, 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()
- 然后执行 JSONP(为什么这里没有 CORS 和 RESTful API?)请求附加参数(cardcvc2、cardexpiredate、cardpan、cardtype) 和我从服务器端获得的哈希:
- 得到结果:
{ "customermessage": "An error occured while processing this transaction (wrong parameters).", "errorcode": "2007", "errormessage": "Hash incorrect", "status": "ERROR" }
我正在使用 python 3.5 和 angular2。
我哪里做错了?
PS:
- 您可以找到示例 php 代码 here,但找不到 python 代码
PPS:
已在网络界面中选择哈希方法:https://pmi.pay1.de/merchants/?navi=portal&rc=1 (Method hash calculation*: SHA2-384 (recommended method)
)
默认情况下,payone 商家帐户使用 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()
这输出:
54321UTF-812345test2222222creditcardcheckJSONyes
a435bff18234ec02a2dffa4d4850a08f
然后,打开 URL 并确保在 URL 中传递的除信用卡参数(和回调方法)之外的所有参数也在散列中。在这个例子中是:
解决方案是不带 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
部分被标记为应该散列的参数。所以它看起来像输入文档。