Subversion Repositories SmartDukaan

Rev

Rev 5635 | Rev 6174 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 5635 Rev 5756
Line 9... Line 9...
9
 
9
 
10
import datetime
10
import datetime
11
from datetime import date
11
from datetime import date
12
import optparse
12
import optparse
13
import sys
13
import sys
-
 
14
import urllib
14
import urllib2
15
import urllib2
15
import traceback
16
import traceback
16
from string import Template
17
from string import Template
17
 
18
 
18
 
19
 
Line 97... Line 98...
97
    pc = PromotionClient().get_client()
98
    pc = PromotionClient().get_client()
98
    pc.addVoucher(voucher)
99
    pc.addVoucher(voucher)
99
 
100
 
100
def generateVoucher(amount):
101
def generateVoucher(amount):
101
    params = "userid=" + username + "&password=" + password + "&amount=" + str(amount) 
102
    params = "userid=" + username + "&password=" + password + "&amount=" + str(amount) 
102
    returnValue = urllib2.urlopen(voucherGenerationUrl + "?" + params).read()
103
    returnValue = urllib.urlopen(voucherGenerationUrl + "?" + params).read()
103
    if "-1" == returnValue:
104
    if "-1" == returnValue:
104
        raise Exception("Credit balance low.")
105
        raise Exception("Credit balance low.")
105
    
106
    
106
    elif "0" == returnValue:
107
    elif "0" == returnValue:
107
        raise Exception("Network or some other failure.")
108
        raise Exception("Network or some other failure.")
Line 117... Line 118...
117
    return voucher.voucherCode
118
    return voucher.voucherCode
118
 
119
 
119
def activateVoucher(voucherCode, userEmail):
120
def activateVoucher(voucherCode, userEmail):
120
    today = date.today() + datetime.timedelta(365/4)
121
    today = date.today() + datetime.timedelta(365/4)
121
    params = "userid=" + username + "&password=" + password + "&cid=" + voucherCode + "&email=" + userEmail + "&expiry=" + today.strftime('%d-%b-%y') 
122
    params = "userid=" + username + "&password=" + password + "&cid=" + voucherCode + "&email=" + userEmail + "&expiry=" + today.strftime('%d-%b-%y') 
122
    returnValue = urllib2.urlopen(voucherActivationUrl + "?" + params).read()
123
    returnValue = urllib.urlopen(voucherActivationUrl + "?" + params).read()
123
    if "1" == returnValue:
124
    if "1" == returnValue:
124
        return True;
125
        return True;
125
    elif "-1" == returnValue:
126
    elif "-1" == returnValue:
126
        raise Exception("Invalid voucher.")
127
        raise Exception("Invalid voucher.")
127
    elif "0" == returnValue:
128
    elif "0" == returnValue:
128
        raise Exception("Network or some other failure.")
129
        raise Exception("Network or some other failure.")
129
    return False
130
    return False
130
 
131
 
131
def deactivateVoucher(voucherCode, reason):
132
def deactivateVoucher(voucherCode, reason):
132
    params = "userid=" + username + "&password=" + password + "&cid=" + voucherCode + "&comment=" + reason 
133
    params = "userid=" + username + "&password=" + password + "&cid=" + voucherCode + "&comment=" + reason 
133
    returnValue = urllib2.urlopen(voucherDeactivationUrl + "?" + params).read()
134
    returnValue = urllib.urlopen(voucherDeactivationUrl + "?" + params).read()
134
    print returnValue
135
    print returnValue
135
    ## 0#2#2#pankaj.kankar@shop2020.in
136
    ## 0#2#2#pankaj.kankar@shop2020.in
136
    tokens = returnValue.split('#')
137
    tokens = returnValue.split('#')
137
    status = tokens[0]
138
    status = tokens[0]
138
    actualAmount = int(tokens[1])
139
    actualAmount = int(tokens[1])
Line 147... Line 148...
147
    return False
148
    return False
148
 
149
 
149
 
150
 
150
def checkVoucherStatus(voucherCode):
151
def checkVoucherStatus(voucherCode):
151
    params = "userid=" + username + "&password=" + password + "&cid=" + voucherCode
152
    params = "userid=" + username + "&password=" + password + "&cid=" + voucherCode
152
    returnValue = urllib2.urlopen(voucherStatusUrl + "?" + params).read()
153
    returnValue = urllib.urlopen(voucherStatusUrl + "?" + params).read()
153
    print returnValue
154
    print returnValue
154
    ## ACTIVATE#2#2#pankaj.kankar@shop2020.in
155
    ## ACTIVATE#2#2#pankaj.kankar@shop2020.in
155
    ## DEACTIVATED#2#2#pankaj.kankar@shop2020.in
156
    ## DEACTIVATED#2#2#pankaj.kankar@shop2020.in
156
    ## CONSUMED
157
    ## CONSUMED
157
    ## EXPIRED
158
    ## EXPIRED