Last active
September 1, 2023 18:25
-
-
Save erdimeola/faa00de1910e7aeb6bff to your computer and use it in GitHub Desktop.
Python - EST 3D Secure Integration
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# -*- coding: utf-8 -*- | |
from django.shortcuts import redirect | |
from django.http import HttpResponse | |
import requests, hashlib, base64, time | |
EST_MERCHANT_ID = "400000200" | |
EST_3D_KEY = "TRPS0200" | |
EST_RETURN_URL = "http://test.domain.com/basarili" | |
EST_FAIL_URL = "http://test.domain.com/basarisiz" | |
EST_3D_URL = 'https://entegrasyon.asseco-see.com.tr/fim/est3Dgate' | |
def build_string(*args): | |
return ''.join([str(a) for a in args]) | |
def prepare_hash(clientid,orderid,amount,okUrl,failUrl,islemtipi,rnd,storekey): | |
string_to_be_hashed = build_string(clientid,orderid,amount,okUrl,failUrl,islemtipi,rnd,storekey) | |
sha1_hashed = hashlib.sha1(string_to_be_hashed).digest() | |
base64_enc = base64.b64encode(sha1_hashed) | |
return base64_enc | |
def make_3d_payment(request,order,credit_card,exp_year,exp_month,cvv,cardholder_name): | |
rnd = int(round(time.time() * 1000)) | |
if credit_card[0] == "4": | |
brand = 1 | |
elif credit_card[0] == "5": | |
brand = 2 | |
elif credit_card[0] == "6": | |
brand = 3 | |
else: | |
brand = "" | |
payload = { | |
'clientid' : EST_MERCHANT_ID, | |
'islemtipi' : 'Auth', | |
'okUrl': EST_RETURN_URL, | |
'failUrl': EST_FAIL_URL, | |
'storetype':'3d_pay', | |
'amount' : "{0:.2f}".format(order.total_price), | |
'currency' : '949', | |
'cardType' : brand, | |
'pan': credit_card, | |
'Ecom_Payment_Card_ExpDate_Year':exp_year, | |
'Ecom_Payment_Card_ExpDate_Month':exp_month, | |
'cv2':cvv, | |
'rnd': rnd, | |
'hash': prepare_hash(EST_MERCHANT_ID,order.order_id,"{0:.2f}".format(order.total_price),EST_RETURN_URL,EST_FAIL_URL,"Auth",rnd,EST_3D_KEY), | |
'oid': order.order_id, | |
'lang':'tr', | |
} | |
resp = requests.post(EST_3D_URL, data=payload, verify=False) | |
return HttpResponse(resp.text) | |
def finalize_3d_payment(request,result): | |
order_id = result.get("oid") | |
response = result.get("Response") | |
if response == "Approved": | |
transaction_id = result.get("TransId") | |
#başarılı olarak kaydet | |
return redirect("success_page") | |
else: | |
return redirect("checkout_page") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment