Skip to content

Commit

Permalink
Merge pull request #5 from ashrafamin91/3.34.4
Browse files Browse the repository at this point in the history
3.34.4
  • Loading branch information
apis17 authored Jun 12, 2024
2 parents b5ece47 + b8f8ce3 commit 7cf3f4b
Show file tree
Hide file tree
Showing 4 changed files with 147 additions and 61 deletions.
27 changes: 26 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ Find all mp_channel list here https://github.com/FiuuPayment/Mobile-XDK-Fiuu_Exa

### Google Pay

Prepare paymentDetails :

HashMap<String, Object> paymentDetails = new HashMap<>();

// TODO: Follow Google’s instructions to request production access for your app: https://developers.google.com/pay/api/android/guides/test-and-deploy/request-prod-access
Expand All @@ -87,12 +89,35 @@ Find all mp_channel list here https://github.com/FiuuPayment/Mobile-XDK-Fiuu_Exa
paymentDetails.put(MOLPayActivity.mp_bill_email, "[email protected]");
paymentDetails.put(MOLPayActivity.mp_bill_mobile, "123456789");

paymentDetails.put(MOLPayActivity.mp_extended_vcode, false); // Set true if your account enabled extended Verify Payment
paymentDetails.put(MOLPayActivity.mp_extended_vcode, false); // Optional : Set true if your account enabled extended Verify Payment

Start payment by sending paymentDetails to ActivityGP.class :

Intent intent = new Intent(MainActivity.this, ActivityGP.class); // Used ActivityGP for Google Pay
intent.putExtra(MOLPayActivity.MOLPayPaymentDetails, paymentDetails);
startActivityForResult(intent, MOLPayActivity.MOLPayXDK);

Get payment result in onActivityResult :
NOTE : Verify payment using formula VrfKey = md5(Amount+secret_key+Domain+TranID+StatCode). Refer Payment results - Google Pay

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
super.onActivityResult(requestCode, resultCode, data);

Log.e("logGooglePay" , "onActivityResult requestCode = " + requestCode);
Log.e("logGooglePay" , "onActivityResult resultCode = " + resultCode);

if (requestCode == MOLPayActivity.MOLPayXDK && data != null){
if (data.getStringExtra(MOLPayActivity.MOLPayTransactionResult) != null) {
Log.d(MOLPayActivity.MOLPAY, "MOLPay result = " + data.getStringExtra(MOLPayActivity.MOLPayTransactionResult));
TextView tw = findViewById(R.id.resultTV);
tw.setText(data.getStringExtra(MOLPayActivity.MOLPayTransactionResult));
}
}

}

## Payment results - Google Pay

=========================================
Expand Down
18 changes: 12 additions & 6 deletions molpayxdk/src/main/java/com/molpay/molpayxdk/MOLPayActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import android.os.Environment;
import android.os.Message;

import androidx.activity.OnBackPressedCallback;
import androidx.annotation.NonNull;
import androidx.annotation.RequiresApi;
import androidx.core.app.ActivityCompat;
Expand Down Expand Up @@ -128,12 +129,6 @@ private void closemolpay() {
}
}

@SuppressLint("MissingSuperCall")
@Override
public void onBackPressed() {
closemolpay();
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
Expand Down Expand Up @@ -242,6 +237,17 @@ public void onReceiveValue(String qrdata) {
return false;
});

// Register a callback for handling the back press
OnBackPressedCallback callback = new OnBackPressedCallback(true) {
@Override
public void handleOnBackPressed() {
Log.e("logGooglePay" , "WebCore onBackPressed");
closemolpay();
}
};

// Add the callback to the OnBackPressedDispatcher
getOnBackPressedDispatcher().addCallback(this, callback);
}

private void nativeWebRequestUrlUpdates(String url) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import android.widget.ProgressBar;
import android.widget.Toast;

import androidx.activity.OnBackPressedCallback;
import androidx.activity.result.ActivityResultLauncher;
import androidx.activity.result.IntentSenderRequest;
import androidx.activity.result.contract.ActivityResultContracts;
Expand Down Expand Up @@ -115,6 +116,18 @@ protected void onCreate(Bundle savedInstanceState) {
// Check Google Pay availability
model = new ViewModelProvider(this).get(ViewModelGP.class);
model.canUseGooglePay.observe(this, this::setGooglePayAvailable);

// Register a callback for handling the back press
OnBackPressedCallback callback = new OnBackPressedCallback(true) {
@Override
public void handleOnBackPressed() {
// Do nothing - prevent user from performing backpress
Log.e("logGooglePay" , "ActivityGP backpressed");
}
};

// Add the callback to the OnBackPressedDispatcher
getOnBackPressedDispatcher().addCallback(this, callback);
}

private void initializeUi() {
Expand Down Expand Up @@ -289,12 +302,16 @@ protected void onActivityResult(int requestCode, int resultCode, @Nullable Inten
case AppCompatActivity.RESULT_CANCELED:
// The user cancelled the payment attempt
// Response Error CallBack
assert data != null;
response = data.getStringExtra("response");
Log.e("logGooglePay" , "RESULT_CANCELED response = " + response);
Intent resultCancel = new Intent();
resultCancel.putExtra(MOLPayActivity.MOLPayTransactionResult, response);
setResult(RESULT_CANCELED, resultCancel);
if (data != null) {
response = data.getStringExtra("response");
Log.e("logGooglePay" , "RESULT_CANCELED response = " + response);
Intent resultCancel = new Intent();
resultCancel.putExtra(MOLPayActivity.MOLPayTransactionResult, response);
setResult(RESULT_CANCELED, resultCancel);
} else {
setResult(RESULT_CANCELED, null);
}

finish();
break;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import android.webkit.WebViewClient;
import android.widget.ProgressBar;

import androidx.activity.OnBackPressedCallback;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.AppCompatTextView;
Expand All @@ -46,6 +47,8 @@ public class WebActivity extends AppCompatActivity {
public static String isSandbox;

private CountDownTimer countDownTimer;
private String requestType = "";

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand Down Expand Up @@ -79,6 +82,13 @@ protected void onCreate(Bundle savedInstanceState) {
wvGateway.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
wvGateway.getSettings().setSupportMultipleWindows(true);

// Mobile web view settings
wvGateway.getSettings().setLoadWithOverviewMode(true);
wvGateway.getSettings().setUseWideViewPort(true);
wvGateway.getSettings().setSupportZoom(true);
wvGateway.getSettings().setBuiltInZoomControls(true);
wvGateway.getSettings().setDisplayZoomControls(false);

PaymentThread paymentThread = new PaymentThread();
paymentThread.setValue(paymentInput, paymentInfo); // set value
Thread thread = new Thread(paymentThread);
Expand All @@ -92,6 +102,17 @@ protected void onCreate(Bundle savedInstanceState) {
e.printStackTrace();
}

// Register a callback for handling the back press
OnBackPressedCallback callback = new OnBackPressedCallback(true) {
@Override
public void handleOnBackPressed() {
// Do nothing - prevent user from performing backpress
Log.e("logGooglePay" , "WebActivity GP backpressed");
}
};

// Add the callback to the OnBackPressedDispatcher
getOnBackPressedDispatcher().addCallback(this, callback);
}

private void onStartTimOut() {
Expand Down Expand Up @@ -129,58 +150,60 @@ public void onTick(long millisUntilFinished) {
thread.join();
queryResultStr[0] = queryResultThread.getValue();

try {
JSONObject queryResultObj = new JSONObject(queryResultStr[0]);
String responseBody = queryResultObj.getString("responseBody");
JSONObject responseBodyObj = new JSONObject(responseBody);
if (queryResultStr[0] != null) {
try {
JSONObject queryResultObj = new JSONObject(queryResultStr[0]);
String responseBody = queryResultObj.getString("responseBody");
JSONObject responseBodyObj = new JSONObject(responseBody);

// If StatCode
if (responseBodyObj.has("StatCode")){
String statCodeValue = responseBodyObj.getString("StatCode");
// If StatCode
if (responseBodyObj.has("StatCode")){
String statCodeValue = responseBodyObj.getString("StatCode");

Intent intent = new Intent();
intent.putExtra("response", String.valueOf(responseBodyObj));
Intent intent = new Intent();
intent.putExtra("response", String.valueOf(responseBodyObj));

Log.e("logGooglePay" , "statCodeValue " + statCodeValue);
Log.e("logGooglePay" , "statCodeValue " + statCodeValue);

if (statCodeValue.equals("00")) {
if (statCodeValueSuccess) {
Log.e("logGooglePay" , "statCodeValueSuccess finish");
onFinish();
}
} else if (statCodeValue.equals("11")) {
cancel();
pbLoading.setVisibility(View.GONE);
tvLoading.setVisibility(View.GONE);

String errorCode = null;
try {
errorCode = responseBodyObj.getString("ErrorCode");
} catch (JSONException e) {
throw new RuntimeException(e);
}
String errorDesc = null;
try {
errorDesc = responseBodyObj.getString("ErrorDesc");
} catch (JSONException e) {
throw new RuntimeException(e);
}
if (statCodeValue.equals("00")) {
if (statCodeValueSuccess) {
Log.e("logGooglePay" , "statCodeValueSuccess finish");
onFinish();
}
} else if (statCodeValue.equals("11")) {
cancel();
pbLoading.setVisibility(View.GONE);
tvLoading.setVisibility(View.GONE);

String errorCode = null;
try {
errorCode = responseBodyObj.getString("ErrorCode");
} catch (JSONException e) {
throw new RuntimeException(e);
}
String errorDesc = null;
try {
errorDesc = responseBodyObj.getString("ErrorDesc");
} catch (JSONException e) {
throw new RuntimeException(e);
}

new AlertDialog.Builder(WebActivity.this)
.setTitle("Payment Failed")
.setMessage(errorCode + " : " + errorDesc)
.setCancelable(false)
.setPositiveButton("CLOSE", (dialog, which) -> {
setResult(RESULT_CANCELED, intent);
finish();
}).show();
} else if (statCodeValue.equals("22")) {
// Do Nothing - It will auto handle
new AlertDialog.Builder(WebActivity.this)
.setTitle("Payment Failed")
.setMessage(errorCode + " : " + errorDesc)
.setCancelable(false)
.setPositiveButton("CLOSE", (dialog, which) -> {
setResult(RESULT_CANCELED, intent);
finish();
}).show();
} else if (statCodeValue.equals("22")) {
// Do Nothing - It will auto handle
}
}
}

} catch (JSONException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
}
}
} catch (InterruptedException e) {
e.printStackTrace();
Expand Down Expand Up @@ -226,11 +249,19 @@ private void onLoadHtmlWebView(String plainHtml) {
tvLoading.setVisibility(View.VISIBLE);
statCodeValueSuccess = false;

String encodedHtml = Base64.encodeToString(plainHtml.getBytes(), Base64.NO_PADDING);

Log.e("logGooglePay" , "plainHtml = " + plainHtml);

if (plainHtml.contains("xdkHTMLRedirection")) {
xdkHTMLRedirection = StringUtils.substringBetween(plainHtml, "xdkHTMLRedirection' value='", "'");
wvGateway.loadData(xdkHTMLRedirection, "text/html", "base64");
} else if (requestType.equalsIgnoreCase("REDIRECT")) {
wvGateway.loadData(encodedHtml, "text/html", "base64");
pbLoading.setVisibility(View.GONE);
tvLoading.setVisibility(View.GONE);
wvGateway.setVisibility(View.VISIBLE);
} else {
String encodedHtml = Base64.encodeToString(plainHtml.getBytes(), Base64.NO_PADDING);
wvGateway.loadData(encodedHtml, "text/html", "base64");
}

Expand All @@ -240,6 +271,9 @@ public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request

if (request.getUrl().toString().contains("result.php")) {
statCodeValueSuccess = true;
pbLoading.setVisibility(View.VISIBLE);
tvLoading.setVisibility(View.VISIBLE);
wvGateway.setVisibility(View.GONE);
}

return super.shouldOverrideUrlLoading(view, request);
Expand Down Expand Up @@ -300,6 +334,9 @@ public void onRequestData(JSONObject response) {
if (txnData.has("AppDeepLinkURL")) {
// AppData.getInstance().setRedirectAppUrl(txnData.getString("AppDeepLinkURL"));
}
if (txnData.has("RequestType")) {
requestType = txnData.getString("RequestType");
}
if (txnData.has("RequestData")) {

if (txnData.get("RequestData") instanceof JSONObject) {
Expand Down Expand Up @@ -390,8 +427,9 @@ public void run() {

RMSGooglePay pay = new RMSGooglePay();
JSONObject result = (JSONObject) pay.queryPaymentResult(transaction);
resp = result.toString();

if (result != null) {
resp = result.toString();
}
}
}

Expand Down

0 comments on commit 7cf3f4b

Please sign in to comment.