def comp_act(user, conference): if not TicketItem.objects.filter( add_on=False, ticketing_event__act_submission_event=True, ticketing_event__conference=conference).exists(): return False comp_ticket = TicketItem.objects.filter( add_on=False, ticketing_event__act_submission_event=True, ticketing_event__conference=conference).first() purchaser = Purchaser( matched_to_user=user, first_name=user.first_name, last_name=user.last_name, email=user.email) purchaser.save() transaction = Transaction( purchaser=purchaser, ticket_item=comp_ticket, amount=0, order_date=datetime.now(), shipping_method="Comp'ed", order_notes="Comped through IDD", reference="auto", payment_source="GBE") transaction.save() return True
def empty_cart(request): cart = Cart(request) transaction = Transaction(user=request.user) transaction.save() for item in cart: item.product.unlock_seat(transaction) cart.remove(item.product) context = {'total': 0} html = render(request, 'cart.html', context) return StreamingHttpResponse(html)
def buy(request, event): event = get_object_or_404(Event, pk=event) prices = event.get_prices() context = {'event': event, 'prices': prices} if request.method == 'POST': data = request.POST #make a new transaction transaction = Transaction(user=request.user) transaction.save() # go through the available prices and see what the user has requested for price in prices: if price.enabled: this_price = "%s-%s" % (price.category.id, price.buyer_type.id) if this_price in data: # for each of these buyer_types lock a seat and add it to the cart number_of_seats = int(data[this_price]) if number_of_seats > 0 and number_of_seats < 10: locked_seats = event.lock_seats(transaction, price.buyer_type, price.price, number_of_seats) if locked_seats: logging.info('Locked %s seats', (len(locked_seats))) # add sets to cart... cart = Cart(request) for seat in locked_seats: logging.info('Adding seat to cart: %s' , (seat.id)) cart.add(seat, seat.price, 1) context.update({'success': 'Seats added to shopping cart'}) else: context.update({'error': 'Not enough seats available'}) logging.error('Failed to lock seats') html = render(request, 'buy.html', context) return StreamingHttpResponse(html)
def pay_application_fee(sender, **kwargs): activity = "PayPal Purchase Processing" ipn_obj = sender ipn_obj_link = reverse("admin:%s_%s_change" % ("ipn", "paypalipn"), args=(ipn_obj.id, )) paid = False purchased_tickets = [] if ipn_obj.payment_status == ST_PP_COMPLETED: # Check that the receiver email has not been tampered with if ipn_obj.receiver_email != PayPalSettings.objects.first( ).business_email: # Not a valid payment notify_admin_on_error( activity, "Email not valid: %s" % ipn_obj.receiver_email, ipn_obj_link) return # Get user and bid custom = ipn_obj.custom.split('-') if custom[0] not in ('Act', 'Vendor') or custom[2] != "User": notify_admin_on_error(activity, "Can't parse custom: %s" % ipn_obj.custom, ipn_obj_link) return try: user = User.objects.get(pk=int(custom[3])) bid = eval(custom[0]).objects.get(pk=int(custom[1])) if bid.submitted is True: notify_admin_on_error( activity, "Payment recieved for a bid that has already been " + "submitted. Bid name: %s, Bid Type: %s, Bid PK: %s" % (bid.b_title, bid.__class__.__name__, bid.pk), ipn_obj_link) except: notify_admin_on_error( activity, "Can't get object in custom: %s" % ipn_obj.custom, ipn_obj_link) return # Check values ticket_items = get_fee_list(custom[0], bid.b_conference) ticket_pk_list = list(map(int, ipn_obj.item_number.split())) # minimum should be more than suggested donation if ticket_items.filter(is_minimum=True).exists() and float( ipn_obj.mc_gross) >= ticket_items.filter( is_minimum=True).order_by('cost').first().cost and ( ipn_obj.mc_currency == 'USD'): paid = True purchased_tickets = [ ticket_items.filter(is_minimum=True).order_by('cost').first() ] # or total set of items should match total cost, and there should be # one non-add-on elif len(ticket_pk_list) > 0: counter = 1 total = 0 cost = ticket_items.filter(id__in=ticket_pk_list).aggregate( Sum('cost')) if float(ipn_obj.mc_gross) >= float(cost['cost__sum']) and ( ipn_obj.mc_currency == 'USD') and ticket_items.filter( id__in=ticket_pk_list, add_on=False).exists(): paid = True purchased_tickets = ticket_items.filter(pk__in=ticket_pk_list) elif not ticket_items.filter(id__in=ticket_pk_list, add_on=False).exists(): notify_admin_on_error( activity, "Add ons received without a main ticket", ipn_obj_link) return if paid: buyer = Purchaser(matched_to_user=user, first_name=ipn_obj.first_name, last_name=ipn_obj.last_name, address=ipn_obj.address_street, city=ipn_obj.address_city, state=ipn_obj.address_state, zip=ipn_obj.address_zip, country=ipn_obj.address_country, email=ipn_obj.payer_email, phone=ipn_obj.contact_phone) buyer.save() for ticket in purchased_tickets: amount = ticket.cost if ticket.is_minimum is True: amount = ipn_obj.mc_gross transaction = Transaction(ticket_item=ticket, purchaser=buyer, amount=amount, order_date=ipn_obj.payment_date, payment_source="PayPalIPN", invoice=ipn_obj.invoice, custom=ipn_obj.custom) transaction.save() bid.submitted = True bid.save() notify_reviewers_on_bid_change( user.profile, bid, bid.__class__.__name__, "Submission", bid.b_conference, '%s Reviewers' % bid.__class__.__name__, reverse('%s_review' % bid.__class__.__name__.lower(), urlconf='gbe.urls')) else: notify_admin_on_error(activity, "Transaction was not paid", ipn_obj_link)
def bpt_save_order_to_database(event_id, bpt_order): ''' Function takes an XML order object from the BPT order list call and returns an equivalent transaction object. event_id - the ID of the event associated to this order bpt_order - the order object from the BPT call Returns: the Transaction object. May throw an exception. ''' trans = Transaction() # Locate the TicketItem or throw exception if it doesn't exist. ticket_item_id = '%s-%s' % (event_id, bpt_order.find('price_id').text) trans.ticket_item = TicketItem.objects.get(ticket_id=ticket_item_id) trans.amount = trans.ticket_item.cost # Build a purchaser object. purchaser = Purchaser() purchaser.first_name = unicode(bpt_order.find('fname').text) purchaser.last_name = unicode(bpt_order.find('lname').text) purchaser.address = unicode(bpt_order.find('address').text) purchaser.city = unicode(bpt_order.find('city').text) purchaser.state = unicode(bpt_order.find('state').text) purchaser.zip = unicode(bpt_order.find('zip').text) purchaser.country = unicode(bpt_order.find('country').text) purchaser.email = unicode(bpt_order.find('email').text) purchaser.phone = unicode(bpt_order.find('phone').text) # This is a little bit of a hack.. if we don't know who the user is that # purchased the ticket, we assign it to the limbo user. tracker_id = unicode(bpt_order.find('tracker_id').text) matched_user = attempt_match_purchaser_to_user(purchaser, tracker_id) if (matched_user == -1): purchaser.matched_to_user = User.objects.get(username='******') else: purchaser.matched_to_user = User.objects.get(id=matched_user) # Attempt to see if purchaser exists in database, otherwise it is new. pur_id = locate_matching_purchaser(purchaser) if (pur_id != -1): trans.purchaser = Purchaser.objects.get(id=pur_id) else: purchaser.save() pur_id = locate_matching_purchaser(purchaser) trans.purchaser = Purchaser.objects.get(id=pur_id) # Build out the remainder of the transaction. trans.order_date = pytz.utc.localize( datetime.strptime( bpt_order.find('order_time').text, "%Y-%m-%d %H:%M:%S")) trans.shipping_method = unicode(bpt_order.find('shipping_method').text) trans.order_notes = unicode(bpt_order.find('order_notes').text) trans.reference = unicode(bpt_order.find('ticket_number').text) trans.payment_source = 'Brown Paper Tickets' trans.save()