Ejemplo n.º 1
0
def disable_billing(request, username):
    user = get_object_or_404(User, username=username)
    if user == request.user or request.user.is_staff:
        api = PaymentAPI()
        api.disable_recurring(username)
        email.announce_billing_disable(user)
    return HttpResponseRedirect(reverse('members.views.user', kwargs={'username': request.user.username}))
Ejemplo n.º 2
0
def disable_billing(request, username):
    user = get_object_or_404(User, username=username)
    if user == request.user or request.user.is_staff:
        api = PaymentAPI()
        api.disable_recurring(username)
        email.announce_billing_disable(user)
    return HttpResponseRedirect(reverse('member:profile:view', kwargs={'username': user.username}))
Ejemplo n.º 3
0
def disable_billing(sender, **kwargs):
    # Turn off automatic billing when
    # ANY change is made to the membership
    user = kwargs['user']
    payment_api = PaymentAPI()
    if payment_api.enabled:
        payment_api.disable_recurring(user.username)
Ejemplo n.º 4
0
 def has_billing_profile(self):
     try:
         api = PaymentAPI()
         if api.get_customers(self.user.username):
             return True
     except Exception:
         pass
     return False
Ejemplo n.º 5
0
 def has_billing_profile(self):
     try:
         api = PaymentAPI()
         if api.get_customers(self.user.username):
             return True
     except Exception:
         pass
     return False
Ejemplo n.º 6
0
def usaepay_members(request):
    members = []
    api = PaymentAPI()
    for m in Member.objects.active_members():
        username = m.user.username
        customers = api.get_customers(username)
        if customers:
            for c in customers:
                if c.Enabled:
                    members.append({'member': m, 'username': username, 'next': c.Next, 'customer_number': c.CustNum})
    return render_to_response('staff/usaepay_members.html', {'members': members}, context_instance=RequestContext(request))
Ejemplo n.º 7
0
    def save(self):
        if not self.is_valid():
            raise Exception('The form must be valid in order to save')
        membership_id = self.cleaned_data['membership_id']

        adding = False
        membership = None
        if membership_id:
            # Editing
            membership = Membership.objects.get(id=membership_id)
        else:
            # Adding
            adding = True
            membership = Membership()

        # Is this right?  Do I really need a DB call so I have the object?
        membership.member = Member.objects.get(id=self.cleaned_data['member'])

        # Any change triggers disabling of the automatic billing
        username = membership.member.user.username
        try:
            api = PaymentAPI()
            api.disable_recurring(username)
            logger.debug("Automatic Billing Disabled for '%s'" % username)
        except Exception as e:
            logger.error(e)

        # We need to look at their last membership but we'll wait until after the save
        last_membership = membership.member.last_membership()

        # Save this membership
        membership.membership_plan = self.cleaned_data['membership_plan']
        membership.start_date = self.cleaned_data['start_date']
        membership.end_date = self.cleaned_data['end_date']
        membership.monthly_rate = self.cleaned_data['monthly_rate']
        membership.dropin_allowance = self.cleaned_data['dropin_allowance']
        membership.daily_rate = self.cleaned_data['daily_rate']
        membership.has_desk = self.cleaned_data['has_desk']
        membership.has_key = self.cleaned_data['has_key']
        membership.has_mail = self.cleaned_data['has_mail']
        membership.guest_of = self.cleaned_data['guest_of']
        membership.save()

        # Save the note if we were given one
        note = self.cleaned_data['note']
        if note:
            MemberNote.objects.create(member=membership.member,
                                      created_by=self.created_by,
                                      note=note)

        if adding:
            email.send_new_membership(membership.member.user)

        return membership
Ejemplo n.º 8
0
def usaepay_members(request):
    members = []
    api = PaymentAPI()
    for u in User.helper.active_members():
        username = u.username
        customers = api.get_customers(username)
        if customers:
            for c in customers:
                if c.Enabled:
                    members.append({'user': u, 'username': username, 'next': c.Next, 'customer_number': c.CustNum})
    return render(request, 'staff/usaepay_members.html', {'members': members})
Ejemplo n.º 9
0
def usaepay_members(request):
    members = []
    api = PaymentAPI()
    for u in User.helper.active_members():
        username = u.username
        customers = api.get_customers(username)
        if customers:
            for c in customers:
                if c.Enabled:
                    members.append({'user': u, 'username': username, 'next': c.Next, 'customer_number': c.CustNum})
    return render(request, 'staff/billing/usaepay_members.html', {'members': members})
