|
|
|
|
@@ -1,48 +1,53 @@
|
|
|
|
|
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;
|
|
|
|
|
import android.support.annotation.RequiresApi;
|
|
|
|
|
import android.support.v7.widget.LinearLayoutManager;
|
|
|
|
|
import android.support.v7.widget.RecyclerView;
|
|
|
|
|
import android.util.Log;
|
|
|
|
|
import android.view.LayoutInflater;
|
|
|
|
|
import android.view.View;
|
|
|
|
|
import android.view.ViewGroup;
|
|
|
|
|
import android.widget.Toast;
|
|
|
|
|
import android.webkit.JavascriptInterface;
|
|
|
|
|
import android.webkit.WebResourceError;
|
|
|
|
|
import android.webkit.WebResourceRequest;
|
|
|
|
|
import android.webkit.WebView;
|
|
|
|
|
import android.webkit.WebViewClient;
|
|
|
|
|
|
|
|
|
|
import com.afollestad.materialdialogs.DialogAction;
|
|
|
|
|
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;
|
|
|
|
|
import java.util.Calendar;
|
|
|
|
|
import java.util.Date;
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
import java.util.Random;
|
|
|
|
|
|
|
|
|
|
import butterknife.BindString;
|
|
|
|
|
import butterknife.BindView;
|
|
|
|
|
import butterknife.ButterKnife;
|
|
|
|
|
import butterknife.OnClick;
|
|
|
|
|
import ch.datatrans.payment.AliasPaymentMethod;
|
|
|
|
|
import ch.datatrans.payment.BusinessException;
|
|
|
|
|
import ch.datatrans.payment.Payment;
|
|
|
|
|
import ch.datatrans.payment.PaymentMethod;
|
|
|
|
|
import ch.datatrans.payment.PaymentMethodType;
|
|
|
|
|
import ch.datatrans.payment.android.DisplayContext;
|
|
|
|
|
import ch.datatrans.payment.android.IPaymentProcessStateListener;
|
|
|
|
|
import ch.datatrans.payment.android.PaymentProcessAndroid;
|
|
|
|
|
import ch.datatrans.payment.android.ResourceProvider;
|
|
|
|
|
import ch.pizzaleu.android.R;
|
|
|
|
|
import ch.pizzaleu.android.activity.BaseActivity;
|
|
|
|
|
import ch.pizzaleu.android.activity.CreateOrderActivity;
|
|
|
|
|
@@ -57,9 +62,9 @@ import ch.pizzaleu.android.helper.DialogHelper;
|
|
|
|
|
import ch.pizzaleu.android.helper.PriceHelper;
|
|
|
|
|
import ch.pizzaleu.android.helper.SessionHelper;
|
|
|
|
|
import ch.pizzaleu.android.helper.SharedPrefsHelper;
|
|
|
|
|
import ch.pizzaleu.android.model.DatatransInitInfoModel;
|
|
|
|
|
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;
|
|
|
|
|
@@ -73,7 +78,7 @@ import retrofit2.Response;
|
|
|
|
|
* Created by cimenmus on 17/10/2017.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
public class CreateOrderSummaryFragment extends CreateOrderBaseFragment implements IPaymentProcessStateListener {
|
|
|
|
|
public class CreateOrderSummaryFragment extends CreateOrderBaseFragment {
|
|
|
|
|
|
|
|
|
|
@BindView(R.id.orderPersonFullnamePizzalinkInfoLayout) AppInfoView orderPersonFullnamePizzalinkInfoLayout;
|
|
|
|
|
@BindView(R.id.orderShippingMethodPizzalinkInfoLayout) AppInfoView orderShippingMethodPizzalinkInfoLayout;
|
|
|
|
|
@@ -110,7 +115,6 @@ public class CreateOrderSummaryFragment extends CreateOrderBaseFragment implemen
|
|
|
|
|
private ProductOnOrderSummaryRecyclerAdapter productOnOrderSummaryRecyclerAdapter;
|
|
|
|
|
private StoreShiftModel storeShiftModel;
|
|
|
|
|
private PaymentTokenModel braintreePaymentTokenModel;
|
|
|
|
|
private DatatransInitInfoModel datatransInitInfoModel;
|
|
|
|
|
|
|
|
|
|
public CreateOrderSummaryFragment() {}
|
|
|
|
|
|
|
|
|
|
@@ -524,14 +528,9 @@ public class CreateOrderSummaryFragment extends CreateOrderBaseFragment implemen
|
|
|
|
|
createOrderActivity.getSelectedPaymentMethod().getPaymentMethodType() == PaymentMethodModel.PaymentMethodType.TRANSFER){
|
|
|
|
|
createOrder(getCreateOrderParams(null));
|
|
|
|
|
}
|
|
|
|
|
else if(createOrderActivity.getSelectedPaymentMethod().getPaymentMethodType() == PaymentMethodModel.PaymentMethodType.POST_FINANCE_CARD) {
|
|
|
|
|
DialogHelper.hideLoadingDialog();
|
|
|
|
|
Toast.makeText(BaseActivity.currentActivity, "Post Finance payment has not been implemented yet.", Toast.LENGTH_LONG).show();
|
|
|
|
|
}
|
|
|
|
|
else if(createOrderActivity.getSelectedPaymentMethod().getPaymentMethodType() == PaymentMethodModel.PaymentMethodType.TWINT) {
|
|
|
|
|
DialogHelper.hideLoadingDialog();
|
|
|
|
|
//startDatatransPayment();
|
|
|
|
|
Toast.makeText(BaseActivity.currentActivity, "Twint payment has not been implemented yet.", Toast.LENGTH_LONG).show();
|
|
|
|
|
else if(createOrderActivity.getSelectedPaymentMethod().getPaymentMethodType() == PaymentMethodModel.PaymentMethodType.POST_FINANCE_CARD ||
|
|
|
|
|
createOrderActivity.getSelectedPaymentMethod().getPaymentMethodType() == PaymentMethodModel.PaymentMethodType.TWINT) {
|
|
|
|
|
createOrder(getCreateOrderParams(null));
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
DialogHelper.hideLoadingDialog();
|
|
|
|
|
@@ -548,7 +547,14 @@ public class CreateOrderSummaryFragment extends CreateOrderBaseFragment implemen
|
|
|
|
|
public void onResponse(Call<ResponseObject<Integer>> call, Response<ResponseObject<Integer>> response) {
|
|
|
|
|
DialogHelper.hideLoadingDialog();
|
|
|
|
|
if(response.isSuccessful() && response.body().isSuccess()){
|
|
|
|
|
createOrderActivity.onNextClicked(FRAGMENT_NAME);
|
|
|
|
|
|
|
|
|
|
if(createOrderActivity.getSelectedPaymentMethod().getPaymentMethodType() == PaymentMethodModel.PaymentMethodType.POST_FINANCE_CARD ||
|
|
|
|
|
createOrderActivity.getSelectedPaymentMethod().getPaymentMethodType() == PaymentMethodModel.PaymentMethodType.TWINT){
|
|
|
|
|
showPaymentWebView(response.body().getData());
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
createOrderActivity.onNextClicked(FRAGMENT_NAME);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
ApiErrorUtils.parseError(response);
|
|
|
|
|
@@ -589,34 +595,6 @@ public class CreateOrderSummaryFragment extends CreateOrderBaseFragment implemen
|
|
|
|
|
return params;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// for datatrans payment
|
|
|
|
|
private HashMap<String, Object> getCreateOrderParams(String datatransTransactionId, String datatransPaymentMethodName){
|
|
|
|
|
HashMap<String, Object> params = new HashMap<>();
|
|
|
|
|
params.put("customer_id", SessionHelper.getUser().getId());
|
|
|
|
|
params.put("shipping_method_title", createOrderActivity.getSelectedShippingMethod().getTitle());
|
|
|
|
|
params.put("shipping_method_code", createOrderActivity.getSelectedShippingMethod().getCode());
|
|
|
|
|
params.put("address_id", createOrderActivity.getSelectedShippingAddress().getId());
|
|
|
|
|
params.put("payment_method_title", createOrderActivity.getSelectedPaymentMethod().getTitle());
|
|
|
|
|
params.put("payment_method_code", createOrderActivity.getSelectedPaymentMethod().getCode());
|
|
|
|
|
params.put("comment", createOrderNote());
|
|
|
|
|
params.put("is_pizza_pass_campaign", createOrderActivity.getCartInfo().isPizzapassCampaignUsed());
|
|
|
|
|
params.put("is_kebap_pass_campaign", createOrderActivity.getCartInfo().isKebappassCampaignUsed());
|
|
|
|
|
params.put("application_id", ApiConstants.APP_TYPE_ID_ANDROID);
|
|
|
|
|
params.put("datatrans_merchant_id", datatransInitInfoModel.getMerchantId());
|
|
|
|
|
params.put("datatrans_ref_no", datatransInitInfoModel.getReferenceNumber());
|
|
|
|
|
params.put("datatrans_transaction_id", datatransTransactionId);
|
|
|
|
|
params.put("datatrans_payment_method_name", datatransPaymentMethodName);
|
|
|
|
|
|
|
|
|
|
if(SessionHelper.getSelectedCoupon() != null){
|
|
|
|
|
params.put("coupon", SessionHelper.getSelectedCoupon().getCode());
|
|
|
|
|
}
|
|
|
|
|
if(dateOfOrderString != null && !dateOfOrderString.isEmpty() &&
|
|
|
|
|
timeOfOrder != null && !timeOfOrder.isEmpty()){
|
|
|
|
|
params.put("delivery_date", dateOfOrderString + " " + timeOfOrder);
|
|
|
|
|
}
|
|
|
|
|
return params;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private String createOrderNote(){
|
|
|
|
|
|
|
|
|
|
CreateOrderActivity createOrderActivity = (CreateOrderActivity) BaseActivity.currentActivity;
|
|
|
|
|
@@ -752,7 +730,6 @@ public class CreateOrderSummaryFragment extends CreateOrderBaseFragment implemen
|
|
|
|
|
fixCartTotalList();
|
|
|
|
|
orderPriceRecyclerAdapter.notifyDataSetChanged();
|
|
|
|
|
createBraintreePaymentToken();
|
|
|
|
|
//getDatatransInitInfoModel();
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
DialogHelper.hideLoadingDialog();
|
|
|
|
|
@@ -796,34 +773,6 @@ public class CreateOrderSummaryFragment extends CreateOrderBaseFragment implemen
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void getDatatransInitInfoModel(){
|
|
|
|
|
|
|
|
|
|
Call<ResponseObject<DatatransInitInfoModel>> call = ApiService.apiInterface.getDatatransInitInfoModel(
|
|
|
|
|
"/" + SessionHelper.getSelectedStore().getStoreName() + ApiEndPoints.API_GET_DATATRANS_INFO + SessionHelper.getCustomerToken().getToken());
|
|
|
|
|
|
|
|
|
|
call.enqueue(new Callback<ResponseObject<DatatransInitInfoModel>>() {
|
|
|
|
|
@Override
|
|
|
|
|
public void onResponse(Call<ResponseObject<DatatransInitInfoModel>> call, Response<ResponseObject<DatatransInitInfoModel>> response) {
|
|
|
|
|
DialogHelper.hideLoadingDialog();
|
|
|
|
|
if(response.isSuccessful() &&
|
|
|
|
|
response.body().getData() != null &&
|
|
|
|
|
response.body().isSuccess()){
|
|
|
|
|
datatransInitInfoModel = response.body().getData();
|
|
|
|
|
Log.i("fuhrfuhruhfr", "fhurhfurfhurfh");
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
ApiErrorUtils.parseError(response);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onFailure(Call<ResponseObject<DatatransInitInfoModel>> call, Throwable t) {
|
|
|
|
|
DialogHelper.hideLoadingDialog();
|
|
|
|
|
DialogHelper.showFailedDialog();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void startBraintreePayment(){
|
|
|
|
|
|
|
|
|
|
// CVV kodu default olarak gozukmuyor.
|
|
|
|
|
@@ -871,131 +820,6 @@ public class CreateOrderSummaryFragment extends CreateOrderBaseFragment implemen
|
|
|
|
|
startActivityForResult(paymentRequest.getIntent(BaseActivity.currentActivity), REQUEST_CODE_BRAINTREE_PAYMENT);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void startDatatransPayment(){
|
|
|
|
|
|
|
|
|
|
if(datatransInitInfoModel == null ||
|
|
|
|
|
datatransInitInfoModel.getMerchantId().isEmpty() ||
|
|
|
|
|
datatransInitInfoModel.getReferenceNumber().isEmpty()){
|
|
|
|
|
/*
|
|
|
|
|
datatransInitInfoModel = new DatatransInitInfoModel(
|
|
|
|
|
ApiConstants.DATATRANS_MERCHANT_ID_TEST,
|
|
|
|
|
String.valueOf(Integer.valueOf(ApiConstants.DATATRANS_REFERENCE_NUMBER_TEST) + new Random().nextInt(1000)));
|
|
|
|
|
*/
|
|
|
|
|
DialogHelper.showAlertDialog(BaseActivity.currentActivity, getString(R.string.something_went_wrong));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String currencyCode = "CHF";
|
|
|
|
|
String amountString = PriceHelper.removeCurrencyFromPrice(cartTotalList.get(cartTotalList.size() - 1).getText());
|
|
|
|
|
double amountDouble;
|
|
|
|
|
int amountInt;
|
|
|
|
|
try {
|
|
|
|
|
amountDouble = Double.valueOf(amountString);
|
|
|
|
|
amountDouble *= 100; // we have to multiply amount with 100 -> e.g. if amout is CHF 10, you have to send 10*100 = 1000
|
|
|
|
|
amountInt = (int) amountDouble;
|
|
|
|
|
}catch (Exception e){
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
String signature = null;
|
|
|
|
|
//DisplayContext displayContext = new DisplayContext(new ResourceProvider(), createOrderActivity);
|
|
|
|
|
DisplayContext displayContext = new DisplayContext(new ResourceProvider(), createOrderActivity.getPaymentContainerLayout());
|
|
|
|
|
|
|
|
|
|
// Payment method selection/input by library (standard mode)
|
|
|
|
|
Payment payment = new Payment(datatransInitInfoModel.getMerchantId(), datatransInitInfoModel.getReferenceNumber(), currencyCode, amountInt, signature);
|
|
|
|
|
ArrayList<PaymentMethod> datatransPaymentMethods = new ArrayList<>();
|
|
|
|
|
/*
|
|
|
|
|
datatransPaymentMethods.add(new PaymentMethod(PaymentMethodType.VISA));
|
|
|
|
|
datatransPaymentMethods.add(new PaymentMethod(PaymentMethodType.MASTERCARD));
|
|
|
|
|
datatransPaymentMethods.add(new PaymentMethod(PaymentMethodType.AMEX));
|
|
|
|
|
datatransPaymentMethods.add(new PaymentMethod(PaymentMethodType.DINERS));
|
|
|
|
|
datatransPaymentMethods.add(new PaymentMethod(PaymentMethodType.JCB));
|
|
|
|
|
datatransPaymentMethods.add(new PaymentMethod(PaymentMethodType.PAYPAL));
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(createOrderActivity.getSelectedPaymentMethod().getPaymentMethodType() == PaymentMethodModel.PaymentMethodType.TWINT){
|
|
|
|
|
datatransPaymentMethods.add(new PaymentMethod(PaymentMethodType.TWINT));
|
|
|
|
|
}
|
|
|
|
|
else if(createOrderActivity.getSelectedPaymentMethod().getPaymentMethodType() == PaymentMethodModel.PaymentMethodType.POST_FINANCE_CARD){
|
|
|
|
|
datatransPaymentMethods.add(new PaymentMethod(PaymentMethodType.PFCARD));
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PaymentProcessAndroid datatransPaymentProcess = new PaymentProcessAndroid(displayContext, payment, datatransPaymentMethods);
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
//Payment method preselected by app, input by library
|
|
|
|
|
PaymentMethodType selectedPaymentMethodType;
|
|
|
|
|
if(createOrderActivity.getSelectedPaymentMethod().getPaymentMethodType() == PaymentMethodModel.PaymentMethodType.TWINT){
|
|
|
|
|
selectedPaymentMethodType = PaymentMethodType.TWINT;
|
|
|
|
|
}
|
|
|
|
|
else if(createOrderActivity.getSelectedPaymentMethod().getPaymentMethodType() == PaymentMethodModel.PaymentMethodType.POST_FINANCE_CARD){
|
|
|
|
|
selectedPaymentMethodType = PaymentMethodType.PFCARD;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
AliasRequest aliasRequest = new AliasRequest(merchantId, currencyCode, new PaymentMethod(selectedPaymentMethodType));
|
|
|
|
|
PaymentProcessAndroid datatransPaymentProcess = new PaymentProcessAndroid(displayContext, aliasRequest);
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
// common part
|
|
|
|
|
datatransPaymentProcess.setTestingEnabled(true);
|
|
|
|
|
datatransPaymentProcess.addStateListener(this);
|
|
|
|
|
datatransPaymentProcess.start();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void paymentProcessStateChanged(final PaymentProcessAndroid datatransPaymentProcess) {
|
|
|
|
|
BaseActivity.currentActivity.runOnUiThread(new Runnable() {
|
|
|
|
|
@Override
|
|
|
|
|
public void run() {
|
|
|
|
|
switch (datatransPaymentProcess.getState()) {
|
|
|
|
|
|
|
|
|
|
case STARTED:
|
|
|
|
|
createOrderActivity.setPaymentLayoutVisibility(true);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case NOT_STARTED:
|
|
|
|
|
createOrderActivity.setPaymentLayoutVisibility(false);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case COMPLETED:
|
|
|
|
|
createOrderActivity.setPaymentLayoutVisibility(false);
|
|
|
|
|
String transcationId = datatransPaymentProcess.getTransactionId();
|
|
|
|
|
String paymentMethodName = datatransPaymentProcess.getPaymentMethodType().getName();
|
|
|
|
|
AliasPaymentMethod aliasPaymentMethod = datatransPaymentProcess.getAliasPaymentMethod();
|
|
|
|
|
if (aliasPaymentMethod != null) {
|
|
|
|
|
String json = aliasPaymentMethod.toJson();
|
|
|
|
|
Log.i("dgyef", "vryf");
|
|
|
|
|
// serialize and securely store aliasPaymentMethod for reuse
|
|
|
|
|
}
|
|
|
|
|
createDatatransPayment(transcationId, paymentMethodName);
|
|
|
|
|
break;
|
|
|
|
|
case CANCELED:
|
|
|
|
|
createOrderActivity.setPaymentLayoutVisibility(false);
|
|
|
|
|
DialogHelper.showAlertDialog(BaseActivity.currentActivity, paymentCanceledText);
|
|
|
|
|
break;
|
|
|
|
|
case ERROR:
|
|
|
|
|
createOrderActivity.setPaymentLayoutVisibility(false);
|
|
|
|
|
Exception e = datatransPaymentProcess.getException();
|
|
|
|
|
if (e instanceof BusinessException) {
|
|
|
|
|
BusinessException be = (BusinessException)e;
|
|
|
|
|
int errorCode = be.getErrorCode();// Datatrans error code if needed
|
|
|
|
|
// display some error message
|
|
|
|
|
} else {
|
|
|
|
|
// unexpected technical exception, either fatal TechnicalException or // javax.net.ssl.SSLException (certificate error)
|
|
|
|
|
}
|
|
|
|
|
DialogHelper.showAlertDialog(BaseActivity.currentActivity, e.getMessage());
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void createBraintreePayment(final DropInResult dropInResult){
|
|
|
|
|
DialogHelper.showLoadingDialog();
|
|
|
|
|
Call<ResponseObject> call = ApiService.apiInterface.createBraintreePayment(
|
|
|
|
|
@@ -1023,40 +847,6 @@ public class CreateOrderSummaryFragment extends CreateOrderBaseFragment implemen
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void createDatatransPayment(final String transactionId, final String datatransPaymentMethodName){
|
|
|
|
|
DialogHelper.showLoadingDialog();
|
|
|
|
|
|
|
|
|
|
HashMap<String, Object> params = new HashMap<>();
|
|
|
|
|
params.put("merchant_id", datatransInitInfoModel.getMerchantId());
|
|
|
|
|
params.put("ref_no", datatransInitInfoModel.getReferenceNumber());
|
|
|
|
|
params.put("transaction_id", transactionId);
|
|
|
|
|
params.put("datatrans_payment_method_name", datatransPaymentMethodName);
|
|
|
|
|
params.put("amount", PriceHelper.removeCurrencyFromPrice(createOrderActivity.getCartInfo().getCartTotalModel().getText()));
|
|
|
|
|
|
|
|
|
|
Call<ResponseObject> call = ApiService.apiInterface.createDatatransPayment(
|
|
|
|
|
"/" + SessionHelper.getSelectedStore().getStoreName() + ApiEndPoints.API_CREATE_DATATRANS_PAYMENT + SessionHelper.getCustomerToken().getToken(), params);
|
|
|
|
|
call.enqueue(new Callback<ResponseObject>() {
|
|
|
|
|
@Override
|
|
|
|
|
public void onResponse(Call<ResponseObject> call, final Response<ResponseObject> response) {
|
|
|
|
|
DialogHelper.hideLoadingDialog();
|
|
|
|
|
if(response.isSuccessful() &&
|
|
|
|
|
response.body().getData() != null &&
|
|
|
|
|
response.body().isSuccess()){
|
|
|
|
|
createOrder(getCreateOrderParams(transactionId, datatransPaymentMethodName));
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
ApiErrorUtils.parseError(response);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onFailure(Call<ResponseObject> call, Throwable t) {
|
|
|
|
|
DialogHelper.hideLoadingDialog();
|
|
|
|
|
DialogHelper.showFailedDialog();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private HashMap<String, Object> getBraintreePaymentParams(DropInResult dropInResult){
|
|
|
|
|
HashMap<String, Object> params = new HashMap<>();
|
|
|
|
|
params.put("payment_method_nonce", dropInResult.getPaymentMethodNonce().getNonce());
|
|
|
|
|
@@ -1318,6 +1108,69 @@ public class CreateOrderSummaryFragment extends CreateOrderBaseFragment implemen
|
|
|
|
|
tempTotalList.clear();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void showPaymentWebView(int orderId){
|
|
|
|
|
createOrderActivity.setPaymentWebViewVisibility(true);
|
|
|
|
|
final WebView paymentWebView = createOrderActivity.getPaymentWebView();
|
|
|
|
|
paymentWebView.setVisibility(View.VISIBLE);
|
|
|
|
|
paymentWebView.getSettings().setJavaScriptEnabled(true);
|
|
|
|
|
paymentWebView.setWebViewClient(new WebViewClient(){
|
|
|
|
|
|
|
|
|
|
@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)){
|
|
|
|
|
createOrderActivity.setPaymentWebViewVisibility(false);
|
|
|
|
|
}
|
|
|
|
|
else if(request.getUrl().toString().equals("http://www.pizza-leu.ch/") ||
|
|
|
|
|
request.getUrl().toString().equals("https://www.pizza-leu.ch/")){
|
|
|
|
|
createOrderActivity.setPaymentWebViewVisibility(false);
|
|
|
|
|
createOrderActivity.onNextClicked(FRAGMENT_NAME);
|
|
|
|
|
}
|
|
|
|
|
else if(request.getUrl().toString().contains("http://www.pizza-leu.ch/") ||
|
|
|
|
|
request.getUrl().toString().contains("https://www.pizza-leu.ch/")){
|
|
|
|
|
createOrderActivity.setPaymentWebViewVisibility(false);
|
|
|
|
|
DialogHelper.showAlertDialog(BaseActivity.currentActivity, getString(R.string.error_message));
|
|
|
|
|
}
|
|
|
|
|
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)){
|
|
|
|
|
createOrderActivity.setPaymentWebViewVisibility(false);
|
|
|
|
|
}
|
|
|
|
|
else if(url.equals("http://www.pizza-leu.ch/") ||
|
|
|
|
|
url.equals("https://www.pizza-leu.ch/")){
|
|
|
|
|
createOrderActivity.setPaymentWebViewVisibility(false);
|
|
|
|
|
createOrderActivity.onNextClicked(FRAGMENT_NAME);
|
|
|
|
|
}
|
|
|
|
|
else if(url.contains("http://www.pizza-leu.ch/") || url.contains("https://www.pizza-leu.ch/")){
|
|
|
|
|
createOrderActivity.setPaymentWebViewVisibility(false);
|
|
|
|
|
DialogHelper.showAlertDialog(BaseActivity.currentActivity, getString(R.string.error_message));
|
|
|
|
|
}
|
|
|
|
|
return super.shouldOverrideUrlLoading(view, url);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onPageFinished(WebView view, String url) {
|
|
|
|
|
view.loadUrl("javascript:PaymentResponseHandler.handlePaymentResponse" +
|
|
|
|
|
"('<html>'+document.getElementsByTagName('html')[0].innerHTML+'</html>');");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) {
|
|
|
|
|
super.onReceivedError(view, request, error);
|
|
|
|
|
DialogHelper.showAlertDialog(BaseActivity.currentActivity, getString(R.string.error_message));
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
paymentWebView.loadUrl(ApiConstants.PAYMENT_WEBVIEW_URL_POSTFINANCE_TWINT + orderId);
|
|
|
|
|
paymentWebView.addJavascriptInterface(new PaymentJavaScriptInterface(getActivity()), "PaymentResponseHandler");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private String fixEndTime(String endTime){
|
|
|
|
|
try {
|
|
|
|
|
String[] time = endTime.split(":");
|
|
|
|
|
@@ -1345,4 +1198,48 @@ public class CreateOrderSummaryFragment extends CreateOrderBaseFragment implemen
|
|
|
|
|
return endTime;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class PaymentJavaScriptInterface {
|
|
|
|
|
|
|
|
|
|
private Context ctx;
|
|
|
|
|
|
|
|
|
|
PaymentJavaScriptInterface(Context ctx) {
|
|
|
|
|
this.ctx = ctx;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@JavascriptInterface
|
|
|
|
|
public void handlePaymentResponse(String html) {
|
|
|
|
|
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();
|
|
|
|
|
Gson gson = new Gson();
|
|
|
|
|
PostfinancePaymentResponseModel postfinancePaymentResponseModel = gson.fromJson(json, PostfinancePaymentResponseModel.class);
|
|
|
|
|
|
|
|
|
|
if(postfinancePaymentResponseModel.isSuccess()){
|
|
|
|
|
createOrderActivity.onNextClicked(FRAGMENT_NAME);
|
|
|
|
|
}
|
|
|
|
|
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){
|
|
|
|
|
DialogHelper.showAlertDialog(BaseActivity.currentActivity, getString(R.string.error_message));
|
|
|
|
|
Crashlytics.logException(e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|