Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

2checkout ipn validation response python

import hmac
import hashlib
import datetime

from django.http import HttpResponse
from django.views.decorators.csrf import csrf_exempt


def hmac_md5(key, value):
    message = value.encode('utf-8')
    return hmac.new(key.encode('utf-8'), message, digestmod=hashlib.md5).hexdigest()

@csrf_exempt
def subscription_listener(request):
    if request.method == "GET":
        return HttpResponse("Hello")

    if request.method == "POST":
        pass_str = "SECRET_KEY_HERE"
        DATE = datetime.datetime.now().strftime("%Y%m%d%H%M%S")

        original_dict = dict(request.POST)
        base_string_for_return_hash = str(len(original_dict['IPN_PID[]'][0])) + str(
            original_dict['IPN_PID[]'][0]) + str(
            len(original_dict['IPN_PNAME[]'][0])) + str(original_dict['IPN_PNAME[]'][0]) + str(
            len(original_dict['IPN_DATE'][0])) + str(original_dict['IPN_DATE'][0]) + str(len(DATE)) + str(DATE)

        hashed = hmac_md5(pass_str, base_string_for_return_hash)
        
        response = "<EPAYMENT>{}|{}</EPAYMENT>".format(DATE, hashed)

        return HttpResponse(response)
Comment

PREVIOUS NEXT
Code Example
Python :: Wireframes and Surface Plots 
Python :: plot true values vs actucal vales 
Python :: django reverse accessor clashes for abstract class 
Python :: python how to dump exception stak 
Python :: add values to pandas plot 
Python :: tusha 
Python :: convert int to binary python 
Python :: how to kick and ban members with discord.py 
Python :: prime numbers from 1 to 100 in python 
Python :: While importing we detected an older version of numpy in 
Python :: python run async function without await 
Python :: kivy video recorder 
Python :: explore data dataframe pandas 
Python :: python empty array length n grepper 
Python :: execute command dynamo civid 
Python :: python find first char index from a string stackoverflow 
Python :: where is memory and register in python python 
Python :: load python 
Python :: python class optional arguments 
Python :: trigger to print on python 
Python :: Overwrite text in python 
Python :: Count the number of Non-Missing Values in the DataFrame 
Python :: python too many values to unpack 
Python :: Adding a new nested object in the list using a Deep copy in Python 
Python :: how to get the string between brackets in a string in python 
Python :: updating lists 
Python :: iterar 2 listas en simultaneo python 
Python :: is tkinter built into python 
Python :: linear plot 1D vector for x python 
Python :: python two list into dictinaray list comprehension 
ADD CONTENT
Topic
Content
Source link
Name
1+6 =