Ejemplo n.º 10
0
    def save(self):
        if not self.is_valid():
            raise Exception('The form must be valid in order to save')
        membership_id = self.cleaned_data['membership_id']

        adding = False
        membership = None
        if membership_id:
            # Editing
            membership = Membership.objects.get(id=membership_id)
        else:
            # Adding
            adding = True
            membership = Membership()

        # Is this right?  Do I really need a DB call so I have the object?
        membership.member = Member.objects.get(id=self.cleaned_data['member'])

        # Any change triggers disabling of the automatic billing
        username = membership.member.user.username
        try:
            api = PaymentAPI()
            api.disable_recurring(username)
            logger.debug("Automatic Billing Disabled for '%s'" % username)
        except Exception as e:
            logger.error(e)

        # We need to look at their last membership but we'll wait until after the save
        last_membership = membership.member.last_membership()

        # Save this membership
        membership.membership_plan = self.cleaned_data['membership_plan']
        membership.start_date = self.cleaned_data['start_date']
        membership.end_date = self.cleaned_data['end_date']
        membership.monthly_rate = self.cleaned_data['monthly_rate']
        membership.dropin_allowance = self.cleaned_data['dropin_allowance']
        membership.daily_rate = self.cleaned_data['daily_rate']
        membership.has_desk = self.cleaned_data['has_desk']
        membership.has_key = self.cleaned_data['has_key']
        membership.has_mail = self.cleaned_data['has_mail']
        membership.guest_of = self.cleaned_data['guest_of']
        membership.save()

        # Save the note if we were given one
        note = self.cleaned_data['note']
        if note:
            MemberNote.objects.create(member=membership.member, created_by=self.created_by, note=note)

        if adding:
            email.send_new_membership(membership.member.user)

        return membership
Ejemplo n.º 11
0
def usaepay_members(request):
    members = []
    api = PaymentAPI()
    for u in User.helper.active_members():
        username = u.username
        customers = api.get_customers(username)
        if customers:
            for c in customers:
                if c.Enabled:
                    members.append({"user": u, "username": username, "next": c.Next, "customer_number": c.CustNum})
    return render_to_response(
        "staff/usaepay_members.html", {"members": members}, context_instance=RequestContext(request)
    )
Ejemplo n.º 12
0
def usaepay_void(request):
    transaction = None
    try:
        api = PaymentAPI()
        if 'transaction_id' in request.POST:
            transaction_id = int(request.POST.get('transaction_id'))
            transaction = api.get_transaction(transaction_id)

            if 'username' in request.POST and 'confirmed' in request.POST:
                username = request.POST.get('username')
                api.void_transaction(username, transaction_id)
                messages.add_message(request, messages.INFO, "Transaction for %s voided" % username)
                return HttpResponseRedirect(reverse('staff_charges_today'))
    except Exception as e:
        messages.add_message(request, messages.ERROR, e)
    return render(request, 'staff/usaepay_void.html', {'transaction':transaction})
Ejemplo n.º 13
0
def usaepay_void(request):
    transaction = None
    try:
        api = PaymentAPI()
        if 'transaction_id' in request.POST:
            transaction_id = int(request.POST.get('transaction_id'))
            transaction = api.get_transaction(transaction_id)

            if 'username' in request.POST and 'confirmed' in request.POST:
                username = request.POST.get('username')
                api.void_transaction(username, transaction_id)
                messages.add_message(request, messages.INFO, "Transaction for %s voided" % username)
                return HttpResponseRedirect(reverse('staff:billing:charges_today'))
    except Exception as e:
        messages.add_message(request, messages.ERROR, e)
    return render(request, 'staff/billing/usaepay_void.html', {'transaction':transaction})
Ejemplo n.º 14
0
def usaepay_void(request):
    transaction = None
    try:
        api = PaymentAPI()
        if "transaction_id" in request.POST:
            transaction_id = int(request.POST.get("transaction_id"))
            transaction = api.get_transaction(transaction_id)

            if "username" in request.POST and "confirmed" in request.POST:
                username = request.POST.get("username")
                api.void_transaction(username, transaction_id)
                messages.add_message(request, messages.INFO, "Transaction for %s voided" % username)
                return HttpResponseRedirect(reverse("staff_charges_today"))
    except Exception as e:
        messages.add_message(request, messages.ERROR, e)

    return render_to_response(
        "staff/usaepay_void.html", {"transaction": transaction}, context_instance=RequestContext(request)
    )
