Allow for charging customers

This commit is contained in:
fnux 2020-03-03 18:16:25 +01:00
commit e0cb6ac670
4 changed files with 32 additions and 20 deletions

View file

@ -21,7 +21,7 @@ def handle_stripe_error(f):
'error': None
}
common_message = "Currently it's not possible to make payments."
common_message = "Currently it is not possible to make payments."
try:
response_object = f(*args, **kwargs)
response = {
@ -114,11 +114,15 @@ def get_card(customer_id, card_id):
return stripe.Customer.retrieve_source(customer_id, card_id)
@handle_stripe_error
def charge_customer(amount, source):
def charge_customer(amount, customer_id, card_id):
# Amount is in CHF but stripes requires smallest possible unit.
# See https://stripe.com/docs/api/charges/create
adjusted_amount = int(amount * 100)
return stripe.Charge.create(
amount=amount,
currenty=CURRENCY,
source=source)
amount=adjusted_amount,
currency=CURRENCY,
customer=customer_id,
source=card_id)
@handle_stripe_error
def create_customer(name, email):