Skip to content

Commit

Permalink
Clarify free download logic.
Browse files Browse the repository at this point in the history
  • Loading branch information
alecpm committed Sep 7, 2022
1 parent 0839d3d commit 9e45701
Showing 1 changed file with 29 additions and 28 deletions.
57 changes: 29 additions & 28 deletions jazkarta/shop/browser/checkout/stripe.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,14 @@ def handle_submit(self):
else:
contact_info[f] = None

if amount and 'nocharge' not in self.request.form:
if not amount and 'nocharge' in self.request.form:
method = 'Free download'
charge_result = {
'success': True,
'err_msg': "Free download",
'err_code': None,
}
else:
method = 'Online Payment'
if self.is_superuser():
method = self.request.form.get('method', 'None')
Expand All @@ -57,40 +64,34 @@ def handle_submit(self):
raise Forbidden('Invalid payment method: None')

charge_result = {'success': True}
if amount and method == 'Online Payment':
if 'stripeToken' not in self.request.form:
self.error = 'Unable to process payment. Please try again.'
return
card_token = self.request.form['stripeToken']

try:
charge_result = process_interactive_payment(
self.cart, card_token, contact_info)
charge_result['success'] = True
except PaymentProcessingException as e:
charge_result = {
'success': False,
'err_msg': e.message,
'err_code': getattr(e, 'code', None),
}
self.error = e.message
else:
method = 'Free download'
charge_result = {
'success': True,
'err_msg': "Free download",
'err_code': None,
}

if amount and method == 'Online Payment':
if 'stripeToken' not in self.request.form:
self.error = 'Unable to process payment. Please try again.'
return
card_token = self.request.form['stripeToken']

try:
charge_result = process_interactive_payment(
self.cart, card_token, contact_info)
charge_result['success'] = True
except PaymentProcessingException as e:
charge_result = {
'success': False,
'err_msg': e.message,
'err_code': getattr(e, 'code', None),
}
self.error = e.message

if not self.error:
try:
self.store_order(method, charge_result, userid, contact_info)
self.notify_purchased()
self.clear_cart()
except ConflictError:
self.error = ('Failed to store results of payment after '
'multiple retries. Please contact us for '
'assistance. ')
self.error = ('Failed to store results of payment after '
'multiple retries. Please contact us for '
'assistance. ')

# This code runs after the payment is processed
# to update various data in the ZODB.
Expand Down

0 comments on commit 9e45701

Please sign in to comment.