コード例 #1
0
ファイル: sales.py プロジェクト: rangsutu88/Tktr
 def reject_payment_view_do(self):
     payments = self.request.root.payments
     # Get payment if possible
     if not self.request.matchdict["ref_code"] in self.request.root.payments:
         return HTTPFound(
             location=self.request.route_path("admin_payments"))
     payment = payments[self.request.matchdict["ref_code"]]
     # Process form
     reason = self.request.POST["reason"]
     if len(reason) < 5:
         self.request.session.flash(
             "You did not provide a full reason for payment rejection.",
             "error")
         return HTTPFound(location=self.request.route_path(
             "admin_payment_reject", ref_code=payment.__name__))
     # Remove payment and return all tickets
     issuer = Issuer(self.request.root)
     issuer.cancelPayment(payment.__name__)
     # Forward on
     self.request.session.flash(
         "The payment has been rejected successfully.", "info")
     logging.info("%s: Rejected payment %s for user %s with reason %s" %
                  (self.user.username, payment.__name__,
                   payment.owner.username, reason))
     # Inform customer of the reason
     if payment.owner.profile != None:
         emailer = GenericEmail(self.request)
         emailer.compose_and_send(
             "Payment Rejection",
             """Your ticket purchase (reference code %s) has been rejected for the following reason:<br /><br />%s"""
             % (payment.ref_code, reason), payment.owner.__name__)
     return HTTPFound(location=self.request.route_path("admin_payments"))
コード例 #2
0
ファイル: accounts.py プロジェクト: rangsutu88/Tktr
 def user_profile_view(self):
     if not self.request.matchdict["user_id"] in self.request.root.users:
         self.request.session.flash("Requested user does not exist!", "error")
         return HTTPFound(location=self.request.route_path("admin_accounts"))
     user = self.request.root.users[self.request.matchdict["user_id"]]
     if "action" in self.request.GET:
         if self.request.GET["action"] == "counttotal":
             user.total_tickets = len(user.tickets)
             self.request.session.flash("Recounted the total number of tickets this user has.", "info")
         elif self.request.GET["action"] == "sendtickets":
             emailer = GenericEmail(self.request)
             emailer.compose_and_send(
                 "Event Tickets",
                 """Please find the tickets you have purchased attached as a PDF to this email. Please download and print-out the tickets and bring them with you to the event.""",
                 user.__name__,
                 pdf_attachment=TicketDownload(self.request).user_tickets_pdf(user)
             )
             self.request.session.flash("All tickets have been sent to this user via email.", "info")
     if user.profile == None:
         self.request.session.flash("Requested user had not setup a profile, now has a blank profile.", "info")
         user.profile = UserProfile()
         user.profile.__parent__ = user
     return {
         "chosen_user": user
     }
コード例 #3
0
 def admin_test_email_view(self):
     if "submit" in self.request.POST:
         user_id = self.request.POST["user_id"]
         success = GenericEmail(self.request).compose_and_send(
             "Testing Email System", "Here is the test email", user_id)
         if success == True:
             self.request.session.flash("Sent message successfully!",
                                        "info")
         else:
             self.request.session.flash(
                 "Message did not send successfully!", "error")
     return {}
コード例 #4
0
ファイル: sales.py プロジェクト: rangsutu88/Tktr
    def single_payment_view(self):
        payments = self.request.root.payments
        # Get payment if possible
        if not self.request.matchdict["ref_code"] in self.request.root.payments:
            return HTTPFound(
                location=self.request.route_path("admin_payments"))
        payment = payments[self.request.matchdict["ref_code"]]
        if "action" in self.request.GET:
            if self.request.GET["action"] == "recalculate":
                if payment.method == "stripe":
                    payment.processing = int(payment.item_total *
                                             self.stripe_percentage)
                    payment.total = int(payment.item_total *
                                        (1 + self.stripe_percentage))
                else:
                    payment.processing = 0
                    payment.total = payment.item_total
                self.request.session.flash("Recalculated the payment total.",
                                           "info")
            elif self.request.GET["action"] == "emailconfirm":
                PurchaseConfirmationEmail(self.request).compose_and_send(
                    payment.ref_code)
                self.request.session.flash(
                    "A payment confirmation has been sent via email.", "info")
            elif self.request.GET["action"] == "sendtickets":
                emailer = GenericEmail(self.request)
                emailer.compose_and_send(
                    "Event Tickets",
                    """Please find the tickets you purchased in payment %s attached as a PDF to this email. Please download and print-out the tickets and bring them with you to the event."""
                    % (payment.ref_code),
                    payment.owner.__name__,
                    pdf_attachment=TicketDownload(
                        self.request).payment_tickets_pdf(payment))
                self.request.session.flash(
                    "The tickets in this payment have been sent via email.",
                    "info")

        return {
            "payment": payment,
        }
