def get_context_data(self, **kwargs): context = super(TransactionListView, self).get_context_data(**kwargs) # Retrieve customer information from the backend context.update({'organization': self.customer}) last4, exp_date = backend.retrieve_card(self.customer) context.update({ 'last4': last4, 'exp_date': exp_date, 'organization': self.customer }) return context
def billing_info(request, organization_id): context = { 'user': request.user } context.update(csrf(request)) customer = valid_manager_for_organization(request.user, organization_id) context.update({'organization': customer }) # Retrieve customer information from the backend last4, exp_date = backend.retrieve_card(customer) # Retrieve latest transactions period_end = datetime.datetime.now() - datetime.timedelta(days=31) transactions = Transaction.objects.filter( Q(orig_organization=customer) | Q(dest_organization=customer) ).order_by('created_at')[:25] context.update({ 'last4': last4, 'exp_date': exp_date, 'transactions': transactions, }) return render(request, "saas/billing_info.html", context)
def get_context_data(self, **kwargs): if not 'object_list' in kwargs: cart = self.get_queryset() kwargs.update({'object_list': cart}) context = super(PlaceOrderView, self).get_context_data(**kwargs) # Reduce price by as much Coupon. coupons = Coupon.objects.filter( user=self.request.user, customer=self.customer, redeemed=False) total_amount, discount_amount = self.amounts(self.object_list, coupons) context.update({'coupons': coupons, 'discount_amount': discount_amount, 'coupon_form': RedeemCouponForm(), 'total_amount': total_amount, 'organization': self.customer}) if total_amount: context.update({'STRIPE_PUB_KEY': settings.STRIPE_PUB_KEY}) # Retrieve customer information from the backend last4, exp_date = backend.retrieve_card(self.customer) if last4 != "N/A": context.update({'last4': last4, 'exp_date': exp_date}) return context
def pay_now(request, organization_id): context = { 'user': request.user } context.update(csrf(request)) customer = valid_manager_for_organization(request.user, organization_id) context.update({'organization': customer }) balance_dues = balance(customer) if balance_dues < 0: balance_credits = - balance_dues balance_dues = 0 else: balance_credits = None if request.method == 'POST': form = PayNowForm(request.POST) if form.is_valid(): amount = int(form.cleaned_data['amount'] * 100) if form.cleaned_data['full_amount']: amount = balance_dues if amount > 50: # Stripe will not processed charges less than 50 cents. last4, exp_date = backend.retrieve_card(customer) charge = Charge.objects.charge_card( customer, amount=amount, user=request.user) context.update({ 'charge_id': charge.pk, 'amount': amount, 'last4': last4, 'exp_date': exp_date}) return render(request, "saas/payment_receipt.html", context) else: messages.error(request, 'We do not create charges for less than 50 cents') else: messages.error(request,'Unable to create charge') else: form = PayNowForm() context.update({'balance_credits': balance_credits, 'balance_dues': balance_dues, 'form': form}) return render(request, "saas/pay_now.html", context)