- datatrans deleted

- posfinance added
This commit is contained in:
2019-12-21 23:58:31 +03:00
parent 2f9e02c32e
commit 3a7482841d
11 changed files with 260 additions and 299 deletions

Binary file not shown.

Binary file not shown.

View File

@@ -92,6 +92,7 @@ dependencies {
implementation 'io.nlopez.smartlocation:library:3.3.3'
implementation 'q.rorbin:badgeview:1.1.0'
implementation 'com.braintreepayments.api:braintree:2.22.0'
implementation 'org.jsoup:jsoup:1.11.1'
implementation('com.braintreepayments.api:drop-in:3.7.1') {
exclude group: 'com.braintreepayments.api', module: 'braintree'
}
@@ -99,7 +100,6 @@ dependencies {
transitive = true
}
implementation(name:'datatrans_payment_v3.5.1', ext:'aar')
api 'com.google.guava:guava:26.0-android'
testImplementation 'junit:junit:4.12'
}

View File

@@ -5,6 +5,7 @@ import android.os.Bundle;
import android.support.v4.app.FragmentManager;
import android.support.v7.widget.CardView;
import android.view.View;
import android.webkit.WebView;
import android.widget.FrameLayout;
import com.badoualy.stepperindicator.StepperIndicator;
@@ -31,7 +32,7 @@ import ch.pizzaleu.android.model.cart.CartInfoModel;
public class CreateOrderActivity extends BaseActivity {
@BindView(R.id.createOrderCardView) CardView createOrderCardView;
@BindView(R.id.paymentContainerLayout) FrameLayout paymentContainerLayout;
@BindView(R.id.paymentWebView) WebView paymentWebView;
@BindView(R.id.stepperIndicator) StepperIndicator stepperIndicator;
private FragmentManager fragmentManager;
@@ -240,20 +241,30 @@ public class CreateOrderActivity extends BaseActivity {
return orderNote;
}
public void setPaymentLayoutVisibility(final boolean show){
runOnUiThread(new Runnable() {
@Override
public void run() {
if(show){
createOrderCardView.setVisibility(View.GONE);
paymentContainerLayout.setVisibility(View.VISIBLE);
}
else {
createOrderCardView.setVisibility(View.VISIBLE);
paymentContainerLayout.setVisibility(View.GONE);
}
public void setPaymentWebViewVisibility(final boolean show){
if(show){
createOrderCardView.setVisibility(View.GONE);
paymentWebView.setVisibility(View.VISIBLE);
}
else {
createOrderCardView.setVisibility(View.VISIBLE);
paymentWebView.setVisibility(View.GONE);
}
}
@Override
public void onBackPressed() {
if(paymentWebView.getVisibility() == View.VISIBLE){
if(paymentWebView.canGoBack()){
paymentWebView.goBack();
}
});
else{
setPaymentWebViewVisibility(false);
}
}
else{
super.onBackPressed();
}
}
public void setOrderNote(String orderNote){
@@ -288,7 +299,7 @@ public class CreateOrderActivity extends BaseActivity {
this.paymentMethodList = paymentMethodList;
}
public FrameLayout getPaymentContainerLayout() {
return paymentContainerLayout;
public WebView getPaymentWebView() {
return paymentWebView;
}
}

View File

@@ -43,4 +43,8 @@ public class ApiConstants {
public static final String ONESIGNAL_NOTIFICATION_TAG_KEY = "notificationAllowed";
public static final String ONESIGNAL_NOTIFICATION_TAG_VALUE = "true";
public static final String PAYMENT_WEBVIEW_URL_POSTFINANCE_TWINT = "https://pizza-leu.ch/pizzaleu/index.php?route=mobile/service/postFinancePayment&order_id=";
public static final String PAYMENT_WEBVIEW_SUCCESS_POSTFINANCE_TWINT = "postFinancePaymentIsSuccess";
public static final String PAYMENT_WEBVIEW_FAIL_POSTFINANCE_TWINT = "postFinancePaymentIsFailed";
}

View File

@@ -10,7 +10,6 @@ import ch.pizzaleu.android.model.CampaignBannerModel;
import ch.pizzaleu.android.model.CampaignModel;
import ch.pizzaleu.android.model.CheckCouponModel;
import ch.pizzaleu.android.model.CountryModel;
import ch.pizzaleu.android.model.DatatransInitInfoModel;
import ch.pizzaleu.android.model.DeleteAddressResponseModel;
import ch.pizzaleu.android.model.PaymentMethodsResponseModel;
import ch.pizzaleu.android.model.PaymentTokenModel;
@@ -215,12 +214,6 @@ public interface ApiInterface {
@POST
Call<ResponseObject> createBraintreePayment(@Url String url,
@FieldMap HashMap<String, Object> body);
@FormUrlEncoded
@POST
Call<ResponseObject> createDatatransPayment(@Url String url,
@FieldMap HashMap<String, Object> body);
@FormUrlEncoded
@POST
Call<ResponseObject> repeatOrder(@Url String url,
@@ -240,9 +233,6 @@ public interface ApiInterface {
@GET
Call<ResponseObject<PaymentTokenModel>> createBraintreePaymentToken(@Url String url);
@GET
Call<ResponseObject<DatatransInitInfoModel>> getDatatransInitInfoModel(@Url String url);
@GET(ApiEndPoints.API_GET_CAMPAIGN_BANNERS)
Call<ResponseArray<CampaignBannerModel>> getCampaignBanners();

View File

@@ -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);
}
}
}
}

View File

@@ -1,31 +0,0 @@
package ch.pizzaleu.android.model;
import com.google.gson.annotations.SerializedName;
public class DatatransInitInfoModel {
@SerializedName("merchant_id")
private String merchantId;
@SerializedName("ref_no")
private String referenceNumber;
public DatatransInitInfoModel(String merchantId, String referenceNumber) {
this.merchantId = merchantId;
this.referenceNumber = referenceNumber;
}
public String getMerchantId() {
if(merchantId == null){
merchantId = "";
}
return merchantId;
}
public String getReferenceNumber() {
if(referenceNumber == null){
referenceNumber = "";
}
return referenceNumber;
}
}

View File

@@ -0,0 +1,34 @@
package ch.pizzaleu.android.model;
import com.google.gson.annotations.SerializedName;
public class PostfinancePaymentResponseModel {
private boolean success;
private String message;
@SerializedName("error_code")
private int errorCode;
@SerializedName("data")
private PostfinancePaymentSuccessModel paymentSuccessModel;
public boolean isSuccess() {
return success;
}
public String getMessage() {
if(message == null){
message = "";
}
return message;
}
public int getErrorCode() {
return errorCode;
}
public PostfinancePaymentSuccessModel getPaymentSuccessModel() {
return paymentSuccessModel;
}
}

View File

@@ -0,0 +1,55 @@
package ch.pizzaleu.android.model;
import com.google.gson.annotations.SerializedName;
public class PostfinancePaymentSuccessModel {
private String route;
@SerializedName("orderID")
private String orderId;
@SerializedName("PM")
private String paymentMethodName;
@SerializedName("STATUS")
private String status;
@SerializedName("PAYID")
private String paymentId;
public String getRoute() {
if(route == null){
route = "";
}
return route;
}
public String getOrderId() {
if(orderId == null){
orderId = "";
}
return orderId;
}
public String getPaymentMethodName() {
if(paymentMethodName == null){
paymentMethodName = "";
}
return paymentMethodName;
}
public String getStatus() {
if(status == null){
status = "";
}
return status;
}
public String getPaymentId() {
if(paymentId == null){
paymentId = "";
}
return paymentId;
}
}

View File

@@ -79,11 +79,12 @@
</android.support.v7.widget.CardView>
<FrameLayout
android:id="@+id/paymentContainerLayout"
<WebView
android:id="@+id/paymentWebView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white"
android:layout_margin="12dp"
android:visibility="gone"/>
</RelativeLayout>