| 132 |
ashish |
1 |
'''
|
|
|
2 |
Created on 25-Mar-2010
|
|
|
3 |
|
|
|
4 |
@author: ashish
|
|
|
5 |
'''
|
|
|
6 |
import urlparse
|
|
|
7 |
from shop2020.thriftpy.config.ttypes import ConfigException
|
|
|
8 |
from thrift.transport import TSocket
|
|
|
9 |
from thrift.transport.TTransport import TFramedTransport
|
|
|
10 |
from thrift.protocol.TBinaryProtocol import TBinaryProtocol
|
|
|
11 |
from shop2020.thriftpy.config import Configuration
|
|
|
12 |
from shop2020.config.client.ConfigClient import ConfigClient
|
|
|
13 |
import datetime
|
|
|
14 |
from shop2020.utils.Utils import to_java_date
|
|
|
15 |
from shop2020.thriftpy.model.v1.order import TransactionService
|
| 1124 |
chandransh |
16 |
from shop2020.thriftpy.model.v1.order.ttypes import Transaction, LineItem, TransactionStatus, Order
|
| 132 |
ashish |
17 |
|
| 194 |
ashish |
18 |
|
| 132 |
ashish |
19 |
class TransactionClient:
|
|
|
20 |
file_path = '/tmp/config.properties'
|
|
|
21 |
|
|
|
22 |
def __init__(self):
|
|
|
23 |
config_client = ConfigClient()
|
| 410 |
rajveer |
24 |
self.host = config_client.get_property("transaction_service_server_host")
|
|
|
25 |
self.port = config_client.get_property("transaction_service_server_port")
|
| 132 |
ashish |
26 |
|
|
|
27 |
self.start_client()
|
|
|
28 |
|
|
|
29 |
|
|
|
30 |
def start_client(self):
|
|
|
31 |
try:
|
|
|
32 |
self.transport = TSocket.TSocket(self.host, self.port)
|
|
|
33 |
self.transport = TFramedTransport(self.transport)
|
|
|
34 |
self.protocol = TBinaryProtocol(self.transport)
|
|
|
35 |
self.client = TransactionService.Client(self.protocol)
|
|
|
36 |
self.transport.open()
|
|
|
37 |
except:
|
|
|
38 |
raise ConfigException(101, 'unable to load the client')
|
|
|
39 |
|
|
|
40 |
def createTransaction(self, transaction):
|
|
|
41 |
self.client.createTransaction(transaction)
|
| 483 |
rajveer |
42 |
|
|
|
43 |
def getTransaction(self, transaction_id):
|
|
|
44 |
return self.client.getTransaction(transaction_id)
|
| 304 |
ashish |
45 |
|
|
|
46 |
def createAlert(self, transaction_id, type, comment):
|
|
|
47 |
self.client.setAlert(transaction_id, False, type, comment)
|
| 132 |
ashish |
48 |
|
| 304 |
ashish |
49 |
def get_client(self):
|
|
|
50 |
return self.client
|
|
|
51 |
|
| 132 |
ashish |
52 |
if __name__ == '__main__':
|
| 11173 |
vikram.rag |
53 |
transaction_client = TransactionClient().get_client()
|
|
|
54 |
list = ['OD40220054474']
|
|
|
55 |
print transaction_client.getCreatedOrdersForFlipkart(list)
|
|
|
56 |
'''transaction = Transaction()
|
| 132 |
ashish |
57 |
transaction.shoppingCartid = 2
|
|
|
58 |
transaction.customer_id = 4
|
|
|
59 |
transaction.createdOn = to_java_date(datetime.datetime.now())
|
| 483 |
rajveer |
60 |
transaction.statusDescription = "INIT phase"
|
|
|
61 |
transaction.transactionStatus = TransactionStatus.INIT
|
|
|
62 |
|
|
|
63 |
#transaction.expectedDeliveryTime = to_java_date(datetime.datetime.now())
|
|
|
64 |
|
| 1124 |
chandransh |
65 |
#payment_info = PaymentInfo()
|
|
|
66 |
#payment_info.payments
|
|
|
67 |
#payment_info.payments = {}
|
|
|
68 |
#payment = Payment()
|
|
|
69 |
#payment.merchant_tx_id = "123"
|
|
|
70 |
#payment.bank_tx_id = "ICIC0001"
|
|
|
71 |
#payment.mode = "CARD"
|
|
|
72 |
#payment.amount = 23.5
|
|
|
73 |
#payment.status = PaymentStatus.SUCCESS
|
|
|
74 |
#payment.submissionTimestamp = to_java_date(datetime.datetime.now())
|
|
|
75 |
#payment.completionTimestamp = to_java_date(datetime.datetime.now())
|
|
|
76 |
#payment.description = "Sample payment"
|
|
|
77 |
#payment_info.payments[to_java_date(datetime.datetime.now())] = payment
|
|
|
78 |
#transaction.paymentInfo = payment_info
|
| 483 |
rajveer |
79 |
|
|
|
80 |
order = Order()
|
|
|
81 |
|
|
|
82 |
order.lineitems = []
|
| 132 |
ashish |
83 |
line_item = LineItem()
|
|
|
84 |
line_item.addedOn = to_java_date(datetime.datetime.now())
|
| 483 |
rajveer |
85 |
line_item.unit_weight = 10
|
|
|
86 |
line_item.total_weight = 10
|
|
|
87 |
line_item.unit_price = 8
|
|
|
88 |
line_item.total_price = 8
|
|
|
89 |
order.lineitems.append(line_item)
|
| 7033 |
anupam.sin |
90 |
order.total_amount = 100.0
|
| 194 |
ashish |
91 |
|
| 7033 |
anupam.sin |
92 |
transaction.orders = []
|
|
|
93 |
transaction.orders.append(order)
|
| 132 |
ashish |
94 |
|
| 7033 |
anupam.sin |
95 |
transaction_client.createTransaction(transaction)
|
| 11173 |
vikram.rag |
96 |
#transaction_client.createAlert(2, 1, "Not yet shipped")'''
|
| 132 |
ashish |
97 |
|