diff --git a/README.md b/README.md index cc19088..3f3abd6 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,4 @@ # pokeranalytics_backend +CRITIQUE! +Sur le serveur alwaysdata, toutes les commandes python utilisent la commande python3.12 diff --git a/subscriptions/urls.py b/subscriptions/urls.py index e013861..bc930c1 100644 --- a/subscriptions/urls.py +++ b/subscriptions/urls.py @@ -6,5 +6,5 @@ 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('test/', views.test, name='test'), + path('test/', views.test, name='test'), ] diff --git a/subscriptions/views.py b/subscriptions/views.py index 4040eb6..f3c2b23 100644 --- a/subscriptions/views.py +++ b/subscriptions/views.py @@ -26,6 +26,30 @@ 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 test(request): + try: + # Construct the path to payload.txt at the root of the Django project + payload_file_path = os.path.join(settings.BASE_DIR, 'payload.txt') + + # Read the content of the file + with open(payload_file_path, 'r') as file: + payload_content = file.read() + + # Call save_payload_file with the content + save_payload_file(payload_content) + + # Return success response + return JsonResponse({'status': 'success', 'message': 'Payload processed successfully'}) + + except FileNotFoundError: + return JsonResponse({'status': 'error', 'message': 'payload.txt file not found'}, status=404) + + except Exception as e: + # Log the exception + logging.error(f"Error in test endpoint: {str(e)}") + return JsonResponse({'status': 'error', 'message': str(e)}, status=500) + # @csrf_exempt # def app_store_webhook_prod(request): @@ -92,12 +116,12 @@ def decodePayload(signedPayload): revocationDateTime = datetime.datetime.fromtimestamp(transaction_info.revocationDate / 1000) offer_type = None - if payload.offerType is not None: - offer_type = int(payload.offerType) + if transaction_info.offerType is not None: + offer_type = int(transaction_info.offerType) offer_discount_type = None - if payload.offerDiscountType is not None: - offer_discount_type = payload.offerDiscountType.value + if transaction_info.offerDiscountType is not None: + offer_discount_type = transaction_info.offerDiscountType.value notification = ASSNotification( notificationType=payload.notificationType, @@ -118,7 +142,7 @@ def decodePayload(signedPayload): transactionId=transaction_info.transactionId, transactionReason=transaction_info.rawTransactionReason, offerDiscountType=offer_discount_type, - offerIdentifier=payload.offerIdentifier, + offerIdentifier=transaction_info.offerIdentifier, offerType=offer_type, ) notification.save()