Last active
July 9, 2018 05:56
-
-
Save ratpik/4078e9933daed1389d8c to your computer and use it in GitHub Desktop.
PayTM Android 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
<html> | |
<head> | |
<meta http-equiv="Content-Type" content="text/html;charset=ISO-8859-1"> | |
<title> Paytm </title> | |
<script type="text/javascript"> | |
function response(){ | |
return document.getElementById('response').value; | |
} | |
</script> | |
</head> | |
<body> | |
Redirecting back to the app <br/> | |
<form name="frm" method="post"> | |
<input type="hidden" id="response" name="responseField" value="{ {% for key, value in params.items %} {{key}} : {{value}}, {% endfor %} }" | |
</form> | |
</body> | |
</html> |
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
package com.drc.paytm_example; | |
import java.util.HashMap; | |
import java.util.Map; | |
import java.util.Random; | |
import android.app.Activity; | |
import android.os.Bundle; | |
import android.util.Log; | |
import android.view.Window; | |
import com.paytm.pgsdk.PaytmMerchant; | |
import com.paytm.pgsdk.PaytmOrder; | |
import com.paytm.pgsdk.PaytmPGService; | |
import com.paytm.pgsdk.PaytmPaymentTransactionCallback; | |
public class MainActivity extends Activity | |
{ | |
private int randomInt = 0; | |
private PaytmPGService Service = null; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) | |
{ | |
super.onCreate(savedInstanceState); | |
Log.d("LOG", "onCreate of MainActivity"); | |
getWindow().requestFeature(Window.FEATURE_PROGRESS); | |
setContentView(R.layout.activity_main); | |
Random randomGenerator = new Random(); | |
randomInt = randomGenerator.nextInt(1000000000); | |
//Service = PaytmPGService.getStagingService(); //for testing environment | |
Service = PaytmPGService.getProductionService(); | |
/*PaytmMerchant constructor takes two parameters | |
1) Checksum generation url | |
2) Checksum verification url | |
Merchant should replace the below values with his values*/ | |
PaytmMerchant Merchant = new PaytmMerchant("<checksum_signing_url>","<checksum_validation_url>"); | |
//below parameter map is required to construct PaytmOrder object, Merchant should replace below map values with his own values | |
Map<String, String> paramMap = new HashMap<String, String>(); | |
//these are mandatory parameters | |
paramMap.put("REQUEST_TYPE", "DEFAULT"); | |
paramMap.put("ORDER_ID", String.valueOf(randomInt)); | |
paramMap.put("MID", "mymerchantid"); | |
paramMap.put("CUST_ID", "CUST123"); | |
paramMap.put("CHANNEL_ID", "WAP"); | |
paramMap.put("INDUSTRY_TYPE_ID", "Retail120"); | |
paramMap.put("WEBSITE", "mywebsite"); | |
paramMap.put("TXN_AMOUNT", "1"); | |
paramMap.put("THEME", "merchant"); | |
PaytmOrder Order = new PaytmOrder(paramMap); | |
Service.initialize(Order, Merchant, null); | |
Service.startPaymentTransaction(this, false, true, new PaytmPaymentTransactionCallback() { | |
@Override | |
public void onTransactionSuccess(Bundle bundle) { | |
Log.i("Success","onTransactionSuccess :"+bundle); | |
} | |
@Override | |
public void onTransactionFailure(String s, Bundle bundle) { | |
Log.i("Failure", "onTransactionFailure " + s); | |
} | |
@Override | |
public void networkNotAvailable() { | |
Log.i("Failure", "networkNotAvailable"); | |
} | |
@Override | |
public void clientAuthenticationFailed(String s) { | |
Log.i("Failure", "clientAuthenticationFailed " + s); | |
} | |
@Override | |
public void someUIErrorOccurred(String s) { | |
Log.i("Failure", "someUIErrorOccurred " + s); | |
} | |
@Override | |
public void onErrorLoadingWebPage(int i, String s, String s1) { | |
Log.i("Failure", "onErrorLoadingWebPage" + s + " " + s1); | |
} | |
}); | |
} | |
} |
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
@ajax_request | |
@require_http_methods(["GET", "POST"]) | |
@csrf_exempt | |
def paytm_sign(request): | |
data = request.GET or request.POST | |
request_type, channel_id, cust_id, email, industry_type_id, mid, mobile_no, order_id, theme, txn_amount, website = \ | |
data.get('REQUEST_TYPE'), data.get('CHANNEL_ID'), data.get('CUST_ID'), data.get('EMAIL'), data.get('INDUSTRY_TYPE_ID'), \ | |
data.get('MID'), data.get('MOBILE_NO'), data.get('ORDER_ID'), data.get('THEME'), data.get('TXN_AMOUNT'), data.get('WEBSITE') | |
if not mid == settings.PAYTM_MERCHANT_ID: | |
return {"payt_STATUS" : 2} | |
param_dict = dict() | |
param_dict['REQUEST_TYPE'] = request_type | |
param_dict['CHANNEL_ID'] = channel_id | |
param_dict['CUST_ID'] = cust_id | |
param_dict['EMAIL'] = email | |
param_dict['INDUSTRY_TYPE_ID'] = industry_type_id | |
param_dict['MID'] = mid | |
param_dict['MOBILE_NO'] = mobile_no | |
param_dict['ORDER_ID'] = order_id | |
param_dict['THEME'] = theme | |
param_dict['TXN_AMOUNT'] = txn_amount | |
param_dict['WEBSITE'] = website | |
__sign__(param_dict) | |
checksum_param = param_dict.pop('CHECKSUMHASH') | |
return { | |
"CHECKSUMHASH": checksum_param, | |
"ORDER_ID": order_id, | |
"payt_STATUS": 1 | |
} | |
#create checksum | |
def __sign__(param_dict): | |
param_dict['CHECKSUMHASH'] = checksum.generate_checksum(param_dict, settings.PAYTM_MERCHANT_KEY) | |
@require_http_methods(["GET", "POST"]) | |
@csrf_exempt | |
def paytm_callback(request): | |
data = request.GET or request.POST | |
subsid, mid, txnid, orderid, banktxnid, txnamount, currency, status, respcode, respmsg, txndate, gatewayname, bankname, paymentmode, checksumhash= \ | |
data.get('SUBSID'), data.get('MID'), data.get('TXNID'), data.get('ORDERID'), data.get('BANKTXNID'), data.get('TXNAMOUNT'), data.get('CURRENCY'), data.get('STATUS'), \ | |
data.get('RESPCODE'), data.get('RESPMSG'), data.get('TXNDATE'), data.get('GATEWAYNAME'), data.get('BANKNAME'), data.get('PAYMENTMODE'), data.get('CHECKSUMHASH') | |
param_dict = { | |
#'SUBSID' : subsid, #TIf subsid is unavailable, leave it out of the checksum verification process, SUBSID is optional | |
'MID' : mid, | |
'TXNID' : txnid, | |
'ORDERID' : orderid, | |
'BANKTXNID' : banktxnid, | |
'TXNAMOUNT' : txnamount, | |
'CURRENCY' : currency, | |
'STATUS' : status, | |
'RESPCODE' : respcode, | |
'RESPMSG' : respmsg, | |
'TXNDATE' : txndate, | |
'GATEWAYNAME' : gatewayname, | |
'BANKNAME' : bankname, | |
'PAYMENTMODE' : paymentmode, | |
'CHECKSUMHASH' : checksumhash | |
} | |
if not __validate(param_dict, settings.PAYTM_MERCHANT_KEY): | |
param_dict['IS_CHECKSUM_VALID'] = "N" | |
return render_to_response('paytm/checkout.html', | |
{'params' : param_dict}) | |
param_dict['IS_CHECKSUM_VALID'] = "Y" | |
return render_to_response('paytm/checkout.html', | |
{'params' : param_dict}) | |
# verify checksum | |
def __validate(param_dict, merchant_key): | |
if 'CHECKSUMHASH' not in param_dict: | |
return False | |
checksum_param = param_dict.pop('CHECKSUMHASH') | |
return checksum.verify_checksum(param_dict, merchant_key, checksum_param) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
can you provide me full code for intergrete paytm in android app