def test_finish_order(self): order = start_order(self.user, self.account) add_tickets(order, self.tickettype.id, 9) order.checkout() finish_order(order, send_mail=False) self.assertEqual(self.tickettype.availability, AVAILABLE) self.assertEqual(len(order.get_tickets()), 9)
def paper(client_id, order_key, user_id): """ Skips the payment provider and finishes the order as a paper ticket """ order = lookup_order_by_key(order_key) user = lookup_user_by_id(user_id) order.checkout(user) order.meta['paper'] = True result = order_to_dict(order, include_ordered_tickets=True) finish_order(order, send_mail=False) return result
def handle_payed(psp, context): """ The transaction has been charged and completed. """ order = psp.get_order() Session.refresh(order) if not order.is_purchased(): # update user information with new data from payment provider update_user_information(order, psp.get_buyer_information()) # increase transaction counter increment_transaction_count(order.account, order.get_ticket_count()) # create & mail tickets finish_order(order, send_mail=True)
def gift(client_id, order_key, user_id=None): """ Skips the payment provider and finishes the order as a gift """ order = lookup_order_by_key(order_key) if user_id is not None: user = lookup_user_by_id(user_id) else: user = None order.checkout(user) order.meta['gifted'] = True result = order_to_dict(order, include_ordered_tickets=True) finish_order(order, as_guest=True) return result
def checkout_order(client_id, order_key, payment_required=True, redirect_url=None, user_id=None): """ Checks out the order and returns the redirect url necessary for the payment. """ """ Locks an order so no other ticket orders can be added to it and links the accounts payment provider to it. Args: order_key: Key of the order payment_required Skips payment provider if set to False, defaults to True redirect_url URL used by paymentprovider to redirect user after purchase user_id Allows late-binding of user to the order during checkout phase. Only gets bound when the order previously did not have a user connected to it. Returns: The payment information necessary to complete the order. Raises: OrderLockedError if the order has already been checked out. """ result = dict() try: order = om.lookup_order_by_key(order_key) # assure order has not been locked before if order.is_locked(): raise ex.OrderLockedError("the order has already been checked out.") if user_id is not None: user = lookup_user_by_id(user_id) else: user = None order.checkout(user) order.touch() order.meta['redirect_url'] = redirect_url # payment is necessary when total is not zero and not a gift if payment_required and order.get_total() > 0: # the organising account has no psp set up if len(order.account.paymentproviders) == 0: raise ex.PaymentError("the account has no payment provider configured to handle an order.") # tickettype has currency allowed by psp # order_currency = order.account.paymentproviders[0].get_info("currency") # if order_currency != tickettype.currency_id: # raise ex.CurrencyError("not allowed to order with this currency.") # link payment provider to order account = order.account psp = lookup_payment_provider(account.id) # DEFAULT PSP HACK! if psp is None: psp = lookup_payment_provider(21) order.payment_provider_id = psp.get_provider_info().id payment_info = psp.checkout_order(order) if payment_info is None: raise ex.PaymentError("received error from payment service provider.") result['payment_info'] = payment_info result['status'] = order.status # no payment necessary, mark as purchased. else: result['status'] = order.status finish_order(order) except ex.TickeeError as e: blogger.error("failed checking out order %s: %s" % (order_key, e)) transaction.abort() return marshalling.error(e) else: order = om.lookup_order_by_key(order_key) result['order'] = order_to_dict(order, include_ordered_tickets=True, include_total=True) transaction.commit() return result
def test_finish_full_order(self): order = start_order(self.user, self.account) add_tickets(order, self.tickettype.id, 10) order.checkout() finish_order(order, send_mail=False) self.assertEqual(self.tickettype.availability, SOLD)