You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
81 lines
2.2 KiB
Python
81 lines
2.2 KiB
Python
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
|
|
payload = {
|
|
'apiOperation': 'INITIATE_CHECKOUT',
|
|
'apiUsername': api_username,
|
|
'apiPassword': api_password,
|
|
'merchant': merchant_id,
|
|
'interaction.operation': 'PURCHASE',
|
|
'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/nvp/version/72', data=payload)
|
|
|
|
print("Response Content:", response)
|
|
|
|
if response.status_code == 200:
|
|
res = response.json()
|
|
print(res)
|
|
|
|
return JsonResponse({"session_id": res})
|
|
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) |