Ejemplo n.º 15
0
def usaepay_transactions(request, year, month, day):
    d = date(year=int(year), month=int(month), day=int(day))
    open_batch = False
    amex = []
    visamc = []
    ach = []
    settled_checks = []
    other_transactions = []
    totals = {'amex_total':0, 'visamc_total':0, 'ach_total':0, 'total':0}
    open_xero_invoices = XeroAPI().get_open_invoices_by_user()
    try:
        api = PaymentAPI()

        if 'close_batch' in request.GET:
            api.close_current_batch()
            messages.add_message(request, messages.INFO, "Current batch closed")

        transactions = api.get_transactions(year, month, day)
        totals['total_count'] = len(transactions)

        # Pull the settled checks seperately
        settled_checks = api.get_checks_settled_by_date(year, month, day)

        for t in transactions:
            # Pull the member and the amount they owe
            member = Member.objects.filter(user__username = t['username']).first()
            if member:
                t['member'] = member
                t['open_bill_amount'] = member.open_bill_amount()
                t['xero_invoices'] = open_xero_invoices.get(t['username'], [])
                for i in t['xero_invoices']:
                    if i['AmountDue'] != t['amount']:
                        t['xero_invoices'].remove(i)

            # Total up all the Settled transactions
            if t['transaction_type'] == "Sale" and t['status'] != "Declined" and t['status'] != "Error":
                totals['total'] = totals['total'] + t['amount']
                if t['card_type'] == "A":
                    amex.append(t)
                    totals['amex_total'] = totals['amex_total'] + t['amount']
                elif t['card_type'] == "V" or t['card_type'] == "M":
                    visamc.append(t)
                    totals['visamc_total'] = totals['visamc_total'] + t['amount']
                elif t['card_type'] == "ACH":
                    ach.append(t)
                    totals['ach_total'] = totals['ach_total'] + t['amount']

                # Presence of authorized transactions means this batch is still open
                if t['status'] == "Authorized":
                    open_batch = True
            else:
                other_transactions.append(t)


    except Exception as e:
        messages.add_message(request, messages.ERROR, e)

    return render_to_response('staff/charges.html', {'date': d, 'amex': amex, 'visamc': visamc, 'ach':ach, 'open_batch':open_batch,
                                                      'other_transactions': other_transactions, 'settled_checks':settled_checks, 'totals':totals,
                                                      'next_date': d + timedelta(days=1), 'previous_date': d - timedelta(days=1)}, context_instance=RequestContext(request))
Ejemplo n.º 16
0
 def auto_bill_enabled(self):
     if not hasattr(settings, 'USA_EPAY_SOAP_KEY'):
         return None
     api = PaymentAPI()
     return api.auto_bill_enabled(self.user.username)
Ejemplo n.º 17
0
 def auto_bill_enabled(self):
     api = PaymentAPI()
     return api.auto_bill_enabled(self.user.username)
Ejemplo n.º 18
0
 def trigger_change_subscription(self, user):
     # Turn off automatic billing
     payment_api = PaymentAPI()
     if payment_api.enabled:
         payment_api.disable_recurring(user.username)
