From 683f61c54ac4d4b487e4ee6e89e4fad8f5a19f4a Mon Sep 17 00:00:00 2001 From: emile Date: Mon, 8 Apr 2024 20:25:35 +0300 Subject: [PATCH] new --- .../__pycache__/views.cpython-310.pyc | Bin 2335 -> 2546 bytes osinaweb/customercore/views.py | 21 +++++++++++++----- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/osinaweb/customercore/__pycache__/views.cpython-310.pyc b/osinaweb/customercore/__pycache__/views.cpython-310.pyc index 7bf03a5f8396d70b1bf841f27e70b2144e2050a5..c7143e45f165e6dd9e75e8c91b3c8048c9ae4502 100644 GIT binary patch delta 738 zcmYjP%W4!s6s@Z6uCAVbW+rMLMicOnm*`>$L_~}cUAV|1g4iITGq)uj$C;tKhM1w- zfRikzfR`l%@s@?JHS{8&FP5o2A0tB^XI=LggWe>ylZS$!!>hW4kCdcX|#S@8cVC#xBmR z)ato#qK`9sz(yo;p?|%Wh>x8Zr0)urx5BfBnFIMHIz-+>!--zjuGG;2l^rxqZX*NL@r9R_|+iaygCuv?PMw7qR hjFb4Rc+2ML`66sld}QbFnPNCq9-GyMa;=1->RuJ3A0n8VYUU+ z9(yQrt(ZXn0sjC6&;ADiFW&XggIAp`q66Q|`*@G{hVMHme8`8rAmGTHZ`bBt9J9l) zjQfYz+kVU-fN&3ua4Y!u`5p-aqw!2VFqKfvb4$Be5tRc+S;__%7;x~8cuI$>GPh}g zuP6iuBz2?>p>j6q*qNXa!N_12W?mDqVGv7Q$>9vl?jhxlJ;+b+stFz8lqoj$p)kQI zKSgr}c`{I3c~CqeBfR?*HIXqtn;B-tGJtb1-@$Mm77j?pT1bX(-(i&c7!3eFu1es+GsX;#Mr$ucEHJxxUt1uidTRT3)HuS{H9GujuF2PL;R( zsNZSyV-d+tuiNrWw~@r68*Rm>&66le20a1#hc(b+yW!xe1(A&OZ+jm<();v#VP=|3 zq?lUU+Z~wN*?mX9cP=>;;&u;W{mEG<&6}}Lb1!2l>o0DF6HGAuMZys4pKgWL4O0#EENkSiWM(|eG5_z0L|oQ_-N1Ey P%&y|H{>n-g;UWG5#(R+J diff --git a/osinaweb/customercore/views.py b/osinaweb/customercore/views.py index bfd60fdc..01fca607 100644 --- a/osinaweb/customercore/views.py +++ b/osinaweb/customercore/views.py @@ -36,6 +36,10 @@ def pricing(request, *args, **kwargs): return render(request, 'pricing.html', context) +import requests +import base64 +import uuid +from django.http import JsonResponse @customer_login_required def initiate_checkout(request): @@ -50,8 +54,6 @@ def initiate_checkout(request): # Data for Initiate Checkout operation data = { "apiOperation": "INITIATE_CHECKOUT", - "apiUsername": api_username, - "apiPassword": api_password, "merchant": merchant_id, "interaction.operation": "PURCHASE", "interaction.merchant.name": merchant_name, @@ -61,9 +63,18 @@ def initiate_checkout(request): "order.description": "description_of_order" } - try: - response = requests.post("https://creditlibanais-netcommerce.gateway.mastercard.com/api/nvp/version/72", data=data) + # Encode the username and password in Base64 format + credentials = f"{api_username}:{api_password}" + encoded_credentials = base64.b64encode(credentials.encode()).decode() + + # Construct the headers with the Authorization header + headers = { + "Authorization": f"Basic {encoded_credentials}", + "Content-Type": "application/json" + } + + response = requests.post("https://creditlibanais-netcommerce.gateway.mastercard.com/api/nvp/version/72", json=data, headers=headers) print("Response Content:", response.content.decode()) # Print response content @@ -79,4 +90,4 @@ def initiate_checkout(request): except Exception as e: print("Exception:", e) # Print exception traceback - return JsonResponse({"error": "Internal Server Error"}, status=500) \ No newline at end of file + return JsonResponse({"error": "Internal Server Error"}, status=500)