diff --git a/.gitignore b/.gitignore index 2b47c14..78768ef 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,8 @@ # ---> Python + +pokeranalytics_backend/settings_local.py +myenv/ + # Byte-compiled / optimized / DLL files __pycache__/ *.py[cod] diff --git a/pokeranalytics_backend/settings.py b/pokeranalytics_backend/settings.py index 52cb0f6..c645e41 100644 --- a/pokeranalytics_backend/settings.py +++ b/pokeranalytics_backend/settings.py @@ -25,7 +25,7 @@ SECRET_KEY = 'django-insecure-v9l*b^t^2eqp877kdrt%5g#y=8$e%e^sa!65(1@t+rp@avwx+@ ASS_KEY_FILE = BASE_DIR / 'AppleRootCA-G3.cer' # SECURITY WARNING: don't run with debug turned on in production! -DEBUG = True +DEBUG = False ALLOWED_HOSTS = ['*'] @@ -125,3 +125,7 @@ STATIC_ROOT = os.path.join(BASE_DIR, 'static/') # https://docs.djangoproject.com/en/4.1/ref/settings/#default-auto-field DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' + +APNS_ENVIRONMENT_SANDBOX = False + +from .settings_local import * diff --git a/subscriptions/admin.py b/subscriptions/admin.py index eaae5dc..2d3ceb4 100644 --- a/subscriptions/admin.py +++ b/subscriptions/admin.py @@ -1,4 +1,10 @@ from django.contrib import admin from .models import ASSNotification -admin.site.register(ASSNotification) +class ASSNotificationAdmin(admin.ModelAdmin): + list_display = ['notificationType', 'subtype', 'signedDate', 'transactionId', 'price'] + search_fields = ('first_name', 'last_name') + list_filter = [] + ordering = ['last_name', 'first_name'] + +admin.site.register(ASSNotification, ASSNotificationAdmin) diff --git a/subscriptions/models.py b/subscriptions/models.py index 244165d..c8c0c5e 100644 --- a/subscriptions/models.py +++ b/subscriptions/models.py @@ -27,3 +27,8 @@ class ASSNotification(models.Model): succeededCount = models.IntegerField(null=True, blank=True) failedCount = models.IntegerField(null=True, blank=True) requestIdentifier = models.CharField(max_length=100, null=True, blank=True) + + # Offers + offerDiscountType = models.CharField(max_length=100, null=True, blank=True) + offerIdentifier = models.CharField(max_length=100, null=True, blank=True) + offerType = models.IntegerField(null=True, blank=True) diff --git a/subscriptions/urls.py b/subscriptions/urls.py index 39f59ec..e013861 100644 --- a/subscriptions/urls.py +++ b/subscriptions/urls.py @@ -5,6 +5,6 @@ from . import views urlpatterns = [ path("", views.index, name="index"), path('app-store-webhook/', views.app_store_webhook, name='app_store_webhook'), - path('app-store-webhook-prod/', views.app_store_webhook_prod, name='app_store_webhook_prod'), + # path('app-store-webhook-prod/', views.app_store_webhook_prod, name='app_store_webhook_prod'), # path('test/', views.test, name='test'), ] diff --git a/subscriptions/views.py b/subscriptions/views.py index 56191ef..9c62f9a 100644 --- a/subscriptions/views.py +++ b/subscriptions/views.py @@ -9,21 +9,14 @@ from appstoreserverlibrary.api_client import AppStoreServerAPIClient, APIExcepti from appstoreserverlibrary.models.Environment import Environment import requests +from pokeranalytics_backend.settings import APNS_ENVIRONMENT_SANDBOX + import json, jwt import base64 import os import datetime -# from OpenSSL.crypto import ( -# X509Store, -# X509StoreContext, -# X509StoreContextError, -# load_certificate, -# FILETYPE_ASN1, -# FILETYPE_PEM -# ) - ROOT_CER_URL = "https://www.apple.com/certificateauthority/AppleRootCA-G3.cer" G6_CER_URL = "https://www.apple.com/certificateauthority/AppleWWDRCAG6.cer" root_cert_bytes: bytes = requests.get(ROOT_CER_URL).content @@ -32,16 +25,16 @@ g6_cert_bytes: bytes = requests.get(G6_CER_URL).content def index(request): return HttpResponse("Hello, world. You're at the subs index.") -@csrf_exempt -def app_store_webhook_prod(request): +# @csrf_exempt +# def app_store_webhook_prod(request): - decoded = request.body.decode('utf-8') - fulljson = json.loads(decoded) - signedPayload = fulljson['signedPayload'] +# decoded = request.body.decode('utf-8') +# fulljson = json.loads(decoded) +# signedPayload = fulljson['signedPayload'] - decodePayload(signedPayload) +# decodePayload(signedPayload) - return JsonResponse({'status': 'success'}) +# return JsonResponse({'status': 'success'}) @csrf_exempt def app_store_webhook(request): @@ -56,11 +49,11 @@ def app_store_webhook(request): def decodePayload(signedPayload): - # with open('payload.txt') as f: - # signedPayload = f.read() - enable_online_checks = True environment = Environment.PRODUCTION + if APNS_ENVIRONMENT_SANDBOX == True: + environment = Environment.SANDBOX + bundle_id = "stax.SlashPoker.nosebleed" app_apple_id = 1073540690 verifier = SignedDataVerifier([root_cert_bytes, g6_cert_bytes], enable_online_checks, environment, bundle_id, app_apple_id) @@ -100,6 +93,9 @@ def decodePayload(signedPayload): storefront=transaction_info.storefront, transactionId=transaction_info.transactionId, transactionReason=transaction_info.rawTransactionReason, + offerDiscountType=payload.offerDiscountType, + offerIdentifier=payload.offerIdentifier, + offerType=payload.offerType, ) notification.save() elif payload.summary: