def create_order_from_express_paypal(nvp_dict): """ Create order in DB with ordered items """ #create order #create items #return order object order = Order() order.email = nvp_dict.get('email') order.b_first_name = nvp_dict.get('firstname') order.b_last_name = nvp_dict.get('lastname') order.b_address_countryname = nvp_dict.get('shiptocountryname') order.b_address_countrycode = nvp_dict.get('shiptocountrycode') order.b_address_zip = nvp_dict.get('shiptozip') order.b_address_state = nvp_dict.get('shiptostate') order.b_address_city = nvp_dict.get('shiptocity') order.b_address_street = nvp_dict.get('shiptostreet') \ + nvp_dict.get('shiptostreet2', "") order.shipping_address_flag = False order.status = order.NEW_ORDER order.paypal_transaction_id = nvp_dict.get('transactionid') order.save() item_ids = [(key, value) for key, value in nvp_dict.iteritems() if key.startswith("l_paymentrequest_0_number")] print item_ids for index, i in enumerate(item_ids): product = Prize.objects.get(pk=i[1]) order_item = OrderItem() order_item.order_id = order.id order_item.product = product order_item.number = product.number order_item.amount = nvp_dict.get('l_paymentrequest_0_amt' + str(index)) order_item.quantity = nvp_dict.get('l_paymentrequest_0_qty' + str(index)) order_item.save() return order
def save_order_items(nvp_dict, order): item_ids = [(key, value) for key, value in nvp_dict.iteritems() if key.startswith("l_paymentrequest_0_number")] print item_ids for index, i in enumerate(item_ids): product = Prize.objects.get(pk=i[1]) order_item = OrderItem() order_item.order_id = order.id order_item.product = product order_item.number = product.number order_item.name = product.name order_item.amount = nvp_dict.get('l_paymentrequest_0_amt' + str(index)) order_item.quantity = nvp_dict.get('l_paymentrequest_0_qty' + str(index)) order_item.size, order_item.color \ = get_size_and_color_from_paypal(nvp_dict.get('l_paymentrequest_0_desc' + str(index))) print nvp_dict.get('l_paymentrequest_0_desc' + str(index)) order_item.save()
def create_order_from_direct_paypal(nvp_dict): """ Create order in DB with ordered items """ #create order #create items #return order object """ <QueryDict: {u'l_paymentrequest_0_number0': [4], u's_countrycode': [u'AX'], u'b_state': [u'sdf'], u'card_first_name': [u'sdf'], u's_last_name': [u'sdf'], u's_street': [u'sdf'], u'acct': [u'4239530610456015'], u'l_paymentrequest_0_amt0': [32], u'l_paymentrequest_0_name0': [u'Raw Edge Design Letters Print Black Polyester VEST'], u's_city': [u'sdf'], u's_state': [u'sdf'], u'version': [u'116.0'], u's_countryname': [u'Aland Islands'], u'build': [u'16770825'], u'cvv2': [u'123'], u'b_street': [u'dd'], u'email': [u'*****@*****.**'], u'l_paymentrequest_0_qty0': [2], u'b_countrycode': [u'AU'], u'b_countryname': [u'Afghanistan'], u'timestamp': [u'2015-06-14T10:22:07Z'], u'currencycode': [u'USD'], u'card_last_name': [u'sdf'], u's_zip': [u'dsf'], u'paymentrequest_0_amt': [64.0], u'phone': [u'sdf'], u'b_country': [u'1'], u'cardyear': [u'2020'], u'transactionid': [u'06M899763J781091D'], u'amt': [u'64.00'], u's_first_name': [u'sdf'], u'cvv2match': [u'M'], u'cardmonth': [u'05'], u'ack': [u'Success'], u'b_city': [u'sdf'], u'creditcardtype': [u'visa'], u'b_last_name': [u'dddddd'], u'b_zip': [u'sdf'], u'avscode': [u'X'], u'b_first_name': [u'sads'], u'correlationid': [u'dba9b733e476']}> """ order = Order() order.email = nvp_dict.get('email') order.phone = nvp_dict.get('phone', "") order.b_first_name = nvp_dict.get('b_first_name') order.b_last_name = nvp_dict.get('b_last_name') order.b_address_countryname = nvp_dict.get('b_countryname') order.b_address_countrycode = nvp_dict.get('b_countrycode') order.b_address_zip = nvp_dict.get('b_zip') order.b_address_state = nvp_dict.get('b_state') order.b_address_city = nvp_dict.get('b_city') order.b_address_street = nvp_dict.get('b_street') order.s_first_name = nvp_dict.get('s_first_name', "") order.s_last_name = nvp_dict.get('s_last_name', "") order.s_address_countryname = nvp_dict.get('s_countryname', "") order.s_address_countrycode = nvp_dict.get('s_countrycode', "") order.s_address_zip = nvp_dict.get('s_zip', "") order.s_address_state = nvp_dict.get('s_state', "") order.s_address_city = nvp_dict.get('s_city', "") order.s_address_street = nvp_dict.get('s_street', "") order.status = order.NEW_ORDER order.paypal_transaction_id = nvp_dict.get('transactionid') order.save() item_ids = [(key, value) for key, value in nvp_dict.iteritems() if key.startswith("l_paymentrequest_0_number")] #print item_ids for index, i in enumerate(item_ids): product = Prize.objects.get(pk=i[1]) order_item = OrderItem() order_item.order_id = order.id order_item.product = product order_item.number = product.number order_item.amount = nvp_dict.get('l_paymentrequest_0_amt' + str(index)) order_item.quantity = nvp_dict.get('l_paymentrequest_0_qty' + str(index)) order_item.save() return order