I am developing an Ecommerce app in which I want to integrate Payumoney payment gateway. Can someone help me with some procedure, link or tutorial, how to do so? Thanks.
-
78K View and closed intresting – Lavekush Agrawal Jan 21 '16 at 06:45
-
Did you implement this ? Can you share code pls if so ? – Manu Mar 14 '16 at 10:00
6 Answers
I have done Perfectly :) :) You have to edit SuccessURL
and FailureURL
:
Its Working for Me Perfectly.
public class PayUMoneyActivity extends AppCompatActivity {
/**
* Adding WebView as setContentView
*/
WebView webView;
/**
* Context for Activity
*/
Context activity;
/**
* Order Id
* To Request for Updating Payment Status if Payment Successfully Done
*/
int mId; //Getting from Previous Activity
/**
* Required Fields
*/
// Test Variables
/*
private String mMerchantKey = "FCyqqZ";
private String mSalt = "sfBpGA8E";
private String mBaseURL = "https://test.payu.in";
*/
// Final Variables
private String mMerchantKey = "Your Merchant Key";
private String mSalt = "Salt";
private String mBaseURL = "https://secure.payu.in";
private String mAction = ""; // For Final URL
private String mTXNId; // This will create below randomly
private String mHash; // This will create below randomly
private String mProductInfo = "Food Items"; //Passing String only
private String mFirstName; // From Previous Activity
private String mEmailId; // From Previous Activity
private double mAmount; // From Previous Activity
private String mPhone; // From Previous Activity
private String mServiceProvider = "payu_paisa";
private String mSuccessUrl = "your success URL";
private String mFailedUrl = "Your Failure URL";
boolean isFromOrder;
/**
* Handler
*/
Handler mHandler = new Handler();
/**
* @param savedInstanceState
*/
@SuppressLint({"AddJavascriptInterface", "SetJavaScriptEnabled"})
@Override
protected void onCreate(Bundle savedInstanceState) {
getWindow().requestFeature(Window.FEATURE_PROGRESS);
super.onCreate(savedInstanceState);
/**
* Setting WebView to Screen
*/
setContentView(R.layout.activity_webview_for_payumoney);
/**
* Creating WebView
*/
webView = (WebView) findViewById(R.id.payumoney_webview);
/**
* Context Variable
*/
activity = getApplicationContext();
/**
* Actionbar Settings
*/
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
ActionBar ab = getSupportActionBar();
ab.setDisplayHomeAsUpEnabled(true);
// enabling action bar app icon and behaving it as toggle button
ab.setHomeButtonEnabled(true);
ab.setTitle(getString(R.string.title_activity_online_payment));
/**
* Getting Intent Variables...
*/
Bundle bundle = getIntent().getExtras();
if (bundle != null) {
mFirstName = bundle.getString("name");
mEmailId = bundle.getString("email");
mAmount = bundle.getDouble("amount");
mPhone = bundle.getString("phone");
mId = bundle.getInt("id");
isFromOrder = bundle.getBoolean("isFromOrder");
Log.i(TAG, "" + mFirstName + " : " + mEmailId + " : " + mAmount + " : " + mPhone);
/**
* Creating Transaction Id
*/
Random rand = new Random();
String randomString = Integer.toString(rand.nextInt()) + (System.currentTimeMillis() / 1000L);
mTXNId = hashCal("SHA-256", randomString).substring(0, 20);
mAmount = new BigDecimal(mAmount).setScale(0, RoundingMode.UP).intValue();
/**
* Creating Hash Key
*/
mHash = hashCal("SHA-512", mMerchantKey + "|" +
mTXNId + "|" +
mAmount + "|" +
mProductInfo + "|" +
mFirstName + "|" +
mEmailId + "|||||||||||" +
mSalt);
/**
* Final Action URL...
*/
mAction = mBaseURL.concat("/_payment");
/**
* WebView Client
*/
webView.setWebViewClient(new WebViewClient() {
@Override
public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) {
super.onReceivedError(view, request, error);
Toast.makeText(activity, "Oh no! " + error, Toast.LENGTH_SHORT).show();
}
@Override
public void onReceivedSslError(WebView view,
SslErrorHandler handler, SslError error) {
Toast.makeText(activity, "SSL Error! " + error, Toast.LENGTH_SHORT).show();
handler.proceed();
}
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
return super.shouldOverrideUrlLoading(view, url);
}
@Override
public void onPageFinished(WebView view, String url) {
if (url.equals(mSuccessUrl)) {
Intent intent = new Intent(PayUMoneyActivity.this, PaymentStatusActivity.class);
intent.putExtra("status", true);
intent.putExtra("transaction_id", mTXNId);
intent.putExtra("id", mId);
intent.putExtra("isFromOrder", isFromOrder);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
} else if (url.equals(mFailedUrl)) {
Intent intent = new Intent(PayUMoneyActivity.this, PaymentStatusActivity.class);
intent.putExtra("status", false);
intent.putExtra("transaction_id", mTXNId);
intent.putExtra("id", mId);
intent.putExtra("isFromOrder", isFromOrder);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
}
super.onPageFinished(view, url);
}
});
webView.setVisibility(View.VISIBLE);
webView.getSettings().setBuiltInZoomControls(true);
webView.getSettings().setCacheMode(2);
webView.getSettings().setDomStorageEnabled(true);
webView.clearHistory();
webView.clearCache(true);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setSupportZoom(true);
webView.getSettings().setUseWideViewPort(false);
webView.getSettings().setLoadWithOverviewMode(false);
webView.addJavascriptInterface(new PayUJavaScriptInterface(PayUMoneyActivity.this), "PayUMoney");
/**
* Mapping Compulsory Key Value Pairs
*/
Map<String, String> mapParams = new HashMap<>();
mapParams.put("key", mMerchantKey);
mapParams.put("txnid", mTXNId);
mapParams.put("amount", String.valueOf(mAmount));
mapParams.put("productinfo", mProductInfo);
mapParams.put("firstname", mFirstName);
mapParams.put("email", mEmailId);
mapParams.put("phone", mPhone);
mapParams.put("surl", mSuccessUrl);
mapParams.put("furl", mFailedUrl);
mapParams.put("hash", mHash);
mapParams.put("service_provider", mServiceProvider);
webViewClientPost(webView, mAction, mapParams.entrySet());
} else {
Toast.makeText(activity, "Something went wrong, Try again.", Toast.LENGTH_LONG).show();
}
}
/**
* Posting Data on PayUMoney Site with Form
*
* @param webView
* @param url
* @param postData
*/
public void webViewClientPost(WebView webView, String url,
Collection<Map.Entry<String, String>> postData) {
StringBuilder sb = new StringBuilder();
sb.append("<html><head></head>");
sb.append("<body onload='form1.submit()'>");
sb.append(String.format("<form id='form1' action='%s' method='%s'>", url, "post"));
for (Map.Entry<String, String> item : postData) {
sb.append(String.format("<input name='%s' type='hidden' value='%s' />", item.getKey(), item.getValue()));
}
sb.append("</form></body></html>");
Log.d("TAG", "webViewClientPost called: " + sb.toString());
webView.loadData(sb.toString(), "text/html", "utf-8");
}
/**
* Hash Key Calculation
*
* @param type
* @param str
* @return
*/
public String hashCal(String type, String str) {
byte[] hashSequence = str.getBytes();
StringBuffer hexString = new StringBuffer();
try {
MessageDigest algorithm = MessageDigest.getInstance(type);
algorithm.reset();
algorithm.update(hashSequence);
byte messageDigest[] = algorithm.digest();
for (int i = 0; i < messageDigest.length; i++) {
String hex = Integer.toHexString(0xFF & messageDigest[i]);
if (hex.length() == 1)
hexString.append("0");
hexString.append(hex);
}
} catch (NoSuchAlgorithmException NSAE) {
}
return hexString.toString();
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if(item.getItemId() == android.R.id.home) {
onPressingBack();
}
return super.onOptionsItemSelected(item);
}
@Override
public void onBackPressed() {
onPressingBack();
}
/**
* On Pressing Back
* Giving Alert...
*/
private void onPressingBack() {
final Intent intent;
if(isFromOrder)
intent = new Intent(PayUMoneyActivity.this, ProductInCartList.class);
else
intent = new Intent(PayUMoneyActivity.this, MainActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
AlertDialog.Builder alertDialog = new AlertDialog.Builder(PayUMoneyActivity.this);
// Setting Dialog Title
alertDialog.setTitle("Warning");
// Setting Dialog Message
alertDialog.setMessage("Do you cancel this transaction?");
// On pressing Settings button
alertDialog.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
finish();
startActivity(intent);
}
});
// on pressing cancel button
alertDialog.setNegativeButton("No", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
// Showing Alert Message
alertDialog.show();
}
public class PayUJavaScriptInterface {
Context mContext;
/**
* Instantiate the interface and set the context
*/
PayUJavaScriptInterface(Context c) {
mContext = c;
}
public void success(long id, final String paymentId) {
mHandler.post(new Runnable() {
public void run() {
mHandler = null;
Toast.makeText(PayUMoneyActivity.this, "Payment Successfully.", Toast.LENGTH_SHORT).show();
}
});
}
}
}
EDITED:
You can use https://www.payumoney.com/dev-guide/webcheckout/redirect.html now.

- 60,504
- 58
- 273
- 437
-
-
You just have to put some web url which will use in `onPageFinished` – Pratik Butani Jul 08 '16 at 02:48
-
-
Now they are giving API, you can try API - https://www.payumoney.com/dev-guide/ – Pratik Butani Apr 15 '18 at 15:08
-
Hi,I am use some www.success..php and same as failur thay both work on test mode,and also have entry my PayUMoeny Account.but same code in live mode not working.have any change in test mode and live mode?? – Bhoomika Prajapati Apr 16 '18 at 05:48
-
@bhoomika what you are getting as error in live mode? Any error? – Pratik Butani Apr 16 '18 at 05:52
-
@PratikButani Everything is working fine but how i do I get another full response , and what is the use of PayUJavaScriptInterface , its never triggered – Nirav Joshi May 25 '18 at 13:56
-
Is that secure hard coding merchant key ,salt etc in android ?. – sreekanth balu Dec 20 '19 at 06:49
-
-
@PratikButani for testing its okay . But for production I think its recommended to keep salt , key on remote web server and generate hash to use it to post to payumoney . – sreekanth balu Dec 20 '19 at 07:29
-
Build Custom Integration
As per payumoney: If you are building your website from scratch you need to make a post request to our
API
. Pass yourkey
and othermandatory variable
. This also include the Success and Failure page URL, where you wish to take your user on success and failure cases.Step 1: Create a store with any of our e-commerce platform partners.
Step 2: Choose PayUMoney as Payment option.
Step 3: Enter PayUMoney credentials and you are ready to go.
Note: You need to develop your own web services which take data from your client application and forward the request to payumoney server then take responses of callback after that your web services will notify you with result.
FlipKart, FreeCharge, Snapdeal etc they have their own url who will take responsibility to initiate the payment gateway,
So conclusion is that you need to support from your server team to initiate the payment and return the result back to your client application.
You can find the more information about payumoney and api payumoney integration,

