如何在 Android 中集成 PayU 货币网关? [关闭]
Posted
技术标签:
【中文标题】如何在 Android 中集成 PayU 货币网关? [关闭]【英文标题】:How to integrate PayU money Gateway in Android? [closed] 【发布时间】:2015-07-08 04:28:56 【问题描述】:我正在开发一个电子商务应用程序,我想在其中集成 Payumoney 支付网关。有人可以帮我一些程序,链接或教程,怎么做?谢谢。
【问题讨论】:
8K 查看和封闭的兴趣 你实现了吗?如果可以,您可以分享代码吗? 【参考方案1】:我做得很完美:) :) 你必须编辑 SuccessURL
和 FailureURL
:
它非常适合我。
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();
);
已编辑:
您现在可以使用https://www.payumoney.com/dev-guide/webcheckout/redirect.html。
【讨论】:
什么是 SuccessURL 和 failureURL。你能帮帮我吗? 您只需输入一些网址,这些网址将用于onPageFinished
你能给我一个 URL 的例子吗?
现在他们提供API,你可以试试API - payumoney.com/dev-guide
嗨,我使用了一些 www.success..php 和 failur 一样,它们都可以在测试模式下工作,并且也可以输入我的 PayUMoeny 帐户。但是在实时模式下相同的代码不起作用。有任何测试模式和直播模式的变化??【参考方案2】:
通过这个官方链接 PayUMoney Developer site
GitHub Link For Android
希望对你有帮助
https://github.com/payu-intrepos/Android-SDK-Sample-App
【讨论】:
注意:这是面向美国而非印度的 PayU。 github.com/payu-intrepos/Android-SDK-Sample-App【参考方案3】:构建自定义集成
根据 payumoney:如果您是从头开始构建网站,您 需要向我们的
API
提出发帖请求。通过您的key
和其他mandatory variable
。这也包括成功和失败页面 URL,您希望将用户带到成功和失败案例的位置。第 1 步:与我们的任何电子商务平台合作伙伴一起创建商店。
第 2 步:选择 PayUMoney 作为付款选项。
第 3 步:输入 PayUMoney 凭据,您就可以开始了。
注意:您需要开发自己的网络服务,从您的客户端应用程序获取数据并将请求转发到 payumoney 服务器,然后接受回调响应,之后您的网络服务将通知您结果。
FlipKart、FreeCharge、Snapdeal 等他们有自己的 url,负责启动支付网关,
因此结论是,您需要服务器团队的支持来启动付款并将结果返回给您的客户端应用程序。
您可以找到有关payumoney和apipayumoney integration的更多信息,
【讨论】:
drive.google.com/… 我需要这样的 你好,我现在在安卓应用中使用payu网关,你能告诉我payu android sdk和自定义浏览器之间的区别是什么我必须同时使用还是什么??【参考方案4】:这就是我在我的应用程序中所做的
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();
这里是payumoney布局
<?xml version="1.0" encoding="utf-8"?>
<WebView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/help_webview"
android:layout_
android:layout_
android:scrollbars="none"
/>
我还在 Github 上上传了通用版本:-
https://github.com/hiteshsahu/Android-Universal-Web-Content-Loader
【讨论】:
【参考方案5】:这是通过网络浏览器集成 PayUMoney 的完整代码指南。
http://navraj.net/?p=22
它已经在真实世界的应用程序中进行了测试和部署
【讨论】:
感谢您的回答.. 请分享示例代码兄弟。我的邮件 - rranjithkumar100@gmail.com【参考方案6】:集成支付网关的最简单方法是为您的应用程序使用 webview。
可以看到,FlipKart、FreeCharge、Snapdeal等大部分应用都使用相同的
【讨论】:
我知道但很抱歉,但我不知道如何使用 webview 进行应用程序。您能否提供一些链接或示例代码? 步骤 1 使用 PayU 测试服务器上的测试信用卡成功完成测试交易。商户 ID:gtKFFx SALT:eCwWELxi PayU 测试 URL:test.payu.in/_payment 以下是在测试模式下进行测试交易的测试卡详细信息 卡名 - 任何名称 卡号:5123456789012346 CVV:123 到期:2017 年 5 月 第 2 步成功完成测试交易。商家密钥:XYZ SALT:转到 --> payu.in/index?returnUrl=salt# 生产 URL 为:secure.payu.in/_payment 对于集成套件:github.com/payu-india 在github.com你可以选择Payu php kit-->github.com/payu-india/Payu_php_kit 我建议你先从上面的链接中下载文档,它比这该死的容易...... @JaydeepGoswami 您能否更详细地解释一下如何将数据和哪些数据发送到 Web 视图 TEST TRANSACTION url?以上是关于如何在 Android 中集成 PayU 货币网关? [关闭]的主要内容,如果未能解决你的问题,请参考以下文章
在 android 中集成 payU Money 时成功 url 和失败 url 是啥?
如何在 Android 应用程序中集成 BHIM 应用程序支付网关?
在 ionic android 移动应用程序中集成 ccavenue 支付网关