def get_context_data(self, **kwargs): """ Add data for Bpoint. """ # Override method so the bankcard and billing address forms can be # added to the context. ctx = super(PaymentDetailsView, self).get_context_data(**kwargs) method = self.checkout_session.payment_method() custom_template = self.checkout_session.custom_template() ctx['store_card'] = True user = None # only load stored cards if the user is an admin or has legitimately logged in if self.checkout_session.basket_owner() and is_payment_admin( self.request.user): user = EmailUser.objects.get( id=int(self.checkout_session.basket_owner())) elif self.request.user.is_authenticated(): user = self.request.user if user: cards = user.stored_cards.all() if cards: ctx['cards'] = cards ctx['custom_template'] = custom_template ctx['bpay_allowed'] = settings.BPAY_ALLOWED ctx['payment_method'] = method ctx['bankcard_form'] = kwargs.get('bankcard_form', forms.BankcardForm()) ctx['billing_address_form'] = kwargs.get('billing_address_form', forms.BillingAddressForm()) return ctx
def get(self, request, *args, **kwargs): payment_method = self.request.GET.get('method', 'other') context = template_context(self.request) sanction_outcome_id = int(kwargs['sanction_outcome_pk']) sanction_outcome = SanctionOutcome.objects.get(id=sanction_outcome_id) try: recipient = sanction_outcome.get_offender()[0].email submitter = sanction_outcome.get_offender()[0] except Exception as e: recipient = sanction_outcome.get_offender()[0].email submitter = sanction_outcome.get_offender()[0] # TODO: make sure the if-conditional below if is_payment_admin(request.user): try: lines = sanction_outcome.as_line_items # logger.info('{} Show Park Bookings Preview for BPAY/Other/monthly invoicing'.format('User {} with id {}'.format(proposal.submitter.get_full_name(),proposal.submitter.id), proposal.id)) context.update({ 'lines': lines, # 'line_details': request.POST['payment'], 'sanction_outcome_id': sanction_outcome_id, 'submitter': submitter, 'payment_method': payment_method, }) return render(request, self.template_name, context) except Exception as e: logger.error( 'Error creating record payment preview: {}'.format(e)) else: logger.error( 'Error creating record payment preview for the sanction outcome: {}' .format(sanction_outcome.lodgement_number)) raise
def apiary_url(request): if settings.DOMAIN_DETECTED == 'apiary': PUBLIC_URL = 'https://apiary.dbca.wa.gov.au/' displayed_system_name = settings.APIARY_SYSTEM_NAME support_email = settings.APIARY_SUPPORT_EMAIL else: PUBLIC_URL = 'https://das.dbca.wa.gov.au' displayed_system_name = settings.SYSTEM_NAME support_email = settings.SUPPORT_EMAIL is_payment_officer = is_payment_admin(request.user) return { 'DOMAIN_DETECTED': settings.DOMAIN_DETECTED, 'DEBUG': settings.DEBUG, 'DEV_STATIC': settings.DEV_STATIC, 'DEV_STATIC_URL': settings.DEV_STATIC_URL, 'TEMPLATE_GROUP': settings.DOMAIN_DETECTED, 'SYSTEM_NAME': settings.SYSTEM_NAME, 'PUBLIC_URL': PUBLIC_URL, 'APPLICATION_GROUP': settings.DOMAIN_DETECTED, 'DISPLAYED_SYSTEM_NAME': displayed_system_name, 'SUPPORT_EMAIL': support_email, 'is_payment_admin': is_payment_officer, 'build_tag': settings.BUILD_TAG, }
def post(self, request, *args, **kwargs): payment_method = self.request.GET.get('method') context = template_context(self.request) proposal_id = int(kwargs['proposal_pk']) proposal = Proposal.objects.get(id=proposal_id) try: recipient = proposal.applicant.email submitter = proposal.applicant except: recipient = proposal.submitter.email submitter = proposal.submitter #if isinstance(proposal.org_applicant, Organisation) and (proposal.org_applicant.monthly_invoicing_allowed or proposal.org_applicant.bpay_allowed or proposal.org_applicant.other_allowed): if isinstance(proposal.org_applicant, Organisation) and ( proposal.org_applicant.monthly_invoicing_allowed or proposal.org_applicant.bpay_allowed or (settings.OTHER_PAYMENT_ALLOWED and is_payment_admin(request.user))): try: lines = create_lines(request) logger.info( '{} Show Park Bookings Preview for BPAY/Other/monthly invoicing' .format( 'User {} with id {}'.format( proposal.submitter.get_full_name(), proposal.submitter.id), proposal.id)) context.update({ 'lines': lines, 'line_details': request.POST['payment'], 'proposal_id': proposal_id, 'submitter': submitter, 'payment_method': payment_method, }) return render(request, self.template_name, context) except Exception, e: logger.error('Error creating booking preview: {}'.format(e))
def get_is_payment_admin(self, obj): return is_payment_admin(obj)
def is_payment_admin(self,user): return helpers.is_payment_admin(user)
def post(self, request, *args, **kwargs): payment_method = self.request.POST.get('method') context = template_context(self.request) sanction_outcome_id = int(kwargs['sanction_outcome_pk']) sanction_outcome = SanctionOutcome.objects.get(id=sanction_outcome_id) if is_payment_admin(request.user): try: # infringement_penalty, created = InfringementPenalty.objects.get_or_create(sanction_outcome=sanction_outcome) # infringement_penalty.created_by = request.user # infringement_penalty.payment_type = InfringementPenalty.PAYMENT_TYPE_RECEPTION # infringement_penalty.save() if not sanction_outcome.infringement_penalty: sanction_outcome.infringement_penalty = InfringementPenalty.objects.create( ) sanction_outcome.infringement_penalty.created_by = request.user sanction_outcome.infringement_penalty.payment_type = InfringementPenalty.PAYMENT_TYPE_RECEPTION sanction_outcome.save() invoice_reference = None if sanction_outcome and payment_method == 'other': invoice = create_other_invoice(request, sanction_outcome) # fee_inv = create_other_invoice(request, sanction_outcome) # invoice_reference = fee_inv.invoice_reference # invoice = Invoice.objects.get(reference=fee_inv.invoice_reference) logger.info( '{} paid for sanction outcome: {} with payment method {}' .format( sanction_outcome.get_offender()[0].get_full_name(), sanction_outcome.lodgement_number, payment_method)) if payment_method == 'other': if is_payment_admin(request.user): return HttpResponseRedirect( reverse('payments:invoice-payment') + '?invoice={}'.format(invoice.reference)) else: raise PermissionDenied except Exception as e: logger.error('Error Creating record payment: {}'.format(e)) # if booking: # booking.delete() raise else: logger.error( 'Error Creating record payment for Sanction Outcome: {}'. format(sanction_outcome.lodgement_number)) raise # if isinstance(proposal.org_applicant, Organisation): # try: # if proposal.org_applicant.bpay_allowed and payment_method=='bpay': # booking_type = Booking.BOOKING_TYPE_INTERNET # elif proposal.org_applicant.monthly_invoicing_allowed and payment_method=='monthly_invoicing': # booking_type = Booking.BOOKING_TYPE_MONTHLY_INVOICING # #elif proposal.org_applicant.other_allowed and payment_method=='other': # else: # booking_type = Booking.BOOKING_TYPE_RECEPTION # # booking = create_booking(request, proposal, booking_type=booking_type) # invoice_reference = None # if booking and payment_method=='bpay': # # BPAY/OTHER invoice are created immediately. Monthly invoices are created later by Cron # ret = create_bpay_invoice(submitter, booking) # invoice_reference = booking.invoice.reference # # if booking and payment_method=='other': # # BPAY/Other invoice are created immediately. Monthly invoices are created later by Cron # ret = create_other_invoice(submitter, booking) # invoice_reference = booking.invoice.reference # # if booking and payment_method=='monthly_invoicing': # # For monthly_invoicing, invoice is created later by Cron. Now we only create a confirmation # ret = create_monthly_confirmation(submitter, booking) # # logger.info('{} Created Park Bookings with payment method {} for Proposal ID {}'.format('User {} with id {}'.format(proposal.submitter.get_full_name(),proposal.submitter.id), payment_method, proposal.id)) # #send_monthly_invoicing_confirmation_tclass_email_notification(request, booking, invoice, recipients=[recipient]) # context.update({ # 'booking': booking, # 'booking_id': booking.id, # 'submitter': submitter, # 'monthly_invoicing': True if payment_method=='monthly_invoicing' else False, # 'invoice_reference': invoice_reference # }) # if payment_method=='other': # if is_payment_admin(request.user): # return HttpResponseRedirect(reverse('payments:invoice-payment') + '?invoice={}'.format(invoice_reference)) # else: # raise PermissionDenied # else: # return render(request, self.template_name, context) # # # except Exception, e: # logger.error('Error Creating booking: {}'.format(e)) # if booking: # booking.delete() # raise # else: # logger.error('Error Creating booking: {}'.format(e)) # raise
def is_payment_officer(context): request = context['request'] return is_payment_admin(request.user)
def get_user_action(self, obj): url_list = [] # Retrieve existing invoice if there is inv_ref = '' if obj.infringement_penalty: ipi = obj.infringement_penalty.infringement_penalty_invoices.all().last() if ipi: inv_ref = ipi.invoice_reference user = self.context.get('request', {}).user view_url = '<a href=/internal/sanction_outcome/' + str(obj.id) + '>View</a>' process_url = '<a href=/internal/sanction_outcome/' + str(obj.id) + '>Process</a>' view_payment_url = '<a href="/ledger/payments/invoice/payment?invoice=' + inv_ref + '">View Payment</a>' if inv_ref else '' cc_payment_url = '<a href="#" data-pay-infringement-penalty="' + str(obj.id) + '">Pay</a>' record_payment_url = '<a href="' + reverse('payments:invoice-payment') + '?invoice={}'.format(inv_ref) + '">Record Payment</a>' if inv_ref \ else '<a href="' + reverse('preview_deferred_invoicing', kwargs={'sanction_outcome_pk': obj.id}) + '">Record Payment</a>' if user == obj.get_offender()[0]: # If offender if obj.payment_status == 'unpaid' and obj.status == SanctionOutcome.STATUS_AWAITING_PAYMENT: url_list.append(cc_payment_url) elif is_internal(self.context.get('request')): if obj.status not in SanctionOutcome.FINAL_STATUSES: # infringement notice is not in the final statuses if user.id == obj.assigned_to_id: # if user is assigned to the object, the user can process it url_list.append(process_url) elif (obj.allocated_group and not obj.assigned_to_id) and user.id in [member.id for member in obj.allocated_group.members]: # if user belongs to the same group of the object # and no one is assigned to the object, # the user can process it url_list.append(process_url) if is_payment_admin(user): if inv_ref: # There is an invoice if obj.payment_status != SanctionOutcome.PAYMENT_STATUS_PAID: if obj.payment_status == SanctionOutcome.PAYMENT_STATUS_PARTIALLY_PAID: # Partially paid url_list.append(record_payment_url) elif obj.payment_status == SanctionOutcome.PAYMENT_STATUS_UNPAID: url_list.append(cc_payment_url) url_list.append(record_payment_url) else: # Paid url_list.append(view_payment_url) else: if obj.payment_status != SanctionOutcome.PAYMENT_STATUS_PAID and obj.status == SanctionOutcome.STATUS_AWAITING_PAYMENT: url_list.append(cc_payment_url) url_list.append(record_payment_url) else: # Should not reach here logger.warn('Sanction Outcome: {} payment status is PAID, but no invoices found.') if not url_list: # In other case user can view url_list.append(view_url) urls = '<br />'.join(url_list) return urls
def is_payment_officer(context): request = context['request'] #user= request.user._wrapped if hasattr(request.user,'_wrapped') else request.user return is_payment_admin(request.user)
def is_payment_admin(self, user): return helpers.is_payment_admin(user)
def post(self, request, *args, **kwargs): payment_method = self.request.POST.get('method') context = template_context(self.request) proposal_id = int(kwargs['proposal_pk']) proposal = Proposal.objects.get(id=proposal_id) try: recipient = proposal.applicant.email submitter = proposal.applicant except: recipient = proposal.submitter.email submitter = proposal.submitter if isinstance(proposal.org_applicant, Organisation): try: if proposal.org_applicant.bpay_allowed and payment_method=='bpay': booking_type = Booking.BOOKING_TYPE_INTERNET elif proposal.org_applicant.monthly_invoicing_allowed and payment_method=='monthly_invoicing': booking_type = Booking.BOOKING_TYPE_MONTHLY_INVOICING #elif proposal.org_applicant.other_allowed and payment_method=='other': else: booking_type = Booking.BOOKING_TYPE_RECEPTION booking = create_booking(request, proposal, booking_type=booking_type) invoice_reference = None if booking and payment_method=='bpay': # BPAY/OTHER invoice are created immediately. Monthly invoices are created later by Cron ret = create_bpay_invoice(submitter, booking) invoice_reference = booking.invoice.reference if booking and payment_method=='other': # BPAY/Other invoice are created immediately. Monthly invoices are created later by Cron ret = create_other_invoice(submitter, booking) invoice_reference = booking.invoice.reference if booking and payment_method=='monthly_invoicing': # For monthly_invoicing, invoice is created later by Cron. Now we only create a confirmation ret = create_monthly_confirmation(submitter, booking) logger.info('{} Created Park Bookings with payment method {} for Proposal ID {}'.format('User {} with id {}'.format(proposal.submitter.get_full_name(),proposal.submitter.id), payment_method, proposal.id)) #send_monthly_invoicing_confirmation_tclass_email_notification(request, booking, invoice, recipients=[recipient]) context.update({ 'booking': booking, 'booking_id': booking.id, 'submitter': submitter, 'monthly_invoicing': True if payment_method=='monthly_invoicing' else False, 'invoice_reference': invoice_reference }) if payment_method=='other': if is_payment_admin(request.user): return HttpResponseRedirect(reverse('payments:invoice-payment') + '?invoice={}'.format(invoice_reference)) else: raise PermissionDenied else: return render(request, self.template_name, context) except Exception, e: logger.error('Error Creating booking: {}'.format(e)) if booking: booking.delete() raise