コード例 #5
0
ファイル: signup.py プロジェクト: rangsutu88/Tktr
 def signup_view(self):
     if not self.public_signup_enabled:
         self.request.session.flash(
             "Public sign-ups are not currently enabled!", "error")
         return HTTPFound(location=self.request.route_path('welcome'))
     # If form data submitted
     if "submit" in self.request.POST:
         email = (self.request.POST["email"] if "email" in self.request.POST
                  and len(self.request.POST["email"]) > 0 else None)
         username = (self.request.POST["username"]
                     if "username" in self.request.POST
                     and len(self.request.POST["username"]) > 0 else None)
         pwd_one = (self.request.POST["password"]
                    if "password" in self.request.POST
                    and len(self.request.POST["password"]) > 0 else None)
         pwd_two = (self.request.POST["confirm_password"]
                    if "confirm_password" in self.request.POST
                    and len(self.request.POST["confirm_password"]) > 0 else
                    None)
         discount_code = (self.request.POST["discount_code"]
                          if "discount_code" in self.request.POST
                          and len(self.request.POST["discount_code"]) > 0
                          else None)
         # Check if all fields filled
         if email == None or username == None or pwd_one == None or pwd_two == None:
             self.request.session.flash(
                 "One or more fields was not filled, please try again.",
                 "error")
             return {
                 "email": email,
                 "username": username,
                 "discount_code": discount_code
             }
         # Now run additional checks
         validator = Email()
         if not validator(email):
             self.request.session.flash(
                 "Please enter a valid email address.", "error")
             return {
                 "email": email,
                 "username": username,
                 "discount_code": discount_code
             }
         # Username checks
         username = username.lower()
         if len(username) < 3 or " " in username:
             self.request.session.flash(
                 "Please enter a valid username of more than 3 characters and containing no spaces.",
                 "error")
             return {
                 "email": email,
                 "username": username,
                 "discount_code": discount_code
             }
         if username in self.request.root.users or (re.match(
                 r"^[a-zA-Z]+[0-9]+$", username) != None):
             self.request.session.flash(
                 "A user already exists with the username you specified, please try again.",
                 "error")
             return {
                 "email": email,
                 "username": username,
                 "discount_code": discount_code
             }
         # Password checks
         if pwd_one != pwd_two:
             self.request.session.flash(
                 "Your passwords do not appear to match, please try again.",
                 "error")
             return {
                 "email": email,
                 "username": username,
                 "discount_code": discount_code
             }
         if len(pwd_one) < 5 or (re.match(r"(?=.{6,}).*", pwd_one) == None):
             self.request.session.flash(
                 "Your password is too short or not complex enough, please enter a stronger password.",
                 "error")
             return {
                 "email": email,
                 "username": username,
                 "discount_code": discount_code
             }
         # Passed all checks - create an account...
         group = self.request.root.groups['ungrouped']
         # - See if we can find a discount group
         if discount_code != None:
             found_discount = False
             for group_key in self.request.root.groups:
                 test_group = self.request.root.groups[group_key]
                 if test_group.access_code != None and len(
                         test_group.access_code
                 ) > 0 and test_group.access_code == discount_code:
                     group = test_group
                     found_discount = True
                     break
             if not found_discount:
                 self.request.session.flash(
                     "The discount code entered is not valid, please check it and try again.",
                     "error")
                 return {
                     "email": email,
                     "username": username,
                     "discount_code": discount_code
                 }
         # - Now setup user
         user = User()
         user.username = user.__name__ = username
         user.password_salt = Coding().generateUniqueCode()
         user.password = salt_password(pwd_one, user.password_salt)
         user.profile = UserProfile()
         user.profile.__parent__ = user
         user.profile.raven_user = False
         user.profile.email = email
         user.__parent__ = group
         group.members.append(user)
         self.request.root.users[user.__name__] = user
         # ...send an email telling them about their new account...
         emailer = GenericEmail(self.request)
         emailer.compose_and_send(
             "Account Created",
             """Thank you for creating an account on our ticketing system, this email is just to remind you that your username is %s. No further action is required."""
             % (user.username), user.__name__)
         # ...and finally login
         header = remember(self.request, user.__name__)
         self.request.session["user_id"] = user.__name__
         return HTTPFound(
             location=self.request.route_path('user_profile_edit'),
             headers=header)
     return {"email": None, "username": None, "discount_code": None}
コード例 #6
0
    def make_transfer(self, old_user, new_user, ticket, transfer_fee, stripe_charge=None):
        payment = ticket.payment
        
        # Open a new payment for the new owner, deduct the value of money associated
        # with this ticket from the original payment and add it to this payment, then
        # open a transfer payment stage and move the ticket across. If the original payment
        # was gifted then need to treat specially
        
        new_payment = Payment()
        new_payment.__parent__ = new_user
        new_payment.owner = new_user
        
        # Find out if it was gifted
        gifted = (len([x for x in payment.history if x.method == "gifted"]) > 0)
        
        # Open the finance stage
        finance_stage = PaymentStage()
        finance_stage.__parent__ = new_payment
        finance_stage.completed = finance_stage.received = finance_stage.cashed = True
        finance_stage.stage_owner = old_user.__name__
        finance_stage.date = datetime.now()
        if gifted:
            finance_stage.method = "gifted"
        else:
            finance_stage.method = "banktransfer"
        finance_stage.amount_paid = ticket.total_cost
        new_payment.history.append(finance_stage)
        
        # Open the ticket transfer stage
        transfer_stage = PaymentStage()
        transfer_stage.__parent__ = new_payment
        transfer_stage.amount_paid = transfer_fee
        transfer_stage.processing_charge = transfer_fee
        transfer_stage.completed = transfer_stage.received = transfer_stage.cashed = True
        transfer_stage.stage_owner = new_user.__name__
        transfer_stage.date = datetime.now()
        if stripe_charge != None:
            transfer_stage.method = "stripe"
            transfer_stage.method_properties["last_four"] = stripe_charge["source"]["last4"]
            transfer_stage.method_properties["ref_code"] = stripe_charge["id"]
        else:
            transfer_stage.method = "gifted"
        transfer_stage.transfer = True
        new_payment.history.append(transfer_stage)
        
        # Open the outgoing ticket transfer stage for the original owner
        out_trans_stage = PaymentStage()
        out_trans_stage.__parent__ = payment
        if not gifted:
            out_trans_stage.amount_paid = -ticket.total_cost # To make sure books balance!
        out_trans_stage.completed = out_trans_stage.received = out_trans_stage.cashed = True
        out_trans_stage.stage_owner = new_user.__name__
        out_trans_stage.date = datetime.now()
        if stripe_charge != None:
            out_trans_stage.method = "stripe"
            out_trans_stage.method_properties["last_four"] = stripe_charge["source"]["last4"]
            out_trans_stage.method_properties["ref_code"] = stripe_charge["id"]
        else:
            out_trans_stage.method = "gifted"
        out_trans_stage.transfer = True
        payment.history.append(out_trans_stage)
        
        # Mark new payment as having been completed today
        new_payment.completed_date = datetime.now()

        # Move the ticket over to the new payment
        new_payment.tickets.append(ticket)
        payment.tickets.remove(ticket)
        
        # Move the ticket over to the new user (different to above)
        new_user.tickets.append(ticket)
        new_user.total_tickets += 1 # We increment, but don't decrement (stop scalpers)
        old_user.tickets.remove(ticket)
        ticket.__parent__ = new_user
        ticket.payment = new_payment
        ticket.owner = new_user
        
        # Register payment
        new_user.payments.append(new_payment)
        self.request.root.payments[new_payment.__name__] = new_payment
        
        # If the receiver only has one ticket, then make this their main ticket
        if len(new_user.tickets) == 1:
            ticket.guest_info = new_user.profile
        # Else gift one free guest detail alteration and clear existing details
        else:
            ticket.guest_info = None
            ticket.change_enabled = True
            
        # Transfer complete - notify
        GenericEmail(self.request).compose_and_send(
            "Ticket Transfer Complete",
            "The ticket %s has been successfully transferred to %s. If you did not request this change, please get in touch with us by email or phone (details at the bottom of this message)."
            % (ticket.__name__, new_user.profile.fullname),
            old_user.__name__
        )
        GenericEmail(self.request).compose_and_send(
            "Ticket Transfer from %s" % old_user.profile.fullname,
            "You have been transferred a ticket (%s) from %s. If you think this is a mistake, please get in touch with us by email or phone (details at the bottom of this message)."
            % (ticket.__name__, old_user.profile.fullname),
            new_user.__name__
        )
        self.request.session.flash("Ticket transfer successful!", "info")
        return HTTPFound(location=self.request.route_path("user_profile"))
コード例 #7
0
    def transfer_ticket_payment_view(self):
        # Check agreements
        if not self.user.purchase_agreement:
            return HTTPFound(
                location=self.request.route_path("purchase_agreement_act"))
        elif not self.user.privacy_agreement:
            return HTTPFound(
                location=self.request.route_path("privacy_policy_act"))

        tick_id = self.request.matchdict["tick_id"]
        ticket = None
        # Find ticket
        for tick in self.user.tickets:
            if tick.__name__ == tick_id:
                ticket = tick
                break
        # Safety
        if ticket == None:
            self.request.session.flash("Ticket does not exist.", "error")
            return HTTPFound(location=self.request.route_path("user_profile"))
        # Check that ticket is paid for
        elif not ticket.payment.paid:
            self.request.session.flash(
                "The payment has not been completed for this ticket, therefore you cannot transfer it.",
                "error")
            return HTTPFound(location=self.request.route_path("user_profile"))
        # Also check that if they are exchanging their own ticket that they don't have guests
        elif ticket.guest_info == ticket.owner.profile and len(
                self.user.tickets) > 1:
            self.request.session.flash(
                "You may not exchange your own ticket while you still have guest tickets.",
                "error")
            return HTTPFound(location=self.request.route_path("user_profile"))
        # Now check we have received a valid posted username
        if not "transfer_to" in self.request.session:
            self.request.session.flash(
                "You must enter a username to transfer the ticket to!",
                "error")
            return HTTPFound(location=self.request.route_path(
                "transfer_ticket", tick_id=tick_id))
        elif not self.request.session["transfer_to"].lower(
        ) in self.request.root.users or self.request.session[
                "transfer_to"].lower() == self.user.__name__:
            self.request.session.flash(
                "You must enter a valid username (someone with an account) to transfer the ticket to!",
                "error")
            return HTTPFound(location=self.request.route_path(
                "transfer_ticket", tick_id=tick_id))
        recipient = self.request.session["transfer_to"].lower()
        # OK, now if we have a payment deal with it
        if "stripeToken" in self.request.POST:
            # Double check the username
            username = self.request.POST["username"].lower().replace(" ", "")
            if len(username) <= 2:
                self.request.session.flash(
                    "You must enter a valid username to transfer the ticket to. You have not been charged.",
                    "error")
                return HTTPFound(location=self.request.route_path(
                    "transfer_ticket", tick_id=tick_id))
            if not username in self.request.root.users:
                self.request.session.flash(
                    "The username \"%s\" does not exist within the system, please check again. You have not been charged."
                    % username, "error")
                return HTTPFound(location=self.request.route_path(
                    "transfer_ticket", tick_id=tick_id))
            elif self.request.root.users[
                    username].profile == None or not self.request.root.users[
                        username].profile.complete:
                self.request.session.flash(
                    "The username \"%s\" does not have a complete profile, please complete it before transferring. You have not been charged."
                    % username, "error")
                return HTTPFound(location=self.request.route_path(
                    "transfer_ticket", tick_id=tick_id))
            # Run Stripe payment to authorise
            organisation_name = self.get_payment_method('stripe').settings[
                PROP_KEYS.ORGANISATION_NAME].value
            transfer_fee = PROP_KEYS.getProperty(self.request,
                                                 PROP_KEYS.TRANSFER_FEE)
            token = self.request.POST["stripeToken"]
            stripe.api_key = self.get_payment_method('stripe').settings[
                PROP_KEYS.STRIPE_API_KEY].value
            charge = None
            error = None
            try:
                charge = stripe.Charge.create(
                    amount=transfer_fee,
                    currency="gbp",
                    source=token,
                    description=organisation_name,
                )
                if "paid" in charge and charge["paid"] == True:
                    # Ok, now exchange
                    new_user = self.request.root.users[username]
                    payment = ticket.payment
                    old_user = ticket.owner

                    # Open a new payment for the new owner, deduct the value of money associated
                    # with this ticket from the original payment and add it to this payment, then
                    # open a transfer payment stage and move the ticket across. If the original payment
                    # was gifted then need to treat specially

                    new_payment = Payment()
                    new_payment.__parent__ = new_user
                    new_payment.owner = new_user

                    # Find out if it was gifted
                    gifted = (len([
                        x for x in payment.history if x.method == "gifted"
                    ]) > 0)

                    # Open the finance stage
                    finance_stage = PaymentStage()
                    finance_stage.__parent__ = new_payment
                    finance_stage.completed = finance_stage.received = finance_stage.cashed = True
                    finance_stage.stage_owner = old_user.__name__
                    finance_stage.date = datetime.now()
                    if gifted:
                        finance_stage.method = "gifted"
                    else:
                        finance_stage.method = "banktransfer"
                    finance_stage.amount_paid = ticket.total_cost
                    new_payment.history.append(finance_stage)

                    # Open the ticket transfer stage
                    transfer_stage = PaymentStage()
                    transfer_stage.__parent__ = new_payment
                    transfer_stage.method_properties["last_four"] = charge[
                        "source"]["last4"]
                    transfer_stage.method_properties["ref_code"] = charge["id"]
                    transfer_stage.amount_paid = transfer_fee
                    transfer_stage.processing_charge = transfer_fee
                    transfer_stage.completed = transfer_stage.received = transfer_stage.cashed = True
                    transfer_stage.stage_owner = new_user.__name__
                    transfer_stage.date = datetime.now()
                    transfer_stage.method = "stripe"
                    transfer_stage.transfer = True
                    new_payment.history.append(transfer_stage)

                    # Open the outgoing ticket transfer stage for the original owner
                    out_trans_stage = PaymentStage()
                    out_trans_stage.__parent__ = payment
                    if not gifted:
                        out_trans_stage.amount_paid = -ticket.total_cost  # To make sure books balance!
                    out_trans_stage.completed = out_trans_stage.received = out_trans_stage.cashed = True
                    out_trans_stage.stage_owner = new_user.__name__
                    out_trans_stage.date = datetime.now()
                    out_trans_stage.method = "stripe"
                    out_trans_stage.method_properties["last_four"] = charge[
                        "source"]["last4"]
                    out_trans_stage.method_properties["ref_code"] = charge[
                        "id"]
                    out_trans_stage.transfer = True
                    payment.history.append(out_trans_stage)

                    # Mark new payment as having been completed today
                    new_payment.completed_date = datetime.now()

                    # Move the ticket over to the new payment
                    new_payment.tickets.append(ticket)
                    payment.tickets.remove(ticket)

                    # Move the ticket over to the new user (different to above)
                    new_user.tickets.append(ticket)
                    new_user.total_tickets += 1  # We increment, but don't decrement (stop scalpers)
                    old_user.tickets.remove(ticket)
                    ticket.__parent__ = new_user
                    ticket.payment = new_payment
                    ticket.owner = new_user

                    # Register payment
                    new_user.payments.append(new_payment)
                    self.request.root.payments[
                        new_payment.__name__] = new_payment

                    # If the receiver only has one ticket, then make this their main ticket
                    if len(new_user.tickets) == 1:
                        ticket.guest_info = new_user.profile
                    # Else gift one free guest detail alteration and clear existing details
                    else:
                        ticket.guest_info = None
                        ticket.change_enabled = True

                    # Transfer complete - notify
                    GenericEmail(self.request).compose_and_send(
                        "Ticket Transfer Complete",
                        "The ticket %s has been successfully transferred to %s. If you did not request this change, please get in touch with us by email or phone (details at the bottom of this message)."
                        % (ticket.__name__, new_user.profile.fullname),
                        old_user.__name__)
                    GenericEmail(self.request).compose_and_send(
                        "Ticket Transfer from %s" % old_user.profile.fullname,
                        "You have been transferred a ticket (%s) from %s. If you think this is a mistake, please get in touch with us by email or phone (details at the bottom of this message)."
                        % (ticket.__name__, old_user.profile.fullname),
                        new_user.__name__)
                    self.request.session.flash("Ticket transfer successful!",
                                               "info")
                    return HTTPFound(
                        location=self.request.route_path("user_profile"))
                else:
                    error = "The payment failed, please check your details and try again!"
                    if "failure_message" in charge and charge[
                            "failure_message"] != None:
                        error = charge["failure_message"]
            except stripe.error.CardError, e:
                logging.error(self.user.username +
                              ": Stripe invalid card error occurred: %s" % e)
                error = e
            except stripe.error.InvalidRequestError, e:
                logging.error(self.user.username +
                              ": Stripe invalid card request occurred: %s" % e)
                error = e
コード例 #8
0
ファイル: sales.py プロジェクト: rangsutu88/Tktr
    def enter_payment_view(self):
        payments = self.request.root.payments
        # Get payment if possible
        if not self.request.matchdict["ref_code"] in self.request.root.payments:
            return HTTPFound(
                location=self.request.route_path("admin_payments"))
        payment = payments[self.request.matchdict["ref_code"]]
        active_stage = (payment.history[len(payment.history) - 1] if
                        (len(payment.history) > 0) else None)
        # Check if already marked as paid
        if payment.paid:
            return HTTPFound(location=self.request.route_path(
                'admin_single_payment', ref_code=payment.__name__))
        # Process form
        error = None
        if "submit" in self.request.POST:
            try:
                if not "amount" in self.request.POST or float(
                        self.request.POST['amount']) <= 0:
                    error = "An amount of money greater than zero must be specified"
                elif not "method" in self.request.POST or self.get_payment_method(
                        self.request.POST["method"]) == None:
                    error = "A valid payment method must be specified"
                elif not "year" in self.request.POST or not "month" in self.request.POST or not "day" in self.request.POST:
                    error = "A valid date must be entered"
                elif int(self.request.POST["year"]) < 2000 or int(
                        self.request.POST["month"]) < 1 or int(
                            self.request.POST["month"]) > 12 or int(
                                self.request.POST["day"]) < 1 or int(
                                    self.request.POST["day"]) > 31:
                    error = "A valid date must be entered"
                # elif not "status" in self.request.POST or self.request.POST["status"] not in ["cashed", "received"]: error = "You must select a valid payment status"
                if not error:
                    # Process this payment stage through
                    amount = floor(float(self.request.POST["amount"]) * 100.0)
                    method = self.request.POST["method"]
                    year = int(self.request.POST["year"])
                    month = int(self.request.POST["month"])
                    day = int(self.request.POST["day"])
                    transaction_date = datetime(year=year,
                                                month=month,
                                                day=day)
                    # - First check if the active stage is the current method
                    if active_stage.method != method:
                        # Update payment method to match that entered
                        active_stage = PaymentStage()
                        active_stage.__parent__ = payment
                        active_stage.method = method
                        active_stage.stage_owner = payment.owner.__name__
                        payment.history.append(active_stage)
                    # Update amount paid
                    active_stage.amount_paid = amount
                    active_stage.completed = True  # Doesn't mean 'fully paid' just something has happened at this stage

                    # Check for a complete sale
                    if active_stage.amount_remaining <= active_stage.amount_paid:
                        payment.completed_date = transaction_date
                        # Send payment confirmation email
                        emailer = GenericEmail(self.request)
                        emailer.compose_and_send(
                            "Ticket Payment Completed",
                            """Your ticket purchase (reference code %s) has now been confirmed as a result of your complete payment being received on %s and there is no 
                            further action required.""" %
                            (payment.ref_code,
                             payment.completed_date.strftime("%d/%m/%Y")),
                            payment.owner.__name__)
                    else:
                        # We need to open up a new stage with the same type as the previous
                        new_stage = PaymentStage()
                        new_stage.__parent__ = payment
                        new_stage.method = method
                        new_stage.stage_owner = payment.owner.__name__
                        payment.history.append(new_stage)
                        # Send partial payment confirmation email
                        emailer = GenericEmail(self.request)
                        emailer.compose_and_send(
                            "Partial Ticket Payment Received",
                            """A payment of %s for your tickets with reference code %s has now been received on %s. Please remember to complete the remainder of your
                            payment (%s) in order for your tickets to the event to be confirmed."""
                            % (self.format_price(amount), payment.ref_code,
                               transaction_date.strftime("%d/%m/%Y"),
                               self.format_price(payment.amount_remaining)),
                            payment.owner.__name__)
                    logging.info(
                        "%s: Created a new payment stage for payment %s for user %s"
                        % (self.user.username, payment.__name__,
                           payment.owner.username))
                    self.request.session.flash("Payment entered successfully",
                                               "info")
                    return HTTPFound(location=self.request.route_path(
                        "admin_single_payment", ref_code=payment.__name__))
            except Exception:
                logging.exception(
                    "%s: An error occurred adding a payment stage to payment %s"
                    % (self.user.username, payment.__name__))
                error = "An unknown error has occurred"
        return {
            "payment": payment,
            "date": datetime.now(),
            "active_stage": active_stage,
            "error": error
        }
