def testBalanceMethods(self): order = make_test_order(self.US, '', include_non_taxed=True) order.recalculate_total(save=False) price = order.total subtotal = order.sub_total self.assertEqual(subtotal, Decimal('105.00')) self.assertEqual(price, Decimal('115.00')) self.assertEqual(order.balance, price) paytype = active_gateways()[0][0].upper() pmt = OrderPayment(order=order, payment=paytype, amount=Decimal("5.00")) pmt.save() self.assertEqual(order.balance, Decimal("110.00")) self.assertEqual(order.balance_paid, Decimal("5.00")) self.assert_(order.is_partially_paid) pmt = OrderPayment(order=order, payment=paytype, amount=Decimal("110.00")) pmt.save() self.assertEqual(order.balance, Decimal("0.00")) self.assertEqual(order.is_partially_paid, False) self.assert_(order.paid_in_full)
def testBalanceMethods(self): order = make_test_order(self.US, '', include_non_taxed=True) order.recalculate_total(save=False) price = order.total subtotal = order.sub_total self.assertEqual(subtotal, Decimal('105.00')) self.assertEqual(price, Decimal('115.00')) self.assertEqual(order.balance, price) paytype = active_gateways()[0][0].upper() pmt = OrderPayment(order = order, payment=paytype, amount=Decimal("5.00")) pmt.save() self.assertEqual(order.balance, Decimal("110.00")) self.assertEqual(order.balance_paid, Decimal("5.00")) self.assert_(order.is_partially_paid) pmt = OrderPayment(order = order, payment=paytype, amount=Decimal("110.00")) pmt.save() self.assertEqual(order.balance, Decimal("0.00")) self.assertEqual(order.is_partially_paid, False) self.assert_(order.paid_in_full)
def labelled_gateway_choices(): choices = [] for module, group in active_gateways(): defaultlabel = module.split('.')[-1] label = _(config_value(group, 'LABEL', default = defaultlabel)) choices.append((group, label)) signals.payment_choices.send(None, choices=choices) return choices
def make_order_payment(order, paytype=None, amount=None): if not paytype: paytype = active_gateways()[0][0] if not amount: amount = order.balance pmt = OrderPayment(order=order, payment=paytype.upper(), amount=amount) pmt.save() return pmt
def labelled_gateway_choices(): choices = [] for module, group in active_gateways(): defaultlabel = module.split('.')[-1] label = _(config_value(group, 'LABEL', default=defaultlabel)) key = config_value(group, 'KEY') choices.append((key, label)) signals.payment_choices.send(None, choices=choices) return choices
def testSmallPayment(self): order = make_test_order(self.US, '', include_non_taxed=True) order.recalculate_total(save=False) price = order.total subtotal = order.sub_total paytype = active_gateways()[0][0].upper() pmt = OrderPayment(order = order, payment=paytype, amount=Decimal("0.000001")) pmt.save() self.assert_(order.is_partially_paid)
def credit_choices(settings=None, include_module_if_no_choices=False): choices = [] keys = [] for module, group in active_gateways(): vals = config_choice_values(group, 'CREDITCHOICES') for key, label in vals: if not key in keys: keys.append(key) pair = (key, ugettext(label)) choices.append(pair) if include_module_if_no_choices and not vals: key = config_value(group, 'KEY') label = config_value(group, 'LABEL') pair = (key, ugettext(label)) choices.append(pair) return choices
def balance_remaining(request): """Allow the user to pay the remaining balance.""" order = None orderid = request.session.get('orderID') if orderid: try: order = Order.objects.get(pk=orderid) except Order.DoesNotExist: # TODO: verify user against current user pass if not order: url = urlresolvers.reverse('satchmo_checkout-step1') return HttpResponseRedirect(url) if request.method == "POST": new_data = request.POST.copy() form = PaymentMethodForm(data=new_data, order=order) if form.is_valid(): data = form.cleaned_data modulename = data['paymentmethod'] if not modulename.startswith('PAYMENT_'): modulename = 'PAYMENT_' + modulename paymentmodule = config_get_group(modulename) url = lookup_url(paymentmodule, 'satchmo_checkout-step2') return HttpResponseRedirect(url) else: form = PaymentMethodForm(order=order) ctx = RequestContext(request, {'form' : form, 'order' : order, 'paymentmethod_ct': len(active_gateways()) }) return render_to_response('shop/checkout/balance_remaining.html', context_instance=ctx)
def get_context_data(self, **kwargs): context = super(BalanceRemainingView, self).get_context_data(**kwargs) context['paymentmethod_ct'] = len(active_gateways()) return context