Subversion Repositories SmartDukaan

Rev

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

Rev 13934 Rev 13939
Line 20... Line 20...
20
            'Accept' : 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',      
20
            'Accept' : 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',      
21
            'Accept-Language' : 'en-US,en;q=0.8',                     
21
            'Accept-Language' : 'en-US,en;q=0.8',                     
22
            'Accept-Charset' : 'ISO-8859-1,utf-8;q=0.7,*;q=0.3'
22
            'Accept-Charset' : 'ISO-8859-1,utf-8;q=0.7,*;q=0.3'
23
        }
23
        }
24
CASHBACK_URL = 'http://api.profittill.com/cashbacks/index/%s/%s'
24
CASHBACK_URL = 'http://api.profittill.com/cashbacks/index/%s/%s'
25
USER_LOOKUP_URL = 'http://api.profittill.com/user_account/saholic/%s'
25
USER_LOOKUP_URL = 'http://api.profittill.com/user_accounts/saholic/%s'
26
WALLET_CREDIT_URL = 'http://localhost:8080/mobileapi/wallet!batchUpdate'
26
WALLET_CREDIT_URL = 'http://localhost:8080/mobileapi/wallet!batchUpdate'
27
 
27
 
28
def getStore(source_id):
28
def getStore(source_id):
29
    #module = sourceMap[source_id]
29
    #module = sourceMap[source_id]
30
    store = Store(source_id)
30
    store = Store(source_id)
Line 186... Line 186...
186
            client.Dtr.merchantOrder.update({'subOrders.cashBackStatus':Store.CB_CREDIT_IN_PROCESS},{'$set':{'subOrders.$.cashBackStatus':Store.CB_CREDITED, 'subOrders.$.batchId':batchId}}, multi=True)
186
            client.Dtr.merchantOrder.update({'subOrders.cashBackStatus':Store.CB_CREDIT_IN_PROCESS},{'$set':{'subOrders.$.cashBackStatus':Store.CB_CREDITED, 'subOrders.$.batchId':batchId}}, multi=True)
187
            for key, value in userAmountMap:
187
            for key, value in userAmountMap:
188
                client.Dtr.refund.insert({"userId": key, "batch":batchId, "userAmount":value, "timestamp":datetime.strftime(datetimeNow,"%Y-%m-%d %H:%M:%S")})
188
                client.Dtr.refund.insert({"userId": key, "batch":batchId, "userAmount":value, "timestamp":datetime.strftime(datetimeNow,"%Y-%m-%d %H:%M:%S")})
189
                client.Dtr.user.update({"userId":key}, {'$inc': { "credited": value}}, upsert=True)
189
                client.Dtr.user.update({"userId":key}, {'$inc': { "credited": value}}, upsert=True)
190
        else:
190
        else:
191
            tprint("Error Occurred while running batch.. Rolling Back")
191
            tprint("Error Occurred while running batch. Rolling Back")
192
            client.Dtr.merchantOrder.update({'subOrders.cashBackStatus':Store.CB_CREDIT_IN_PROCESS},{'$set':{'subOrders.$.cashBackStatus':Store.CB_APPROVED}}, multi=True)    
192
            client.Dtr.merchantOrder.update({'subOrders.cashBackStatus':Store.CB_CREDIT_IN_PROCESS},{'$set':{'subOrders.$.cashBackStatus':Store.CB_APPROVED}}, multi=True)    
193
    
193
    
194
def refundToWallet(batchId, userAmountMap):
194
def refundToWallet(batchId, userAmountMap):
195
    batchUpdateMap = {}
195
    batchUpdateMap = {}
196
    try :
196
    try :
197
        saholicUserAmountMap = {}
197
        saholicUserAmountMap = {}
198
        for key, value in userAmountMap.iteritems():
198
        for key, value in userAmountMap.iteritems():
199
            userLookupRequest = urllib2.Request(USER_LOOKUP_URL %(key), headers=headers)
199
            userLookupRequest = urllib2.Request(USER_LOOKUP_URL %(key), headers=headers)
200
            try:
200
            try:
201
                response = urllib2.urlopen(userLookupRequest).read()
201
                response = urllib2.urlopen(userLookupRequest).read()
202
                saholicUserId = json.loads(response)['account_id']
202
                saholicUserId = json.loads(response)['account_key']
203
                saholicUserAmountMap[saholicUserId] = value
203
                saholicUserAmountMap[saholicUserId] = value
204
            except:
204
            except:
205
                tprint("Could not fetch saholic id for user : " + str(key))
205
                tprint("Could not fetch saholic id for user : " + str(key))
206
                continue
206
                continue
-
 
207
        if len(saholicUserAmountMap) > 0:
207
        batchUpdateMap['userAmount'] = json.dumps(saholicUserAmountMap)
208
            batchUpdateMap['userAmount'] = json.dumps(saholicUserAmountMap)
208
        batchUpdateMap['batchId'] = batchId
209
            batchUpdateMap['batchId'] = batchId
209
        request = urllib2.Request(WALLET_CREDIT_URL, headers=headers)
210
            request = urllib2.Request(WALLET_CREDIT_URL, headers=headers)
210
        data = urllib.urlencode(batchUpdateMap)
211
            data = urllib.urlencode(batchUpdateMap)
211
        response = urllib2.urlopen(request, data)
212
            response = urllib2.urlopen(request, data)
212
        return json.loads(response.read())['response']['credited']
213
            return json.loads(response.read())['response']['credited']
-
 
214
        else:
-
 
215
            tprint("Nothing to Refund")
-
 
216
            return False
213
    except:
217
    except:
214
        traceback.print_exc()
218
        traceback.print_exc()
215
        tprint("Could not batch refund")
219
        tprint("Could not batch refund")
216
        return False
220
        return False
217
    
221
    
Line 223... Line 227...
223
    #print store.getCashbackAmount('864683341', 100)
227
    #print store.getCashbackAmount('864683341', 100)
224
    #data = urllib.urlencode({'orderId':6000, 'amount':200})
228
    #data = urllib.urlencode({'orderId':6000, 'amount':200})
225
    #request = urllib2.Request(WALLET_CREDIT_URL % (483649), headers=headers)
229
    #request = urllib2.Request(WALLET_CREDIT_URL % (483649), headers=headers)
226
    #response = urllib2.urlopen(request, data)
230
    #response = urllib2.urlopen(request, data)
227
    #print response.read()
231
    #print response.read()
228
    #settlePayBack()
232
    settlePayBack()
229
    batchId =1 
233
    
230
    userAmount = {483649:3.0}
-
 
231
    refundToWallet(batchId, userAmount)
-
 
232
        
234
        
233
if __name__ == '__main__':
-
 
234
    main()
-
 
235
 
235
 
236
 
236
 
237
###
237
###
238
#Settlement process is suposed to be a batch and run weekly
238
#Settlement process is suposed to be a batch and run weekly
239
#It is should be running on first hour of mondays. As cron should
239
#It is should be running on first hour of mondays. As cron should
Line 271... Line 271...
271
        gz.close()
271
        gz.close()
272
        return html
272
        return html
273
 
273
 
274
def tprint(*msg):
274
def tprint(*msg):
275
    print datetime.now(), "-", msg
275
    print datetime.now(), "-", msg
276
    
-
 
277
276
    
-
 
277
if __name__ == '__main__':
-
 
278
    main()
-
 
279
278
280