diff --git a/osinaweb/customercore/__pycache__/views.cpython-310.pyc b/osinaweb/customercore/__pycache__/views.cpython-310.pyc index 26742e40..a6357399 100644 Binary files a/osinaweb/customercore/__pycache__/views.cpython-310.pyc and b/osinaweb/customercore/__pycache__/views.cpython-310.pyc differ diff --git a/osinaweb/customercore/views.py b/osinaweb/customercore/views.py index 7abe2d20..37e7e0a4 100644 --- a/osinaweb/customercore/views.py +++ b/osinaweb/customercore/views.py @@ -4,6 +4,8 @@ from django.http import JsonResponse import requests from .decorators import * import uuid +import urllib.parse + # Create your views here. @customer_login_required @@ -39,7 +41,6 @@ def pricing(request, *args, **kwargs): @customer_login_required def initiate_checkout(request): - # Your Mastercard API credentials api_username = 'merchant.TEST06127800' api_password = '37846250a67c70e7fe9f82cf6ca81f93' merchant_id = 'TEST06127800' @@ -47,35 +48,32 @@ def initiate_checkout(request): order_id = str(uuid.uuid4())[:8] - # Data for Initiate Checkout operation payload = { 'apiOperation': 'INITIATE_CHECKOUT', 'apiUsername': api_username, 'apiPassword': api_password, 'merchant': merchant_id, - 'interaction.operation': 'PURCHASE', - 'interaction.merchant.name': merchant_name, + 'interaction.operation': 'PURCHASE', + 'interaction.merchant.name': merchant_name, 'order.id': order_id, 'order.amount': '100.00', 'order.currency': 'USD', - 'order.description': 'description_of_order' + 'order.description': 'description_of_order', } - try: - response = requests.post('https://creditlibanais-netcommerce.gateway.mastercard.com/api/nvp/version/72', data=payload) + response = requests.post('https://creditlibanais-netcommerce.gateway.mastercard.com/api/nvp/version/78', data=payload) - print("Response Content:", response.text) + print('Response Content:', response.text) if response.status_code == 200: - res = response.json() - print(res) - - return JsonResponse({"session_id": res}) + response_data = response.text + parsed_data = dict(item.split('=') for item in response_data.split('&')) + session_id = parsed_data.get('session.id') + return JsonResponse({'session_id': session_id}, status=200) else: - print("Response Status Code:", response.status_code) # Print status code - return JsonResponse({"error": "Failed to initiate checkout"}, status=500) - + print('Response Status Code:', response.status_code) + return JsonResponse({'error': 'Failed to initiate checkout'}, status=500) except Exception as e: - print("Exception:", e) # Print exception traceback - return JsonResponse({"error": "Internal Server Error"}, status=500) \ No newline at end of file + print('Exception:', e) + return JsonResponse({'error': 'Internal Server Error'}, status=500) \ No newline at end of file