forked from uncloud/uncloud
Allow for charging customers
This commit is contained in:
parent
94a39ed81d
commit
e0cb6ac670
4 changed files with 32 additions and 20 deletions
|
|
@ -86,16 +86,19 @@ class PaymentMethod(models.Model):
|
|||
def charge(self, amount):
|
||||
if amount > 0: # Make sure we don't charge negative amount by errors...
|
||||
if self.source == 'stripe':
|
||||
# TODO: wire to stripe, see meooow-payv1/strip_utils.py
|
||||
payment = Payment(owner=self.owner, source=self.source, amount=amount)
|
||||
payment.save() # TODO: Check return status
|
||||
stripe_customer = StripeCustomer.objects.get(owner=self.owner).stripe_id
|
||||
charge_request = uncloud_pay.stripe.charge_customer(amount, stripe_customer, self.stripe_card_id)
|
||||
if charge_request['error'] == None:
|
||||
payment = Payment(owner=self.owner, source=self.source, amount=amount)
|
||||
payment.save() # TODO: Check return status
|
||||
|
||||
return True
|
||||
return payment
|
||||
else:
|
||||
raise Exception('Stripe error: {}'.format(charge_request['error']))
|
||||
else:
|
||||
# We do not handle that source yet.
|
||||
return False
|
||||
raise Exception('This payment method is unsupported/cannot be charged.')
|
||||
else:
|
||||
return False
|
||||
raise Exception('Cannot charge negative amount.')
|
||||
|
||||
class Meta:
|
||||
unique_together = [['owner', 'primary']]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue