You are on page 1of 8

Payment gateway ­ To pay amount online or on the internet , we use payment gateway.

 PG is 
an interface between the user and the merchant website to complete online transaction 
process.

Why payment gateway? ­ Payment gateway encrypts the sensitive information like bank 
password, credits /debit cards numbers & passwords , user's profile name to ensure that the 
data passes correctly between the user & the merchant(shopping) website.

Before Integration:
* We need a target URL(PG landing page) .

* We have to send Merchant Id,WorkingKey,Checksum,Order id,Currency Type,Txn 
Type,Action Id ,Redirecturl and Amount.when we hit the target URL.(Always 
Currency='USD',TxnType='A' ,ActionID='TXN').

* For Merchant Id and WorkingKey You should subscribe in CCAVENUE.Once you 
subcribe they will provide you with Merchant id and WorkingKey.And checksum is an 
encrypted value of Merchant Id,WorkingKey,Order id,Amount,Redirecturland Currency.

Here we have two type of payments ­­Rupee Payments and Dollar Payments.

For Rupee Payment:
Checksum = getchecksum
(Merchant_Id,Amount,Order_Id,Redirect_Url,WorkingKey)

def getchecksum(MerchantId,Amount,OrderId ,URL,WorkingKey):
pay_id = MerchantId+"|"+OrderId+"|"+Amount+"|"+URL
+"|"+WorkingKey
adler = 1
adler = adler32(adler,pay_id)
return adler

def verifyChecksum
(MerchantId,OrderId,Amount,AuthDesc,CheckSum,WorkingKey):
pay_id = "%s|%s|%s|%s|%s"%
(MerchantId,OrderId,Amount,AuthDesc,WorkingKey)
adler = 1;
adler = adler32(adler,pay_id)

if int(adler) == int(CheckSum):
return "true" 
else:
return "false"
 
  def payment(request):
  CCAVENUE = "https://www.ccavenue.com/shopzone/
cc_details.jsp"  (this common for all Rupee Payment)
Merchant_Id = ""
  WorkingKey = ""
  Order_Id = ""
  Amount=""
  Redirect_Url = "http://sitename/redirecturl"  (after all payments done it 
will call this  redirectuel function)
 Checksum = getchecksum
(Merchant_Id,Amount,Order_Id,Redirect_Url,WorkingKey)
  return render_to_response("payment.html")
 
 * Two types of ‘AuthDesc’ statuses will be sent by CCAvenueTM namely ‘Y’, ‘N’ OR ‘B’.
 Y ­ indicates that the transaction has been successfully authorised by the gateway.
 N ­ indicates an unsuccessful transaction, as it did not receive authorisation from
 the gateway.
 B – indicates that the transaction is in batch processing mode and the authorisation
 status can only be determined at a later point in time. This happens only in very rare
 cases if any of the Gateway servers is down and we opt to process orders offline. In the
 case of these transactions the authorisation status is available only after 5­6 hours by
 mail from CCAvenueTM and at the "Pending Orders” section.

 
 

def redirecturl(request):
Merchant_Id=request.POST.get('Merchant_Id')
Order_Id=request.POST.get('Order_Id')
Amount=request.POST.get('Amount')
WorkingKey=""
AuthDesc=request.POST.get('AuthDesc')
CheckSum=request.POST.get('CheckSum')
Checksum = verifyChecksum
(Merchant_Id,Order_Id,Amount,AuthDesc,CheckSum,WorkingKey)
if Checksum=="true" and AuthDesc=="Y":
Message="Thank you for shopping with us. Your credit card 
has been charged and your transaction is successful. We will be shipping your order to you 
soon."
elif Checksum=="true" and AuthDesc=="B":
Message="Thank you for shopping with us.We will keep you 
posted regarding the status of your order through e­mail"
elif Checksum=="true" and AuthDesc=="N":
Message="Thank you for shopping with us.However,the 
transaction has been declined."
else:
Message="Security Error. Illegal access detected."
return render_to_response("redirecturl.html")