コード例 #9
0
ファイル: sales.py プロジェクト: rangsutu88/Tktr
 def remove_ticket_view(self):
     payments = self.request.root.payments
     # Get payment if possible
     if not self.request.matchdict["ref_code"] in self.request.root.payments:
         return HTTPFound(
             location=self.request.route_path("admin_payments"))
     payment = payments[self.request.matchdict["ref_code"]]
     #if payment.paid:
     #    self.request.session.flash("This payment has already been confirmed, you cannot remove a ticket anymore.", "error")
     #    return HTTPFound(location=self.request.route_path('admin_single_payment', ref_code=payment.__name__))
     ticket = [
         x for x in payment.tickets
         if x.__name__ == self.request.matchdict["tick_id"]
     ][0]
     if "submit" in self.request.POST:
         if not "reason" in self.request.POST or len(
                 self.request.POST["reason"]) < 10:
             self.request.session.flash(
                 "You must enter a reason for the ticket to be removed from the payment.",
                 "error")
             return {"payment": payment, "ticket": ticket}
         else:
             reason = self.request.POST["reason"]
             pool = ticket.tick_type.__parent__
             owner = ticket.owner
             # Release all addons
             ticket.release_addons()
             # Remove from the user
             owner.tickets.remove(ticket)
             owner.total_tickets -= 1
             payment.tickets.remove(ticket)
             pool.tickets.append(ticket)
             ticket.__parent__ = pool
             # Blank out user details
             ticket.owner = None
             ticket.payment = None
             ticket.issue_date = None
             ticket.guest_info = None
             logging.info(
                 "%s: Removed ticket %s from payment %s of user %s" %
                 (self.user.username, ticket.__name__, payment.__name__,
                  owner.username))
             # Check if the payment is now empty, and close it if so
             if len(payment.tickets) == 0:
                 owner.payments.remove(payment)
                 self.request.root.payments.pop(payment.__name__, None)
                 logging.info(
                     "%s: Closed payment %s of user %s" %
                     (self.user.username, payment.__name__, owner.username))
             # The amount due from the payment is automatically recalculated
             self.request.session.flash(
                 "The ticket has been removed from the payment and returned to the pool.",
                 "info")
             emailer = GenericEmail(self.request)
             emailer.compose_and_send(
                 "Ticket Cancellation",
                 """A ticket has been removed from payment %s for the following reason:<br /><br />%s"""
                 % (payment.ref_code, reason), payment.owner.__name__)
             return HTTPFound(location=self.request.route_path(
                 'admin_single_payment', ref_code=payment.__name__))
     return {"payment": payment, "ticket": ticket}
