from django.shortcuts import render from django.contrib.auth.decorators import login_required from django.http import JsonResponse import requests from .decorators import * import uuid # Create your views here. @customer_login_required def customer_invoices(request, *args, **kwargs): context = { } return render(request, 'listing_pages/customer-invoices.html', context) @customer_login_required def customer_products(request, *args, **kwargs): context = { } return render(request, 'listing_pages/customer-products.html', context) @customer_login_required def pricing(request, *args, **kwargs): context = { } return render(request, 'pricing.html', context) @customer_login_required def initiate_checkout(request): # Your Mastercard API credentials api_username = "merchant.TEST06127800" api_password = "37846250a67c70e7fe9f82cf6ca81f93" merchant_id = "TEST06127800" merchant_name = "Ositcom Sal" order_id = str(uuid.uuid4())[:8] # Data for Initiate Checkout operation data = { "apiOperation": "INITIATE_CHECKOUT", "apiUsername": api_username, "apiPassword": api_password, "merchant": merchant_id, "interaction.operation": "AUTHORIZE", "interaction.merchant.name": merchant_name, "order.id": order_id, "order.amount": "100.00", "order.currency": "USD", "order.description": "description_of_order" } try: response = requests.post("https://creditlibanais-netcommerce.gateway.mastercard.com/api/rest/version/78/merchant/TEST06127800/session", data=data) print("Response Content:", response.content.decode()) # Print response content if response.status_code == 200: response_data = response.text parsed_data = dict(item.split("=") for item in response_data.split("&")) session_id = parsed_data.get("session.id") success_indicator = parsed_data.get("successIndicator") return JsonResponse({"session_id": session_id, "success_indicator": success_indicator}) else: print("Response Status Code:", response.status_code) # Print 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)