Skip to content

Commit

Permalink
Merge pull request #11 from AltaPay/support-get-terminals
Browse files Browse the repository at this point in the history
Add support for API/getTerminals
  • Loading branch information
emicha authored Mar 11, 2024
2 parents a3f78d8 + bd8cc4e commit 79a8f20
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 16 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
Change Log
----------

1.5.6
+++++++++++++++++++++

**Improvements**

- Add support for API/getTerminals

1.5.5
+++++++++++++++++++++

Expand Down
3 changes: 2 additions & 1 deletion altapay/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
__title__ = 'altapay'
__version__ = '1.5.5'
__version__ = '1.5.6'
__author__ = 'Coolshop.com'
__license__ = 'MIT'
__github_url__ = 'https://github.com/coolshop-com/AltaPay'
Expand All @@ -16,5 +16,6 @@
from altapay.payment import Payment # NOQA
from altapay.reservation import Reservation # NOQA
from altapay.resource import Resource # NOQA
from altapay.terminals import Terminals # NOQA
from altapay.transaction import Transaction # NOQA
from altapay.update_order import UpdateOrder # NOQA
23 changes: 23 additions & 0 deletions altapay/terminals.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from __future__ import absolute_import, unicode_literals

from altapay import exceptions
from altapay.resource import Resource


class Terminals(Resource):
def __init__(self, api):
"""
Initialize the Terminal object by fetching terminals data from AltaPay.
:arg api: An API object used for AltaPay communication.
"""
response = api.get('API/getTerminals')['APIResponse']

try:
terminals = response['Body']['Terminals']['Terminal']
except KeyError:
raise exceptions.ResourceNotFoundError('Terminals not found')
if isinstance(terminals, list):
self.terminals = terminals
else:
self.terminals = [terminals]
24 changes: 9 additions & 15 deletions example/example_klarna.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,33 +10,27 @@
import sys, random

# Update this with real path and uncomment before use, please
# sys.path.append('/absolute_path_to/python-client-library')
# sys.path.append('/absolute_path_to/sdk-python')


#sdk path check
sdkPathExists = False
for path in sys.path:
if path.endswith("/python-client-library"):
if path.endswith("/sdk-python"):
sdkPathExists=True
if sdkPathExists is False:
print "Path to python-client-library does not exist, update your environment variable, or put sys.path.append('/absolute_path_to/python-cliend-library') before including altapay sdk modules"
print("Path to sdk-python does not exist, update your environment variable, or put sys.path.append('/absolute_path_to/sdk-python') before including altapay sdk modules")
sys.exit()

from altapay import API, Payment



# These lines are only necessary because we are using utf-8 characters in the billing address:
reload(sys)
sys.setdefaultencoding('utf8')

api = API(mode='test',account='shop api', password='testpassword', url='http://gateway.dev.earth.pensio.com/merchant/')
api = API(mode='test',account='API Username', password='API Password', url='https://testgateway.altapaysecure.com/merchant/')

payment = Payment(api = api)

params = {

'terminal': 'AltaPay Klarna DK',
'terminal': 'AltaPay Klarna DK', # Update terminal name
'shop_orderid': 'Example_Klarna' + str(random.randint(1, 1000)),
'amount': 5.5,
'currency': 'DKK',
Expand Down Expand Up @@ -92,12 +86,12 @@
payment.create(**params)

if payment.success:
print "Success!"
print ("Success!")
# Access the url below and use the social security number 0801363945 in the page form to complete the Klarna order
print payment.url
print (payment.url)
else:
print "Error code: " + str(payment.error_code)
print "Error message: " + payment.error_message
print ("Error code: " + str(payment.error_code))
print ("Error message: " + payment.error_message)

# All the data
#print payment.__data__
31 changes: 31 additions & 0 deletions example/example_terminals.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-

"""
Terminals test script.
"""

import sys, random

# Update this with real path and uncomment before use, please
# sys.path.append('/absolute_path_to/sdk-python')


#sdk path check
sdkPathExists = False
for path in sys.path:
if path.endswith("/sdk-python"):
sdkPathExists=True
if sdkPathExists is False:
print("Path to sdk-python does not exist, update your environment variable, or put sys.path.append('/absolute_path_to/sdk-python') before including altapay sdk modules")
sys.exit()

from altapay import API, Terminals

api = API(mode='test',account='API username', password='API Password', url='https://testgateway.altapaysecure.com/merchant/')

response = Terminals(api = api)

print(response.terminals)
2 changes: 2 additions & 0 deletions tests/integration/test_merchant_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,7 @@ def test_fraud_check_in_charge(self):
'Checkit!')

def test_create_simple_invoice_request(self):
self.skipTest('Skipping test_create_simple_invoice_request')
invoice = Invoice(api=self.api)
params = {
'terminal': altapay_invoice_test_terminal_name,
Expand Down Expand Up @@ -401,6 +402,7 @@ def test_create_simple_invoice_request(self):
self.assertEqual(invoice.success, True)

def test_create_complex_invoice_request(self):
self.skipTest('Skipping test_create_complex_invoice_request')
invoice = Invoice(api=self.api)
params = {
'terminal': altapay_invoice_test_terminal_name,
Expand Down

0 comments on commit 79a8f20

Please sign in to comment.