Rev 701 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
'''Created on 26-Aug-2010@author: ashish'''from shop2020.payment.ttypes import PaymentExceptionfrom shop2020.payments.impl.DataService import Pmntimport datetimefrom shop2020.thriftpy.payments import PaymentServicefrom elixir import *from shop2020.utils.Utils import to_py_datefrom shop2020.thriftpy import paymentsdef create_payment(user_id, cart_id, amount, gateway_id):if not user_id:raise PaymentException(101, "user cannot be null")if not cart_id:raise PaymentException(101, "cart cannot be null")if not amount:raise PaymentException(101, "Amount cannot be null")if not gateway_id:raise PaymentException(101, "Gateway cannot be null")payment = Pmnt()payment.user_id = user_idpayment.cart_id = cart_idpayment.amt = amountpayment.mid = str(cart_id)payment.init_ts = datetime.datetime.now()payment.ps = PaymentService.PaymentStatus.INITsession.commit()return payment.iddef get_payments_for_user(user_id, from_time, to_time, status, gateway_id):if not user_id:raise PaymentException(101, "user cannot be null")query = Pmnt.query.filter_by(user_id=user_id)if from_time:from_date = to_py_date(from_time)query = query.filter(Pmnt.init_ts >= from_date)if to_time:to_date = to_py_date(to_time)query = query.filter(Pmnt.init_ts <= to_date)if status != -1:query = query.filter(Pmnt.ps == status)if gateway_id:query = query.filter(Pmnt.gateway == gateway_id)try:payments = query.all()return paymentsexcept:return Nonedef get_payments_for_cart(cart_id, from_time, to_time, status, gateway_id):if not cart_id:raise PaymentException(101, "user cannot be null")query = Pmnt.query.filter_by(cart_id=cart_id)if from_time:from_date = to_py_date(from_time)query = query.filter(Pmnt.init_ts >= from_date)if to_time:to_date = to_py_date(to_time)query = query.filter(Pmnt.init_ts <= to_date)if status != -1:query = query.filter(Pmnt.ps == status)if gateway_id:query = query.filter(Pmnt.gateway == gateway_id)try:payments = query.all()return paymentsexcept:return Nonedef get_payments(from_time, to_time, status, gateway_id):query = Pmnt.queryif from_time:from_date = to_py_date(from_time)query = query.filter(Pmnt.init_ts >= from_date)if to_time:to_date = to_py_date(to_time)query = query.filter(Pmnt.init_ts <= to_date)if status != -1:query = query.filter(Pmnt.ps == status)if gateway_id:query = query.filter(Pmnt.gateway == gateway_id)try:payments = query.all()return paymentsexcept:return Nonedef change_payment_status(id, status):try:payment = Pmnt.get_by(id=id)payment.ps = statussession.commit()except:raise PaymentException(101, "no payment with such id")def get_payment(id):try:payment = Pmnt.get_by(id=id)return paymentexcept:raise PaymentException(101, "no payment with such id")def add_bank_details(id, bid, btxid, error_code, session_id, postdate, auth_code, ref_code):try:payment = Pmnt.get_by(id=id)return paymentexcept:raise PaymentException(101, "no payment with such id")payment.bid = bidpayment.btxid = btxidpayment.error_code = error_codepayment.session_id = session_idpayment.post_date = postdatepayment.ref_code = ref_codepayment.auth_code = auth_codesession.commit()