Beispiel #1
0
 def test_pay_now(self):
     """Pay the balance of account.
     No Issue."""
     customer, charge_id = self._create_charge_for_balance('ABC')
     charge_succeeded(charge_id)
     next_balance = balance(customer)
     assert(next_balance == 0)
Beispiel #2
0
 def test_pay_now_two_success(self):
     """Pay the balance of account.
     Receive two 'charge.succeeded' events."""
     customer, charge_id = self._create_charge_for_balance('ABC')
     charge_succeeded(charge_id)
     charge_succeeded(charge_id)
     next_balance = balance(customer)
     assert(next_balance == 0)
Beispiel #3
0
def organization_profile(request, organization_id):
    context = { 'user': request.user }
    context.update(csrf(request))
    organization = valid_manager_for_organization(request.user, organization_id)
    balance_dues = balance(organization)
    if balance_dues < 0:
        balance_credits = - balance_dues
        balance_dues = 0
    else:
        balance_credits = None
    context.update({'organization': organization,
                    'managers': organization.managers.all(),
                    'contributors': organization.contributors.all(),
                    'balance_due': balance_dues,
                    'balance_credits': balance_credits,
                    })
    return render(request, "saas/organization_profile.html", context)
Beispiel #4
0
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)
Beispiel #5
0
 def _create_charge_for_balance(self, customer_name):
     customer = Organization.objects.get(name=customer_name)
     prev_balance = balance(customer)
     charge = Charge.objects.charge_card(
         customer, amount=prev_balance)
     return customer, charge.processor_id