Skip to content
This repository was archived by the owner on Jun 19, 2025. It is now read-only.

Commit 6692375

Browse files
committed
- Added option to set LIVE or TEST API mode
- Added examples for create order, update order, retreive order and retrive gateway(s) - Changed code in gateways.py
1 parent 4539134 commit 6692375

File tree

7 files changed

+68
-22
lines changed

7 files changed

+68
-22
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,6 @@ multisafepay/__pycache__/__init__.cpython-37.pyc
66
.idea/modules.xml
77
.idea/misc.xml
88
.idea/encodings.xml
9+
*.pyc
10+
*.xml
11+
*.iml

multisafepay/client.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@
66

77

88
class Client:
9-
def __init__(self, api_key=None):
10-
self.api_url = 'https://testapi.multisafepay.com/v1/json'
9+
def __init__(self, modus=None, api_key=None):
10+
self.modus = modus
11+
self.api_url = None
1112
self.api_key = api_key
1213
self.order = Orders(self)
1314
self.paymentmethod = PaymentMethod
@@ -16,6 +17,15 @@ def __init__(self, api_key=None):
1617
def set_api_key(self, api_key):
1718
self.api_key = self.validate_api_key(api_key)
1819

20+
def set_modus(self, modus):
21+
self.modus = modus
22+
if self.modus is 'TEST':
23+
self.api_url = 'https://testapi.multisafepay.com/v1/json'
24+
elif self.modus is 'LIVE':
25+
self.api_url = 'https://api.multisafepay.com/v1/json'
26+
else:
27+
raise ValueError('Invalid API mode, needs to be LIVE or TEST')
28+
1929
@staticmethod
2030
def validate_api_key(api_key):
2131
api_key = api_key.strip()
@@ -24,10 +34,11 @@ def validate_api_key(api_key):
2434
"characters long".format(api_key=api_key))
2535
return api_key
2636

27-
def execute_http_call(self, http_method, endpoint, data=None,**kwargs):
37+
def execute_http_call(self, http_method, endpoint, data=None, **kwargs):
38+
print(self.api_url)
2839
response = requests.request(http_method,
2940
url='{0}/{1}'.format(self.api_url, endpoint),
3041
headers={'api_key':'{api_key}'.format(
31-
api_key=self.api_key)}, json=data,**kwargs)
42+
api_key=self.api_key)}, json=data, **kwargs)
3243
json_data = json.loads(response.text)
3344
return json_data

app.py renamed to multisafepay/examples/create_order.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
from multisafepay.client import Client
22

33
msp_client = Client()
4-
#fill in TEST API key here
5-
msp_client.set_api_key('')
4+
# Here you can set the mode to TEST or LIVE based on the API you want to use
5+
msp_client.set_modus('TEST')
6+
msp_client.set_api_key('REPLACE WITH API KEY')
67

8+
# The following code will create a iDEAL order
79
print(msp_client.order.create({
810
"type": "redirect",
911
"order_id": "my-order-id-1",
10-
"gateway": msp_client.paymentmethod.EPS,
12+
"gateway": msp_client.paymentmethod.IDEAL,
1113
"currency": "EUR",
1214
"amount": "1000",
1315
"description": "Test Order Description",
@@ -21,4 +23,3 @@
2123
}
2224
}))
2325

24-
print(msp_client.gateways.gateways(country='NL',currency='100'))

multisafepay/examples/get_order.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from multisafepay.client import Client
2+
3+
msp_client = Client()
4+
# Here you can set the mode to TEST or LIVE based on the API you want to use
5+
msp_client.set_modus('TEST')
6+
msp_client.set_api_key('REPLACE WITH API KEY')
7+
8+
print(msp_client.order.get(51))
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from multisafepay.client import Client
2+
3+
msp_client = Client()
4+
# Here you can set the mode to TEST or LIVE based on the API you want to use
5+
msp_client.set_modus('TEST')
6+
msp_client.set_api_key('REPLACE WITH API KEY')
7+
8+
# To retrieve all the gateways you can use the following
9+
print(msp_client.gateways.allgateways())
10+
# To use filters use the following code
11+
print(msp_client.gateways.allgateways('?country=BE&currency=EUR&amount=10000'))
12+
# To retrieve information about one gateway use the following
13+
print(msp_client.gateways.gateway('IDEAL'))
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from multisafepay.client import Client
2+
3+
msp_client = Client()
4+
# Here you can set the mode to TEST or LIVE based on the API you want to use
5+
msp_client.set_modus('TEST')
6+
msp_client.set_api_key('REPLACE WITH API KEY')
7+
8+
# to update a existing order use the following example
9+
print(msp_client.order.update(49, {
10+
"status":"shipped",
11+
"tracktrace_code":"3SMSP0123456789",
12+
"carrier":"MSP Logistics",
13+
"ship_date":"01-01-1911",
14+
"reason":"Fulfilled by warehouse",
15+
"invoice_id":"AB12345"
16+
}))

multisafepay/resources/gateways.py

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,12 @@ def __init__(self, client):
55
self.method = 'GET'
66

77
def gateway(self, gatewayid):
8-
self.endpoint = '{0}/{1}'.format(self.endpoint,gatewayid)
9-
return self.msp_client.execute_http_call(self.method, self.endpoint)
8+
endpoint = '{0}/{1}'.format(self.endpoint,gatewayid)
9+
return self.msp_client.execute_http_call(self.method, endpoint)
1010

11-
def gateways(self, country=None, currency=None, amount=None, include=None):
12-
if country or currency or amount or include:
13-
self.endpoint = '{0}?'.format(self.endpoint)
14-
if country:
15-
self.endpoint = '{0}country={1}'.format(self.endpoint, country)
16-
if currency:
17-
self.endpoint = '{0}&currency={1}'.format(self.endpoint, currency)
18-
if amount:
19-
self.endpoint = '{0}&amount={1}'.format(self.endpoint, amount)
20-
if include:
21-
self.endpoint = '{0}&include={1}'.format(self.endpoint, include)
22-
return self.msp_client.execute_http_call(self.method, self.endpoint)
11+
def allgateways(self, *args):
12+
if not args:
13+
endpoint = self.endpoint
14+
else:
15+
endpoint = '{0}{1}'.format(self.endpoint, *args)
16+
return self.msp_client.execute_http_call(self.method, endpoint)

0 commit comments

Comments
 (0)