Subversion Repositories SmartDukaan

Rev

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

Rev 2966 Rev 3010
Line 6... Line 6...
6
 
6
 
7
import sys
7
import sys
8
import os
8
import os
9
import datetime 
9
import datetime 
10
import time
10
import time
-
 
11
import logging
-
 
12
logging.basicConfig(level=logging.DEBUG)
-
 
13
 
11
from datetime import date
14
from datetime import date
12
from textwrap import dedent
15
from textwrap import dedent
13
from string import Template
16
from string import Template
14
 
17
 
15
from sqlalchemy.sql.expression import and_, or_, desc, not_, distinct
18
from sqlalchemy.sql.expression import and_, or_, desc, not_, distinct
Line 160... Line 163...
160
    transaction.status_message = description
163
    transaction.status_message = description
161
    if new_status == TransactionStatus.FAILED:
164
    if new_status == TransactionStatus.FAILED:
162
        for order in transaction.orders:
165
        for order in transaction.orders:
163
            order.status = OrderStatus.PAYMENT_FAILED
166
            order.status = OrderStatus.PAYMENT_FAILED
164
            order.statusDescription = "Payment Failed"
167
            order.statusDescription = "Payment Failed"
165
    elif new_status == TransactionStatus.IN_PROCESS or new_status == TransactionStatus.AUTHORIZED:
168
    elif new_status == TransactionStatus.AUTHORIZED:
166
        for order in transaction.orders:
169
        for order in transaction.orders:
167
            order.status = OrderStatus.SUBMITTED_FOR_PROCESSING
170
            order.status = OrderStatus.SUBMITTED_FOR_PROCESSING
168
            order.statusDescription = "Submitted to warehouse"
171
            order.statusDescription = "Submitted to warehouse"
169
            #After we got payment success, we will set logistics info also 
172
            #After we got payment success, we will set logistics info also 
170
            logistics_client = LogisticsClient().get_client()
173
            logistics_client = LogisticsClient().get_client()
Line 417... Line 420...
417
    session.commit()
420
    session.commit()
418
    return True
421
    return True
419
    
422
    
420
def accept_order(self, orderId):
423
def accept_order(self, orderId):
421
    order = get_order(orderId)
424
    order = get_order(orderId)
-
 
425
    if order.status == OrderStatus.SUBMITTED_FOR_PROCESSING:
-
 
426
        logging.info("Accepting order with id " + str(orderId))
-
 
427
        if order.transaction.status == TransactionStatus.AUTHORIZED:
-
 
428
            __capture_txn(order.transaction.id)
422
    order.status = OrderStatus.ACCEPTED
429
        order.status = OrderStatus.ACCEPTED
423
    order.statusDescription = "Order Accepted"
430
        order.statusDescription = "Order Accepted"
424
    order.accepted_timestamp = datetime.datetime.now()
431
        order.accepted_timestamp = datetime.datetime.now()
425
    session.commit()
432
        session.commit()
426
    return True
433
        return True
-
 
434
    else:
-
 
435
        logging.warning("Accept called for an unacceptable order")
-
 
436
        return False
-
 
437
 
-
 
438
def __capture_txn(txnId):
-
 
439
    logging.info("Capturing payment for merchant txn:" + str(txnId))
-
 
440
    payment_client = PaymentClient().get_client()
-
 
441
    capture_result = payment_client.capturePayment(txnId)
-
 
442
    if capture_result:
-
 
443
        change_transaction_status(txnId, TransactionStatus.IN_PROCESS, "Payment received");
-
 
444
    else:
-
 
445
        raise TransactionServiceException(115, "Payment capture failed.")
427
 
446
 
428
def bill_order(self, orderId):
447
def bill_order(self, orderId):
429
    order = get_order(orderId)
448
    order = get_order(orderId)
430
    order.status = OrderStatus.BILLED
449
    order.status = OrderStatus.BILLED
431
    order.statusDescription = "Order Billed"
450
    order.statusDescription = "Order Billed"