Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions beanstream/convert.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# -*- coding: utf-8 -*-
types = {
'B': 'Bambora',
'TD': 'TD',
'FD': 'First Data',
'UK': 'UK',
'G': 'Global Payments',
'V': 'Vital',
'EL': 'Elavon',
'E': 'Elavon',
'EFT': 'EFT',
'E/A': 'EBP/ACH',
'PT': 'Paymentech',
'IOP': 'INTERAC Online',
'EMV': 'Europay, Mastercard, Visa',
'DJN': 'Desjardins',
}

import csv
import json

messages = {}

def is_approved(message):
message_up = message.upper()
if (
'approved'.upper() in message_up or
'approval'.upper() in message_up and
not 'duplicate'.upper() in message_up
):
return True
return False

def make_line(line):
return str(line[0]), {
"type": types[line[1].upper()],
"approved": is_approved(line[3]),
"cardholder_message": line[2],
"merchant_message": line[3],
}

for line in csv.reader(open('messages.csv')):
if '-' in line[0]:
from_id, to_id = line[0].split('-')
from_id, to_id = int(from_id), int(to_id)
for id in range(from_id, to_id+1):
id2, value = make_line(line)
messages[id2] = value
else:
id2, value = make_line(line)
messages[id2] = value

print(json.dumps(messages, indent=2))
6 changes: 5 additions & 1 deletion beanstream/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ class ForbiddenException(BeanstreamApiException):#HTTP status code 403
class InternalServerException(BeanstreamApiException):#default
pass

class NotFoundException(BeanstreamApiException):
pass


def getMappedException(httpstatuscode):
code=str(httpstatuscode)
Expand All @@ -61,7 +64,8 @@ def getMappedException(httpstatuscode):
error_dict={
'1':UnAuthorizedException,
'2':BusinessRuleException,
'3':ForbiddenException
'3':ForbiddenException,
'4':NotFoundException,
}
if code in error_dict:
return error_dict[code]
Expand Down
1 change: 1 addition & 0 deletions beanstream/gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ def get_legato_token(self, card_number, expiry_month, expiry_year, cvd):
connection.request('POST', '/scripts/tokenization/tokens', data, headers)
response = connection.getresponse()
body = response.read()
print(body)
body = body.decode('utf-8')

result = json.loads(body)
Expand Down
Loading