def test_maximum_refund_amount(self):
     bank_account = balanced.BankAccount(
         **bank_accounts.BANK_ACCOUNT).save()
     merchant = self.mp.create_merchant(
         self._email_address(),
         merchant=merchants.BUSINESS_MERCHANT,
         bank_account_uri=bank_account.uri,
     )
     balanced.bust_cache()
     self.mp = balanced.Marketplace.my_marketplace
     if self.mp.in_escrow:
         merchant.credit(self.mp.in_escrow)
     card = self.mp.create_card(**cards.CARD)
     buyer = self.mp.create_buyer(self._email_address(), card.uri)
     debit = buyer.debit(200)
     bank_account = balanced.BankAccount(
         **bank_accounts.BANK_ACCOUNT).save()
     merchant.credit(100)
     with self.assertRaises(balanced.exc.HTTPError) as ex_ctx:
         debit.refund()
     ex = ex_ctx.exception
     self.assertIn('balance insufficient to issue refund', str(ex))
     ex = ex_ctx.exception
     buyer.debit(100)
     debit.refund()
Exemplo n.º 2
0
 def bulk_pay_view(self, request):
     charges = []
     index = 0
     total = 0
     while True:
         prefix = 'bank_account_%s' % index
         uri = request.POST.get(prefix)
         if not uri:
             break
         description = request.POST.get('%s_description' % prefix)
         amount = float(request.POST.get('%s_amount' % prefix))
         amount = int(amount * 100)
         bank_account = BankAccount.objects.get(pk=uri)
         total += amount
         charges.append(
             (bank_account, amount, description)
         )
         index += 1
     balanced.bust_cache()
     escrow = balanced.Marketplace.my_marketplace.in_escrow
     if total > escrow:
         raise Exception('You have insufficient funds.')
     for bank_account, amount, description in charges:
         bank_account.credit(amount, description)
     return redirect(urlresolvers.reverse('admin:index'))
Exemplo n.º 3
0
 def test_maximum_refund_amount(self):
     bank_account = balanced.BankAccount(
         **bank_accounts.BANK_ACCOUNT).save()
     merchant = self.mp.create_merchant(
         self._email_address(),
         merchant=merchants.BUSINESS_MERCHANT,
         bank_account_uri=bank_account.uri,
     )
     balanced.bust_cache()
     self.mp = balanced.Marketplace.my_marketplace
     if self.mp.in_escrow:
         merchant.credit(self.mp.in_escrow)
     card = self.mp.create_card(**cards.CARD)
     buyer = self.mp.create_buyer(self._email_address(), card.uri)
     debit = buyer.debit(200)
     bank_account = balanced.BankAccount(
         **bank_accounts.BANK_ACCOUNT).save()
     merchant.credit(100)
     with self.assertRaises(balanced.exc.HTTPError) as ex_ctx:
         debit.refund()
     ex = ex_ctx.exception
     self.assertIn('balance insufficient to issue refund', str(ex))
     ex = ex_ctx.exception
     buyer.debit(100)
     debit.refund()
Exemplo n.º 4
0
 def clean(self):
     if not self.is_valid():
         return self.cleaned_data
     data = self.cleaned_data
     balanced.bust_cache()
     escrow = balanced.Marketplace.my_marketplace.in_escrow
     amount = int(float(data['amount']) * 100)
     if amount > escrow:
         raise forms.ValidationError('You have insufficient funds to cover '
                                     'this transfer.')
     return data
Exemplo n.º 5
0
 def clean(self):
     if not self.is_valid():
         return self.cleaned_data
     data = self.cleaned_data
     balanced.bust_cache()
     escrow = balanced.Marketplace.my_marketplace.in_escrow
     amount = int(float(data['amount']) * 100)
     if amount > escrow:
         raise forms.ValidationError('You have insufficient funds to cover '
                                     'this transfer.')
     return data
Exemplo n.º 6
0
 def test_maximum_credit_amount(self):
     bank_account = balanced.BankAccount(**bank_accounts.BANK_ACCOUNT).save()
     merchant_account = self.mp.create_merchant(
         self._email_address(), merchant=merchants.BUSINESS_MERCHANT, bank_account_uri=bank_account.uri
     )
     balanced.bust_cache()
     self.mp = balanced.Marketplace.my_marketplace
     if self.mp.in_escrow:
         merchant_account.credit(self.mp.in_escrow)
     with self.assertRaises(balanced.exc.HTTPError) as ex_ctx:
         merchant_account.credit(100)
     ex = ex_ctx.exception
     self.assertIn("has insufficient funds to cover a transfer of", str(ex))
     card = self.mp.create_card(**cards.CARD)
     buyer = self.mp.create_buyer(self._email_address(), card.uri)
     buyer.debit(200)
     merchant_account.credit(100)
Exemplo n.º 7
0
 def bulk_pay_view(self, request):
     charges = []
     index = 0
     total = 0
     while True:
         prefix = 'bank_account_%s' % index
         uri = request.POST.get(prefix)
         if not uri:
             break
         description = request.POST.get('%s_description' % prefix)
         amount = float(request.POST.get('%s_amount' % prefix))
         amount = int(amount * 100)
         bank_account = BankAccount.objects.get(pk=uri)
         total += amount
         charges.append((bank_account, amount, description))
         index += 1
     balanced.bust_cache()
     escrow = balanced.Marketplace.my_marketplace.in_escrow
     if total > escrow:
         raise Exception('You have insufficient funds.')
     for bank_account, amount, description in charges:
         bank_account.credit(amount, description)
     return redirect(urlresolvers.reverse('admin:index'))
Exemplo n.º 8
0
print "cool! let's create a new card."
card = balanced.Card(card_number="5105105105105100", expiration_month="12", expiration_year="2015").save()
print "Our card uri: " + card.uri

print "create our **buyer** account"
buyer = marketplace.create_buyer("*****@*****.**", card.uri)
print "our buyer account: " + buyer.uri

print "hold some amount of funds on the buyer, lets say 15$"
the_hold = buyer.hold(1500)

print "ok, no more holds! lets just capture it (for the full amount)"
debit = the_hold.capture()

print "hmm, how much money do i have in escrow? should equal the debit amount"
balanced.bust_cache()
marketplace = balanced.Marketplace.my_marketplace
if marketplace.in_escrow != 1500:
    raise Exception("1500 is not in escrow! this is wrong")
print "i have {} in escrow!".format(marketplace.in_escrow)

print "cool. now let me refund the full amount"
refund = debit.refund()  # the full amount!

print (
    "ok, we have a merchant that's signing up, let's create an account for "
    "them first, lets create their bank account."
)

bank_account = balanced.BankAccount(account_number="1234567890", bank_code="12", name="Jack Q Merchant").save()
Exemplo n.º 9
0
print "Our card uri: " + card.uri

print "create our **buyer** account"
buyer = marketplace.create_buyer("*****@*****.**", card.uri)
print "our buyer account: " + buyer.uri

print "hold some amount of funds on the buyer, lets say 15$"
the_hold = buyer.hold(1500)

print "the hold has a fee of {} cents".format(the_hold.fee)

print "ok, no more holds! lets just capture it (for the full amount)"
debit = the_hold.capture()

print "hmm, how much money do i have in escrow? should equal the debit amount"
balanced.bust_cache()
marketplace = balanced.Marketplace.my_marketplace
if marketplace.in_escrow != 1500:
    raise Exception("1500 is not in escrow! this is wrong")
print "i have {} in escrow!".format(marketplace.in_escrow)

print "cool. now let me refund the full amount"
refund = debit.refund()  # the full amount!

print "notice how Balanced refunds you your fees? refund fees: {}".format(
    refund.fee)
if refund.fee + debit.fee:
    raise Exception("Woah, fees are incorrect")

print(
    "ok, we have a merchant that's signing up, let's create an account for "