def directory_set_inv_payment(user, directory, **kwargs): if get_setting('module', 'directories', 'directoriesrequirespayment'): if not directory.invoice: inv = Invoice() inv.object_type = ContentType.objects.get(app_label=directory._meta.app_label, model=directory._meta.module_name) inv.object_id = directory.id profile = user.get_profile() inv.title = "Directory Add Invoice" inv.bill_to = '%s %s' % (user.first_name, user.last_name) inv.bill_to_first_name = user.first_name inv.bill_to_last_name = user.last_name inv.bill_to_company = profile.company inv.bill_to_address = profile.address inv.bill_to_city = profile.city inv.bill_to_state = profile.state inv.bill_to_zip_code = profile.zipcode inv.bill_to_country = profile.country inv.bill_to_phone = profile.phone inv.bill_to_fax = profile.fax inv.bill_to_email = profile.email inv.ship_to = inv.bill_to inv.ship_to_first_name = user.first_name inv.ship_to_last_name = user.last_name inv.ship_to_company = profile.company inv.ship_to_address = profile.address inv.ship_to_city = profile.city inv.ship_to_state = profile.state inv.ship_to_zip_code = profile.zipcode inv.ship_to_country = profile.country inv.ship_to_phone = profile.phone inv.ship_to_fax = profile.fax inv.ship_to_email = profile.email inv.terms = "Due on Receipt" inv.due_date = datetime.now() inv.ship_date = datetime.now() inv.message = 'Thank You.' inv.status = True inv.total = get_directory_price(user, directory) inv.subtotal = inv.total inv.balance = inv.total inv.estimate = 1 inv.status_detail = 'estimate' inv.save(user) # update job directory.invoice = inv directory.save() if is_admin(user): if directory.payment_method in ['paid - cc', 'paid - check', 'paid - wire transfer']: boo_inv = inv.tender(user) # payment payment = Payment() boo = payment.payments_pop_by_invoice_user(user, inv, inv.guid) payment.mark_as_paid() payment.method = directory.payment_method payment.save(user) # this will make accounting entry inv.make_payment(user, payment.amount)
def corp_memb_inv_add(user, corp_memb, **kwargs): """ Add an invoice for this corporate membership """ renewal = kwargs.get('renewal', False) renewal_total = kwargs.get('renewal_total', 0) renew_entry = kwargs.get('renew_entry', None) if not corp_memb.invoice or renewal: inv = Invoice() if renew_entry: inv.object_type = ContentType.objects.get(app_label=renew_entry._meta.app_label, model=renew_entry._meta.module_name) inv.object_id = renew_entry.id else: inv.object_type = ContentType.objects.get(app_label=corp_memb._meta.app_label, model=corp_memb._meta.module_name) inv.object_id = corp_memb.id inv.title = "Corporate Membership Invoice" inv.bill_to = corp_memb.name inv.bill_to_company = corp_memb.name inv.bill_to_address = corp_memb.address inv.bill_to_city = corp_memb.city inv.bill_to_state = corp_memb.state inv.bill_to_zip_code = corp_memb.zip inv.bill_to_country = corp_memb.country inv.bill_to_phone = corp_memb.phone inv.bill_to_email = corp_memb.email inv.ship_to = corp_memb.name inv.ship_to_company = corp_memb.name inv.ship_to_address = corp_memb.address inv.ship_to_city = corp_memb.city inv.ship_to_state = corp_memb.state inv.ship_to_zip_code = corp_memb.zip inv.ship_to_country = corp_memb.country inv.ship_to_phone = corp_memb.phone inv.ship_to_email =corp_memb.email inv.terms = "Due on Receipt" inv.due_date = datetime.now() inv.ship_date = datetime.now() inv.message = 'Thank You.' inv.status = True if not renewal: inv.total = corp_memb.corporate_membership_type.price else: inv.total = renewal_total inv.subtotal = inv.total inv.balance = inv.total inv.estimate = 1 inv.status_detail = 'estimate' inv.save(user) if is_admin(user): # if offline payment method if not corp_memb.get_payment_method().is_online: inv.tender(user) # tendered the invoice for admin if offline # mark payment as made payment = Payment() payment.payments_pop_by_invoice_user(user, inv, inv.guid) payment.mark_as_paid() payment.method = corp_memb.get_payment_method() payment.save(user) # this will make accounting entry inv.make_payment(user, payment.amount) return inv return None
def job_set_inv_payment(user, job, pricing): if get_setting('module', 'jobs', 'jobsrequirespayment'): if not job.invoice: inv = Invoice() inv.object_type = ContentType.objects.get(app_label=job._meta.app_label, model=job._meta.module_name) inv.object_id = job.id inv.title = "Job Add Invoice" inv.bill_to = job.contact_name first_name = '' last_name = '' if job.contact_name: name_list = job.contact_name.split(' ') if len(name_list) >= 2: first_name = name_list[0] last_name = ' '.join(name_list[1:]) inv.bill_to_first_name = first_name inv.bill_to_last_name = last_name inv.bill_to_company = job.contact_company inv.bill_to_address = job.contact_address inv.bill_to_city = job.contact_city inv.bill_to_state = job.contact_state inv.bill_to_zip_code = job.contact_zip_code inv.bill_to_country = job.contact_country inv.bill_to_phone = job.contact_phone inv.bill_to_fax = job.contact_fax inv.bill_to_email = job.contact_email inv.ship_to = job.contact_name inv.ship_to_first_name = first_name inv.ship_to_last_name = last_name inv.ship_to_company = job.contact_company inv.ship_to_address = job.contact_address inv.ship_to_city = job.contact_city inv.ship_to_state = job.contact_state inv.ship_to_zip_code = job.contact_zip_code inv.ship_to_country = job.contact_country inv.ship_to_phone = job.contact_phone inv.ship_to_fax = job.contact_fax inv.ship_to_email =job.contact_email inv.terms = "Due on Receipt" inv.due_date = datetime.now() inv.ship_date = datetime.now() inv.message = 'Thank You.' inv.status = True inv.total = get_job_price(user, job, pricing) inv.subtotal = inv.total inv.balance = inv.total inv.estimate = 1 inv.status_detail = 'estimate' inv.save(user) # update job job.invoice = inv job.save() if is_admin(user): if job.payment_method in ['paid - cc', 'paid - check', 'paid - wire transfer']: boo_inv = inv.tender(user) # payment payment = Payment() boo = payment.payments_pop_by_invoice_user(user, inv, inv.guid) payment.mark_as_paid() payment.method = job.payment_method payment.save(user) # this will make accounting entry inv.make_payment(user, payment.amount)
def pay_online(request, invoice_id, guid="", template_name="payments/pay_online.html"): # check if they have the right to view the invoice invoice = get_object_or_404(Invoice, pk=invoice_id) if not invoice.allow_view_by(request.user, guid): raise Http403 # tender the invoice if not invoice.is_tendered: invoice.tender(request.user) # log an event for invoice edit log_defaults = { 'event_id' : 312000, 'event_data': '%s (%d) edited by %s' % (invoice._meta.object_name, invoice.pk, request.user), 'description': '%s edited' % invoice._meta.object_name, 'user': request.user, 'request': request, 'instance': invoice, } EventLog.objects.log(**log_defaults) # generate the payment payment = Payment() boo = payment.payments_pop_by_invoice_user(request.user, invoice, guid) # log an event for payment add log_defaults = { 'event_id' : 281000, 'event_data': '%s (%d) added by %s' % (payment._meta.object_name, payment.pk, request.user), 'description': '%s added' % payment._meta.object_name, 'user': request.user, 'request': request, 'instance': payment, } EventLog.objects.log(**log_defaults) # post payment form to gateway and redirect to the vendor so customer can pay from there if boo: merchant_account = (get_setting("site", "global", "merchantaccount")).lower() if merchant_account == 'stripe': return HttpResponseRedirect(reverse('stripe.payonline', args=[payment.id])) else: if merchant_account == "authorizenet": form = prepare_authorizenet_sim_form(request, payment) post_url = settings.AUTHNET_POST_URL elif merchant_account == 'firstdata': from payments.firstdata.utils import prepare_firstdata_form form = prepare_firstdata_form(request, payment) post_url = settings.FIRSTDATA_POST_URL elif merchant_account == 'paypalpayflowlink': from payments.payflowlink.utils import prepare_payflowlink_form form = prepare_payflowlink_form(request, payment) post_url = settings.PAYFLOWLINK_POST_URL else: # more vendors form = None post_url = "" else: form = None post_url = "" return render_to_response(template_name, {'form':form, 'post_url':post_url}, context_instance=RequestContext(request))