I am developing an app in which I want to integrate PayUMoney payment gateway. I am not able to get pure PayU Money Integration Details. I have an account of PayU Money but there is no Merchant key-salt.
I have sent a mail to merchantcare@payumoney.com
and I got this mail from PayU Team
Dear QnA,
Greetings from PayU!
We request you to kindly share Play store application link of your app from the registered email id of the account in order to get your App integrated with PayUmoney.
Please note that your website (or app) should be live ( Homepage, Products/Service with proper image, Product/Services Description and rates (in INR), Add to cart and Checkout Page etc.). Be informed that you need to sign an agreement in order to complete the process.
Feel free to get back to us for any other clarification.
Regards,
Sanju
PayUmoney Team
_______________________________________________________________________
APART OF THIS
I don't have any idea how to Integrate PayUmoney in Android Application? I have use a tutorial with there Testing Details that was working fine when we change testing details to our it giveing issue Like not showing any Guest Account Login for none PayuMoney Users.
How to resolve all these issues Please have a look.
Thanks
- 5 years ago
You have to add first PayUMoney Dependency :
compile 'com.payumoney.sdkui:plug-n-play:1.2.0'
Add PayUMoney Gradle in your Gradle file and Sync
And to Avoid Multidex Error add Multidex Dependency :
compile 'com.android.support:multidex:1.0.2'
Now you have to Create MainActivity.java (Create Activity or Go on you Payment Activity) from where you want to start PayU Money Payment.
MainActivity.java
import android.app.AlertDialog; import android.app.ProgressDialog; import android.content.DialogInterface; import android.content.Intent; import android.content.SharedPreferences; import android.graphics.Color; import android.os.AsyncTask; import android.os.Bundle; import android.os.Handler; import android.support.design.widget.TextInputLayout; import android.support.v7.widget.AppCompatRadioButton; import android.support.v7.widget.Toolbar; import android.text.Editable; import android.text.TextUtils; import android.text.TextWatcher; import android.util.Log; import android.view.View; import android.widget.EditText; import android.widget.TextView; import android.widget.Toast; import com.payumoney.core.PayUmoneyConfig; import com.payumoney.core.PayUmoneyConstants; import com.payumoney.core.PayUmoneySdkInitializer; import com.payumoney.core.entity.TransactionResponse; import com.payumoney.sdkui.ui.utils.PayUmoneyFlowManager; import com.payumoney.sdkui.ui.utils.ResultModel; import com.techximum.funbook.JsonParser.Pref; import com.techximum.funbook.R; import org.json.JSONException; import org.json.JSONObject; import java.io.IOException; import java.io.InputStream; import java.net.HttpURLConnection; import java.net.MalformedURLException; import java.net.ProtocolException; import java.net.URL; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.util.HashMap; import java.util.Iterator; import java.util.regex.Matcher; import java.util.regex.Pattern; public class MainActivity extends BaseActivity { public static final String TAG = "MainActivity : "; private String userMobile, userEmail; private SharedPreferences settings; private SharedPreferences.Editor editor; private SharedPreferences userDetailsPreference; private EditText email_et, mobile_et; private TextInputLayout email_til, mobile_til; private TextView logoutBtn; //private AppPreference mAppPreference; boolean is_pro_SENDBOK = true; // private Button payNowButton; private PayUmoneySdkInitializer.PaymentParam mPaymentParams; String productName_ = ""; double productAmount = 0; String EMAIL = "", MOBILE = ""; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // mAppPreference = new AppPreference(); Toolbar toolbar = (Toolbar) findViewById(R.id.custom_toolbar); setSupportActionBar(toolbar); toolbar.setTitleTextColor(Color.WHITE); toolbar.setTitle(getString(R.string.app_name)); settings = getSharedPreferences("settings", MODE_PRIVATE); logoutBtn = (TextView) findViewById(R.id.logout_button); email_et = (EditText) findViewById(R.id.email_et); mobile_et = (EditText) findViewById(R.id.mobile_et); //amount_et = (EditText) findViewById(R.id.amount_et); //amount_et.setFilters(new InputFilter[]{new DecimalDigitsInputFilter(7, 2)}); email_til = (TextInputLayout) findViewById(R.id.email_til); mobile_til = (TextInputLayout) findViewById(R.id.mobile_til); if (PayUmoneyFlowManager.isUserLoggedIn(getApplicationContext())) { logoutBtn.setVisibility(View.VISIBLE); } else { logoutBtn.setVisibility(View.GONE); } //logoutBtn.setOnClickListener(this); AppCompatRadioButton radio_btn_sandbox = (AppCompatRadioButton) findViewById(R.id.radio_btn_sandbox); AppCompatRadioButton radio_btn_production = (AppCompatRadioButton) findViewById(R.id.radio_btn_production); // payNowButton = (Button) findViewById(R.id.pay_now_button); // payNowButton.setOnClickListener(this); initListeners(); //Set Up SharedPref setUpUserDetails(); if (settings.getBoolean("is_prod_env", false)) { new EnvironmentPayuM_Bind().setPAYEnvironment(AppEnvironment.PRODUCTION); radio_btn_production.setChecked(true); } else { new EnvironmentPayuM_Bind().setPAYEnvironment(AppEnvironment.SANDBOX); radio_btn_sandbox.setChecked(true); } setupCitrusConfigs(); } public static String hashCal(String str) { byte[] hashseq = str.getBytes(); StringBuilder hexString = new StringBuilder(); try { MessageDigest algorithm = MessageDigest.getInstance("SHA-512"); algorithm.reset(); algorithm.update(hashseq); byte messageDigest[] = algorithm.digest(); for (byte aMessageDigest : messageDigest) { String hex = Integer.toHexString(0xFF & aMessageDigest); if (hex.length() == 1) { hexString.append("0"); } hexString.append(hex); } } catch (NoSuchAlgorithmException ignored) { } return hexString.toString(); } public static void setErrorInputLayout(EditText editText, String msg, TextInputLayout textInputLayout) { textInputLayout.setError(msg); editText.requestFocus(); } public static boolean isValidEmail(String strEmail) { return strEmail != null && android.util.Patterns.EMAIL_ADDRESS.matcher(strEmail).matches(); } public static boolean isValidPhone(String phone) { Pattern pattern = Pattern.compile(AppPreference.PHONE_PATTERN); Matcher matcher = pattern.matcher(phone); return matcher.matches(); } private void setUpUserDetails() { userDetailsPreference = getSharedPreferences(AppPreference.USER_DETAILS, MODE_PRIVATE); Bundle bundle = getIntent().getExtras(); if (bundle != null) { productAmount = bundle.getDouble("productAmount"); productName_ = bundle.getString("productName"); } EMAIL = Pref.getString(this, "email_pref"); //User's EmailID here MOBILE = "9876543210"; // User's Mobile Number userEmail = userDetailsPreference.getString(AppPreference.USER_EMAIL, EMAIL); userMobile = userDetailsPreference.getString(AppPreference.USER_MOBILE, MOBILE); email_et.setText(userEmail); mobile_et.setText(userMobile); // amount_et.setText(productAmount + ""); } @Override protected void onResume() { super.onResume(); // payNowButton.setEnabled(true); if (PayUmoneyFlowManager.isUserLoggedIn(getApplicationContext())) { logoutBtn.setVisibility(View.VISIBLE); } else { logoutBtn.setVisibility(View.GONE); } } /** * This function sets the mode to PRODUCTION in Shared Preference */ private void selectProdEnv() { new Handler(getMainLooper()).postDelayed(new Runnable() { @Override public void run() { new EnvironmentPayuM_Bind().setPAYEnvironment(AppEnvironment.PRODUCTION); editor = settings.edit(); editor.putBoolean("is_prod_env", true); editor.apply(); if (PayUmoneyFlowManager.isUserLoggedIn(getApplicationContext())) { logoutBtn.setVisibility(View.VISIBLE); } else { logoutBtn.setVisibility(View.GONE); } setupCitrusConfigs(); } }, AppPreference.MENU_DELAY); } /** * This function sets the mode to SANDBOX in Shared Preference */ private void selectSandBoxEnv() { new EnvironmentPayuM_Bind().setPAYEnvironment(AppEnvironment.SANDBOX); editor = settings.edit(); editor.putBoolean("is_prod_env", false); editor.apply(); if (PayUmoneyFlowManager.isUserLoggedIn(getApplicationContext())) { logoutBtn.setVisibility(View.VISIBLE); } else { logoutBtn.setVisibility(View.GONE); } setupCitrusConfigs(); } private void setupCitrusConfigs() { AppEnvironment appEnvironment = new EnvironmentPayuM_Bind().getPAYEnvironment(); if (appEnvironment == AppEnvironment.PRODUCTION) { Toast.makeText(MainActivity.this, "Environment Set to Production", Toast.LENGTH_SHORT).show(); } else { Toast.makeText(MainActivity.this, "Environment Set to SandBox", Toast.LENGTH_SHORT).show(); } userEmail = email_et.getText().toString().trim(); userMobile = mobile_et.getText().toString().trim(); if (validateDetails(userEmail, userMobile)) { launchPayUMoneyFlow(); } } /** * This function sets the layout for activity */ @Override protected int getLayoutResource() { return R.layout.activity_pay_umoney; } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); // Result Code is -1 send from Payumoney activity Log.d("MainActivity", "request code " + requestCode + " resultcode " + resultCode); if (requestCode == PayUmoneyFlowManager.REQUEST_CODE_PAYMENT && resultCode == RESULT_OK && data != null) { TransactionResponse transactionResponse = data.getParcelableExtra(PayUmoneyFlowManager.INTENT_EXTRA_TRANSACTION_RESPONSE); ResultModel resultModel = data.getParcelableExtra(PayUmoneyFlowManager.ARG_RESULT); // Check which object is non-null if (transactionResponse != null && transactionResponse.getPayuResponse() != null) { if (transactionResponse.getTransactionStatus().equals(TransactionResponse.TransactionStatus.SUCCESSFUL)) { //Success Transaction } else { //Failure Transaction } // Response from Payumoney String payuResponse = transactionResponse.getPayuResponse(); // Response from SURl and FURL String merchantResponse = transactionResponse.getTransactionDetails(); new AlertDialog.Builder(this) .setCancelable(false) .setMessage("Payu's Data : " + payuResponse + "\n\n\n Merchant's Data: " + merchantResponse) .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { dialog.dismiss(); } }).show(); } else if (resultModel != null && resultModel.getError() != null) { Log.d(TAG, "Error response : " + resultModel.getError().getTransactionResponse()); } else { Log.d(TAG, "Both objects are null!"); } } } private void initListeners() { email_et.addTextChangedListener(new EditTextInputWatcher(email_til)); mobile_et.addTextChangedListener(new EditTextInputWatcher(mobile_til)); AppPreference.selectedTheme = R.style.AppTheme_Grey; if (is_pro_SENDBOK) { selectSandBoxEnv(); } else { selectProdEnv(); } /*switch_disable_cards.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton compoundButton, boolean b) { PPConfig.getInstance().disableSavedCards(b); } }); switch_disable_netBanks.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton compoundButton, boolean b) { PPConfig.getInstance().disableNetBanking(b); } }); switch_disable_wallet.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton compoundButton, boolean b) { PPConfig.getInstance().disableWallet(b); } }); */ } /** * This fucntion checks if email and mobile number are valid or not. * * @param email email id entered in edit text * @param mobile mobile number entered in edit text * @return boolean value */ public boolean validateDetails(String email, String mobile) { email = email.trim(); mobile = mobile.trim(); if (TextUtils.isEmpty(mobile)) { setErrorInputLayout(mobile_et, getString(R.string.err_phone_empty), mobile_til); return false; } else if (!isValidPhone(mobile)) { setErrorInputLayout(mobile_et, getString(R.string.err_phone_not_valid), mobile_til); return false; } else if (TextUtils.isEmpty(email)) { setErrorInputLayout(email_et, getString(R.string.err_email_empty), email_til); return false; } else if (!isValidEmail(email)) { setErrorInputLayout(email_et, getString(R.string.email_not_valid), email_til); return false; } else { return true; } } /** * This function prepares the data for payment and launches payumoney plug n play sdk */ private void launchPayUMoneyFlow() { PayUmoneyConfig payUmoneyConfig = PayUmoneyConfig.getInstance(); //Use this to set your custom text on result screen button payUmoneyConfig.setDoneButtonText("Pay For Your Album"); //Use this to set your custom title for the activity payUmoneyConfig.setPayUmoneyActivityTitle(productName_); PayUmoneySdkInitializer.PaymentParam.Builder builder = new PayUmoneySdkInitializer.PaymentParam.Builder(); double amount = 0; try { amount = productAmount; } catch (Exception e) { e.printStackTrace(); } String txnId = "funbook" + System.currentTimeMillis() + ""; String phone = mobile_til.getEditText().getText().toString().trim(); String productName = productName_; String firstName = Pref.getString(getBaseContext(), "userName_pref"); String email = email_til.getEditText().getText().toString().trim(); String udf1 = ""; String udf2 = ""; String udf3 = ""; String udf4 = ""; String udf5 = ""; String udf6 = ""; String udf7 = ""; String udf8 = ""; String udf9 = ""; String udf10 = ""; AppEnvironment appEnvironment = new EnvironmentPayuM_Bind().getPAYEnvironment(); builder.setAmount(amount) .setTxnId(txnId) .setPhone(phone) .setProductName(productName) .setFirstName(firstName) .setEmail(email) .setsUrl(appEnvironment.surl()) .setfUrl(appEnvironment.furl()) .setUdf1(udf1) .setUdf2(udf2) .setUdf3(udf3) .setUdf4(udf4) .setUdf5(udf5) .setUdf6(udf6) .setUdf7(udf7) .setUdf8(udf8) .setUdf9(udf9) .setUdf10(udf10) .setIsDebug(appEnvironment.debug()) .setKey(appEnvironment.merchant_Key()) .setMerchantId(appEnvironment.merchant_ID()); try { mPaymentParams = builder.build(); /* * Hash should always be generated from your server side. * */ generateHashFromServer(mPaymentParams); /* *//** * Do not use below code when going live * Below code is provided to generate hash from sdk. * It is recommended to generate hash from server side only. * */ } catch (Exception e) { // some exception occurred Toast.makeText(this, e.getMessage(), Toast.LENGTH_LONG).show(); //payNowButton.setEnabled(true); } } /** * Thus function calculates the hash for transaction * * @param paymentParam payment params of transaction * @return payment params along with calculated merchant hash */ private PayUmoneySdkInitializer.PaymentParam calculateServerSideHashAndInitiatePayment1(final PayUmoneySdkInitializer.PaymentParam paymentParam) { StringBuilder stringBuilder = new StringBuilder(); HashMap<String, String> params = paymentParam.getParams(); stringBuilder.append(params.get(PayUmoneyConstants.KEY) + "|"); stringBuilder.append(params.get(PayUmoneyConstants.TXNID) + "|"); stringBuilder.append(params.get(PayUmoneyConstants.AMOUNT) + "|"); stringBuilder.append(params.get(PayUmoneyConstants.PRODUCT_INFO) + "|"); stringBuilder.append(params.get(PayUmoneyConstants.FIRSTNAME) + "|"); stringBuilder.append(params.get(PayUmoneyConstants.EMAIL) + "|"); stringBuilder.append(params.get(PayUmoneyConstants.UDF1) + "|"); stringBuilder.append(params.get(PayUmoneyConstants.UDF2) + "|"); stringBuilder.append(params.get(PayUmoneyConstants.UDF3) + "|"); stringBuilder.append(params.get(PayUmoneyConstants.UDF4) + "|"); stringBuilder.append(params.get(PayUmoneyConstants.UDF5) + "||||||"); AppEnvironment appEnvironment = new EnvironmentPayuM_Bind().getPAYEnvironment(); stringBuilder.append(appEnvironment.salt()); String hash = hashCal(stringBuilder.toString()); paymentParam.setMerchantHash(hash); return paymentParam; } /** * This method generates hash from server. * * @param paymentParam payments params used for hash generation */ public void generateHashFromServer(PayUmoneySdkInitializer.PaymentParam paymentParam) { //nextButton.setEnabled(false); // lets not allow the user to click the button again and again. HashMap<String, String> params = paymentParam.getParams(); // lets create the post params StringBuffer postParamsBuffer = new StringBuffer(); postParamsBuffer.append(concatParams(PayUmoneyConstants.KEY, params.get(PayUmoneyConstants.KEY))); postParamsBuffer.append(concatParams(PayUmoneyConstants.AMOUNT, params.get(PayUmoneyConstants.AMOUNT))); postParamsBuffer.append(concatParams(PayUmoneyConstants.TXNID, params.get(PayUmoneyConstants.TXNID))); postParamsBuffer.append(concatParams(PayUmoneyConstants.EMAIL, params.get(PayUmoneyConstants.EMAIL))); postParamsBuffer.append(concatParams("productinfo", params.get(PayUmoneyConstants.PRODUCT_INFO))); postParamsBuffer.append(concatParams("firstname", params.get(PayUmoneyConstants.FIRSTNAME))); postParamsBuffer.append(concatParams(PayUmoneyConstants.UDF1, params.get(PayUmoneyConstants.UDF1))); postParamsBuffer.append(concatParams(PayUmoneyConstants.UDF2, params.get(PayUmoneyConstants.UDF2))); postParamsBuffer.append(concatParams(PayUmoneyConstants.UDF3, params.get(PayUmoneyConstants.UDF3))); postParamsBuffer.append(concatParams(PayUmoneyConstants.UDF4, params.get(PayUmoneyConstants.UDF4))); postParamsBuffer.append(concatParams(PayUmoneyConstants.UDF5, params.get(PayUmoneyConstants.UDF5))); String postParams = postParamsBuffer.charAt(postParamsBuffer.length() - 1) == '&' ? postParamsBuffer.substring(0, postParamsBuffer.length() - 1).toString() : postParamsBuffer.toString(); // lets make an api call GetHashesFromServerTask getHashesFromServerTask = new GetHashesFromServerTask(); getHashesFromServerTask.execute(postParams); } protected String concatParams(String key, String value) { return key + "=" + value + "&"; } /** * This AsyncTask generates hash from server. */ private class GetHashesFromServerTask extends AsyncTask<String, String, String> { private ProgressDialog progressDialog; @Override protected void onPreExecute() { super.onPreExecute(); progressDialog = new ProgressDialog(MainActivity.this); progressDialog.setMessage("Please wait..."); progressDialog.show(); } @Override protected String doInBackground(String... postParams) { String merchantHash = ""; try { URL url = new URL("https://payu.herokuapp.com/get_hash"); //TODO Below url is just for testing purpose, merchant needs to replace this with their server side hash generation url String postParam = postParams[0]; byte[] postParamsByte = postParam.getBytes("UTF-8"); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setRequestMethod("POST"); conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); conn.setRequestProperty("Content-Length", String.valueOf(postParamsByte.length)); conn.setDoOutput(true); conn.getOutputStream().write(postParamsByte); InputStream responseInputStream = conn.getInputStream(); StringBuffer responseStringBuffer = new StringBuffer(); byte[] byteContainer = new byte[1024]; for (int i; (i = responseInputStream.read(byteContainer)) != -1; ) { responseStringBuffer.append(new String(byteContainer, 0, i)); } JSONObject response = new JSONObject(responseStringBuffer.toString()); Iterator<String> payuHashIterator = response.keys(); while (payuHashIterator.hasNext()) { String key = payuHashIterator.next(); switch (key) { /** * This hash is mandatory and needs to be generated from merchant's server side * */ case "payment_hash": merchantHash = response.getString(key); break; default: break; } } } catch (MalformedURLException e) { e.printStackTrace(); } catch (ProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (JSONException e) { e.printStackTrace(); } return merchantHash; } @Override protected void onPostExecute(String merchantHash) { super.onPostExecute(merchantHash); progressDialog.dismiss(); // payNowButton.setEnabled(true); if (merchantHash.isEmpty() || merchantHash.equals("")) { Toast.makeText(MainActivity.this, "Could not generate hash", Toast.LENGTH_SHORT).show(); } else { mPaymentParams.setMerchantHash(merchantHash); PayUmoneyFlowManager.startPayUMoneyFlow(mPaymentParams, MainActivity.this, AppPreference.selectedTheme, true); } } } public static class EditTextInputWatcher implements TextWatcher { private TextInputLayout textInputLayout; EditTextInputWatcher(TextInputLayout textInputLayout) { this.textInputLayout = textInputLayout; } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { } @Override public void afterTextChanged(Editable s) { if (s.toString().length() > 0) { textInputLayout.setError(null); textInputLayout.setErrorEnabled(false); } } } }
AppEnvironment.java
/** * Created by Hemant Sharma on 20/3/18. */ public enum AppEnvironment { SANDBOX { @Override public String merchant_Key() { return "LLKwG0"; } @Override public String merchant_ID() { return "393463"; } @Override public String furl() { return "https://www.payumoney.com/mobileapp/payumoney/failure.php"; } @Override public String surl() { return "https://www.payumoney.com/mobileapp/payumoney/success.php"; } @Override public String salt() { return "qauKbEAJ"; } @Override public boolean debug() { return true; } }, PRODUCTION { @Override public String merchant_Key() { return "dcwQGU"; } //O15vkB @Override public String merchant_ID() { return "4931752"; } //4819816 @Override public String furl() { return "https://www.payumoney.com/mobileapp/payumoney/failure.php"; } @Override public String surl() { return "https://www.payumoney.com/mobileapp/payumoney/success.php"; } @Override public String salt() { return "dzC2i5pp"; } //LU1EhObh @Override public boolean debug() { return false; } }; public abstract String merchant_Key(); public abstract String merchant_ID(); public abstract String furl(); public abstract String surl(); public abstract String salt(); public abstract boolean debug(); }
BaseActivity.java
import android.os.Bundle; import android.support.v4.content.ContextCompat; import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.Toolbar; import android.view.MenuItem; import com.techximum.funbook.R; public abstract class BaseActivity extends AppCompatActivity { public Toolbar toolbar; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(getLayoutResource()); toolbar = (Toolbar) findViewById(R.id.toolbar); if (toolbar != null) { setSupportActionBar(toolbar); getSupportActionBar().setDisplayShowHomeEnabled(true); getSupportActionBar().setLogo(R.drawable.logo_color_funbook); toolbar.setTitleTextColor(ContextCompat.getColor(this, R.color.graycolorLogin)); } } protected abstract int getLayoutResource(); @Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. int id = item.getItemId(); //noinspection SimplifiableIfStatement if (id == android.R.id.home) { onBackPressed(); return true; } return super.onOptionsItemSelected(item); } }
EnvironmentPayuM_Bind.java
/** * Created by Hemant on 3/20/2018. */ public class EnvironmentPayuM_Bind { AppEnvironment appEnvironment; EnvironmentPayuM_Bind() { appEnvironment = AppEnvironment.SANDBOX; } public AppEnvironment getPAYEnvironment() { return appEnvironment; } public void setPAYEnvironment(AppEnvironment appEnvironment) { this.appEnvironment = appEnvironment; } }
- 3 years ago
public class MakePaymentClass { public MakePaymentClass(Activity act, String phone, String productName, String fName, String emailID, String amount, StartPaymentMethod startPayment) { if (Long.parseLong(amount) > 0) { try { String userName = (fName.trim()).replace(" ", "_"); String txnId = (new SimpleDateFormat("yyyyMMddHHmm").format(new Date())); String udf = ""; PayUmoneySdkInitializer.PaymentParam.Builder builder = new PayUmoneySdkInitializer.PaymentParam.Builder(); builder.setAmount(amount) // Payment amount .setTxnId(txnId) // Transaction ID .setPhone(phone) // User Phone number .setProductName(productName) // Product Name or description .setFirstName(userName) // User First name .setEmail(emailID) // User Email ID .setsUrl(PAYUMONEY_SURL) // Success URL (surl) .setfUrl(PAYUMONEY_FURL) //Failure URL (furl) .setUdf1(udf) .setUdf2(udf) .setUdf3(udf) .setUdf4(udf) .setUdf5(udf) .setUdf6(udf) .setUdf7(udf) .setUdf8(udf) .setUdf9(udf) .setUdf10(udf) .setIsDebug(false) // Integration environment - true (Debug)/ false(Production) .setKey(PAYUMONEY_Key) // Merchant key .setMerchantId(PAYUMONEY_MID); // Merchant ID String hashSequence = (PAYUMONEY_Key + "|" + txnId + "|" + amount + "|" + productName + "|" + userName + "|" + emailID + "|" + udf + "|" + udf + "|" + udf + "|" + udf + "|" + udf + "||||||" + PAYUMONEY_Salt).trim(); //Log.d("PAYmENThashSend", hashSequence);//declare paymentParam object String serverCalculatedHash = hashCal("SHA-512", hashSequence); //Log.d("PAYmENThashREsponce", serverCalculatedHash);//declare paymentParam object PayUmoneySdkInitializer.PaymentParam paymentParam = builder.build(); //set the hash paymentParam.setMerchantHash(serverCalculatedHash); startPayment.pay(paymentParam); } catch (Exception e) { showCustDialog(act,"Payment Error",""+e.getMessage()); e.printStackTrace(); } } else { Toast.makeText(act, "You can't Pay Less then " + act.getString(R.string.rupee) + "1", Toast.LENGTH_SHORT).show(); } } private String hashCal(String type, String hashString) { StringBuilder hash = new StringBuilder(); MessageDigest messageDigest = null; try { messageDigest = MessageDigest.getInstance(type); messageDigest.update(hashString.getBytes()); byte[] mdbytes = messageDigest.digest(); for (byte hashByte : mdbytes) { hash.append(Integer.toString((hashByte & 0xff) + 0x100, 16).substring(1)); } } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } return hash.toString(); } public interface StartPaymentMethod { void pay(PayUmoneySdkInitializer.PaymentParam paymentParam); }
To call or make payment
new MakePaymentClass(mActivity, contactNo, producteName,First, UserName,paidAmount, new MakePaymentClass.StartPaymentMethod() { @Override public void pay(PayUmoneySdkInitializer.PaymentParam paymentParam) { dialog.dismiss(); // Invoke the following function to open the checkout page. PayUmoneyFlowManager.startPayUMoneyFlow(paymentParam, mActivity, R.style.AppTheme_Green, true); } });
Hot Questions