Ejemplo n.º 19
0
def usaepay_transactions(request, year, month, day):
    d = date(year=int(year), month=int(month), day=int(day))
    open_batch = False
    amex = []
    visamc = []
    ach = []
    settled_checks = []
    other_transactions = []
    totals = {'amex_total':0, 'visamc_total':0, 'ach_total':0, 'settled_checks':0, 'total':0}

    open_xero_invoices = {}
    try:
        open_xero_invoices = XeroAPI().get_open_invoices_by_user()
    except Exception:
        # Xero not integrated
        pass

    try:
        api = PaymentAPI()

        if 'close_batch' in request.GET:
            api.close_current_batch()
            messages.add_message(request, messages.INFO, "Current batch closed")

        # Pull the settled checks seperately
        settled_checks = api.get_checks_settled_by_date(year, month, day)
        add_bills_and_invoices(settled_checks, open_xero_invoices)
        for t in settled_checks:
            totals['settled_checks'] = totals['settled_checks'] + t['amount']

        # Pull the transactions and suplement the information
        transactions = api.get_transactions(year, month, day)
        add_bills_and_invoices(transactions, open_xero_invoices)

        # Total up all the Settled transactions
        totals['total_count'] = len(transactions) + len(settled_checks)
        for t in transactions:
            if t['transaction_type'] == "Sale" and t['status'] != "Declined" and t['status'] != "Error":
                totals['total'] = totals['total'] + t['amount']
                if t['card_type'] == "A":
                    amex.append(t)
                    totals['amex_total'] = totals['amex_total'] + t['amount']
                elif t['card_type'] == "V" or t['card_type'] == "M":
                    visamc.append(t)
                    totals['visamc_total'] = totals['visamc_total'] + t['amount']
                elif t['card_type'] == "ACH":
                    ach.append(t)
                    totals['ach_total'] = totals['ach_total'] + t['amount']

                # Presence of authorized transactions means this batch is still open
                if t['status'] == "Authorized":
                    open_batch = True
            else:
                other_transactions.append(t)
    except Exception as e:
        messages.add_message(request, messages.ERROR, e)

    context = {
        'date': d,
        'amex': amex,
        'visamc': visamc,
        'ach':ach,
        'open_batch':open_batch,
        'other_transactions': other_transactions,
        'settled_checks':settled_checks,
        'totals':totals,
        'previous_date': d - timedelta(days=1),
        'next_date': d + timedelta(days=1),
    }
    return render(request, 'staff/billing/charges.html', context)
Ejemplo n.º 20
0
def usaepay_transactions(request, year, month, day):
    d = date(year=int(year), month=int(month), day=int(day))
    open_batch = False
    ach = []
    credit_cards = []
    settled_checks = []
    other_transactions = []
    totals = {'cc_total':0, 'ach_total':0, 'settled_checks':0, 'total':0}

    open_xero_invoices = {}
    try:
        open_xero_invoices = XeroAPI().get_open_invoices_by_user()
    except Exception:
        # Xero not integrated
        pass

    try:
        api = PaymentAPI()

        if 'close_batch' in request.GET:
            api.close_current_batch()
            messages.add_message(request, messages.INFO, "Current batch closed")

        # Pull the settled checks seperately
        settled_checks = api.get_checks_settled_by_date(year, month, day)
        add_bills_and_invoices(settled_checks, open_xero_invoices)
        for t in settled_checks:
            totals['settled_checks'] = totals['settled_checks'] + t['amount']

        # Pull the transactions and suplement the information
        transactions = api.get_transactions(year, month, day)
        add_bills_and_invoices(transactions, open_xero_invoices)

        # Total up all the Settled transactions
        totals['total_count'] = len(transactions) + len(settled_checks)
        for t in transactions:
            if t['transaction_type'] == "Sale" and t['status'] != "Declined" and t['status'] != "Error":
                totals['total'] = totals['total'] + t['amount']
                if t['card_type'] == "ACH":
                    ach.append(t)
                    totals['ach_total'] = totals['ach_total'] + t['amount']
                else:
                    credit_cards.append(t)
                    totals['cc_total'] = totals['cc_total'] + t['amount']

                # Presence of authorized transactions means this batch is still open
                if t['status'] == "Authorized":
                    open_batch = True
            else:
                other_transactions.append(t)
    except Exception as e:
        messages.add_message(request, messages.ERROR, e)

    context = {
        'date': d,
        'ach':ach,
        'credit_cards': credit_cards,
        'open_batch':open_batch,
        'other_transactions': other_transactions,
        'settled_checks':settled_checks,
        'totals':totals,
        'previous_date': d - timedelta(days=1),
        'next_date': d + timedelta(days=1),
    }
    return render(request, 'staff/billing/charges.html', context)
