|
|
|
|
@@ -1,11 +1,7 @@
|
|
|
|
|
package ch.pizzaleu.android.fragment.createOrder;
|
|
|
|
|
|
|
|
|
|
import android.annotation.SuppressLint;
|
|
|
|
|
import android.annotation.TargetApi;
|
|
|
|
|
import android.app.Activity;
|
|
|
|
|
import android.content.Context;
|
|
|
|
|
import android.content.Intent;
|
|
|
|
|
import android.net.http.SslError;
|
|
|
|
|
import android.os.Build;
|
|
|
|
|
import android.os.Bundle;
|
|
|
|
|
import android.support.annotation.NonNull;
|
|
|
|
|
@@ -16,7 +12,6 @@ import android.util.Log;
|
|
|
|
|
import android.view.LayoutInflater;
|
|
|
|
|
import android.view.View;
|
|
|
|
|
import android.view.ViewGroup;
|
|
|
|
|
import android.webkit.JavascriptInterface;
|
|
|
|
|
import android.webkit.WebResourceError;
|
|
|
|
|
import android.webkit.WebResourceRequest;
|
|
|
|
|
import android.webkit.WebView;
|
|
|
|
|
@@ -27,16 +22,11 @@ import com.afollestad.materialdialogs.MaterialDialog;
|
|
|
|
|
import com.braintreepayments.api.dropin.DropInActivity;
|
|
|
|
|
import com.braintreepayments.api.dropin.DropInRequest;
|
|
|
|
|
import com.braintreepayments.api.dropin.DropInResult;
|
|
|
|
|
import com.crashlytics.android.Crashlytics;
|
|
|
|
|
import com.google.android.gms.wallet.Cart;
|
|
|
|
|
import com.google.gson.Gson;
|
|
|
|
|
import com.wdullaer.materialdatetimepicker.date.DatePickerDialog;
|
|
|
|
|
import com.wdullaer.materialdatetimepicker.time.TimePickerDialog;
|
|
|
|
|
import com.wdullaer.materialdatetimepicker.time.Timepoint;
|
|
|
|
|
|
|
|
|
|
import org.jsoup.Jsoup;
|
|
|
|
|
import org.jsoup.nodes.Document;
|
|
|
|
|
|
|
|
|
|
import java.text.DateFormat;
|
|
|
|
|
import java.text.SimpleDateFormat;
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
@@ -64,7 +54,6 @@ import ch.pizzaleu.android.helper.SessionHelper;
|
|
|
|
|
import ch.pizzaleu.android.helper.SharedPrefsHelper;
|
|
|
|
|
import ch.pizzaleu.android.model.PaymentMethodModel;
|
|
|
|
|
import ch.pizzaleu.android.model.PaymentTokenModel;
|
|
|
|
|
import ch.pizzaleu.android.model.PostfinancePaymentResponseModel;
|
|
|
|
|
import ch.pizzaleu.android.model.StoreShiftModel;
|
|
|
|
|
import ch.pizzaleu.android.model.cart.CartInfoModel;
|
|
|
|
|
import ch.pizzaleu.android.model.cart.CartProductModel;
|
|
|
|
|
@@ -1121,48 +1110,78 @@ public class CreateOrderSummaryFragment extends CreateOrderBaseFragment {
|
|
|
|
|
@RequiresApi(Build.VERSION_CODES.N)
|
|
|
|
|
@Override
|
|
|
|
|
public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
|
|
|
|
|
if(request.getUrl().toString().contains(ApiConstants.PAYMENT_WEBVIEW_SUCCESS_POSTFINANCE_TWINT) ||
|
|
|
|
|
request.getUrl().toString().contains(ApiConstants.PAYMENT_WEBVIEW_FAIL_POSTFINANCE_TWINT)){
|
|
|
|
|
/*
|
|
|
|
|
// Canceled because response json from PostFinance fr apple Webview is not valid
|
|
|
|
|
// payment success or fail. response json will handle at "handlePaymentResponse" method of "PaymentJavaScriptInterface" class below
|
|
|
|
|
if(request.getUrl().toString().contains(ApiConstants.PAYMENT_WEBVIEW_REDIRECT_URL_POSTFINANCE_TWINT_SUCCESS) ||
|
|
|
|
|
request.getUrl().toString().contains(ApiConstants.PAYMENT_WEBVIEW_REDIRECT_URL_POSTFINANCE_TWINT_FAIL)){
|
|
|
|
|
createOrderActivity.setPaymentWebViewVisibility(false);
|
|
|
|
|
}
|
|
|
|
|
else if(request.getUrl().toString().equals(ApiConstants.PAYMENT_WEBVIEW_MAIN_PAGE_HTTP) ||
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
// payment success
|
|
|
|
|
if(request.getUrl().toString().contains(ApiConstants.PAYMENT_WEBVIEW_REDIRECT_URL_POSTFINANCE_TWINT_SUCCESS) ||
|
|
|
|
|
request.getUrl().toString().equals(ApiConstants.PAYMENT_WEBVIEW_MAIN_PAGE_HTTP) ||
|
|
|
|
|
request.getUrl().toString().equals(ApiConstants.PAYMENT_WEBVIEW_MAIN_PAGE_HTTPS)){
|
|
|
|
|
createOrderActivity.setPaymentWebViewVisibility(false);
|
|
|
|
|
createOrderActivity.onNextClicked(FRAGMENT_NAME);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
else if(request.getUrl().toString().contains(ApiConstants.PAYMENT_WEBVIEW_MAIN_PAGE_HTTP) ||
|
|
|
|
|
// payment fail
|
|
|
|
|
else if(request.getUrl().toString().contains(ApiConstants.PAYMENT_WEBVIEW_REDIRECT_URL_POSTFINANCE_TWINT_FAIL) ||
|
|
|
|
|
request.getUrl().toString().contains(ApiConstants.PAYMENT_WEBVIEW_MAIN_PAGE_HTTP) ||
|
|
|
|
|
request.getUrl().toString().contains(ApiConstants.PAYMENT_WEBVIEW_MAIN_PAGE_HTTPS)){
|
|
|
|
|
createOrderActivity.setPaymentWebViewVisibility(false);
|
|
|
|
|
DialogHelper.showAlertDialog(BaseActivity.currentActivity, getString(R.string.error_message));
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return super.shouldOverrideUrlLoading(view, request);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@SuppressWarnings("deprecation")
|
|
|
|
|
@Override
|
|
|
|
|
public boolean shouldOverrideUrlLoading(WebView view, String url) {
|
|
|
|
|
if(url.contains(ApiConstants.PAYMENT_WEBVIEW_SUCCESS_POSTFINANCE_TWINT) ||
|
|
|
|
|
url.contains(ApiConstants.PAYMENT_WEBVIEW_FAIL_POSTFINANCE_TWINT)){
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
// Canceled because response json from PostFinance fr apple Webview is not valid
|
|
|
|
|
// payment success or fail. response json will handle at "handlePaymentResponse" method of "PaymentJavaScriptInterface" class below
|
|
|
|
|
if(url.contains(ApiConstants.PAYMENT_WEBVIEW_REDIRECT_URL_POSTFINANCE_TWINT_SUCCESS) ||
|
|
|
|
|
url.contains(ApiConstants.PAYMENT_WEBVIEW_REDIRECT_URL_POSTFINANCE_TWINT_FAIL)){
|
|
|
|
|
createOrderActivity.setPaymentWebViewVisibility(false);
|
|
|
|
|
}
|
|
|
|
|
else if(url.equals(ApiConstants.PAYMENT_WEBVIEW_MAIN_PAGE_HTTP) ||
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
// payment success
|
|
|
|
|
if(url.contains(ApiConstants.PAYMENT_WEBVIEW_REDIRECT_URL_POSTFINANCE_TWINT_SUCCESS) ||
|
|
|
|
|
url.equals(ApiConstants.PAYMENT_WEBVIEW_MAIN_PAGE_HTTP) ||
|
|
|
|
|
url.equals(ApiConstants.PAYMENT_WEBVIEW_MAIN_PAGE_HTTPS)){
|
|
|
|
|
createOrderActivity.setPaymentWebViewVisibility(false);
|
|
|
|
|
createOrderActivity.onNextClicked(FRAGMENT_NAME);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
else if(url.contains(ApiConstants.PAYMENT_WEBVIEW_MAIN_PAGE_HTTP) ||
|
|
|
|
|
// payment fail
|
|
|
|
|
else if(url.contains(ApiConstants.PAYMENT_WEBVIEW_REDIRECT_URL_POSTFINANCE_TWINT_FAIL) ||
|
|
|
|
|
url.contains(ApiConstants.PAYMENT_WEBVIEW_MAIN_PAGE_HTTP) ||
|
|
|
|
|
url.contains(ApiConstants.PAYMENT_WEBVIEW_MAIN_PAGE_HTTPS)){
|
|
|
|
|
createOrderActivity.setPaymentWebViewVisibility(false);
|
|
|
|
|
DialogHelper.showAlertDialog(BaseActivity.currentActivity, getString(R.string.error_message));
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return super.shouldOverrideUrlLoading(view, url);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
// Canceled because response json from PostFinance fr apple Webview is not valid
|
|
|
|
|
@Override
|
|
|
|
|
public void onPageFinished(WebView view, String url) {
|
|
|
|
|
view.loadUrl("javascript:PaymentResponseHandler.handlePaymentResponse" +
|
|
|
|
|
"('<html>'+document.getElementsByTagName('html')[0].innerHTML+'</html>');");
|
|
|
|
|
"(document.getElementsByTagName('pre')[0].innerHTML);");
|
|
|
|
|
}
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) {
|
|
|
|
|
@@ -1172,7 +1191,8 @@ public class CreateOrderSummaryFragment extends CreateOrderBaseFragment {
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
paymentWebView.loadUrl(ApiConstants.PAYMENT_WEBVIEW_URL_POSTFINANCE_TWINT + orderId);
|
|
|
|
|
paymentWebView.addJavascriptInterface(new PaymentJavaScriptInterface(getActivity()), "PaymentResponseHandler");
|
|
|
|
|
// Canceled because response json from PostFinance fr apple Webview is not valid
|
|
|
|
|
//paymentWebView.addJavascriptInterface(new PaymentJavaScriptInterface(getActivity()), "PaymentResponseHandler");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private String fixEndTime(String endTime){
|
|
|
|
|
@@ -1203,6 +1223,8 @@ public class CreateOrderSummaryFragment extends CreateOrderBaseFragment {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
// Canceled because response json from PostFinance fr apple Webview is not valid
|
|
|
|
|
class PaymentJavaScriptInterface {
|
|
|
|
|
|
|
|
|
|
private Context ctx;
|
|
|
|
|
@@ -1212,13 +1234,11 @@ public class CreateOrderSummaryFragment extends CreateOrderBaseFragment {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@JavascriptInterface
|
|
|
|
|
public void handlePaymentResponse(String html) {
|
|
|
|
|
public void handlePaymentResponse(String jsonString) {
|
|
|
|
|
try{
|
|
|
|
|
if(html.contains("success") && html.contains("message") && html.contains("error_code") && html.contains("data")){
|
|
|
|
|
Document document = Jsoup.parse(html);
|
|
|
|
|
String json = document.getElementsByTag("pre").text();
|
|
|
|
|
if(jsonString.contains("success") && jsonString.contains("message") && jsonString.contains("error_code") && jsonString.contains("data")){
|
|
|
|
|
Gson gson = new Gson();
|
|
|
|
|
PostfinancePaymentResponseModel postfinancePaymentResponseModel = gson.fromJson(json, PostfinancePaymentResponseModel.class);
|
|
|
|
|
PostfinancePaymentResponseModel postfinancePaymentResponseModel = gson.fromJson(jsonString, PostfinancePaymentResponseModel.class);
|
|
|
|
|
|
|
|
|
|
if(postfinancePaymentResponseModel.isSuccess()){
|
|
|
|
|
createOrderActivity.onNextClicked(FRAGMENT_NAME);
|
|
|
|
|
@@ -1226,18 +1246,6 @@ public class CreateOrderSummaryFragment extends CreateOrderBaseFragment {
|
|
|
|
|
else {
|
|
|
|
|
DialogHelper.showAlertDialog(BaseActivity.currentActivity, postfinancePaymentResponseModel.getMessage());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
final WebView paymentWebView = createOrderActivity.getPaymentWebView();
|
|
|
|
|
paymentWebView.post(new Runnable() {
|
|
|
|
|
@Override
|
|
|
|
|
public void run() {
|
|
|
|
|
paymentWebView.removeJavascriptInterface("PaymentResponseHandler");
|
|
|
|
|
paymentWebView.loadData("<html><head></head><body></body></html>", "text/html", "UTF-8");
|
|
|
|
|
paymentWebView.clearHistory();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
*/
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e){
|
|
|
|
|
@@ -1246,4 +1254,5 @@ public class CreateOrderSummaryFragment extends CreateOrderBaseFragment {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
*/
|
|
|
|
|
}
|
|
|
|
|
|