For Dollar Payment:

def getchecksum(MerchantId,Amount,OrderId ,URL,WorkingKey,Currency):
pay_id = MerchantId+"|"+OrderId+"|"+Amount+"|"+WorkingKey
+"|"+Currency+"|"+URL
adler = 1
adler = adler32(adler,pay_id)
return adler
def verifyChecksum
(MerchantId,OrderId,Amount,Auth_Status,checkSumAll,WorkingKey,Currency):
pay_id = "%s|%s|%s|%s|%s|%s"%
(MerchantId,OrderId,Amount,WorkingKey,Currency,Auth_Status)
adler = 1;
adler = adler32(adler,pay_id)

if int(adler) == int(CheckSum):
return "true" 
else:
return "false"

def payment(request):
CCAVENUE = "https://www.ccavenue.com/shopzone/
cc_details.jsp"  (this common for all Dollar Payment)
Merchant_Id = ""
WorkingKey = ""
Order_Id = ""
Amount=""
Redirect_Url = "http://sitename/redirecturl"  (after all payments done it 
will call this redirectuel function)
Checksum = getchecksum
(Merchant_Id,Amount,Order_Id,Redirect_Url,WorkingKey,Currency)
return render_to_response("payment.html")

* Two types of ‘Auth_Status’ statuses will be sent by CCAvenueTM namely ‘Y’, ‘N’ 
OR ‘B’.
          Y ­ indicates that the transaction has been successfully authorised by the gateway.
          N ­ indicates an unsuccessful transaction, as it did not receive authorisation from
          the gateway.
          B – indicates that the transaction is in batch processing mode and the authorisation
          status can only be determined at a later point in time. This happens only in very rare
          cases if any of the Gateway servers is down and we opt to process orders offline. In 
the
          case of these transactions the authorisation status is available only after 5­6 hours by
          mail from CCAvenueTM and at the "Pending Orders” section.

def redirecturl(request):
Merchant_Id=request.POST.get('Merchant_Id')
Order_Id=request.POST.get('Order_Id')
Amount=request.POST.get('Amount')
WorkingKey=""
Auth_Status=request.POST.get('Auth_Status')
checkSumAll=request.POST.get('checkSumAll')
Currency == "USD"
Checksum = verifyChecksum
(Merchant_Id,Order_Id,Amount,Auth_Status,checkSumAll,WorkingKey,Currency)
if Checksum=="true" and AuthDesc=="Y":
Message="Thank you for shopping with us. Your credit card 
has been charged and your transaction is successful. We will be shipping your order to you 
soon."
elif Checksum=="true" and AuthDesc=="B":
Message="Thank you for shopping with us.We will keep you 
posted regarding the status of your order through e­mail"
elif Checksum=="true" and AuthDesc=="N":
Message="Thank you for shopping with us.However,the 
transaction has been declined."
else:
Message="Security Error. Illegal access detected."
return render_to_response("redirecturl.html")

And this code is common for both the Payments:

def adler32(adler , str):
BASE =  65521 
s1 = adler & 0xffff 
s2 = (adler >> 16) & 0xffff
Ord=()
for i in range(0,len(str)):
s1 = (s1 + ord(str[i])) % BASE 
s2 = (s2 + s1) % BASE ;
left = leftshift(s2 , 16) + s1
return leftshift(s2 , 16) + s1

def DecBin(decstr):
decimal=""
while(decstr>0):
dec = int(decstr) % 2
decimal = decimal + str(dec)
decstr = int(decstr) /2
decimal = str(decimal)
temp = list(decimal)
temp.reverse()
decimal = ''.join(temp)
return decimal

def leftshift(str , num):
str = DecBin(str)
i=0
while(i<(64­len(str))):
str = "0"+str
i+=1
for i in range(0,num):
str = str+"0"
str = str[1:]
return cdec(str)

