Skip to content

Commit

Permalink
Deduce Square notification URL from SITE_ROOT_URL
Browse files Browse the repository at this point in the history
  • Loading branch information
binaryf0x committed Oct 21, 2023
1 parent 396c723 commit f0d8e42
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
4 changes: 2 additions & 2 deletions artshow/manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,8 +350,8 @@ def make_payment(request, artist_id):
artist,
f'Art Show space reservation for {artist}',
payment_remaining,
request.build_absolute_uri(reverse('artshow-manage-payment-square',
args=(artist_id,))),
settings.SITE_ROOT_URL + reverse('artshow-manage-payment-square',
args=(artist_id,)),
)
if payment_url is not None:
return redirect(payment_url)
Expand Down
16 changes: 10 additions & 6 deletions artshow/square.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from decimal import Decimal

from django.http import HttpResponse
from django.urls import reverse
from django.utils.timezone import now
from django.views.decorators.csrf import csrf_exempt

Expand Down Expand Up @@ -72,11 +73,14 @@ def process_payment_created_or_updated(body):
payment_id = payment['id']
payment_amount = Decimal(payment['total_money']['amount'] / 100)

square_payment = SquarePayment.objects.get(order_id=order_id)
square_payment.amount = payment_amount
square_payment.payment_type_id = settings.ARTSHOW_PAYMENT_RECEIVED_PK
square_payment.payment_id = payment_id
square_payment.save()
try:
square_payment = SquarePayment.objects.get(order_id=order_id)
square_payment.amount = payment_amount
square_payment.payment_type_id = settings.ARTSHOW_PAYMENT_RECEIVED_PK
square_payment.payment_id = payment_id
square_payment.save()
except SquarePayment.DoesNotExist:
logger.info(f'Got webhook for unknown order: {order_id}')


def process_webhook(body):
Expand All @@ -91,7 +95,7 @@ def webhook(request):
body,
request.headers['x-square-hmacsha256-signature'],
settings.ARTSHOW_SQUARE_SIGNATURE_KEY,
settings.ARTSHOW_SQUARE_NOTIFICATION_URL)
settings.SITE_ROOT_URL + reverse('square-webhook'))

if not valid:
logger.debug('Received invalid webhook!')
Expand Down
1 change: 0 additions & 1 deletion artshowjockey/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,6 @@
ARTSHOW_SQUARE_ACCESS_TOKEN = env.str('ACCESS_TOKEN', default='')
ARTSHOW_SQUARE_SIGNATURE_KEY = env.str('SIGNATURE_KEY', default='')
ARTSHOW_SQUARE_ENVIRONMENT = env.str('ENVIRONMENT', default='sandbox')
ARTSHOW_SQUARE_NOTIFICATION_URL = env.str('NOTIFICATION_URL', default='')

SITE_ID = 1
SITE_NAME = ARTSHOW_SHOW_NAME
Expand Down

0 comments on commit f0d8e42

Please sign in to comment.