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}))
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)
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}))
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", "") 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 == "edit_billing_details": address = request.POST.get("address") zipcode = request.POST.get("zipcode") email = request.POST.get("email") api.update_billing_details(customer_id, address, zipcode, email) messages.add_message(request, messages.INFO, "Billing detail 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) context = {'user': user, 'history': history, 'settings':settings } return render(request, 'staff/billing/usaepay.html', context)
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
def trigger_change_subscription(self, user): # Turn off automatic billing payment_api = PaymentAPI() if payment_api.enabled: payment_api.disable_recurring(user.username)