|
|
@ -4,8 +4,6 @@ from django.http import JsonResponse
|
|
|
|
import requests
|
|
|
|
import requests
|
|
|
|
from .decorators import *
|
|
|
|
from .decorators import *
|
|
|
|
import uuid
|
|
|
|
import uuid
|
|
|
|
import json
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Create your views here.
|
|
|
|
# Create your views here.
|
|
|
|
@customer_login_required
|
|
|
|
@customer_login_required
|
|
|
@ -39,7 +37,6 @@ def pricing(request, *args, **kwargs):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@customer_login_required
|
|
|
|
@customer_login_required
|
|
|
|
def initiate_checkout(request):
|
|
|
|
def initiate_checkout(request):
|
|
|
|
# Your Mastercard API credentials
|
|
|
|
# Your Mastercard API credentials
|
|
|
@ -53,6 +50,8 @@ def initiate_checkout(request):
|
|
|
|
# Data for Initiate Checkout operation
|
|
|
|
# Data for Initiate Checkout operation
|
|
|
|
data = {
|
|
|
|
data = {
|
|
|
|
"apiOperation": "INITIATE_CHECKOUT",
|
|
|
|
"apiOperation": "INITIATE_CHECKOUT",
|
|
|
|
|
|
|
|
"apiUsername": api_username,
|
|
|
|
|
|
|
|
"apiPassword": api_password,
|
|
|
|
"merchant": merchant_id,
|
|
|
|
"merchant": merchant_id,
|
|
|
|
"interaction.operation": "PURCHASE",
|
|
|
|
"interaction.operation": "PURCHASE",
|
|
|
|
"interaction.merchant.name": merchant_name,
|
|
|
|
"interaction.merchant.name": merchant_name,
|
|
|
@ -62,13 +61,9 @@ def initiate_checkout(request):
|
|
|
|
"order.description": "description_of_order"
|
|
|
|
"order.description": "description_of_order"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
json_data = json.dumps(data)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Set up Basic HTTP authentication
|
|
|
|
|
|
|
|
auth = (api_username, api_password)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
response = requests.post("https://creditlibanais-netcommerce.gateway.mastercard.com/api/rest/version/78/merchant/TEST06127800/session", json=json_data, auth=auth)
|
|
|
|
response = requests.post("https://creditlibanais-netcommerce.gateway.mastercard.com/api/nvp/version/72", data=data)
|
|
|
|
|
|
|
|
|
|
|
|
print("Response Content:", response.content.decode()) # Print response content
|
|
|
|
print("Response Content:", response.content.decode()) # Print response content
|
|
|
|
|
|
|
|
|
|
|
@ -84,4 +79,4 @@ def initiate_checkout(request):
|
|
|
|
|
|
|
|
|
|
|
|
except Exception as e:
|
|
|
|
except Exception as e:
|
|
|
|
print("Exception:", e) # Print exception traceback
|
|
|
|
print("Exception:", e) # Print exception traceback
|
|
|
|
return JsonResponse({"error": "Internal Server Error"}, status=500)
|
|
|
|
return JsonResponse({"error": "Internal Server Error"}, status=500)
|