- 6,040
- 7
- 52
- 85
-
https://drive.google.com/folderview?id=0B4URmsDLhGXmfjFmbDQ5b2V0bVhjdTZMNExMVHRFMG1PRFFYeUV0LU9nSWU4U0pqaW00OU0&usp=drive_web&ddrp=1# i need like this – kartheeki j Sep 02 '15 at 06:43
-
hello i am using payu gateway in android app now can you please tell me what is the dfference between payu android sdk and custom browser do i have to use both or what ?? – Sudhanshu Gaur Dec 09 '15 at 11:19
Simplest way to integrate Payment gateway is to use a webview for your application.
You can see that most of the applications like FlipKart, FreeCharge, Snapdeal etc., use the same

- 132
- 1
- 9
-
1I know that but sorry, but I don't know how to use a webview for application. Can you please provide some link or sample code to do so? – gautamprajapati Apr 29 '15 at 04:42
-
1STEP 1 Complete a successful test transaction using the test credit card on PayU’s test server. Merchant ID: gtKFFx SALT: eCwWELxi PayU Test URL: https://test.payu.in/_payment Below are the test card details for doing a test transaction in the testing mode Card Name – Any name Card Number: 5123456789012346 CVV: 123 Expiry: may 2017 STEP 2 Once you have done the test transaction successfully. Merchant Key: XYZ SALT: go to --> https://www.payu.in/index?returnUrl=salt# The production URL is: https://secure.payu.in/_payment For Integration Kit: https://github.com/payu-india – Jaydeep Goswami Apr 29 '15 at 04:50
-
in github.com you may select Payu php kit-->https://github.com/payu-india/Payu_php_kit – Jaydeep Goswami Apr 29 '15 at 04:52
-
I would suggest you to download the documentation first from the above link its damn easy than.. – Jaydeep Goswami Apr 29 '15 at 04:55
-
@JaydeepGoswami Can you please explain in more detail that how to send data & which data to web view TEST TRANSACTION url? – VVB Jun 25 '15 at 05:06
-
-
As i said you.. First of all download the Library Files from http://github.com/payu-india and – Jaydeep Goswami Jul 10 '15 at 05:59
-
There you'll find one Documentation File in .pdf format and one library file which you need to include in the file from where you are calling your payment gateway. After that simply call the method specified in the documentation along with the necessary parameters to be passed – Jaydeep Goswami Jul 10 '15 at 06:01
-
in android native you can JSON Encode your data (i.e., Parameters) and send it to the server script ( .php or .asp file) – Jaydeep Goswami Jul 10 '15 at 06:02
-
hello i am using payu gateway in android app now can you please tell me what is the dfference between payu android sdk and custom browser do i have to use both or what ?? – Sudhanshu Gaur Dec 09 '15 at 11:21
This is how I did in my Application
public class PayYouMoneyFragment extends Fragment {
/** The Constant PAYU_MONEY_URL. */
private static final String PAYU_MONEY_URL = "https://www.payumoney.com/paybypayumoney/#/BCDCEAE6A98116CB48BDE55C440BC69D";
/**
* Instantiates a new pay you money fragment.
*/
public PayYouMoneyFragment() {
// Empty constructor required for fragment subclasses
}
/**
* The Class MyWebViewClient.
*/
private class MyWebViewClient extends WebViewClient {
/** The web view previous state. */
private int webViewPreviousState;
/** The page started. */
private final int PAGE_STARTED = 0x1;
/** The page redirected. */
private final int PAGE_REDIRECTED = 0x2;
/** The dialog. */
Dialog dialog = new Dialog(getActivity());
/* (non-Javadoc)
* @see android.webkit.WebViewClient#shouldOverrideUrlLoading(android.webkit.WebView, java.lang.String)
*/
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
/* (non-Javadoc)
* @see android.webkit.WebViewClient#onPageStarted(android.webkit.WebView, java.lang.String, android.graphics.Bitmap)
*/
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view, url, favicon);
webViewPreviousState = PAGE_STARTED;
if (dialog == null || !dialog.isShowing())
dialog = ProgressDialog.show(getActivity(), "",
"Loading Please Wait", true, true,
new OnCancelListener() {
@Override
public void onCancel(DialogInterface dialog) {
// do something
}
});
}
/* (non-Javadoc)
* @see android.webkit.WebViewClient#onPageFinished(android.webkit.WebView, java.lang.String)
*/
@Override
public void onPageFinished(WebView view, String url) {
if (webViewPreviousState == PAGE_STARTED) {
dialog.dismiss();
dialog = null;
}
}
}
/** The btn back. */
Button btnBack;
/** The webview. */
WebView webview;
/* (non-Javadoc)
* @see android.support.v4.app.Fragment#onCreateView(android.view.LayoutInflater, android.view.ViewGroup, android.os.Bundle)
*/
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.payumoney_fragment, container,
false);
webview = (WebView) rootView.findViewById(R.id.payu_webview);
webview.setWebViewClient(new MyWebViewClient());
webview.getSettings().setDomStorageEnabled(true);
webview.getSettings().setJavaScriptEnabled(true);
openURL();
return rootView;
}
/**
* Opens the URL in a browser.
*/
private void openURL() {
webview.loadUrl(PAYU_MONEY_URL);
webview.requestFocus();
}
public static Fragment newInstance() {
return new PayYouMoneyFragment();
}
}
and here is payumoney layout
<?xml version="1.0" encoding="utf-8"?>
<WebView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/help_webview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scrollbars="none"
/>
I have also uploaded generalized version on Github :-
https://github.com/hiteshsahu/Android-Universal-Web-Content-Loader

- 41,955
- 17
- 205
- 154
Here is a complete code guide to PayUMoney integration via web browser.
Its been tested and deployed in a real world application

- 95
- 1
- 8
-
Thanks for your answer.. Please share the sample code bro. my mail - rranjithkumar100@gmail.com – Ranjithkumar Oct 06 '17 at 14:36
Go through this official link PayUMoney Developer site
I hope will be helpful

- 552
- 7
- 22