PayU 統合のためにアプリにカスタム ブラウザを統合しました。PayU URL ( https://secure.payu.in/_payment ) にパラメーターを送信していません。サーバー側でこれを行っています(PayUにパラメーターを送信しています)。ブラウザのカスタマイズだけが必要なので、これを使用しています。これは私には問題なく機能していますが、支払いが成功した後、空の白い画面が表示されます。この白い空の画面の後にアプリに移動する方法。
カスタム ブラウザの URL を取得するにはどうすればよいですか?
参照リンク: https://github.com/payu-intrepos/Android-Custom-Browser/wiki/v5.2.2
依存:
compile 'com.payu.custombrowser:payu-custom-browser:5.2.2'
コード:
カスタムブラウザxl:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/r_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal">
<FrameLayout
android:id="@+id/parent"
android:visibility="gone"
android:layout_alignParentBottom="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<WebView
android:id="@+id/webview"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<LinearLayout
android:layout_width="match_parent"
android:id="@+id/trans_overlay"
android:layout_height="match_parent"
android:orientation="horizontal"
>
</LinearLayout>
</RelativeLayout>
custombrowser.java
try {
Class.forName("com.payu.custombrowser.Bank");
final Bank bank = new Bank() {
@Override
public void registerBroadcast(BroadcastReceiver broadcastReceiver, IntentFilter filter) {
mReceiver = broadcastReceiver;
registerReceiver(broadcastReceiver, filter);
}
@Override
public void unregisterBroadcast(BroadcastReceiver broadcastReceiver) {
if(mReceiver != null){
unregisterReceiver(mReceiver);
mReceiver = null;
}
}
@Override
public void onHelpUnavailable() {
findViewById(R.id.parent).setVisibility(View.GONE);
findViewById(R.id.trans_overlay).setVisibility(View.GONE);
}
@Override
public void onBankError() {
findViewById(R.id.parent).setVisibility(View.GONE);
findViewById(R.id.trans_overlay).setVisibility(View.GONE);
}
@Override
public void onHelpAvailable() {
findViewById(R.id.parent).setVisibility(View.VISIBLE);
}
};
Bundle args = new Bundle();
args.putInt("webView", R.id.webview);
args.putInt("tranLayout",R.id.trans_overlay);
args.putInt("mainLayout",R.id.r_layout);
args.putBoolean("showCustom", true);
bank.setArguments(args);
findViewById(R.id.parent).bringToFront();
try {
getSupportFragmentManager().beginTransaction().setCustomAnimations(R.anim.cb_fade_in, R.anim.cb_face_out).add(R.id.parent, bank).commit();
}catch(Exception e)
{
e.printStackTrace();
finish();
}
webView.setWebChromeClient(new PayUWebChromeClient(bank));
webView.setWebViewClient(new PayUWebViewClient(bank));
} catch (ClassNotFoundException e) {
webView.getSettings().setSupportMultipleWindows(true);
webView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
webView.addJavascriptInterface(new Object() {
@JavascriptInterface
public void onSuccess() {
onSuccess("");
}
@JavascriptInterface
public void onSuccess(final String result) {
runOnUiThread(new Runnable() {
@Override
public void run() {
Intent intent = new Intent();
intent.putExtra("result", result);
setResult(RESULT_OK, intent);
finish();
}
// }
});
}
@JavascriptInterface
public void onFailure() {
onFailure("");
}
@JavascriptInterface
public void onFailure(final String result) {
runOnUiThread(new Runnable() {
@Override
public void run() {
Intent intent = new Intent();
intent.putExtra("result", result);
setResult(RESULT_CANCELED, intent);
finish();
}
});
}
}, "PayU");
webView.setWebChromeClient(new WebChromeClient() {
});
webView.setWebViewClient(new WebViewClient());
}
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setDomStorageEnabled(true);
String PostData="UserUniqueID=" + UUUID + "&OrderID=" + orderid + "&PFID=" + pid + "&ReloadCash=" + reloadcash + "&DeviceID=" + DEVICEID ;
webView.postUrl(WebUrl.Bankurl, PostData.getBytes());
//Weburl.posturl is my server side bank url.
}
@Override
public void onBackPressed(){
boolean disableBack = false;
if(cancelTransaction){
cancelTransaction = false;
Intent intent = new Intent();
intent.putExtra("result", "Transaction canceled due to back pressed!");
setResult(RESULT_CANCELED, intent);
super.onBackPressed();
return;
}
try {
Log.v("TAG_PAUSEURLL", "" + "PAUSEURL");
Bundle bundle = getPackageManager().getApplicationInfo(getPackageName(), PackageManager.GET_META_DATA).metaData;
disableBack = bundle.containsKey("payu_disable_back") && bundle.getBoolean("payu_disable_back");
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
if(!disableBack) {
AlertDialog.Builder alertDialog = new AlertDialog.Builder(this);
alertDialog.setCancelable(false);
alertDialog.setMessage("Do you really want to cancel the transaction ?");
alertDialog.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
cancelTransaction = true;
dialog.dismiss();
onBackPressed();
}
});
alertDialog.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
alertDialog.show();
}
}
@Override
protected void onDestroy() {
super.onDestroy();
webView.clearCache(true);
webView.clearHistory();
webView.destroy();
}