Voucher Servis Entegrasyonu
This commit is contained in:
@@ -391,9 +391,7 @@ public class CampaignProductDetailsActivity extends BaseActivity {
|
||||
|
||||
|
||||
HashMap<String, Object> params = new HashMap<>();
|
||||
if(SessionHelper.getSelectedCoupon() != null){
|
||||
params.put("coupon", SessionHelper.getSelectedCoupon().getCode());
|
||||
}
|
||||
SessionHelper.addCouponCodeToRequestParamsIfNeeded(params);
|
||||
|
||||
Call<ResponseObject<CartInfoModel>> call = ApiService.apiInterface.getCartProducts(
|
||||
"/" + SessionHelper.getSelectedStore().getStoreName() + ApiEndPoints.API_GET_CART_PRODUCTS + SessionHelper.getCustomerToken().getToken(),
|
||||
|
||||
@@ -141,9 +141,7 @@ public class LoginActivity extends BaseActivity {
|
||||
*/
|
||||
|
||||
HashMap<String, Object> params = new HashMap<>();
|
||||
if(SessionHelper.getSelectedCoupon() != null){
|
||||
params.put("coupon", SessionHelper.getSelectedCoupon().getCode());
|
||||
}
|
||||
SessionHelper.addCouponCodeToRequestParamsIfNeeded(params);
|
||||
|
||||
Call<ResponseObject<CartInfoModel>> call = ApiService.apiInterface.getCartProducts(
|
||||
"/" + SessionHelper.getSelectedStore().getStoreName() + ApiEndPoints.API_GET_CART_PRODUCTS + SessionHelper.getCustomerToken().getToken(),
|
||||
|
||||
@@ -389,9 +389,7 @@ public class ProductDetailsActivity extends BaseActivity {
|
||||
*/
|
||||
|
||||
HashMap<String, Object> params = new HashMap<>();
|
||||
if(SessionHelper.getSelectedCoupon() != null){
|
||||
params.put("coupon", SessionHelper.getSelectedCoupon().getCode());
|
||||
}
|
||||
SessionHelper.addCouponCodeToRequestParamsIfNeeded(params);
|
||||
|
||||
Call<ResponseObject<CartInfoModel>> call = ApiService.apiInterface.getCartProducts(
|
||||
"/" + SessionHelper.getSelectedStore().getStoreName() + ApiEndPoints.API_GET_CART_PRODUCTS + SessionHelper.getCustomerToken().getToken(),
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
package ch.pizzacucina.android.activity;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.support.annotation.NonNull;
|
||||
@@ -460,9 +458,7 @@ public class SplashActivity extends BaseActivity {
|
||||
*/
|
||||
|
||||
HashMap<String, Object> params = new HashMap<>();
|
||||
if(SessionHelper.getSelectedCoupon() != null){
|
||||
params.put("coupon", SessionHelper.getSelectedCoupon().getCode());
|
||||
}
|
||||
SessionHelper.addCouponCodeToRequestParamsIfNeeded(params);
|
||||
|
||||
Call<ResponseObject<CartInfoModel>> call = ApiService.apiInterface.getCartProducts(
|
||||
"/" + SessionHelper.getSelectedStore().getStoreName() + ApiEndPoints.API_GET_CART_PRODUCTS + SessionHelper.getCustomerToken().getToken(),
|
||||
|
||||
@@ -46,7 +46,8 @@ public class ApiEndPoints {
|
||||
public static final String API_UPDATE_PROFILE = PREFIX + "updateCustomerInfo" + SUFFIX + "&token=";
|
||||
public static final String API_REMOVE_RPODUCT_FORM_CART = PREFIX + "removeProductFromBasket" + SUFFIX + "&token=";
|
||||
public static final String API_GET_ORDER_PRODUCT_LIST = PREFIX + "getOrderProducts" + SUFFIX + "&token=";
|
||||
public static final String API_CHECK_COUPON = PREFIX + "checkCoupon" + SUFFIX + "&token=";
|
||||
public static final String API_CHECK_GENERAL_COUPON = PREFIX + "checkCoupon" + SUFFIX + "&token=";
|
||||
public static final String API_CHECK_PERSONAL_COUPON = PREFIX + "checkVoucher" + SUFFIX + "&token=";
|
||||
public static final String API_CREATE_BRAINTREE_PAYMENT = PREFIX + "checkBrainTreePayment" + SUFFIX + "&token=";
|
||||
public static final String API_REPEAT_ORDER = PREFIX + "reOrder" + SUFFIX + "&token=";
|
||||
public static final String API_CHECK_ORDER_PRICE = PREFIX + "checkOrderPrice" + SUFFIX + "&token=";
|
||||
|
||||
@@ -8,7 +8,8 @@ import ch.pizzacucina.android.model.AddressModel;
|
||||
import ch.pizzacucina.android.model.AppVersionModel;
|
||||
import ch.pizzacucina.android.model.CampaignBannerModel;
|
||||
import ch.pizzacucina.android.model.CampaignModel;
|
||||
import ch.pizzacucina.android.model.CheckCouponModel;
|
||||
import ch.pizzacucina.android.model.GeneralCouponModel;
|
||||
import ch.pizzacucina.android.model.PersonalCouponModel;
|
||||
import ch.pizzacucina.android.model.CountryModel;
|
||||
import ch.pizzacucina.android.model.DeleteAddressResponseModel;
|
||||
import ch.pizzacucina.android.model.PaymentMethodsResponseModel;
|
||||
@@ -195,8 +196,13 @@ public interface ApiInterface {
|
||||
@Field("order_id") String orderId);
|
||||
@FormUrlEncoded
|
||||
@POST
|
||||
Call<ResponseObject<CheckCouponModel>> checkCoupon(@Url String url,
|
||||
@Field("coupon") String couponCode);
|
||||
Call<ResponseObject<GeneralCouponModel>> checkGeneralCoupon(@Url String url,
|
||||
@Field("coupon") String couponCode);
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST
|
||||
Call<ResponseObject<PersonalCouponModel>> checkPersonalCoupon(@Url String url,
|
||||
@Field("voucher") String couponCode);
|
||||
|
||||
@GET("{storeName}" + ApiEndPoints.API_CHECK_CAMPAIGN_PIZZAPASS)
|
||||
Call<ResponseObject<CampaignModel>> checkPizzapassCampaign(@Path("storeName") String storeName,
|
||||
|
||||
@@ -210,9 +210,7 @@ public class CartFragment extends BaseFragment {
|
||||
*/
|
||||
|
||||
HashMap<String, Object> params = new HashMap<>();
|
||||
if(SessionHelper.getSelectedCoupon() != null){
|
||||
params.put("coupon", SessionHelper.getSelectedCoupon().getCode());
|
||||
}
|
||||
SessionHelper.addCouponCodeToRequestParamsIfNeeded(params);
|
||||
|
||||
Call<ResponseObject<CartInfoModel>> call = ApiService.apiInterface.getCartProducts(
|
||||
"/" + SessionHelper.getSelectedStore().getStoreName() + ApiEndPoints.API_GET_CART_PRODUCTS + SessionHelper.getCustomerToken().getToken(),
|
||||
@@ -392,9 +390,7 @@ public class CartFragment extends BaseFragment {
|
||||
*/
|
||||
|
||||
HashMap<String, Object> params = new HashMap<>();
|
||||
if(SessionHelper.getSelectedCoupon() != null){
|
||||
params.put("coupon", SessionHelper.getSelectedCoupon().getCode());
|
||||
}
|
||||
SessionHelper.addCouponCodeToRequestParamsIfNeeded(params);
|
||||
|
||||
Call<ResponseObject<CartInfoModel>> call = ApiService.apiInterface.getCartProducts(
|
||||
"/" + SessionHelper.getSelectedStore().getStoreName() + ApiEndPoints.API_GET_CART_PRODUCTS + SessionHelper.getCustomerToken().getToken(),
|
||||
|
||||
@@ -219,9 +219,7 @@ public class CreateOrderSummaryFragment extends CreateOrderBaseFragment {
|
||||
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);
|
||||
if(SessionHelper.getSelectedCoupon() != null){
|
||||
params.put("coupon", SessionHelper.getSelectedCoupon().getCode());
|
||||
}
|
||||
SessionHelper.addCouponCodeToRequestParamsIfNeeded(params);
|
||||
if(dateOfOrderString != null && !dateOfOrderString.isEmpty() &&
|
||||
timeOfOrder != null && !timeOfOrder.isEmpty()){
|
||||
params.put("delivery_date", dateOfOrderString + " " + timeOfOrder);
|
||||
@@ -721,9 +719,7 @@ public class CreateOrderSummaryFragment extends CreateOrderBaseFragment {
|
||||
if(paymentMethodNonce != null){
|
||||
params.put("payment_method_nonce", paymentMethodNonce);
|
||||
}
|
||||
if(SessionHelper.getSelectedCoupon() != null){
|
||||
params.put("coupon", SessionHelper.getSelectedCoupon().getCode());
|
||||
}
|
||||
SessionHelper.addCouponCodeToRequestParamsIfNeeded(params);
|
||||
if(dateOfOrderString != null && !dateOfOrderString.isEmpty() &&
|
||||
timeOfOrder != null && !timeOfOrder.isEmpty()){
|
||||
params.put("delivery_date", dateOfOrderString + " " + timeOfOrder);
|
||||
@@ -803,9 +799,7 @@ public class CreateOrderSummaryFragment extends CreateOrderBaseFragment {
|
||||
"/" + SessionHelper.getSelectedStore().getStoreName() + ApiEndPoints.API_GET_CART_PRODUCTS + SessionHelper.getCustomerToken().getToken());
|
||||
*/
|
||||
HashMap<String, Object> params = new HashMap<>();
|
||||
if(SessionHelper.getSelectedCoupon() != null){
|
||||
params.put("coupon", SessionHelper.getSelectedCoupon().getCode());
|
||||
}
|
||||
SessionHelper.addCouponCodeToRequestParamsIfNeeded(params);
|
||||
|
||||
Call<ResponseObject<CartInfoModel>> call = ApiService.apiInterface.getCartProducts(
|
||||
"/" + SessionHelper.getSelectedStore().getStoreName() + ApiEndPoints.API_GET_CART_PRODUCTS + SessionHelper.getCustomerToken().getToken(),
|
||||
@@ -843,13 +837,11 @@ public class CreateOrderSummaryFragment extends CreateOrderBaseFragment {
|
||||
*/
|
||||
|
||||
HashMap<String, Object> params = new HashMap<>();
|
||||
if(SessionHelper.getSelectedCoupon() != null){
|
||||
params.put("coupon", SessionHelper.getSelectedCoupon().getCode());
|
||||
}
|
||||
params.put("payment_method", createOrderActivity.getSelectedPaymentMethod().getCode());
|
||||
params.put("payment_method_code", createOrderActivity.getSelectedPaymentMethod().getCode());
|
||||
params.put("shipping_method",createOrderActivity.getSelectedShippingMethod().getCode());
|
||||
params.put("shipping_method_code",createOrderActivity.getSelectedShippingMethod().getCode());
|
||||
SessionHelper.addCouponCodeToRequestParamsIfNeeded(params);
|
||||
|
||||
Call<ResponseObject<CartInfoModel>> call = ApiService.apiInterface.getCartProducts(
|
||||
"/" + SessionHelper.getSelectedStore().getStoreName() + ApiEndPoints.API_GET_CART_PRODUCTS + SessionHelper.getCustomerToken().getToken(),
|
||||
|
||||
@@ -26,7 +26,10 @@ import ch.pizzacucina.android.api.ResponseObject;
|
||||
import ch.pizzacucina.android.helper.DialogHelper;
|
||||
import ch.pizzacucina.android.helper.SessionHelper;
|
||||
import ch.pizzacucina.android.interfaces.RecyclerItemClickListener;
|
||||
import ch.pizzacucina.android.model.CheckCouponModel;
|
||||
import ch.pizzacucina.android.model.CouponModel;
|
||||
import ch.pizzacucina.android.model.CouponType;
|
||||
import ch.pizzacucina.android.model.GeneralCouponModel;
|
||||
import ch.pizzacucina.android.model.PersonalCouponModel;
|
||||
import ch.pizzacucina.android.model.PaymentMethodModel;
|
||||
import ch.pizzacucina.android.model.PaymentMethodsResponseModel;
|
||||
import ch.pizzacucina.android.model.cart.CartInfoModel;
|
||||
@@ -52,7 +55,7 @@ public class PaymentMethodFragment extends CreateOrderBaseFragment {
|
||||
|
||||
private ArrayList<PaymentMethodModel> paymentMethodList = new ArrayList<>();
|
||||
private PaymentMethodsRecyclerAdapter paymentMethodsRecyclerAdapter;
|
||||
private CheckCouponModel couponModel;
|
||||
private CouponModel couponModel;
|
||||
|
||||
private PaymentMethodModel selectedPaymentMethod;
|
||||
|
||||
@@ -99,11 +102,8 @@ public class PaymentMethodFragment extends CreateOrderBaseFragment {
|
||||
}
|
||||
else {
|
||||
createOrderActivity.setCouponCode(couponCodeEditText.getText().toString());
|
||||
checkCoupon();
|
||||
checkPersonalCoupon();
|
||||
}
|
||||
|
||||
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -228,27 +228,77 @@ public class PaymentMethodFragment extends CreateOrderBaseFragment {
|
||||
paymentMethodsRecyclerView.setAdapter(paymentMethodsRecyclerAdapter);
|
||||
}
|
||||
|
||||
private void checkCoupon(){
|
||||
DialogHelper.showLoadingDialog();
|
||||
Call<ResponseObject<CheckCouponModel>> call =
|
||||
ApiService.apiInterface.checkCoupon(
|
||||
"/" + SessionHelper.getSelectedStore().getStoreName() + ApiEndPoints.API_CHECK_COUPON + SessionHelper.getCustomerToken().getToken(),
|
||||
private void checkPersonalCoupon(){
|
||||
Call<ResponseObject<PersonalCouponModel>> call =
|
||||
ApiService.apiInterface.checkPersonalCoupon(
|
||||
"/" + SessionHelper.getSelectedStore().getStoreName() + ApiEndPoints.API_CHECK_PERSONAL_COUPON + SessionHelper.getCustomerToken().getToken(),
|
||||
couponCodeEditText.getText().toString());
|
||||
call.enqueue(new Callback<ResponseObject<CheckCouponModel>>() {
|
||||
call.enqueue(new Callback<ResponseObject<PersonalCouponModel>>() {
|
||||
@Override
|
||||
public void onResponse(Call<ResponseObject<CheckCouponModel>> call, Response<ResponseObject<CheckCouponModel>> response) {
|
||||
public void onResponse(Call<ResponseObject<PersonalCouponModel>> call, Response<ResponseObject<PersonalCouponModel>> response) {
|
||||
if(response.isSuccessful() &&
|
||||
response.body().getData() != null &&
|
||||
response.body().isSuccess()){
|
||||
couponModel = response.body().getData();
|
||||
couponModel.setStoreName(SessionHelper.getSelectedStore().getStoreName());
|
||||
couponModel.checkNull();
|
||||
if(couponModel.isActive()){
|
||||
|
||||
String couponName = "";
|
||||
if(couponModel instanceof PersonalCouponModel){
|
||||
couponName = ((PersonalCouponModel) couponModel).getTheme();
|
||||
}
|
||||
|
||||
SessionHelper.saveSelectedCoupon(couponModel);
|
||||
DialogHelper.showDialogWithPositiveButton(
|
||||
couponUsedDialogTitle,
|
||||
BaseActivity.currentActivity,
|
||||
couponUsedDialogContentPart1 + " " + couponName + " " + couponUsedDialogContentPart2);
|
||||
getCartProducts();
|
||||
}
|
||||
else {
|
||||
checkGeneralCoupon();
|
||||
}
|
||||
}
|
||||
else {
|
||||
DialogHelper.hideLoadingDialog();
|
||||
ApiErrorUtils.parseError(response);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Call<ResponseObject<PersonalCouponModel>> call, Throwable t) {
|
||||
DialogHelper.hideLoadingDialog();
|
||||
DialogHelper.showFailedDialog();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void checkGeneralCoupon(){
|
||||
DialogHelper.showLoadingDialog();
|
||||
Call<ResponseObject<GeneralCouponModel>> call =
|
||||
ApiService.apiInterface.checkGeneralCoupon(
|
||||
"/" + SessionHelper.getSelectedStore().getStoreName() + ApiEndPoints.API_CHECK_GENERAL_COUPON + SessionHelper.getCustomerToken().getToken(),
|
||||
couponCodeEditText.getText().toString());
|
||||
call.enqueue(new Callback<ResponseObject<GeneralCouponModel>>() {
|
||||
@Override
|
||||
public void onResponse(Call<ResponseObject<GeneralCouponModel>> call, Response<ResponseObject<GeneralCouponModel>> response) {
|
||||
if(response.isSuccessful() &&
|
||||
response.body().getData() != null &&
|
||||
response.body().isSuccess()){
|
||||
couponModel = response.body().getData();
|
||||
couponModel.setStoreName(SessionHelper.getSelectedStore().getStoreName());
|
||||
|
||||
String couponName = "";
|
||||
if(couponModel instanceof GeneralCouponModel){
|
||||
couponName = ((GeneralCouponModel) couponModel).getName();
|
||||
}
|
||||
|
||||
if(couponModel.isActive()){
|
||||
SessionHelper.saveSelectedCoupon(couponModel);
|
||||
DialogHelper.showDialogWithPositiveButton(
|
||||
couponUsedDialogTitle,
|
||||
BaseActivity.currentActivity,
|
||||
couponUsedDialogContentPart1 + " " + couponModel.getName() + " " + couponUsedDialogContentPart2);
|
||||
couponUsedDialogContentPart1 + " " + couponName + " " + couponUsedDialogContentPart2);
|
||||
getCartProducts();
|
||||
}
|
||||
else {
|
||||
@@ -263,7 +313,7 @@ public class PaymentMethodFragment extends CreateOrderBaseFragment {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Call<ResponseObject<CheckCouponModel>> call, Throwable t) {
|
||||
public void onFailure(Call<ResponseObject<GeneralCouponModel>> call, Throwable t) {
|
||||
DialogHelper.hideLoadingDialog();
|
||||
DialogHelper.showFailedDialog();
|
||||
}
|
||||
@@ -278,7 +328,15 @@ public class PaymentMethodFragment extends CreateOrderBaseFragment {
|
||||
*/
|
||||
|
||||
HashMap<String, Object> params = new HashMap<>();
|
||||
params.put("coupon", couponModel.getCode());
|
||||
if(couponModel != null){
|
||||
if(couponModel.getCouponType() == CouponType.PERSONAL){
|
||||
params.put("voucher", couponModel.getCode());
|
||||
}
|
||||
else if(couponModel.getCouponType() == CouponType.GENERAL){
|
||||
params.put("coupon", couponModel.getCode());
|
||||
}
|
||||
}
|
||||
|
||||
Call<ResponseObject<CartInfoModel>> call = ApiService.apiInterface.getCartProducts(
|
||||
"/" + SessionHelper.getSelectedStore().getStoreName() + ApiEndPoints.API_GET_CART_PRODUCTS + SessionHelper.getCustomerToken().getToken(),
|
||||
params);
|
||||
|
||||
@@ -4,9 +4,13 @@ import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
|
||||
import ch.pizzacucina.android.model.CheckCouponModel;
|
||||
import ch.pizzacucina.android.model.CouponModel;
|
||||
import ch.pizzacucina.android.model.CouponType;
|
||||
import ch.pizzacucina.android.model.GeneralCouponModel;
|
||||
import ch.pizzacucina.android.model.CustomerTokenModel;
|
||||
import ch.pizzacucina.android.model.PersonalCouponModel;
|
||||
import ch.pizzacucina.android.model.StoreModel;
|
||||
import ch.pizzacucina.android.model.UserModel;
|
||||
|
||||
@@ -74,8 +78,41 @@ public class SessionHelper {
|
||||
clearCustomerInfo();
|
||||
}
|
||||
|
||||
public static void saveSelectedCoupon(CheckCouponModel couponModel){
|
||||
SharedPrefsHelper.saveSelectedCoupon(couponModel);
|
||||
public static void saveSelectedCoupon(CouponModel couponModel){
|
||||
if(couponModel instanceof PersonalCouponModel){
|
||||
PersonalCouponModel personalCouponModel = (PersonalCouponModel) couponModel;
|
||||
SharedPrefsHelper.saveSelectedPersonalCoupon(personalCouponModel);
|
||||
}
|
||||
else if(couponModel instanceof GeneralCouponModel){
|
||||
GeneralCouponModel generalCouponModel = (GeneralCouponModel) couponModel;
|
||||
SharedPrefsHelper.saveSelectedGeneralCoupon(generalCouponModel);
|
||||
}
|
||||
}
|
||||
|
||||
public static CouponModel getSelectedCoupon(){
|
||||
if(SharedPrefsHelper.getSelectedPersonalCoupon() != null){
|
||||
return SharedPrefsHelper.getSelectedPersonalCoupon();
|
||||
}
|
||||
else {
|
||||
return SharedPrefsHelper.getSelectedGeneralCoupon();
|
||||
}
|
||||
}
|
||||
|
||||
public static void clearSelectedCoupon(){
|
||||
SharedPrefsHelper.clearSelectedGeneralCoupon();
|
||||
SharedPrefsHelper.clearSelectedPersonalCoupon();
|
||||
}
|
||||
|
||||
public static void addCouponCodeToRequestParamsIfNeeded(HashMap<String, Object> params){
|
||||
CouponModel selectedCoupon = SessionHelper.getSelectedCoupon();
|
||||
if(SessionHelper.getSelectedCoupon() != null){
|
||||
if(selectedCoupon.getCouponType() == CouponType.PERSONAL){
|
||||
params.put("voucher", SessionHelper.getSelectedCoupon().getCode());
|
||||
}
|
||||
else if(selectedCoupon.getCouponType() == CouponType.GENERAL){
|
||||
params.put("coupon", SessionHelper.getSelectedCoupon().getCode());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static String getSessionId(){
|
||||
@@ -86,14 +123,6 @@ public class SessionHelper {
|
||||
SharedPrefsHelper.saveSessionId(sessionId);
|
||||
}
|
||||
|
||||
public static CheckCouponModel getSelectedCoupon(){
|
||||
return SharedPrefsHelper.getSelectedCoupon();
|
||||
}
|
||||
|
||||
public static void clearSelectedCoupon(){
|
||||
SharedPrefsHelper.clearSelectedCoupon();
|
||||
}
|
||||
|
||||
public static Calendar getTokenDeathDate(String tokenDeathTime){
|
||||
|
||||
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
|
||||
@@ -11,7 +11,8 @@ import java.util.ArrayList;
|
||||
|
||||
import ch.pizzacucina.android.activity.BaseActivity;
|
||||
import ch.pizzacucina.android.model.CategoryModel;
|
||||
import ch.pizzacucina.android.model.CheckCouponModel;
|
||||
import ch.pizzacucina.android.model.GeneralCouponModel;
|
||||
import ch.pizzacucina.android.model.PersonalCouponModel;
|
||||
import ch.pizzacucina.android.model.CustomerTokenModel;
|
||||
import ch.pizzacucina.android.model.StoreModel;
|
||||
import ch.pizzacucina.android.model.UserModel;
|
||||
@@ -36,7 +37,8 @@ public class SharedPrefsHelper {
|
||||
private static final String PREF_KEY_CART_TOTAL_PRICE = SHARED_PREFS_NAME + "cartTotalPrice";
|
||||
private static final String PREF_KEY_USER_SELECTED_STORE = SHARED_PREFS_NAME + "selectedStore";
|
||||
private static final String PREF_KEY_IS_FIRST_TIME = SHARED_PREFS_NAME + "isFirstTime";
|
||||
private static final String PREF_KEY_SELECTED_COUPON = SHARED_PREFS_NAME + "selectedCoupon";
|
||||
private static final String PREF_KEY_SELECTED_GENERAL_COUPON = SHARED_PREFS_NAME + "selectedGeneralCoupon";
|
||||
private static final String PREF_KEY_SELECTED_PERSONAL_COUPON = SHARED_PREFS_NAME + "selectedPersonalCoupon";
|
||||
private static final String PREF_KEY_SESSION_ID = SHARED_PREFS_NAME + "sessionId";
|
||||
|
||||
private static SharedPreferences sharedPreferences =
|
||||
@@ -93,7 +95,8 @@ public class SharedPrefsHelper {
|
||||
editor.remove(PREF_KEY_CUSTOMER_TOKEN);
|
||||
editor.remove(PREF_KEY_CART_ITEM_COUNT);
|
||||
editor.remove(PREF_KEY_CART_TOTAL_PRICE);
|
||||
editor.remove(PREF_KEY_SELECTED_COUPON);
|
||||
editor.remove(PREF_KEY_SELECTED_GENERAL_COUPON);
|
||||
editor.remove(PREF_KEY_SELECTED_PERSONAL_COUPON);
|
||||
editor.remove(PREF_KEY_SESSION_ID);
|
||||
editor.apply();
|
||||
}
|
||||
@@ -167,13 +170,13 @@ public class SharedPrefsHelper {
|
||||
return sharedPreferences.getBoolean(PREF_KEY_IS_FIRST_TIME, true);
|
||||
}
|
||||
|
||||
public static void saveSelectedCoupon(CheckCouponModel couponModel){
|
||||
editor.putString(PREF_KEY_SELECTED_COUPON, gson.toJson(couponModel));
|
||||
public static void saveSelectedGeneralCoupon(GeneralCouponModel couponModel){
|
||||
editor.putString(PREF_KEY_SELECTED_GENERAL_COUPON, gson.toJson(couponModel));
|
||||
editor.apply();
|
||||
}
|
||||
|
||||
public static CheckCouponModel getSelectedCoupon(){
|
||||
CheckCouponModel selectedCouponModel = gson.fromJson(sharedPreferences.getString(PREF_KEY_SELECTED_COUPON, ""), CheckCouponModel.class);
|
||||
public static GeneralCouponModel getSelectedGeneralCoupon(){
|
||||
GeneralCouponModel selectedCouponModel = gson.fromJson(sharedPreferences.getString(PREF_KEY_SELECTED_GENERAL_COUPON, ""), GeneralCouponModel.class);
|
||||
if(selectedCouponModel != null &&
|
||||
selectedCouponModel.getStoreName().toLowerCase().equals(SessionHelper.getSelectedStore().getStoreName().toLowerCase())){
|
||||
return selectedCouponModel;
|
||||
@@ -183,8 +186,29 @@ public class SharedPrefsHelper {
|
||||
}
|
||||
}
|
||||
|
||||
public static void clearSelectedCoupon(){
|
||||
editor.remove(PREF_KEY_SELECTED_COUPON);
|
||||
public static void clearSelectedGeneralCoupon(){
|
||||
editor.remove(PREF_KEY_SELECTED_GENERAL_COUPON);
|
||||
editor.apply();
|
||||
}
|
||||
|
||||
public static void saveSelectedPersonalCoupon(PersonalCouponModel couponModel){
|
||||
editor.putString(PREF_KEY_SELECTED_PERSONAL_COUPON, gson.toJson(couponModel));
|
||||
editor.apply();
|
||||
}
|
||||
|
||||
public static PersonalCouponModel getSelectedPersonalCoupon(){
|
||||
PersonalCouponModel selectedCouponModel = gson.fromJson(sharedPreferences.getString(PREF_KEY_SELECTED_PERSONAL_COUPON, ""), PersonalCouponModel.class);
|
||||
if(selectedCouponModel != null &&
|
||||
selectedCouponModel.getStoreName().toLowerCase().equals(SessionHelper.getSelectedStore().getStoreName().toLowerCase())){
|
||||
return selectedCouponModel;
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static void clearSelectedPersonalCoupon(){
|
||||
editor.remove(PREF_KEY_SELECTED_PERSONAL_COUPON);
|
||||
editor.apply();
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
package ch.pizzacucina.android.model;
|
||||
|
||||
import com.google.gson.annotations.Expose;
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
public class CouponModel {
|
||||
|
||||
@Expose
|
||||
@SerializedName("date_added")
|
||||
private String addedDate;
|
||||
|
||||
private String code;
|
||||
private String storeName;
|
||||
private String status;
|
||||
|
||||
public CouponType getCouponType(){
|
||||
return CouponType.UNKNOWN;
|
||||
}
|
||||
public boolean isActive(){
|
||||
return false;
|
||||
}
|
||||
|
||||
public String getAddedDate() {
|
||||
if(addedDate == null){
|
||||
addedDate = "1970-01-01";
|
||||
}
|
||||
return addedDate;
|
||||
}
|
||||
|
||||
public String getCode() {
|
||||
if(code == null){
|
||||
code = "";
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
public String getStoreName() {
|
||||
if(storeName == null){
|
||||
storeName = "";
|
||||
}
|
||||
return storeName;
|
||||
}
|
||||
|
||||
public String getStatus() {
|
||||
if(status == null){
|
||||
status = "";
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
public void setStoreName(String storeName) {
|
||||
this.storeName = storeName;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package ch.pizzacucina.android.model;
|
||||
|
||||
public enum CouponType {
|
||||
PERSONAL,
|
||||
GENERAL,
|
||||
UNKNOWN
|
||||
}
|
||||
@@ -14,7 +14,7 @@ import java.util.Date;
|
||||
* Created by cimenmus on 6.02.2018.
|
||||
*/
|
||||
|
||||
public class CheckCouponModel {
|
||||
public class GeneralCouponModel extends CouponModel {
|
||||
|
||||
@Expose
|
||||
@SerializedName("coupon_id")
|
||||
@@ -40,89 +40,99 @@ public class CheckCouponModel {
|
||||
@SerializedName("uses_customer")
|
||||
private String userUsageCount;
|
||||
|
||||
@Expose
|
||||
@SerializedName("date_added")
|
||||
private String addedDate;
|
||||
|
||||
private String code;
|
||||
private String name;
|
||||
private String type;
|
||||
private String discount;
|
||||
private String shipping;
|
||||
private String total;
|
||||
private String status;
|
||||
|
||||
|
||||
private String storeName;
|
||||
|
||||
public void checkNull(){
|
||||
|
||||
if(couponId == null){
|
||||
couponId = "";
|
||||
}
|
||||
|
||||
if(startDate == null){
|
||||
startDate = "1970-01-01";
|
||||
}
|
||||
|
||||
if(endDate == null){
|
||||
endDate = "1970-01-01";
|
||||
}
|
||||
|
||||
if(totalUsageCount == null){
|
||||
totalUsageCount = "";
|
||||
}
|
||||
|
||||
if(userUsageCount == null){
|
||||
userUsageCount = "";
|
||||
}
|
||||
|
||||
if(addedDate == null){
|
||||
addedDate = "";
|
||||
}
|
||||
|
||||
if(code == null){
|
||||
code = "";
|
||||
}
|
||||
|
||||
if(name == null){
|
||||
name = "";
|
||||
}
|
||||
|
||||
if(type == null){
|
||||
type = "";
|
||||
}
|
||||
|
||||
if(discount == null){
|
||||
discount = "";
|
||||
}
|
||||
|
||||
if(shipping == null){
|
||||
shipping = "";
|
||||
}
|
||||
|
||||
if(total == null){
|
||||
total = "";
|
||||
}
|
||||
|
||||
if(status == null){
|
||||
status = "";
|
||||
}
|
||||
|
||||
if(productIdList == null){
|
||||
productIdList = new ArrayList<>();
|
||||
}
|
||||
|
||||
if(storeName == null){
|
||||
storeName = "";
|
||||
}
|
||||
}
|
||||
|
||||
public enum CouponDiscountType {
|
||||
FIXED,
|
||||
PERCENT
|
||||
}
|
||||
|
||||
@Override
|
||||
public CouponType getCouponType() {
|
||||
return CouponType.GENERAL;
|
||||
}
|
||||
|
||||
public String getCouponId() {
|
||||
if(couponId == null){
|
||||
couponId = "";
|
||||
}
|
||||
return couponId;
|
||||
}
|
||||
|
||||
public ArrayList<String> getProductIdList() {
|
||||
if(productIdList == null){
|
||||
productIdList = new ArrayList<>();
|
||||
}
|
||||
return productIdList;
|
||||
}
|
||||
|
||||
public String getStartDate() {
|
||||
if(startDate == null){
|
||||
startDate = "1970-01-01";
|
||||
}
|
||||
return startDate;
|
||||
}
|
||||
|
||||
public String getEndDate() {
|
||||
if(endDate == null){
|
||||
endDate = "1970-01-01";
|
||||
}
|
||||
return endDate;
|
||||
}
|
||||
|
||||
public String getTotalUsageCount() {
|
||||
if(totalUsageCount == null){
|
||||
totalUsageCount = "";
|
||||
}
|
||||
return totalUsageCount;
|
||||
}
|
||||
|
||||
public String getUserUsageCount() {
|
||||
if(userUsageCount == null){
|
||||
userUsageCount = "";
|
||||
}
|
||||
return userUsageCount;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
if(name == null){
|
||||
name = "";
|
||||
}
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
if(type == null){
|
||||
type = "";
|
||||
}
|
||||
return type;
|
||||
}
|
||||
|
||||
public String getDiscount() {
|
||||
if(discount == null){
|
||||
discount = "";
|
||||
}
|
||||
return discount;
|
||||
}
|
||||
|
||||
public String getShipping() {
|
||||
if(shipping == null){
|
||||
shipping = "";
|
||||
}
|
||||
return shipping;
|
||||
}
|
||||
|
||||
public String getTotal() {
|
||||
if(total == null){
|
||||
total = "";
|
||||
}
|
||||
return total;
|
||||
}
|
||||
|
||||
public CouponDiscountType getCouponDiscountType(){
|
||||
if(type.toLowerCase().equals("f")){
|
||||
return CouponDiscountType.FIXED;
|
||||
@@ -132,8 +142,9 @@ public class CheckCouponModel {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isActive(){
|
||||
return status.equals("1") && isCouponUsable();
|
||||
return getStatus().equals("1") && isCouponUsable();
|
||||
}
|
||||
|
||||
private boolean isCouponUsable(){
|
||||
@@ -167,123 +178,4 @@ public class CheckCouponModel {
|
||||
}
|
||||
}
|
||||
|
||||
public String getCouponId() {
|
||||
return couponId;
|
||||
}
|
||||
|
||||
public void setCouponId(String couponId) {
|
||||
this.couponId = couponId;
|
||||
}
|
||||
|
||||
public ArrayList<String> getProductIdList() {
|
||||
return productIdList;
|
||||
}
|
||||
|
||||
public void setProductIdList(ArrayList<String> productIdList) {
|
||||
this.productIdList = productIdList;
|
||||
}
|
||||
|
||||
public String getStartDate() {
|
||||
return startDate;
|
||||
}
|
||||
|
||||
public void setStartDate(String startDate) {
|
||||
this.startDate = startDate;
|
||||
}
|
||||
|
||||
public String getEndDate() {
|
||||
return endDate;
|
||||
}
|
||||
|
||||
public void setEndDate(String endDate) {
|
||||
this.endDate = endDate;
|
||||
}
|
||||
|
||||
public String getTotalUsageCount() {
|
||||
return totalUsageCount;
|
||||
}
|
||||
|
||||
public void setTotalUsageCount(String totalUsageCount) {
|
||||
this.totalUsageCount = totalUsageCount;
|
||||
}
|
||||
|
||||
public String getUserUsageCount() {
|
||||
return userUsageCount;
|
||||
}
|
||||
|
||||
public void setUserUsageCount(String userUsageCount) {
|
||||
this.userUsageCount = userUsageCount;
|
||||
}
|
||||
|
||||
public String getAddedDate() {
|
||||
return addedDate;
|
||||
}
|
||||
|
||||
public void setAddedDate(String addedDate) {
|
||||
this.addedDate = addedDate;
|
||||
}
|
||||
|
||||
public String getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public void setCode(String code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getDiscount() {
|
||||
return discount;
|
||||
}
|
||||
|
||||
public void setDiscount(String discount) {
|
||||
this.discount = discount;
|
||||
}
|
||||
|
||||
public String getShipping() {
|
||||
return shipping;
|
||||
}
|
||||
|
||||
public void setShipping(String shipping) {
|
||||
this.shipping = shipping;
|
||||
}
|
||||
|
||||
public String getTotal() {
|
||||
return total;
|
||||
}
|
||||
|
||||
public void setTotal(String total) {
|
||||
this.total = total;
|
||||
}
|
||||
|
||||
public String getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public void setStatus(String status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public String getStoreName() {
|
||||
return storeName;
|
||||
}
|
||||
|
||||
public void setStoreName(String storeName) {
|
||||
this.storeName = storeName;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,116 @@
|
||||
package ch.pizzacucina.android.model;
|
||||
|
||||
import com.google.gson.annotations.Expose;
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
public class PersonalCouponModel extends CouponModel {
|
||||
|
||||
@Expose
|
||||
@SerializedName("voucher_id")
|
||||
private String voucherId;
|
||||
|
||||
@Expose
|
||||
@SerializedName("from_name")
|
||||
private String fromName;
|
||||
|
||||
@Expose
|
||||
@SerializedName("from_email")
|
||||
private String fromEmail;
|
||||
|
||||
@Expose
|
||||
@SerializedName("to_name")
|
||||
private String toName;
|
||||
|
||||
@Expose
|
||||
@SerializedName("to_email")
|
||||
private String toEmail;
|
||||
|
||||
@Expose
|
||||
@SerializedName("voucher_theme_id")
|
||||
private String voucherThemeId;
|
||||
|
||||
private String theme;
|
||||
private String message;
|
||||
private String image;
|
||||
private String amount;
|
||||
|
||||
@Override
|
||||
public CouponType getCouponType() {
|
||||
return CouponType.PERSONAL;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isActive() {
|
||||
return getStatus().equals("1");
|
||||
}
|
||||
|
||||
public String getVoucherId() {
|
||||
if(voucherId == null){
|
||||
voucherId = "";
|
||||
}
|
||||
return voucherId;
|
||||
}
|
||||
|
||||
public String getFromName() {
|
||||
if(fromName == null){
|
||||
fromName = "";
|
||||
}
|
||||
return fromName;
|
||||
}
|
||||
|
||||
public String getFromEmail() {
|
||||
if(fromEmail == null){
|
||||
fromEmail = "";
|
||||
}
|
||||
return fromEmail;
|
||||
}
|
||||
|
||||
public String getToName() {
|
||||
if(toName == null){
|
||||
toName = "";
|
||||
}
|
||||
return toName;
|
||||
}
|
||||
|
||||
public String getToEmail() {
|
||||
if(toEmail == null){
|
||||
toEmail = "";
|
||||
}
|
||||
return toEmail;
|
||||
}
|
||||
|
||||
public String getVoucherThemeId() {
|
||||
if(voucherThemeId == null){
|
||||
voucherThemeId = "";
|
||||
}
|
||||
return voucherThemeId;
|
||||
}
|
||||
|
||||
public String getTheme() {
|
||||
if(theme == null){
|
||||
theme = "";
|
||||
}
|
||||
return theme;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
if(message == null){
|
||||
message = "";
|
||||
}
|
||||
return message;
|
||||
}
|
||||
|
||||
public String getImage() {
|
||||
if(image == null){
|
||||
image = "";
|
||||
}
|
||||
return image;
|
||||
}
|
||||
|
||||
public String getAmount() {
|
||||
if(amount == null){
|
||||
amount = "";
|
||||
}
|
||||
return amount;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user