コード例 #10
0
 def allocate_tickets_view(self):
     if "submit" in self.request.POST:
         username = self.request.POST["username"].lower()
         if not username in self.request.root.users:
             self.request.session.flash(
                 "The user you specified does not exist, ticket allocation failed.",
                 "error")
             return {}
         user = self.request.root.users[username]
         num_tickets = int(float(self.request.POST["numtickets"]))
         if num_tickets <= 0:
             self.request.session.flash(
                 "You must specify a number of tickets to issue, allocation failed.",
                 "error")
         # Build the list of requested tickets and addons
         tick_types = {}
         for i in range(0, num_tickets):
             type_code = self.request.POST["ticket-%i-type" % i]
             addon_code = self.request.POST["ticket-%i-addon" % i]
             if type_code in tick_types:
                 tick_types[type_code]["count"] += 1
                 if addon_code in tick_types[type_code]["addons"]:
                     tick_types[type_code]["addons"][addon_code] += 1
                 else:
                     tick_types[type_code]["addons"][addon_code] = 1
             else:
                 tick_types[type_code] = {
                     "count": 1,
                     "addons": {
                         addon_code: 1
                     }
                 }
         # Check stock of tickets and addons
         for type_key in tick_types:
             number = tick_types[type_key]["count"]
             addons = tick_types[type_key]["addons"]
             if not type_key in self.request.root.ticket_pools:
                 self.request.session.flash(
                     "Invalid ticket type was specified.", "error")
                 return {}
             pool = self.request.root.ticket_pools[type_key]
             if len(pool.tickets) < number:
                 self.request.session.flash(
                     "There is not enough stock of '%s' to allocate the requested tickets."
                     % pool.tick_type.name, "error")
                 return {}
             #if not user.__parent__.__name__ in pool.groups:
             #    self.request.session.flash("The user is not permitted to have tickets of the type '%s'." % pool.tick_type.name, "error")
             #    return {}
             # Now check addons
             for addon_key in addons:
                 if addon_key == "none":
                     continue
                 if not addon_key in pool.tick_type.addons:
                     self.request.session.flash(
                         "Invalid addon type was specified.", "error")
                     return {}
                 addon = pool.tick_type.addons[addon_key]
                 num_addons = addons[addon_key]
                 if addon.remaining < num_addons:
                     self.request.session.flash(
                         "There is not enough stock of the addon '%s' to allocate the requested tickets."
                         % addon.name, "error")
                     return {}
         # Issue the tickets and attach all addons requested
         has_ticket = (user.tickets != None and len(user.tickets) > 0
                       )  # Whether we need to set a ticket to be theirs
         all_tickets = []
         for type_key in tick_types:
             number = tick_types[type_key]["count"]
             addons = tick_types[type_key]["addons"]
             pool = self.request.root.ticket_pools[type_key]
             for i in range(0, number):
                 ticket = pool.tickets[0]
                 user.tickets.append(ticket)
                 pool.tickets.remove(ticket)
                 ticket.__parent__ = user
                 ticket.owner = user
                 ticket.issue_date = datetime.now()
                 ticket.change_enabled = True  # Allow user to update guest details once
                 if not has_ticket:
                     ticket.guest_info = user.profile
                     has_ticket = True
                 else:
                     blank_profile = UserProfile()
                     blank_profile.__parent__ = ticket
                     ticket.guest_info = blank_profile
                 all_tickets.append(ticket)
                 # Attach an addon if available
                 for addon_key in addons:
                     if addon_key == "none" or addons[addon_key] <= 0:
                         continue
                     addon = pool.tick_type.addons[addon_key]
                     ticket.addons[addon.__name__] = addon
                     addon.allocated.append(ticket)
                     addons[addon_key] -= 1
                     break
         # Open a payment and attach all of the tickets into it
         gift = ("gift" in self.request.POST
                 and self.request.POST["gift"] == "gift")
         payment = Payment()
         payment.owner = user
         payment.__parent__ = user
         payment.opened_date = datetime.now()
         for ticket in all_tickets:
             ticket.payment = payment
             payment.tickets.append(ticket)
         if gift:
             new_stage = PaymentStage()
             new_stage.__parent__ = payment
             new_stage.method = "gifted"
             new_stage.amount_paid = int(payment.amount_remaining)
             new_stage.processing_charge = 0
             new_stage.received = new_stage.cashed = True
             new_stage.completed = True
             new_stage.stage_owner = user.__name__
             payment.history.append(new_stage)
             payment.completed_date = datetime.now()
         else:
             new_stage = PaymentStage()
             new_stage.__parent__ = payment
             new_stage.method = "cheque"
             new_stage.method_change = True
             new_stage.stage_owner = user.__name__
             payment.history.append(new_stage)
         # Attach the payment to the user
         user.payments.append(payment)
         user.total_tickets += len(payment.tickets)
         self.request.root.payments[payment.__name__] = payment
         # Send a information email
         if user.profile != None:
             emailer = GenericEmail(self.request)
             if gift:
                 emailer.compose_and_send(
                     "Tickets Allocated",
                     """This is to notify you that %i ticket(s) have been allocated to your account, they have been transferred as a gift and
                     hence no further action is required. If you want to get in touch, your ticket allocation reference is %s."""
                     % (len(payment.tickets), payment.ref_code),
                     payment.owner.__name__)
             else:
                 emailer.compose_and_send(
                     "Tickets Allocated",
                     """This is to notify you that %i ticket(s) have been allocated to your account. You are required to complete payment for
                     your tickets, currently they are set as a default of cheque payment, however you may change this by logging into your ticket
                     account. Your purchase reference is %s and your owed total is %s."""
                     % (len(payment.tickets), payment.ref_code,
                        self.format_price(payment.total)),
                     payment.owner.__name__)
         # Report all good
         self.request.session.flash("Ticket allocation successful!", "info")
         return HTTPFound(location=self.request.route_path("admin_tickets"))
     return {}