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
48 changes: 48 additions & 0 deletions thepay/gateApi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
from collections import OrderedDict
import hashlib
from datetime import tzinfo

from suds.client import Client

from six.moves.urllib.parse import urlencode

from thepay.utils import SignatureMixin


class GateError(Exception):
pass


class GateApi(SignatureMixin):
def __init__(self, config):
"""

:param config: Config
"""
self.config = config
self.client = None

self.connect()

def connect(self):
self.client = Client(self.config.webServicesWsdl)

def _hashParam(self, params):
# this interface is using deprecated md5 hashing
return hashlib.md5(params).hexdigest()

def _buildQuery(self, params):
# this interface uses different way of encoding
return urlencode(params)

def cardCreateRecurrentPayment(self, merchantData, newMerchantData, value):
params = self._signParams(OrderedDict((
('merchantId', self.config.merchantId),
('accountId', self.config.accountId),
('merchantData', merchantData),
('newMerchantData', newMerchantData),
('value', value),
)), self.config.password)
response = self.client.service.cardCreateRecurrentPaymentRequest(**params)
if not response.status:
raise GateError(response.errorDescription)
23 changes: 23 additions & 0 deletions thepay/tests.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
from __future__ import print_function

import unittest
import uuid
import datetime
from datetime import tzinfo, timedelta

from thepay.config import Config
from thepay.dataApi import DataApi
from thepay.gateApi import GateApi, GateError
from thepay.payment import Payment, ReturnPayment
from six.moves import urllib

Expand Down Expand Up @@ -145,3 +147,24 @@ def test_data(self):

def test_missing_data(self):
self.assertRaises(ReturnPayment.MissingParameter, lambda: self.payment.parseData({}))


class GateApiTests(unittest.TestCase):
def setUp(self):
self.config = Config()
self.gateApi = GateApi(self.config)

def test_invalid_cardCreateRecurrentPayment(self):
with self.assertRaises(GateError):
self.gateApi.cardCreateRecurrentPayment(
'4394c54e-27f1-411b-b5e0-3f4e1ecf3e2c',
uuid.uuid4(),
10
)

def test_cardCreateRecurrentPayment(self):
self.gateApi.cardCreateRecurrentPayment(
'c53be2ae-0b84-46e2-90f9-03c144a1a328',
uuid.uuid4(),
10
)