def cdec(num):
dec= 0 
for n in range(0,len(num)):
   temp = int(num[n])
   pw=pow(2 , len(num) ­ n ­ 1)
   dec =  dec + temp*pow(2 , len(num) ­ n ­ 1)
return dec

Sample Html Code Payment.html

Html code :

This is the page which connects to CCAVENUE.

Please dont change the fields name.CCAVENUE will use the same field names.
<html>
<body>
<form method="post" action="https://www.ccavenue.com/shopzone/cc_details.jsp">

<input type="hidden" name="Merchant_Id" value="Merchant_Id">

<input type="hidden" name="Amount" value="Amount">

<input type=hidden name=Currency value="USD">

<input type="hidden" name="Order_Id" value="Order_Id">

<input type=hidden name=Redirect_Url value="Redirect_Url">

<input type=hidden name=TxnType value="A">

<input type=hidden name=actionID value="TXN">

<input type=hidden name=Checksum value="Checksum">

<input type="hidden" name="billing_cust_name" value="firstname">

<input type="hidden" name="billing_middle_name" value="">

<input type="hidden" name="billing_last_name" value="">

<input type="hidden" name="billing_cust_address" value="">

<input type="hidden" name="billing_cust_city" value="">

<input type="hidden" name="billing_cust_state" value="">

<input type="hidden" name="billing_zip_code" value="">

<input type="hidden" name="billing_cust_country" value="">

<input type="hidden" name="billing_cust_tel_Ctry" value="">

<input type="hidden" name="billing_cust_tel_Area" value="">

<input type="hidden" name="billing_cust_tel" value="">
<input type="hidden" name="billing_cust_email" value="">

<input type="hidden" name="billing_cust_notes" value="Send right away!">

<input type="hidden" name="Merchant_Param" value="">

<input type="hidden" name="delivery_cust_name" value="">

<input type="hidden" name="delivery_middle_name" value="">

<input type="hidden" name="delivery_last_name" value="">

<input type="hidden" name="delivery_cust_address" value="">

<input type="hidden" name="delivery_cust_city" value="">

<input type="hidden" name="delivery_cust_state" value="">

<input type="hidden" name="delivery_zip_code" value="">

<input type="hidden" name="delivery_cust_country" value="">

<input type="hidden" name="delivery_cust_tel_Ctry" value="">

<input type="hidden" name="delivery_cust_tel_Area" value="">

<input type="hidden" name="delivery_cust_tel" value="">

<input type="submit" value="Buy Now" text­align="center">
</form>
</body>
</html>

* So that they can check , this data is coming from our merchant id.

* We have to send our last page link (we hit or we send data to PG from this page) & 
return URL(the page where we ll display status of current transaction)

After Integration

    * We user select products & add those product into the shopping basket, he/she has to be 
logged in for further process.

    * After successful log in, he/she has to fill his/her billing & shipping details.

 
    * After submitting those details, the data should be stored in the database & one auto order 
should be generated. The payment status ll be pending till this process.

    * Suppose he/she logs out or some problem occurs in his/her system or in the server. This 
order has already been stored as a pending status.

    * If he/she goes further, they ll find our last page with their current order details ­ like 
order id, total amount, billing address .

    * Here he/she clicks submit button, their details ll be sent to the PG landing page with 
merchant id.

    * We need to send order id & total amount only. These are mandatory parameters.

    * If we want to send additional parameters we have to speak to PG person to add these 
extra fields in PG database.

    * They can also provide some checksum logic to bind whole data for security purpose. So 
that we need to send data as checksum logic says.

    * Merchant site verification ­ performs on the basis of merchant id & our last page link(ip 
address) which we have given them already.

    * After verification, they ll provide available options to perform transaction process.

    * After completion of transaction process, they ll redirect the person to our website or our 
redirect URL with current transaction result.

    * Based on the result, we can update that person order as canceled or confirmed.

 
    * A notification mail has to be sent after this process to the person & to the administrator of 
the merchant site with last transaction details.

This completes payment gateway integration part.

You might also like