adds offer field + improve env

main
Laurent 9 months ago
parent af637d212c
commit 84a1a5eb08
  1. 4
      .gitignore
  2. 6
      pokeranalytics_backend/settings.py
  3. 8
      subscriptions/admin.py
  4. 5
      subscriptions/models.py
  5. 2
      subscriptions/urls.py
  6. 34
      subscriptions/views.py

4
.gitignore vendored

@ -1,4 +1,8 @@
# ---> Python
pokeranalytics_backend/settings_local.py
myenv/
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]

@ -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 *

@ -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)

@ -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)

@ -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'),
]

@ -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:

Loading…
Cancel
Save