|
|
|
@ -4,8 +4,11 @@ from django.views.decorators.csrf import csrf_exempt |
|
|
|
from .models import ASSNotification |
|
|
|
from .models import ASSNotification |
|
|
|
from django.conf import settings |
|
|
|
from django.conf import settings |
|
|
|
|
|
|
|
|
|
|
|
from appstoreserverlibrary.models.Environment import Environment |
|
|
|
|
|
|
|
from appstoreserverlibrary.signed_data_verifier import VerificationException, SignedDataVerifier |
|
|
|
from appstoreserverlibrary.signed_data_verifier import VerificationException, SignedDataVerifier |
|
|
|
|
|
|
|
from appstoreserverlibrary.api_client import AppStoreServerAPIClient, APIException |
|
|
|
|
|
|
|
from appstoreserverlibrary.models.Environment import Environment |
|
|
|
|
|
|
|
import requests |
|
|
|
|
|
|
|
|
|
|
|
import json, jwt |
|
|
|
import json, jwt |
|
|
|
import base64 |
|
|
|
import base64 |
|
|
|
@ -20,7 +23,10 @@ from OpenSSL.crypto import ( |
|
|
|
FILETYPE_PEM |
|
|
|
FILETYPE_PEM |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
from .validate_apple_storekit_2_jwt import get_validated_jwt_content |
|
|
|
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 |
|
|
|
|
|
|
|
g6_cert_bytes: bytes = requests.get(G6_CER_URL).content |
|
|
|
|
|
|
|
|
|
|
|
# import app_store_notifications_v2_validator as asn2 |
|
|
|
# import app_store_notifications_v2_validator as asn2 |
|
|
|
# from app_store_notifications_v2_validator import InvalidTokenError |
|
|
|
# from app_store_notifications_v2_validator import InvalidTokenError |
|
|
|
@ -42,15 +48,27 @@ def test(request): |
|
|
|
def app_store_webhook(request): |
|
|
|
def app_store_webhook(request): |
|
|
|
|
|
|
|
|
|
|
|
decoded = request.body.decode('utf-8') |
|
|
|
decoded = request.body.decode('utf-8') |
|
|
|
json = get_validated_jwt_content(decoded) |
|
|
|
fulljson = json.loads(decoded) |
|
|
|
|
|
|
|
signedPayload = fulljson['signedPayload'] |
|
|
|
|
|
|
|
|
|
|
|
type = json['notificationType'] |
|
|
|
client = AppStoreServerAPIClient(private_key_bytes, key_id, issuer_id, bundle_id, environment) |
|
|
|
|
|
|
|
verifier = SignedDataVerifier([root_cert_bytes, g6_cert_bytes], False, environment, bundle_id) |
|
|
|
|
|
|
|
try: |
|
|
|
|
|
|
|
# response = client.get_transaction_info(<txn-id>) |
|
|
|
|
|
|
|
decoded_txn = verifier.verify_and_decode_signed_transaction(signedPayload) |
|
|
|
|
|
|
|
print(decoded_txn) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
type = data['notificationType'] |
|
|
|
|
|
|
|
|
|
|
|
notification = ASSNotification( |
|
|
|
notification = ASSNotification( |
|
|
|
content=type, |
|
|
|
content=type, |
|
|
|
) |
|
|
|
) |
|
|
|
notification.save() |
|
|
|
notification.save() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
except APIException as e: |
|
|
|
|
|
|
|
print(e) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Parse the JSON payload |
|
|
|
# Parse the JSON payload |
|
|
|
# fulljson = json.loads(decoded) |
|
|
|
# fulljson = json.loads(decoded) |
|
|
|
|