Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deduce Square notification URL from SITE_ROOT_URL #103

Merged
merged 2 commits into from
Oct 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading