forked from uncloud/uncloud
Wire charge-negative-balance to payment methods
This commit is contained in:
parent
059791e2f2
commit
4bed53c8a8
3 changed files with 25 additions and 7 deletions
|
|
@ -1,7 +1,7 @@
|
|||
from django.core.management.base import BaseCommand
|
||||
from uncloud_auth.models import User
|
||||
from uncloud_pay.models import Order, Bill
|
||||
from uncloud_pay.helpers import get_balance_for
|
||||
from uncloud_pay.helpers import get_balance_for, get_payment_method_for
|
||||
|
||||
from datetime import timedelta
|
||||
from django.utils import timezone
|
||||
|
|
@ -19,5 +19,14 @@ class Command(BaseCommand):
|
|||
balance = get_balance_for(user)
|
||||
if balance < 0:
|
||||
print("User {} has negative balance ({}), charging.".format(user.username, balance))
|
||||
# TODO: charge
|
||||
payment_method = get_payment_method_for(user)
|
||||
if payment_method != None:
|
||||
amount_to_be_charged = abs(balance)
|
||||
charge_ok = payment_method.charge(amount_to_be_charged)
|
||||
if not charge_ok:
|
||||
print("ERR: charging {} with method {} failed"
|
||||
.format(user.username, payment_method.uuid)
|
||||
)
|
||||
else:
|
||||
print("ERR: no payment method registered for {}".format(user.username))
|
||||
print("=> Done.")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue