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.
86 lines
2.3 KiB
Python
86 lines
2.3 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):
|
|
api_username = 'merchant.TEST06127800'
|
|
api_password = '37846250a67c70e7fe9f82cf6ca81f93'
|
|
merchant_id = 'TEST06127800'
|
|
merchant_name = 'Ositcom Sal'
|
|
|
|
order_id = str(uuid.uuid4())[:8]
|
|
|
|
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/78', data=payload)
|
|
|
|
print('Response Content:', response.text)
|
|
|
|
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')
|
|
return JsonResponse({'session_id': session_id}, status=200)
|
|
else:
|
|
print('Response Status Code:', response.status_code)
|
|
return JsonResponse({'error': 'Failed to initiate checkout'}, status=500)
|
|
except Exception as e:
|
|
print('Exception:', e)
|
|
return JsonResponse({'error': 'Internal Server Error'}, status=500)
|
|
|
|
|
|
|
|
def webhook_handler(request):
|
|
|
|
project_type = ProjectType.objects.create(name='Hello')
|
|
|
|
return JsonResponse({'message': 'Webhook received and processed successfully'}, status=200)
|