def recurring_payment(con, payment_id, no, tp, callback, dry_run=False): conf = get_config() price = conf.get('price', tp) url = conf.get('payment', 'base') + '/v1/registrations/' + payment_id + '/payments' name, email = q.get_customer_name_email(con, no) # invent names = name.split(" ") if len(names) == 1: lastname = "" firstname = names[0] else: lastname = names[-1] firstname = " ".join(names[:-1]) data = { 'authentication.userId' : conf.get('payment', 'userId'), 'authentication.password' : conf.get('payment', 'password'), 'authentication.entityId' : conf.get('payment', 'recurringEntityId'), 'amount' : price, 'currency' : 'ZAR', 'paymentType' : 'DB', 'recurringType': 'REPEATED', 'merchantTransactionId': "foobarbaz" + str(q.max_id_of_payment_history(con)), 'customer.givenName': firstname, 'customer.surname': lastname, 'customer.email': email, } if dry_run: return reactor.callLater(0, callback, {}, no, tp, price) else: d = treq.post(url, data) d.addCallback(callback, no, tp, price) return d
def onChallenge(self, challenge): if challenge.method != u'wampcra': raise Exception("invalid auth method " + challenge.method) if u'salt' in challenge.extra: raise Exception("salt unimplemented") return auth.compute_wcs(get_config().get('auth', 'secret'), challenge.extra['challenge'])
def auth(self, realm, id, details): if id == 'frontdesk': return { u'role': u'frontdesk', u'secret': unicode(get_config().get('auth', 'secret')) } else: return {}
def upload_signature(self, request): d = request.content.read() prefix = "data:image/png;base64," assert d.startswith(prefix) store_dir = get_config().get('data', 'store_dir') # invent new filename no = list(main.con.execute(select([func.count(members)])))[0][0] fname = os.path.join(store_dir, "signature_%d.png" % int(no)) d = d[len(prefix):] if (len(d) % 4) != 0: d += "=" * (4 - (len(d) % 4)) with open(fname, "w") as f: f.write(base64.b64decode(d, " /")) return fname
def check_payment_status(path): conf = get_config() url = "https://test.oppwa.com/" + path params = "&".join([ "%s=%s" for (k, v) in [ ('authentication.userId', conf.get('payment', 'userId')), ('authentication.password', conf.get('payment', 'password')), ('authentication.entityId', conf.get('payment', 'entityId')), ] ]) try: opener = urllib2.build_opener(urllib2.HTTPHandler) request = urllib2.Request(url + "?" + params, data='') request.get_method = lambda: 'GET' response = opener.open(request) return json.loads(response.read()) except urllib2.HTTPError, e: return {'error': e.code}
def upload_photo(self, request): d = request.content.read() args = {} l = request.uri.split("?")[1].split("&") for item in l: k, v = item.split("=") args[k] = v member_id = args['member_id'] what_for = args['what_for'] prefix = "data:image/png;base64," assert d.startswith(prefix) store_dir = get_config().get('data', 'store_dir') # invent new filename base_no = member_id no = base_no fname = os.path.join(store_dir, "photo_%s.png" % no) count = 1 while os.path.exists(fname): no = base_no + "_" + str(count) fname = os.path.join(store_dir, "photo_%s.png" % no) count += 1 d = d[len(prefix):] if (len(d) % 4) != 0: d += "=" * (4 - (len(d) % 4)) with open(fname, "w") as f: f.write(base64.b64decode(d, " /")) if what_for == 'yourself': d = {'photo': fname} else: d = { 'id_photo': fname, 'last_id_update': int(time.time()), 'last_id_checked': int(time.time()) } main.con.execute( members.update().where(members.c.id == member_id).values(**d)) return json.dumps({ 'success': True, 'filename': fname, 'what_for': what_for, 'member_id': member_id })
def payment_gateway_request(): conf = get_config() url = "https://test.oppwa.com/v1/checkouts" data = { 'authentication.userId': conf.get('payment', 'userId'), 'authentication.password': conf.get('payment', 'password'), 'authentication.entityId': conf.get('payment', 'entityId'), 'amount': '92.00', 'currency': 'ZAR', 'paymentType': 'DB', 'recurringType': 'INITIAL', 'createRegistration': 'true', } try: opener = urllib2.build_opener(urllib2.HTTPHandler) request = urllib2.Request(url, data=urllib.urlencode(data)) request.get_method = lambda: 'POST' response = opener.open(request) return json.loads(response.read()) except urllib2.HTTPError, e: return {'error': e.code}
from sqlalchemy import select, func from txrestapi.resource import APIResource from txrestapi import methods from autobahn.twisted.wamp import ApplicationSession, ApplicationRunner from autobahn.wamp import auth from twisted.internet.defer import inlineCallbacks, returnValue from twisted.web.server import NOT_DONE_YET from twisted.internet import reactor import treq # 62617379690 conf = get_config() DIRECT_BASE_URL = conf.get('payment', 'direct_url') DIRECT_PASSWORD = conf.get('payment', 'direct_password') DIRECT_USERNAME = conf.get('payment', 'direct_user') banks = { 'absa bank': ('Absa Bank', 632005), 'capitec bank': ('Capitec Bank', 470010), 'first national bank (south africa)': ('First National Bank (South Africa)', 250655), 'investec bank': ('Investec Bank', 580105), 'nedbank (south africa)': ('Nedbank (South Africa)', 198765), 'nedbank corporate saver account': ('Nedbank Corporate Saver Account', 720026), 'postbank': ('Postbank', 460005),
def get_prices(self): conf = get_config() d = {} for k in ['regular', 'youth', 'before4', 'yoga', 'couple']: d[k] = conf.get('price', k) return d