Saturday, 30 April 2016

Building an API with Django and GAE Cloud Endpoints


Introduction  

Typically when you build a Django application  and you need to expose your application's data in the form of a RESTful API you would use something like the excellent Django REST Framework or Django Tastypie However if you are hosting your site on Google App Engine there is an alternative called Google Cloud Endpoints that you should check out.
This blog explain you how to make a post request api in django application.

What is GAE cloud endpoints ?

Cloud Endpoints is a robust solution built on Google architecture that powers various Google APIs. It takes care of a lot of the hard work for you such as authentication via OAuth 2 and JSON templating and provides an explorer you can use to test your API in the browser.

An Endpoints API is a remote procedure call (RPC) service that provides remote methods accessible to external clients. Each Endpoints API consists of an RPC service class that subclasses the ProtoRPC remote.Service class, and one or more methods. When you define a method, you must also define message classes for the requests coming into that method and the responses returned by it. A message class performs a mapping function so the incoming data can be extracted and supplied to the service method properly, or supplied properly to the outgoing response.



for more details GAE cloud endpoints


Build Django Application .. !

I hope you guys are already know about the basic configuration and your application run in google app engine.

Here we are going to create a small web application , it contains only two models  Book and Publication Year , when user enter the year , api list out all the book which is published is user requested year.

don't forget to create handler (app.yaml ) in your project .

you can get the running code from my git account : django google endpoints application
clone the project in your machine and create a mysql database , and put some dummy data in to db.
and run in to google appeninge.

cheerrs ......






















Tuesday, 19 April 2016

PayU payment gateway integration with Django

  Introduction  


         This Blog is describes the steps for technical integration process between merchant website and PayU Payment Gateway for enabling online transactions. This Blog is covered payment gateway integration with Django Framework.

PayU Payment Gateway


      PayU offers electronic payment services to merchant website through its partnerships with various banks and payment instrument companies. Through PayU, the customers would be able to make  

Electronic payments through a variety of modes which are mentioned below:

  • Credit cards
  • Debit cards
  • Online net banking accounts
  • EMI payments
  • Cash Cards
  • Email Invoicing
  • IVR
  • Cash on Delivery (COD)


PayU also offers an online interface (known as PayU Dashboard) where the merchant has access to various features like viewing all the transaction details, settlement reports, analytical reports etc.Through this interface, the merchant can also execute actions like capturing, cancelling andrefunding the transactions. This online interface can be accessed through Payu using the username and password provided to you.

Payment Gateway Process Flow 





PayU payment Gateway Process Flow





Steps for Integration Process

The steps for integrating with PayU can technically be described as below:

1)   To start off the integration process, you would be provided a test setup by PayU where you
would be given a test merchant account and test credit card credentials to have a first-hand
experience of the overall transaction flow. Here, you need to make the transaction request
on our test server (and not the production server). Once your testing is complete, then only
you will be ready to move to the PayU production server.

2)   To initiate a transaction, the merchant needs to generate a POST REQUEST - which must
consist of mandatory and optional parameters mentioned in the later section. This POST
REQUEST needs to be hit on the below mentioned PayU URLs:

Test Url                     :  https://test.payu.in/_payment
Production(live) Url : https://secure.payu.in/_payment

3)   In the merchant initiated POST REQUEST, one of the mandatory parameters is named as
hash. The details of this hash parameter have been covered in the later section. But it is
absolutely critical for the merchant to calculate the hash correctly and post to us in the
request.

4) When the transaction POST REQUEST hits the PayU server, a new transaction entry is
created in the PayU Database. To identify each new transaction in the PayU Database, a
unique identifier is created every time at PayU’s end. This identifier is known as the PayU ID
(or MihPayID).

5) With thPOST REQUEST, customer would be re-directed to PayU’s payment page. Customer now selects the particular payment option on PayU’s page (Credit Card/Debit Card/NetBanking etc) and clicks on ‘Pay Now’. PayU re-directs the customer to the chosen bank. Thecustomer goes through the necessary authorization/authentication process at bank’s login page, and the bank gives the success/failure response back to PayU.

6) PayU marks the transaction status on the basis of response received from Bank. PayU
provides the final transaction response string to the merchant through a POST RESPONSE.
The parameters in this response are covered in the subsequent sections.

7) In the POST RESPONSE sent by PayU, you would receive the final status of the transaction.
You will receive the hash parameter here also. Similar to step 3, it is absolutely crucial to
verify this hash value at your end and then only accept/reject the invoice order. This is done
to strictly avoid any tampering attempt by the user.

Note : 
Test URL: The Test URL is provided to PayU merchants to test the integration of their  server with that of PayU or Bank. It is understood that since this is merely a Test URL, the Merchant should not treat any transactions done on this Test server as live and should not deliver the products/services with respect to any such test transactions even in the case your server receive a successful transaction confirmation from PayU/Bank.

Merchants are herein forth requested to set up required control checks on their               (merchant) systems/servers to ensure that only those transactions should get routed to the  PayU test server which are initiated with sole intention of test the environment.

PayU payment Gateway Integration with DJANGO

Onces you create the account With Payu they will provide salt and secretkey. we need this two
credentials for the payment gateway integration

Parameters to be posted by Merchant to PayU in Transaction Request:

  •  key (Mandatory)
  • txnid (Mandatory)
  • amount(Mandatory)
  • productinfo(Mandatory)
  • firstname(Mandatory)
  • email (Mandatory)
  • phone (Mandatory)
  • lastname
  • Udf1-Udf5
  • address1
  • city
  • state
  • country
  • zipcode
  • surl(Mandatory)
  • furl(Mandatory)
  • curl(Mandatory)
  • hash(Checksum)Mandatory)     :sha512(key|txnid|amount|productinfo|firstname|email|udf1|udf2|udf3|udf4|udf5||||||SALT)
  • Udf : user defind field
  • Surl : Sucess URL ( Success redirection URLs ) 
  • Furl : Failure URL ( Failure redirectio URLs )
  • Curl : Cancelation URL( cancelation URLs)
Sample Code : payupayment sample code