Panagiotis Triantafyllou

cosmote pass requests

......@@ -97,6 +97,7 @@ public class Coupon implements Parcelable, Serializable {
private String terms = "";
private Couponset couponsetDetails = new Couponset(true);
private Merchant merchantDetails = new Merchant(true);
private RedeemMerchantDetails redeemDetails = new RedeemMerchantDetails();
public Coupon() {
this.barcode = "";
......@@ -121,6 +122,7 @@ public class Coupon implements Parcelable, Serializable {
this.final_price = 0.0d;
this.short_description = "";
this.terms = "";
this.redeemDetails = new RedeemMerchantDetails();
}
public Coupon(boolean isUniversal) {
......@@ -135,6 +137,7 @@ public class Coupon implements Parcelable, Serializable {
this.redeemDate = new Date();
this.couponsetDetails = new Couponset(isUniversal);
this.merchantDetails = new Merchant(isUniversal);
this.redeemDetails = new RedeemMerchantDetails();
}
/**
......@@ -189,6 +192,10 @@ public class Coupon implements Parcelable, Serializable {
this.final_price = json.optDouble(FINAL_PRICE);
this.short_description = json.optString(SHORT_DESCRIPTION);
this.terms = json.optString(TERMS);
JSONObject tempRedeemDetails = json.optJSONObject("redeemed_merchant_details");
if (tempRedeemDetails != null) {
this.redeemDetails = new RedeemMerchantDetails(tempRedeemDetails);
}
}
}
......@@ -224,6 +231,10 @@ public class Coupon implements Parcelable, Serializable {
if (tempMerchantDetails != null) {
this.merchantDetails = new Merchant(tempMerchantDetails, isUniversal);
}
JSONObject tempRedeemDetails = json.optJSONObject("redeemed_merchant_details");
if (tempRedeemDetails != null) {
this.redeemDetails = new RedeemMerchantDetails(tempRedeemDetails);
}
// this.category = json.optString(CATEGORY);
// this.created = json.optString(CREATED);
......@@ -240,6 +251,75 @@ public class Coupon implements Parcelable, Serializable {
}
}
public class RedeemMerchantDetails {
private static final String IMG_PREVIEW = "img_preview";
private static final String NAME = "name";
private static final String UUID = "uuid";
private static final String REDEEMED_DATE = "redeemed_date";
private String imgPreview = "";
private String name = "";
private String uuid = "";
private String redeemedDate = "";
public RedeemMerchantDetails() {
this.imgPreview = "";
this.name = "";
this.uuid = "";
this.redeemedDate = "";
}
public RedeemMerchantDetails(JSONObject json) {
if (json != null) {
if (json.optJSONObject(IMG_PREVIEW) != null) {
this.imgPreview = json.optString(IMG_PREVIEW);
}
if (json.optJSONObject(NAME) != null) {
this.name = json.optString(NAME);
}
if (json.optJSONObject(UUID) != null) {
this.uuid = json.optString(UUID);
}
if (json.optJSONObject(REDEEMED_DATE) != null) {
this.redeemedDate = json.optString(REDEEMED_DATE);
}
}
}
public String getImgPreview() {
return imgPreview;
}
public void setImgPreview(String imgPreview) {
this.imgPreview = imgPreview;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getUuid() {
return uuid;
}
public void setUuid(String uuid) {
this.uuid = uuid;
}
public String getRedeemedDate() {
return redeemedDate;
}
public void setRedeemedDate(String redeemedDate) {
this.redeemedDate = redeemedDate;
}
}
public Coupon(Parcel source) {
this.barcode = source.readString();
this.category = source.readString();
......@@ -544,6 +624,14 @@ public class Coupon implements Parcelable, Serializable {
this.merchantDetails = merchantDetails;
}
public RedeemMerchantDetails getRedeemDetails() {
return redeemDetails;
}
public void setRedeemDetails(RedeemMerchantDetails redeemDetails) {
this.redeemDetails = redeemDetails;
}
@Override
public int describeContents() {
return 0;
......
/*
* Copyright 2010-2013 Warply Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, without modification, are
* permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE WARPLY LTD ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
* EVENT SHALL WARPLY LTD OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package ly.warp.sdk.io.models;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.ArrayList;
import ly.warp.sdk.utils.WarpUtils;
import ly.warp.sdk.utils.constants.WarpConstants;
/**
* Created by Panagiotis Triantafyllou on 20-Jan-25.
*/
public class MarketPassDetailsModel {
private static final String BARCODE = "barcode";
private static final String SUPERMARKETS = "supermarkets";
private static final String TOTAL_DISCOUNT = "total_available_discount";
private ArrayList<Supermarkets> supermarkets = new ArrayList<Supermarkets>();
private String barcode = "";
private double totalDiscount = 0.0d;
public MarketPassDetailsModel() {
this.supermarkets = new ArrayList<Supermarkets>();
this.barcode = "";
this.totalDiscount = 0.0d;
}
/**
* Basic constructor used to create an object from a String, representing a
* JSON Object
*
* @param json The String, representing the JSON Object
* @throws JSONException Thrown if the String cannot be converted to JSON
*/
public MarketPassDetailsModel(String json) throws JSONException {
this(new JSONObject(json));
}
/**
* Constructor used to create an Object from a given JSON Object
*
* @param json JSON Object used to create the Campaign
*/
public MarketPassDetailsModel(JSONObject json) {
if (json != null) {
if (json.optJSONArray(SUPERMARKETS) != null) {
JSONArray tempSupermarkets = json.optJSONArray(SUPERMARKETS);
if (tempSupermarkets != null && tempSupermarkets.length() > 0) {
for (int i = 0, lim = tempSupermarkets.length(); i < lim; ++i) {
this.supermarkets.add(new Supermarkets(tempSupermarkets.optJSONObject(i)));
}
}
}
this.barcode = json.optString(BARCODE);
this.totalDiscount = json.optDouble(TOTAL_DISCOUNT);
}
}
/**
* Converts the Campaign into a JSON Object
*
* @return The JSON Object created from this campaign
*/
public JSONObject toJSONObject() {
JSONObject jObj = new JSONObject();
try {
jObj.putOpt(BARCODE, this.barcode);
jObj.putOpt(TOTAL_DISCOUNT, this.totalDiscount);
jObj.putOpt(SUPERMARKETS, this.supermarkets);
} catch (JSONException e) {
if (WarpConstants.DEBUG) {
e.printStackTrace();
}
}
return jObj;
}
/**
* String representation of the Campaign, as a JSON object
*
* @return A String representation of JSON object
*/
public String toString() {
if (toJSONObject() != null)
return toJSONObject().toString();
return null;
}
/**
* String representation of the Campaign, as a human readable JSON object
*
* @return A human readable String representation of JSON object
*/
public String toHumanReadableString() {
String humanReadableString = null;
try {
humanReadableString = toJSONObject().toString(2);
} catch (JSONException e) {
WarpUtils.warn("Failed converting Campaign JSON object to String",
e);
}
return humanReadableString;
}
public class Supermarkets {
private static final String LOGO = "logo";
private static final String NAME = "name";
private static final String UUID = "uuid";
private String logo = "";
private String name = "";
private String uuid = "";
public Supermarkets() {
this.logo = "";
this.name = "";
this.uuid = "";
}
public Supermarkets(JSONObject json) {
if (json != null) {
if (json.optJSONObject(LOGO) != null) {
this.logo = json.optString(LOGO);
}
if (json.optJSONObject(NAME) != null) {
this.name = json.optString(NAME);
}
if (json.optJSONObject(UUID) != null) {
this.uuid = json.optString(UUID);
}
}
}
public String getLogo() {
return logo;
}
public void setLogo(String logo) {
this.logo = logo;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getUuid() {
return uuid;
}
public void setUuid(String uuid) {
this.uuid = uuid;
}
}
// ================================================================================
// Getters
// ================================================================================
public ArrayList<Supermarkets> getSupermarkets() {
return supermarkets;
}
public void setSupermarkets(ArrayList<Supermarkets> supermarkets) {
this.supermarkets = supermarkets;
}
public String getBarcode() {
return barcode;
}
public void setBarcode(String barcode) {
this.barcode = barcode;
}
public double getTotalDiscount() {
return totalDiscount;
}
public void setTotalDiscount(double totalDiscount) {
this.totalDiscount = totalDiscount;
}
}
......@@ -174,6 +174,18 @@ public interface ApiService {
@Headers("Content-Type: application/json")
@POST("/oauth/{appUuid}/context")
Call<ResponseBody> getMarketPassDetails(@Path("appUuid") String appUuid,
@Body RequestBody request,
@Header(WarpConstants.HEADER_DATE) String timeStamp,
@Header(WarpConstants.HEADER_LOYALTY_BUNDLE_ID) String bundleId,
@Header(WarpConstants.HEADER_UNIQUE_DEVICE_ID) String deviceId,
@Header(WarpConstants.HEADER_CHANNEL) String channel,
@Header(WarpConstants.HEADER_WEB_ID) String webId,
@Header(WarpConstants.HEADER_SIGNATURE) String signature,
@Header(WarpConstants.HEADER_AUTHORIZATION) String bearer);
@Headers("Content-Type: application/json")
@POST("/oauth/{appUuid}/context")
Call<ResponseBody> sendTelematicsData(@Path("appUuid") String appUuid,
@Body RequestBody request,
@Header(WarpConstants.HEADER_DATE) String timeStamp,
......
......@@ -94,6 +94,7 @@ import ly.warp.sdk.io.models.CouponList;
import ly.warp.sdk.io.models.Couponset;
import ly.warp.sdk.io.models.CouponsetsList;
import ly.warp.sdk.io.models.LoyaltySDKDynatraceEventModel;
import ly.warp.sdk.io.models.MarketPassDetailsModel;
import ly.warp.sdk.io.models.Merchant;
import ly.warp.sdk.io.models.MerchantCategoriesList;
import ly.warp.sdk.io.models.MerchantList;
......@@ -2563,6 +2564,93 @@ public class WarplyManager {
return future;
}
private static ListenableFuture<MarketPassDetailsModel> getMarketPassDetails(ApiService service) {
SettableFuture<MarketPassDetailsModel> future = SettableFuture.create();
String timeStamp = DateFormat.format("yyyy-MM-dd hh:mm:ss", System.currentTimeMillis()).toString();
String apiKey = WarpUtils.getApiKey(Warply.getWarplyContext());
String webId = WarpUtils.getWebId(Warply.getWarplyContext());
Map<String, Object> jsonParamsMarketPassDetails = new ArrayMap<>();
Map<String, Object> jsonParams = new ArrayMap<>();
jsonParams.put("action", "integration");
jsonParams.put("method", "supermarket_profile");
jsonParamsMarketPassDetails.put("consumer_data", jsonParams);
RequestBody marketPassDetailsRequest = RequestBody.create(MediaType.get("application/json; charset=utf-8"), (new JSONObject(jsonParamsMarketPassDetails)).toString());
Call<ResponseBody> marketPassDetailsCall = service.getMarketPassDetails(
WarplyProperty.getAppUuid(Warply.getWarplyContext()),
marketPassDetailsRequest,
timeStamp,
"android:" + Warply.getWarplyContext().getPackageName(),
new WarplyDeviceInfoCollector(Warply.getWarplyContext()).getUniqueDeviceId(),
"mobile",
webId,
WarpUtils.produceSignature(apiKey + timeStamp),
"Bearer " + WarplyDBHelper.getInstance(Warply.getWarplyContext()).getAuthValue("access_token")
);
marketPassDetailsCall.enqueue(new Callback<ResponseBody>() {
@Override
public void onResponse(@NonNull Call<ResponseBody> call, @NonNull Response<ResponseBody> response) {
if (response.code() == 200 && response.body() != null) {
JSONObject marketPassDetailsResponse = null;
try {
marketPassDetailsResponse = new JSONObject(response.body().string());
} catch (Exception e) {
e.printStackTrace();
}
if (marketPassDetailsResponse != null && marketPassDetailsResponse.has("status") && marketPassDetailsResponse.optString("status", "2").equals("1")) {
LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel();
dynatraceEvent.setEventName("custom_success_market_pass_details");
EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent));
final ExecutorService executorMarketPassDetails = Executors.newFixedThreadPool(1);
final JSONObject finalMarketPassDetailsResponse = marketPassDetailsResponse;
executorMarketPassDetails.submit(() -> {
JSONObject marketPassDetailsBody = null;
try {
marketPassDetailsBody = finalMarketPassDetailsResponse.optJSONObject("result");
} catch (Exception e) {
e.printStackTrace();
}
if (marketPassDetailsBody != null) {
MarketPassDetailsModel marketPassDetailsModel = new MarketPassDetailsModel(marketPassDetailsBody);
executorMarketPassDetails.shutdownNow();
future.set(marketPassDetailsModel);
}
});
} else {
LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel();
dynatraceEvent.setEventName("custom_error_market_pass_details");
EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent));
future.set(new MarketPassDetailsModel());
}
} else {
LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel();
dynatraceEvent.setEventName("custom_error_market_pass_details");
EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent));
// future.set(new JSONObject());
future.setException(new Throwable());
}
}
@Override
public void onFailure(@NonNull Call<ResponseBody> call, @NonNull Throwable t) {
LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel();
dynatraceEvent.setEventName("custom_error_market_pass_details");
EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent));
// future.set(new JSONObject());
future.setException(new Throwable());
}
});
return future;
}
public static void getMapData(final CallbackReceiver<ArrayList<UnifiedCampaignModel>> receiver) {
WarpUtils.log("************* WARPLY Get Map Data Request ********************");
WarpUtils.log("[WARP Trace] WARPLY Get Map Data Request is active");
......@@ -3815,108 +3903,6 @@ public class WarplyManager {
});
}
public static void getUserCouponsWithCouponsets(WarplyUserCouponsRequest request, final CallbackReceiver<CouponList> receiver) {
WarpUtils.log("************* WARPLY User Coupons Request ********************");
WarpUtils.log("[WARP Trace] WARPLY User Coupons Request is active");
WarpUtils.log("**************************************************");
WarplyManager.getMerchantsMultilingual(new WarplyMerchantsRequest()
.setIsMultilingual(true)
, new CallbackReceiver<MerchantList>() {
@Override
public void onSuccess(MerchantList result) {
WarplyManagerHelper.setMerchantList(result);
LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel();
dynatraceEvent.setEventName("custom_success_shops_loyalty");
EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent));
getCouponsets(new WarplyGetCouponsetsRequest()
.setLanguage(WarplyProperty.getLanguage(Warply.getWarplyContext())), new CallbackReceiver<CouponsetsList>() {
@Override
public void onSuccess(CouponsetsList result) {
Warply.postReceiveMicroappData(WarpConstants.MICROAPP_COUPONS, true, "context", request.toJson(), new CouponsHook(new CallbackReceiver<CouponList>() {
@Override
public void onSuccess(CouponList response) {
CouponList mCouponList = new CouponList();
for (Coupon coupon : response) {
for (Couponset couponset : result) {
if (coupon.getCouponsetUuid().equals(couponset.getUuid())) {
coupon.setDescription(couponset.getShortDescription());
coupon.setImage(couponset.getImgPreview());
coupon.setName(couponset.getName());
coupon.setMerchantUuid(couponset.getMerchantUuid());
coupon.setInnerText(couponset.getInnerText());
coupon.setDiscount_type(couponset.getDiscount_type());
coupon.setFinal_price(couponset.getFinal_price());
mCouponList.add(coupon);
}
}
}
WarplyManagerHelper.setCouponList(mCouponList);
CouponList mActiveCouponList = new CouponList();
for (Coupon coupon : mCouponList) {
if (coupon.getStatus() == 1) {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm");
Date newDate = new Date();
try {
newDate = simpleDateFormat.parse(coupon.getExpiration());
} catch (ParseException e) {
e.printStackTrace();
}
coupon.setExpirationDate(newDate);
mActiveCouponList.add(coupon);
}
}
Collections.sort(mActiveCouponList, (coupon1, coupon2) -> coupon1.getExpirationDate().compareTo(coupon2.getExpirationDate()));
receiver.onSuccess(mActiveCouponList);
}
@Override
public void onFailure(int errorCode) {
if (errorCode == 401) {
refreshToken(new WarplyRefreshTokenRequest(), new CallbackReceiver<JSONObject>() {
@Override
public void onSuccess(JSONObject result) {
int status = result.optInt("status", 2);
if (status == 1)
getUserCoupons(request, receiver);
else
receiver.onFailure(status);
}
@Override
public void onFailure(int errorCode) {
receiver.onFailure(errorCode);
}
});
} else
receiver.onFailure(errorCode);
}
},
request.getSignature()));
}
@Override
public void onFailure(int errorCode) {
receiver.onFailure(errorCode);
}
});
}
@Override
public void onFailure(int errorCode) {
LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel();
dynatraceEvent.setEventName("custom_error_shops_loyalty");
EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent));
receiver.onFailure(errorCode);
}
});
}
public static void getMerchantsMultilingual(ArrayList<String> catuuids, final CallbackReceiver<MerchantList> receiver) {
WarpUtils.log("************* WARPLY Merchants Request ********************");
WarpUtils.log("[WARP Trace] WARPLY Merchants Request is active");
......@@ -4057,231 +4043,6 @@ public class WarplyManager {
});
}
// public static void getUserCouponsWithCouponsets(final CallbackReceiver<CouponList> receiver) {
// WarpUtils.log("************* WARPLY User Coupons Request ********************");
// WarpUtils.log("[WARP Trace] WARPLY User Coupons Request is active");
// WarpUtils.log("**************************************************");
//
// ApiService service = ApiClient.getRetrofitInstance().create(ApiService.class);
//
// getMerchantsRetro(service, new Callback<ResponseBody>() {
// @Override
// public void onResponse(@NonNull Call<ResponseBody> call, @NonNull Response<ResponseBody> responseMerchants) {
// if (responseMerchants.code() == 200 && responseMerchants.body() != null) {
// JSONObject jobjMerchantsResponse = null;
// try {
// jobjMerchantsResponse = new JSONObject(responseMerchants.body().string());
// } catch (Exception e) {
// e.printStackTrace();
// }
//
// if (jobjMerchantsResponse != null && jobjMerchantsResponse.has("status") && jobjMerchantsResponse.optString("status", "2").equals("1")) {
// LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel();
// dynatraceEvent.setEventName("custom_success_shops_loyalty");
// EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent));
//
// JSONArray jMerchantsBody = null;
// try {
// jMerchantsBody = jobjMerchantsResponse.optJSONObject("context").optJSONObject("MAPP_SHOPS").optJSONArray("result");
// } catch (Exception e) {
// e.printStackTrace();
// }
//
// if (jMerchantsBody != null) {
// MerchantList mMerchantList = new MerchantList();
//
// final ExecutorService executorShops = Executors.newFixedThreadPool(1);
// JSONArray finalMerchantsJBody = jMerchantsBody;
// executorShops.submit(() -> {
// for (int i = 0; i < finalMerchantsJBody.length(); ++i) {
// mMerchantList.add(new Merchant(finalMerchantsJBody.optJSONObject(i)));
// }
// WarplyManagerHelper.setMerchantList(mMerchantList);
// executorShops.shutdownNow();
// });
//
// getCouponsetsRetro(service, new Callback<ResponseBody>() {
// @Override
// public void onResponse(@NonNull Call<ResponseBody> call, @NonNull Response<ResponseBody> responseCouponsets) {
// if (responseCouponsets.code() == 200 && responseCouponsets.body() != null) {
// JSONObject jobjCouponsetsResponse = null;
// try {
// jobjCouponsetsResponse = new JSONObject(responseCouponsets.body().string());
// } catch (Exception e) {
// e.printStackTrace();
// }
//
// if (jobjCouponsetsResponse != null && jobjCouponsetsResponse.has("status") && jobjCouponsetsResponse.optString("status", "2").equals("1")) {
// LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel();
// dynatraceEvent.setEventName("custom_success_couponsets_loyalty");
// EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent));
//
// JSONObject finalJobjCouponsetsResponse = jobjCouponsetsResponse;
// getUserCouponsRetro(service, new Callback<ResponseBody>() {
// @Override
// public void onResponse(@NonNull Call<ResponseBody> call, @NonNull Response<ResponseBody> responseCoupons) {
// if (responseCoupons.code() == 200 && responseCoupons.body() != null) {
// JSONObject jobjCouponsResponse = null;
// try {
// jobjCouponsResponse = new JSONObject(responseCoupons.body().string());
// } catch (Exception e) {
// e.printStackTrace();
// }
//
// if (jobjCouponsResponse != null && jobjCouponsResponse.has("status") && jobjCouponsResponse.optInt("status", 2) == 1) {
// LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel();
// dynatraceEvent.setEventName("custom_success_user_coupons_loyalty");
// EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent));
//
// JSONObject finalJobjCouponsResponse = jobjCouponsResponse;
// final ExecutorService executor = Executors.newFixedThreadPool(1);
// executor.submit(() -> {
// // COUPONS START //
// JSONArray jCouponsBody = null;
// try {
// jCouponsBody = finalJobjCouponsResponse.optJSONArray("result");
// } catch (Exception e) {
// e.printStackTrace();
// }
// // COUPONS END //
//
// // COUPONSETS START //
// JSONArray jCouponsetsBody = null;
// try {
// jCouponsetsBody = finalJobjCouponsetsResponse.optJSONObject("context").optJSONArray("MAPP_COUPON");
// } catch (Exception e) {
// e.printStackTrace();
// }
// // COUPONSETS END //
//
// if (jCouponsetsBody != null && jCouponsBody != null) {
// CouponList mCouponList = new CouponList();
// CouponList mCouponRedeemedList = new CouponList();
// CouponsetsList mCouponsetList = new CouponsetsList();
// for (int i = 0; i < jCouponsetsBody.length(); ++i) {
// Couponset tempCouponset = new Couponset(jCouponsetsBody.optJSONObject(i));
// mCouponsetList.add(tempCouponset);
// for (int j = 0; j < jCouponsBody.length(); ++j) {
// Coupon tempCoupon = new Coupon(jCouponsBody.optJSONObject(j));
// if (tempCoupon.getCouponsetUuid().equals(tempCouponset.getUuid())) {
// tempCoupon.setDescription(tempCouponset.getShortDescription());
// tempCoupon.setImage(tempCouponset.getImgPreview());
// tempCoupon.setName(tempCouponset.getName());
// tempCoupon.setMerchantUuid(tempCouponset.getMerchantUuid());
// tempCoupon.setInnerText(tempCouponset.getInnerText());
// tempCoupon.setDiscount_type(tempCouponset.getDiscount_type());
// tempCoupon.setFinal_price(tempCouponset.getFinal_price());
// mCouponList.add(tempCoupon);
// }
// }
// }
//
// for (int j = 0; j < jCouponsBody.length(); ++j) {
// Coupon tempCoupon = new Coupon(jCouponsBody.optJSONObject(j));
// if (tempCoupon.getStatus() == 0) {
// mCouponRedeemedList.add(tempCoupon);
// }
// }
// WarplyManagerHelper.setCouponsets(mCouponsetList);
// WarplyManagerHelper.setCouponList(mCouponList);
// WarplyManagerHelper.setCouponRedeemedList(mCouponRedeemedList);
//
// CouponList mActiveCouponList = new CouponList();
// for (Coupon coupon : mCouponList) {
// if (coupon.getStatus() == 1) {
// SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm");
// Date newDate = new Date();
// try {
// newDate = simpleDateFormat.parse(coupon.getExpiration());
// } catch (
// ParseException e) {
// e.printStackTrace();
// }
// coupon.setExpirationDate(newDate);
// mActiveCouponList.add(coupon);
// }
// }
//
// Collections.sort(mActiveCouponList, (coupon1, coupon2) -> coupon1.getExpirationDate().compareTo(coupon2.getExpirationDate()));
//
// new Handler(Looper.getMainLooper()).post(() -> receiver.onSuccess(mActiveCouponList));
// executor.shutdownNow();
// }
// });
// } else {
// LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel();
// dynatraceEvent.setEventName("custom_error_user_coupons_loyalty");
// EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent));
// receiver.onFailure(2);
// }
// } else {
// LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel();
// dynatraceEvent.setEventName("custom_error_user_coupons_loyalty");
// EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent));
// receiver.onFailure(responseCoupons.code());
// }
// }
//
// @Override
// public void onFailure(@NonNull Call<ResponseBody> call, @NonNull Throwable t) {
// LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel();
// dynatraceEvent.setEventName("custom_error_user_coupons_loyalty");
// EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent));
// receiver.onFailure(2);
// }
// });
//
// } else {
// LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel();
// dynatraceEvent.setEventName("custom_error_couponsets_loyalty");
// EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent));
// receiver.onFailure(2);
// }
//
// } else {
// LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel();
// dynatraceEvent.setEventName("custom_error_couponsets_loyalty");
// EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent));
// receiver.onFailure(responseCouponsets.code());
// }
// }
//
// @Override
// public void onFailure(@NonNull Call<ResponseBody> call, @NonNull Throwable t) {
// LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel();
// dynatraceEvent.setEventName("custom_error_couponsets_loyalty");
// EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent));
// receiver.onFailure(2);
// }
// });
// }
// } else {
// LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel();
// dynatraceEvent.setEventName("custom_error_shops_loyalty");
// EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent));
//
// receiver.onFailure(2);
// }
// } else {
// LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel();
// dynatraceEvent.setEventName("custom_error_shops_loyalty");
// EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent));
//
// receiver.onFailure(responseMerchants.code());
// }
// }
//
// @Override
// public void onFailure(@NonNull Call<ResponseBody> call, @NonNull Throwable t) {
// LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel();
// dynatraceEvent.setEventName("custom_error_shops_loyalty");
// EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent));
//
// receiver.onFailure(2);
// }
// });
// }
private static /*void*/ ListenableFuture<CouponsetsList> getCouponsetsRetro(ApiService service/*, Callback<ResponseBody> callback*/) {
SettableFuture<CouponsetsList> future = SettableFuture.create();
......@@ -5063,6 +4824,7 @@ public class WarplyManager {
jsonParams.put("action", "user_coupons");
JSONArray jArr = new JSONArray();
jArr.put("merchant");
jArr.put("redemption");
jsonParams.put("details", jArr);
jsonParams.put("language", WarplyProperty.getLanguage(Warply.getWarplyContext()));
// JSONObject jPagination= new JSONObject();
......@@ -5498,4 +5260,39 @@ public class WarplyManager {
}
return false;
}
public static void getMarketPassDetails(final CallbackReceiver<MarketPassDetailsModel> receiver) {
WarpUtils.log("************* WARPLY Market Pass Details Request ********************");
WarpUtils.log("[WARP Trace] WARPLY Market Pass Details is active");
WarpUtils.log("**************************************************");
ApiService service = ApiClient.getRetrofitInstance().create(ApiService.class);
ListeningExecutorService executorService = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(1));
ListenableFuture<MarketPassDetailsModel> futureMarketPassDetails = getMarketPassDetails(service);
ListenableFuture<List<Object>> allResultsFuture = Futures.allAsList(futureMarketPassDetails);
ListenableFuture<MarketPassDetailsModel> mergedResultFuture = Futures.transformAsync(
allResultsFuture,
results -> {
MarketPassDetailsModel resultMarketPassDetails = (MarketPassDetailsModel) results.get(0);
return executorService.submit(() -> resultMarketPassDetails);
},
executorService
);
Futures.addCallback(mergedResultFuture, new FutureCallback<MarketPassDetailsModel>() {
@Override
public void onSuccess(MarketPassDetailsModel mergedResult) {
executorService.shutdownNow();
new Handler(Looper.getMainLooper()).post(() -> receiver.onSuccess(mergedResult));
}
@Override
public void onFailure(Throwable throwable) {
executorService.shutdownNow();
new Handler(Looper.getMainLooper()).post(() -> receiver.onFailure(2));
}
}, executorService);
}
}
......