Search code examples
pythonpayment-gatewaycredit-cardpayone

Verifying credit cards (creditcardcheck) on Payone with Python


I'm trying to verify credit card on PayOne (https://www.payone.de/en/).

List of params I've got from According to 3.4.1 Verifying credit cards (creditcardcheck) and 3.1.2 Standard parameter section of documentation PAYONE_Platform_Client_API_EN.pdf (you can request it here https://www.payone.de/en/contact/).

  1. I calculate the hash value of (aid, api_version, mid, mode, portalid, responsetype, request, storecarddata) (Python) and pass it to client side.
# 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. and then do JSONP (why here is no CORS and RESTful API?) request to with additional params (cardcvc2, cardexpiredate, cardpan, cardtype) and hash that I got from serverside:

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. get result:

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

I'm using python 3.5 and angular2.

What I'm doing wrong here?

PS:

  • you can find example php code here, but no python code

PPS:

The hash method has been chosen in the web interface: https://pmi.pay1.de/merchants/?navi=portal&rc=1 (Method hash calculation*: SHA2-384 (recommended method))


Solution

  • Solution is call endpoint without api_version parameter:

    # 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

    In the same time api_version is noted as required parameter at section 3.1.2 Standard parameter and as parameter that should be hashed at section 3.1.4 Calculation of the HASH value. So it looks like type in documentation.