问题
I am doing my first application. Now i need to integrate payu integration in app using custom browser. i don't have knowledge on how to do this. I searched for this, but i failed. please any one suggest me or provide me links for this integration. thank you in advance.
like this :
https://drive.google.com/folderview?id=0B4URmsDLhGXmfjFmbDQ5b2V0bVhjdTZMNExMVHRFMG1PRFFYeUV0LU9nSWU4U0pqaW00OU0&usp=drive_web&ddrp=1#
回答1:
Although u have to try at least once from yourself there are lot of SO questions available anyways this is complete solution to integrate payu in your app.It is very simple.
First define your variables likes this:
String hash,hashSequence;
String post_Data;
String merchant_key="your key";
String salt="your salt";
String surl = "your surl";
String furl = "your furl";
String productinfo = "your product info or you can put anything here";
String txnid ="";
String amount;
Handler mHandler = new Handler();
String firstname, email,phone;
WebView webView ;
After defining values your on createview should be like this:
@SuppressLint("JavascriptInterface")
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.web_view);
webView = (WebView) findViewById(R.id.webView);
String hashSequence1 = merchant_key + "|" + txnid + "|" + amount + "|" + productinfo + "|" +
firstname+ "|" + email + "|||||||||||" + salt;
hash=hashCal("SHA-512",hashSequence1);
webView.setWebViewClient(new WebViewClient() {
@Override
public void onReceivedError(WebView view, int errorCode,
String description, String failingUrl) {
// TODO Auto-generated method stub
System.out.println(">>>>>>>>>>>>>>onReceivedError>>>>>>>>>>>>>>>>>>");
Toast.makeText(activity, "Oh no! " + description, Toast.LENGTH_SHORT).show();
}
@Override
public void onReceivedSslError(WebView view,
SslErrorHandler handler, SslError error) {
// TODO Auto-generated method stub
System.out.println(">>>>>>>>>>>>>>onReceivedSslError>>>>>>>>>>>>>>>>>>");
Toast.makeText(activity, "SslError! " + error, Toast.LENGTH_SHORT).show();
handler.proceed();
}
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
// TODO Auto-generated method stub
System.out.println(">>>>>>>>>>>>>>shouldOverrideUrlLoading>>>>>>>>>>>>>>>>>>");
return true;
}
@Override
public void onPageFinished(WebView view, String url) {
// TODO Auto-generated method stub
System.out.println(">>>>>>>>>>>>>>onPageFinished>>>>>>>>>>>>>>>>>>");
super.onPageFinished(view, url);
}
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view, url, favicon);
System.out.println(">>>>>>>>>>>>>>onPageStarted>>>>>>>>>>>>>>>>>>");
}
});
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(true);
webView.getSettings().setLoadWithOverviewMode(true);
webView.addJavascriptInterface(new PayUJavaScriptInterface(this), "PayUMoney");
post_Data = "hash="+hash+"&key="+merchant_key+"&txnid="+txnid+"&amount="+amount+
"&productinfo="+productinfo+"&firstname="+firstname+ "&email="+email+"&phone="+phone+
"&surl="+surl+"&furl="+ furl+ "&service_provider="+ "payu_paisa";
webView.postUrl("https://secure.payu.in/_payment", EncodingUtils.getBytes(post_Data, "base64"));
}
PayUJavaScriptInterface method:
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;
Intent intent = new Intent(PayMentGateWay.this, BoutiqueActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
intent.putExtra("result", "success");
intent.putExtra("paymentId", paymentId);
startActivity(intent);
finish();
}
});
}
}
Calculate hash from this method:
public String hashCal(String type,String str){
byte[] hashseq=str.getBytes();
StringBuffer hexString = new StringBuffer();
try{
MessageDigest algorithm = MessageDigest.getInstance(type);
algorithm.reset();
algorithm.update(hashseq);
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();
}
}
That's it.
来源:https://stackoverflow.com/questions/32345519/payment-processing-integration-android