Ejemplo n.º 21
0
def usaepay_user(request, username):
    user = get_object_or_404(User, username=username)

    # When we add a card we POST to USAePay and it comes back to this page
    # Any errors will be communicated to us in this GET variable
    if 'UMerror' in request.GET:
        messages.add_message(request, messages.ERROR, request.GET.get('UMerror'))

    history = None
    try:
        api = PaymentAPI()

        if 'disable_all' in request.POST:
            api.disable_recurring(username)

        customer_id = request.POST.get("customer_id", None)
        action = request.POST.get("action", "")
        #print "action: %s" % action
        #print "cust: %s " % customer_id
        if customer_id:
            if action == "verify_profile":
                # Run a $1.00 authorization to verify this profile works
                api.run_transaction(customer_id, 1.00, "Office Nomads Authorization", auth_only=True)
                messages.add_message(request, messages.INFO, "Profile authorization for %s successful" % username)
            elif action == "delete_profile":
                # TODO
                messages.add_message(request, messages.INFO, "Billing profile deleted for %s" % username)
            elif action == "manual_charge":
                invoice = request.POST.get("invoice")
                description = request.POST.get("description")
                amount = request.POST.get("amount")
                comment = request.POST.get("comment")
                api.run_transaction(customer_id, amount, description, invoice=invoice, comment=comment)
                messages.add_message(request, messages.INFO, "Sale for %s successfully authorized" % username)
            elif action == "edit_recurring":
                next_date = request.POST.get("next_date")
                description = request.POST.get("description")
                comment = request.POST.get("comment")
                amount = request.POST.get("amount")
                enabled = request.POST.get("enabled", "") == "on"
                api.update_recurring(customer_id, enabled, next_date, description,comment, amount)
                messages.add_message(request, messages.INFO, "Recurring billing updated for %s" % username)
        elif action == "email_receipt":
            transaction_id = request.POST.get("transaction_id")
            api.email_receipt(transaction_id, user.email)
            messages.add_message(request, messages.INFO, "Receipt emailed to: %s" % user.email)

        # Lastly pull all customers for this user
        history = api.get_history(username)
    except Exception as e:
        messages.add_message(request, messages.ERROR, e)

    return render_to_response('staff/usaepay.html', {'user': user, 'history': history, 'settings':settings }, context_instance=RequestContext(request))
Ejemplo n.º 22
0
 def auto_bill_enabled(self):
     api = PaymentAPI()
     return api.auto_bill_enabled(self.user.username)
Ejemplo n.º 23
0
 def auto_bill_enabled(self):
     if not hasattr(settings, 'USA_EPAY_KEY'):
         return None
     api = PaymentAPI()
     return api.auto_bill_enabled(self.user.username)
Ejemplo n.º 24
0
def usaepay_transactions(request, year, month, day):
    d = date(year=int(year), month=int(month), day=int(day))
    open_batch = False
    amex = []
    visamc = []
    ach = []
    settled_checks = []
    other_transactions = []
    totals = {"amex_total": 0, "visamc_total": 0, "ach_total": 0, "total": 0}
    open_xero_invoices = XeroAPI().get_open_invoices_by_user()
    try:
        api = PaymentAPI()

        if "close_batch" in request.GET:
            api.close_current_batch()
            messages.add_message(request, messages.INFO, "Current batch closed")

        transactions = api.get_transactions(year, month, day)
        totals["total_count"] = len(transactions)

        # Pull the settled checks seperately
        settled_checks = api.get_checks_settled_by_date(year, month, day)

        for t in transactions:
            # Pull the member and the amount they owe
            u = User.objects.filter(username=t["username"]).first()
            if u:
                # TODO - change to User
                t["member"] = u.profile
                t["open_bill_amount"] = u.profile.open_bill_amount()
                t["xero_invoices"] = open_xero_invoices.get(t["username"], [])
                for i in t["xero_invoices"]:
                    if i["AmountDue"] != t["amount"]:
                        t["xero_invoices"].remove(i)

            # Total up all the Settled transactions
            if t["transaction_type"] == "Sale" and t["status"] != "Declined" and t["status"] != "Error":
                totals["total"] = totals["total"] + t["amount"]
                if t["card_type"] == "A":
                    amex.append(t)
                    totals["amex_total"] = totals["amex_total"] + t["amount"]
                elif t["card_type"] == "V" or t["card_type"] == "M":
                    visamc.append(t)
                    totals["visamc_total"] = totals["visamc_total"] + t["amount"]
                elif t["card_type"] == "ACH":
                    ach.append(t)
                    totals["ach_total"] = totals["ach_total"] + t["amount"]

                # Presence of authorized transactions means this batch is still open
                if t["status"] == "Authorized":
                    open_batch = True
            else:
                other_transactions.append(t)

    except Exception as e:
        messages.add_message(request, messages.ERROR, e)

    return render_to_response(
        "staff/charges.html",
        {
            "date": d,
            "amex": amex,
            "visamc": visamc,
            "ach": ach,
            "open_batch": open_batch,
            "other_transactions": other_transactions,
            "settled_checks": settled_checks,
            "totals": totals,
            "next_date": d + timedelta(days=1),
            "previous_date": d - timedelta(days=1),
        },
        context_instance=RequestContext(request),
    )