Panagiotis Triantafyllou

cosmote pass requests

...@@ -97,6 +97,7 @@ public class Coupon implements Parcelable, Serializable { ...@@ -97,6 +97,7 @@ public class Coupon implements Parcelable, Serializable {
97 private String terms = ""; 97 private String terms = "";
98 private Couponset couponsetDetails = new Couponset(true); 98 private Couponset couponsetDetails = new Couponset(true);
99 private Merchant merchantDetails = new Merchant(true); 99 private Merchant merchantDetails = new Merchant(true);
100 + private RedeemMerchantDetails redeemDetails = new RedeemMerchantDetails();
100 101
101 public Coupon() { 102 public Coupon() {
102 this.barcode = ""; 103 this.barcode = "";
...@@ -121,6 +122,7 @@ public class Coupon implements Parcelable, Serializable { ...@@ -121,6 +122,7 @@ public class Coupon implements Parcelable, Serializable {
121 this.final_price = 0.0d; 122 this.final_price = 0.0d;
122 this.short_description = ""; 123 this.short_description = "";
123 this.terms = ""; 124 this.terms = "";
125 + this.redeemDetails = new RedeemMerchantDetails();
124 } 126 }
125 127
126 public Coupon(boolean isUniversal) { 128 public Coupon(boolean isUniversal) {
...@@ -135,6 +137,7 @@ public class Coupon implements Parcelable, Serializable { ...@@ -135,6 +137,7 @@ public class Coupon implements Parcelable, Serializable {
135 this.redeemDate = new Date(); 137 this.redeemDate = new Date();
136 this.couponsetDetails = new Couponset(isUniversal); 138 this.couponsetDetails = new Couponset(isUniversal);
137 this.merchantDetails = new Merchant(isUniversal); 139 this.merchantDetails = new Merchant(isUniversal);
140 + this.redeemDetails = new RedeemMerchantDetails();
138 } 141 }
139 142
140 /** 143 /**
...@@ -189,6 +192,10 @@ public class Coupon implements Parcelable, Serializable { ...@@ -189,6 +192,10 @@ public class Coupon implements Parcelable, Serializable {
189 this.final_price = json.optDouble(FINAL_PRICE); 192 this.final_price = json.optDouble(FINAL_PRICE);
190 this.short_description = json.optString(SHORT_DESCRIPTION); 193 this.short_description = json.optString(SHORT_DESCRIPTION);
191 this.terms = json.optString(TERMS); 194 this.terms = json.optString(TERMS);
195 + JSONObject tempRedeemDetails = json.optJSONObject("redeemed_merchant_details");
196 + if (tempRedeemDetails != null) {
197 + this.redeemDetails = new RedeemMerchantDetails(tempRedeemDetails);
198 + }
192 } 199 }
193 } 200 }
194 201
...@@ -224,6 +231,10 @@ public class Coupon implements Parcelable, Serializable { ...@@ -224,6 +231,10 @@ public class Coupon implements Parcelable, Serializable {
224 if (tempMerchantDetails != null) { 231 if (tempMerchantDetails != null) {
225 this.merchantDetails = new Merchant(tempMerchantDetails, isUniversal); 232 this.merchantDetails = new Merchant(tempMerchantDetails, isUniversal);
226 } 233 }
234 + JSONObject tempRedeemDetails = json.optJSONObject("redeemed_merchant_details");
235 + if (tempRedeemDetails != null) {
236 + this.redeemDetails = new RedeemMerchantDetails(tempRedeemDetails);
237 + }
227 238
228 // this.category = json.optString(CATEGORY); 239 // this.category = json.optString(CATEGORY);
229 // this.created = json.optString(CREATED); 240 // this.created = json.optString(CREATED);
...@@ -240,6 +251,75 @@ public class Coupon implements Parcelable, Serializable { ...@@ -240,6 +251,75 @@ public class Coupon implements Parcelable, Serializable {
240 } 251 }
241 } 252 }
242 253
254 + public class RedeemMerchantDetails {
255 + private static final String IMG_PREVIEW = "img_preview";
256 + private static final String NAME = "name";
257 + private static final String UUID = "uuid";
258 + private static final String REDEEMED_DATE = "redeemed_date";
259 +
260 +
261 + private String imgPreview = "";
262 + private String name = "";
263 + private String uuid = "";
264 + private String redeemedDate = "";
265 +
266 + public RedeemMerchantDetails() {
267 + this.imgPreview = "";
268 + this.name = "";
269 + this.uuid = "";
270 + this.redeemedDate = "";
271 + }
272 +
273 + public RedeemMerchantDetails(JSONObject json) {
274 + if (json != null) {
275 + if (json.optJSONObject(IMG_PREVIEW) != null) {
276 + this.imgPreview = json.optString(IMG_PREVIEW);
277 + }
278 + if (json.optJSONObject(NAME) != null) {
279 + this.name = json.optString(NAME);
280 + }
281 + if (json.optJSONObject(UUID) != null) {
282 + this.uuid = json.optString(UUID);
283 + }
284 + if (json.optJSONObject(REDEEMED_DATE) != null) {
285 + this.redeemedDate = json.optString(REDEEMED_DATE);
286 + }
287 + }
288 + }
289 +
290 + public String getImgPreview() {
291 + return imgPreview;
292 + }
293 +
294 + public void setImgPreview(String imgPreview) {
295 + this.imgPreview = imgPreview;
296 + }
297 +
298 + public String getName() {
299 + return name;
300 + }
301 +
302 + public void setName(String name) {
303 + this.name = name;
304 + }
305 +
306 + public String getUuid() {
307 + return uuid;
308 + }
309 +
310 + public void setUuid(String uuid) {
311 + this.uuid = uuid;
312 + }
313 +
314 + public String getRedeemedDate() {
315 + return redeemedDate;
316 + }
317 +
318 + public void setRedeemedDate(String redeemedDate) {
319 + this.redeemedDate = redeemedDate;
320 + }
321 + }
322 +
243 public Coupon(Parcel source) { 323 public Coupon(Parcel source) {
244 this.barcode = source.readString(); 324 this.barcode = source.readString();
245 this.category = source.readString(); 325 this.category = source.readString();
...@@ -544,6 +624,14 @@ public class Coupon implements Parcelable, Serializable { ...@@ -544,6 +624,14 @@ public class Coupon implements Parcelable, Serializable {
544 this.merchantDetails = merchantDetails; 624 this.merchantDetails = merchantDetails;
545 } 625 }
546 626
627 + public RedeemMerchantDetails getRedeemDetails() {
628 + return redeemDetails;
629 + }
630 +
631 + public void setRedeemDetails(RedeemMerchantDetails redeemDetails) {
632 + this.redeemDetails = redeemDetails;
633 + }
634 +
547 @Override 635 @Override
548 public int describeContents() { 636 public int describeContents() {
549 return 0; 637 return 0;
......
1 +/*
2 + * Copyright 2010-2013 Warply Ltd. All rights reserved.
3 + *
4 + * Redistribution and use in source and binary forms, without modification, are
5 + * permitted provided that the following conditions are met:
6 + *
7 + * 1. Redistributions of source code must retain the above copyright notice,
8 + * this list of conditions and the following disclaimer.
9 + *
10 + * 2. Redistributions in binary form must reproduce the above copyright notice,
11 + * this list of conditions and the following disclaimer in the documentation
12 + * and/or other materials provided with the distribution.
13 + *
14 + * THIS SOFTWARE IS PROVIDED BY THE WARPLY LTD ``AS IS'' AND ANY EXPRESS OR
15 + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
16 + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
17 + * EVENT SHALL WARPLY LTD OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
18 + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
19 + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
20 + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
21 + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
22 + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
23 + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 + */
25 +
26 +package ly.warp.sdk.io.models;
27 +
28 +import org.json.JSONArray;
29 +import org.json.JSONException;
30 +import org.json.JSONObject;
31 +
32 +import java.util.ArrayList;
33 +
34 +import ly.warp.sdk.utils.WarpUtils;
35 +import ly.warp.sdk.utils.constants.WarpConstants;
36 +
37 +/**
38 + * Created by Panagiotis Triantafyllou on 20-Jan-25.
39 + */
40 +
41 +public class MarketPassDetailsModel {
42 + private static final String BARCODE = "barcode";
43 + private static final String SUPERMARKETS = "supermarkets";
44 + private static final String TOTAL_DISCOUNT = "total_available_discount";
45 +
46 + private ArrayList<Supermarkets> supermarkets = new ArrayList<Supermarkets>();
47 + private String barcode = "";
48 + private double totalDiscount = 0.0d;
49 +
50 + public MarketPassDetailsModel() {
51 + this.supermarkets = new ArrayList<Supermarkets>();
52 + this.barcode = "";
53 + this.totalDiscount = 0.0d;
54 + }
55 +
56 + /**
57 + * Basic constructor used to create an object from a String, representing a
58 + * JSON Object
59 + *
60 + * @param json The String, representing the JSON Object
61 + * @throws JSONException Thrown if the String cannot be converted to JSON
62 + */
63 + public MarketPassDetailsModel(String json) throws JSONException {
64 + this(new JSONObject(json));
65 + }
66 +
67 + /**
68 + * Constructor used to create an Object from a given JSON Object
69 + *
70 + * @param json JSON Object used to create the Campaign
71 + */
72 + public MarketPassDetailsModel(JSONObject json) {
73 + if (json != null) {
74 + if (json.optJSONArray(SUPERMARKETS) != null) {
75 + JSONArray tempSupermarkets = json.optJSONArray(SUPERMARKETS);
76 + if (tempSupermarkets != null && tempSupermarkets.length() > 0) {
77 + for (int i = 0, lim = tempSupermarkets.length(); i < lim; ++i) {
78 + this.supermarkets.add(new Supermarkets(tempSupermarkets.optJSONObject(i)));
79 + }
80 + }
81 + }
82 + this.barcode = json.optString(BARCODE);
83 + this.totalDiscount = json.optDouble(TOTAL_DISCOUNT);
84 + }
85 + }
86 +
87 + /**
88 + * Converts the Campaign into a JSON Object
89 + *
90 + * @return The JSON Object created from this campaign
91 + */
92 + public JSONObject toJSONObject() {
93 + JSONObject jObj = new JSONObject();
94 + try {
95 + jObj.putOpt(BARCODE, this.barcode);
96 + jObj.putOpt(TOTAL_DISCOUNT, this.totalDiscount);
97 + jObj.putOpt(SUPERMARKETS, this.supermarkets);
98 + } catch (JSONException e) {
99 + if (WarpConstants.DEBUG) {
100 + e.printStackTrace();
101 + }
102 + }
103 + return jObj;
104 + }
105 +
106 + /**
107 + * String representation of the Campaign, as a JSON object
108 + *
109 + * @return A String representation of JSON object
110 + */
111 + public String toString() {
112 + if (toJSONObject() != null)
113 + return toJSONObject().toString();
114 + return null;
115 + }
116 +
117 + /**
118 + * String representation of the Campaign, as a human readable JSON object
119 + *
120 + * @return A human readable String representation of JSON object
121 + */
122 + public String toHumanReadableString() {
123 + String humanReadableString = null;
124 + try {
125 + humanReadableString = toJSONObject().toString(2);
126 + } catch (JSONException e) {
127 + WarpUtils.warn("Failed converting Campaign JSON object to String",
128 + e);
129 + }
130 + return humanReadableString;
131 + }
132 +
133 + public class Supermarkets {
134 + private static final String LOGO = "logo";
135 + private static final String NAME = "name";
136 + private static final String UUID = "uuid";
137 +
138 +
139 + private String logo = "";
140 + private String name = "";
141 + private String uuid = "";
142 +
143 + public Supermarkets() {
144 + this.logo = "";
145 + this.name = "";
146 + this.uuid = "";
147 + }
148 +
149 + public Supermarkets(JSONObject json) {
150 + if (json != null) {
151 + if (json.optJSONObject(LOGO) != null) {
152 + this.logo = json.optString(LOGO);
153 + }
154 + if (json.optJSONObject(NAME) != null) {
155 + this.name = json.optString(NAME);
156 + }
157 + if (json.optJSONObject(UUID) != null) {
158 + this.uuid = json.optString(UUID);
159 + }
160 + }
161 + }
162 +
163 + public String getLogo() {
164 + return logo;
165 + }
166 +
167 + public void setLogo(String logo) {
168 + this.logo = logo;
169 + }
170 +
171 + public String getName() {
172 + return name;
173 + }
174 +
175 + public void setName(String name) {
176 + this.name = name;
177 + }
178 +
179 + public String getUuid() {
180 + return uuid;
181 + }
182 +
183 + public void setUuid(String uuid) {
184 + this.uuid = uuid;
185 + }
186 + }
187 +
188 + // ================================================================================
189 + // Getters
190 + // ================================================================================
191 +
192 +
193 + public ArrayList<Supermarkets> getSupermarkets() {
194 + return supermarkets;
195 + }
196 +
197 + public void setSupermarkets(ArrayList<Supermarkets> supermarkets) {
198 + this.supermarkets = supermarkets;
199 + }
200 +
201 + public String getBarcode() {
202 + return barcode;
203 + }
204 +
205 + public void setBarcode(String barcode) {
206 + this.barcode = barcode;
207 + }
208 +
209 + public double getTotalDiscount() {
210 + return totalDiscount;
211 + }
212 +
213 + public void setTotalDiscount(double totalDiscount) {
214 + this.totalDiscount = totalDiscount;
215 + }
216 +}
...@@ -79,13 +79,13 @@ public interface ApiService { ...@@ -79,13 +79,13 @@ public interface ApiService {
79 @Headers("Content-Type: application/json") 79 @Headers("Content-Type: application/json")
80 @POST("/user/v5/{appUuid}/logout") 80 @POST("/user/v5/{appUuid}/logout")
81 Call<ResponseBody> logoutUserJwt(@Path("appUuid") String appUuid, 81 Call<ResponseBody> logoutUserJwt(@Path("appUuid") String appUuid,
82 - @Body RequestBody request, 82 + @Body RequestBody request,
83 - @Header(WarpConstants.HEADER_DATE) String timeStamp, 83 + @Header(WarpConstants.HEADER_DATE) String timeStamp,
84 - @Header(WarpConstants.HEADER_LOYALTY_BUNDLE_ID) String bundleId, 84 + @Header(WarpConstants.HEADER_LOYALTY_BUNDLE_ID) String bundleId,
85 - @Header(WarpConstants.HEADER_UNIQUE_DEVICE_ID) String deviceId, 85 + @Header(WarpConstants.HEADER_UNIQUE_DEVICE_ID) String deviceId,
86 - @Header(WarpConstants.HEADER_CHANNEL) String channel, 86 + @Header(WarpConstants.HEADER_CHANNEL) String channel,
87 - @Header(WarpConstants.HEADER_WEB_ID) String webId, 87 + @Header(WarpConstants.HEADER_WEB_ID) String webId,
88 - @Header(WarpConstants.HEADER_SIGNATURE) String signature); 88 + @Header(WarpConstants.HEADER_SIGNATURE) String signature);
89 89
90 @Headers("Content-Type: application/json") 90 @Headers("Content-Type: application/json")
91 @POST("/oauth/{appUuid}/context") 91 @POST("/oauth/{appUuid}/context")
...@@ -174,6 +174,18 @@ public interface ApiService { ...@@ -174,6 +174,18 @@ public interface ApiService {
174 174
175 @Headers("Content-Type: application/json") 175 @Headers("Content-Type: application/json")
176 @POST("/oauth/{appUuid}/context") 176 @POST("/oauth/{appUuid}/context")
177 + Call<ResponseBody> getMarketPassDetails(@Path("appUuid") String appUuid,
178 + @Body RequestBody request,
179 + @Header(WarpConstants.HEADER_DATE) String timeStamp,
180 + @Header(WarpConstants.HEADER_LOYALTY_BUNDLE_ID) String bundleId,
181 + @Header(WarpConstants.HEADER_UNIQUE_DEVICE_ID) String deviceId,
182 + @Header(WarpConstants.HEADER_CHANNEL) String channel,
183 + @Header(WarpConstants.HEADER_WEB_ID) String webId,
184 + @Header(WarpConstants.HEADER_SIGNATURE) String signature,
185 + @Header(WarpConstants.HEADER_AUTHORIZATION) String bearer);
186 +
187 + @Headers("Content-Type: application/json")
188 + @POST("/oauth/{appUuid}/context")
177 Call<ResponseBody> sendTelematicsData(@Path("appUuid") String appUuid, 189 Call<ResponseBody> sendTelematicsData(@Path("appUuid") String appUuid,
178 @Body RequestBody request, 190 @Body RequestBody request,
179 @Header(WarpConstants.HEADER_DATE) String timeStamp, 191 @Header(WarpConstants.HEADER_DATE) String timeStamp,
......
...@@ -94,6 +94,7 @@ import ly.warp.sdk.io.models.CouponList; ...@@ -94,6 +94,7 @@ import ly.warp.sdk.io.models.CouponList;
94 import ly.warp.sdk.io.models.Couponset; 94 import ly.warp.sdk.io.models.Couponset;
95 import ly.warp.sdk.io.models.CouponsetsList; 95 import ly.warp.sdk.io.models.CouponsetsList;
96 import ly.warp.sdk.io.models.LoyaltySDKDynatraceEventModel; 96 import ly.warp.sdk.io.models.LoyaltySDKDynatraceEventModel;
97 +import ly.warp.sdk.io.models.MarketPassDetailsModel;
97 import ly.warp.sdk.io.models.Merchant; 98 import ly.warp.sdk.io.models.Merchant;
98 import ly.warp.sdk.io.models.MerchantCategoriesList; 99 import ly.warp.sdk.io.models.MerchantCategoriesList;
99 import ly.warp.sdk.io.models.MerchantList; 100 import ly.warp.sdk.io.models.MerchantList;
...@@ -2563,6 +2564,93 @@ public class WarplyManager { ...@@ -2563,6 +2564,93 @@ public class WarplyManager {
2563 return future; 2564 return future;
2564 } 2565 }
2565 2566
2567 + private static ListenableFuture<MarketPassDetailsModel> getMarketPassDetails(ApiService service) {
2568 + SettableFuture<MarketPassDetailsModel> future = SettableFuture.create();
2569 +
2570 + String timeStamp = DateFormat.format("yyyy-MM-dd hh:mm:ss", System.currentTimeMillis()).toString();
2571 + String apiKey = WarpUtils.getApiKey(Warply.getWarplyContext());
2572 + String webId = WarpUtils.getWebId(Warply.getWarplyContext());
2573 +
2574 + Map<String, Object> jsonParamsMarketPassDetails = new ArrayMap<>();
2575 + Map<String, Object> jsonParams = new ArrayMap<>();
2576 + jsonParams.put("action", "integration");
2577 + jsonParams.put("method", "supermarket_profile");
2578 +
2579 + jsonParamsMarketPassDetails.put("consumer_data", jsonParams);
2580 + RequestBody marketPassDetailsRequest = RequestBody.create(MediaType.get("application/json; charset=utf-8"), (new JSONObject(jsonParamsMarketPassDetails)).toString());
2581 +
2582 + Call<ResponseBody> marketPassDetailsCall = service.getMarketPassDetails(
2583 + WarplyProperty.getAppUuid(Warply.getWarplyContext()),
2584 + marketPassDetailsRequest,
2585 + timeStamp,
2586 + "android:" + Warply.getWarplyContext().getPackageName(),
2587 + new WarplyDeviceInfoCollector(Warply.getWarplyContext()).getUniqueDeviceId(),
2588 + "mobile",
2589 + webId,
2590 + WarpUtils.produceSignature(apiKey + timeStamp),
2591 + "Bearer " + WarplyDBHelper.getInstance(Warply.getWarplyContext()).getAuthValue("access_token")
2592 + );
2593 +
2594 + marketPassDetailsCall.enqueue(new Callback<ResponseBody>() {
2595 + @Override
2596 + public void onResponse(@NonNull Call<ResponseBody> call, @NonNull Response<ResponseBody> response) {
2597 + if (response.code() == 200 && response.body() != null) {
2598 + JSONObject marketPassDetailsResponse = null;
2599 + try {
2600 + marketPassDetailsResponse = new JSONObject(response.body().string());
2601 + } catch (Exception e) {
2602 + e.printStackTrace();
2603 + }
2604 +
2605 + if (marketPassDetailsResponse != null && marketPassDetailsResponse.has("status") && marketPassDetailsResponse.optString("status", "2").equals("1")) {
2606 + LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel();
2607 + dynatraceEvent.setEventName("custom_success_market_pass_details");
2608 + EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent));
2609 +
2610 + final ExecutorService executorMarketPassDetails = Executors.newFixedThreadPool(1);
2611 + final JSONObject finalMarketPassDetailsResponse = marketPassDetailsResponse;
2612 + executorMarketPassDetails.submit(() -> {
2613 + JSONObject marketPassDetailsBody = null;
2614 + try {
2615 + marketPassDetailsBody = finalMarketPassDetailsResponse.optJSONObject("result");
2616 + } catch (Exception e) {
2617 + e.printStackTrace();
2618 + }
2619 +
2620 + if (marketPassDetailsBody != null) {
2621 + MarketPassDetailsModel marketPassDetailsModel = new MarketPassDetailsModel(marketPassDetailsBody);
2622 + executorMarketPassDetails.shutdownNow();
2623 + future.set(marketPassDetailsModel);
2624 + }
2625 + });
2626 + } else {
2627 + LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel();
2628 + dynatraceEvent.setEventName("custom_error_market_pass_details");
2629 + EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent));
2630 + future.set(new MarketPassDetailsModel());
2631 + }
2632 + } else {
2633 + LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel();
2634 + dynatraceEvent.setEventName("custom_error_market_pass_details");
2635 + EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent));
2636 +// future.set(new JSONObject());
2637 + future.setException(new Throwable());
2638 + }
2639 + }
2640 +
2641 + @Override
2642 + public void onFailure(@NonNull Call<ResponseBody> call, @NonNull Throwable t) {
2643 + LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel();
2644 + dynatraceEvent.setEventName("custom_error_market_pass_details");
2645 + EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent));
2646 +// future.set(new JSONObject());
2647 + future.setException(new Throwable());
2648 + }
2649 + });
2650 +
2651 + return future;
2652 + }
2653 +
2566 public static void getMapData(final CallbackReceiver<ArrayList<UnifiedCampaignModel>> receiver) { 2654 public static void getMapData(final CallbackReceiver<ArrayList<UnifiedCampaignModel>> receiver) {
2567 WarpUtils.log("************* WARPLY Get Map Data Request ********************"); 2655 WarpUtils.log("************* WARPLY Get Map Data Request ********************");
2568 WarpUtils.log("[WARP Trace] WARPLY Get Map Data Request is active"); 2656 WarpUtils.log("[WARP Trace] WARPLY Get Map Data Request is active");
...@@ -3815,108 +3903,6 @@ public class WarplyManager { ...@@ -3815,108 +3903,6 @@ public class WarplyManager {
3815 }); 3903 });
3816 } 3904 }
3817 3905
3818 - public static void getUserCouponsWithCouponsets(WarplyUserCouponsRequest request, final CallbackReceiver<CouponList> receiver) {
3819 - WarpUtils.log("************* WARPLY User Coupons Request ********************");
3820 - WarpUtils.log("[WARP Trace] WARPLY User Coupons Request is active");
3821 - WarpUtils.log("**************************************************");
3822 -
3823 - WarplyManager.getMerchantsMultilingual(new WarplyMerchantsRequest()
3824 - .setIsMultilingual(true)
3825 - , new CallbackReceiver<MerchantList>() {
3826 - @Override
3827 - public void onSuccess(MerchantList result) {
3828 - WarplyManagerHelper.setMerchantList(result);
3829 - LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel();
3830 - dynatraceEvent.setEventName("custom_success_shops_loyalty");
3831 - EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent));
3832 -
3833 - getCouponsets(new WarplyGetCouponsetsRequest()
3834 - .setLanguage(WarplyProperty.getLanguage(Warply.getWarplyContext())), new CallbackReceiver<CouponsetsList>() {
3835 - @Override
3836 - public void onSuccess(CouponsetsList result) {
3837 - Warply.postReceiveMicroappData(WarpConstants.MICROAPP_COUPONS, true, "context", request.toJson(), new CouponsHook(new CallbackReceiver<CouponList>() {
3838 - @Override
3839 - public void onSuccess(CouponList response) {
3840 - CouponList mCouponList = new CouponList();
3841 - for (Coupon coupon : response) {
3842 - for (Couponset couponset : result) {
3843 - if (coupon.getCouponsetUuid().equals(couponset.getUuid())) {
3844 - coupon.setDescription(couponset.getShortDescription());
3845 - coupon.setImage(couponset.getImgPreview());
3846 - coupon.setName(couponset.getName());
3847 - coupon.setMerchantUuid(couponset.getMerchantUuid());
3848 - coupon.setInnerText(couponset.getInnerText());
3849 - coupon.setDiscount_type(couponset.getDiscount_type());
3850 - coupon.setFinal_price(couponset.getFinal_price());
3851 - mCouponList.add(coupon);
3852 - }
3853 - }
3854 - }
3855 - WarplyManagerHelper.setCouponList(mCouponList);
3856 -
3857 - CouponList mActiveCouponList = new CouponList();
3858 - for (Coupon coupon : mCouponList) {
3859 - if (coupon.getStatus() == 1) {
3860 - SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm");
3861 - Date newDate = new Date();
3862 - try {
3863 - newDate = simpleDateFormat.parse(coupon.getExpiration());
3864 - } catch (ParseException e) {
3865 - e.printStackTrace();
3866 - }
3867 - coupon.setExpirationDate(newDate);
3868 - mActiveCouponList.add(coupon);
3869 - }
3870 - }
3871 -
3872 - Collections.sort(mActiveCouponList, (coupon1, coupon2) -> coupon1.getExpirationDate().compareTo(coupon2.getExpirationDate()));
3873 -
3874 - receiver.onSuccess(mActiveCouponList);
3875 - }
3876 -
3877 - @Override
3878 - public void onFailure(int errorCode) {
3879 - if (errorCode == 401) {
3880 - refreshToken(new WarplyRefreshTokenRequest(), new CallbackReceiver<JSONObject>() {
3881 - @Override
3882 - public void onSuccess(JSONObject result) {
3883 - int status = result.optInt("status", 2);
3884 - if (status == 1)
3885 - getUserCoupons(request, receiver);
3886 - else
3887 - receiver.onFailure(status);
3888 - }
3889 -
3890 - @Override
3891 - public void onFailure(int errorCode) {
3892 - receiver.onFailure(errorCode);
3893 - }
3894 - });
3895 - } else
3896 - receiver.onFailure(errorCode);
3897 - }
3898 - },
3899 - request.getSignature()));
3900 - }
3901 -
3902 - @Override
3903 - public void onFailure(int errorCode) {
3904 - receiver.onFailure(errorCode);
3905 - }
3906 - });
3907 - }
3908 -
3909 - @Override
3910 - public void onFailure(int errorCode) {
3911 - LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel();
3912 - dynatraceEvent.setEventName("custom_error_shops_loyalty");
3913 - EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent));
3914 -
3915 - receiver.onFailure(errorCode);
3916 - }
3917 - });
3918 - }
3919 -
3920 public static void getMerchantsMultilingual(ArrayList<String> catuuids, final CallbackReceiver<MerchantList> receiver) { 3906 public static void getMerchantsMultilingual(ArrayList<String> catuuids, final CallbackReceiver<MerchantList> receiver) {
3921 WarpUtils.log("************* WARPLY Merchants Request ********************"); 3907 WarpUtils.log("************* WARPLY Merchants Request ********************");
3922 WarpUtils.log("[WARP Trace] WARPLY Merchants Request is active"); 3908 WarpUtils.log("[WARP Trace] WARPLY Merchants Request is active");
...@@ -4057,231 +4043,6 @@ public class WarplyManager { ...@@ -4057,231 +4043,6 @@ public class WarplyManager {
4057 }); 4043 });
4058 } 4044 }
4059 4045
4060 -// public static void getUserCouponsWithCouponsets(final CallbackReceiver<CouponList> receiver) {
4061 -// WarpUtils.log("************* WARPLY User Coupons Request ********************");
4062 -// WarpUtils.log("[WARP Trace] WARPLY User Coupons Request is active");
4063 -// WarpUtils.log("**************************************************");
4064 -//
4065 -// ApiService service = ApiClient.getRetrofitInstance().create(ApiService.class);
4066 -//
4067 -// getMerchantsRetro(service, new Callback<ResponseBody>() {
4068 -// @Override
4069 -// public void onResponse(@NonNull Call<ResponseBody> call, @NonNull Response<ResponseBody> responseMerchants) {
4070 -// if (responseMerchants.code() == 200 && responseMerchants.body() != null) {
4071 -// JSONObject jobjMerchantsResponse = null;
4072 -// try {
4073 -// jobjMerchantsResponse = new JSONObject(responseMerchants.body().string());
4074 -// } catch (Exception e) {
4075 -// e.printStackTrace();
4076 -// }
4077 -//
4078 -// if (jobjMerchantsResponse != null && jobjMerchantsResponse.has("status") && jobjMerchantsResponse.optString("status", "2").equals("1")) {
4079 -// LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel();
4080 -// dynatraceEvent.setEventName("custom_success_shops_loyalty");
4081 -// EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent));
4082 -//
4083 -// JSONArray jMerchantsBody = null;
4084 -// try {
4085 -// jMerchantsBody = jobjMerchantsResponse.optJSONObject("context").optJSONObject("MAPP_SHOPS").optJSONArray("result");
4086 -// } catch (Exception e) {
4087 -// e.printStackTrace();
4088 -// }
4089 -//
4090 -// if (jMerchantsBody != null) {
4091 -// MerchantList mMerchantList = new MerchantList();
4092 -//
4093 -// final ExecutorService executorShops = Executors.newFixedThreadPool(1);
4094 -// JSONArray finalMerchantsJBody = jMerchantsBody;
4095 -// executorShops.submit(() -> {
4096 -// for (int i = 0; i < finalMerchantsJBody.length(); ++i) {
4097 -// mMerchantList.add(new Merchant(finalMerchantsJBody.optJSONObject(i)));
4098 -// }
4099 -// WarplyManagerHelper.setMerchantList(mMerchantList);
4100 -// executorShops.shutdownNow();
4101 -// });
4102 -//
4103 -// getCouponsetsRetro(service, new Callback<ResponseBody>() {
4104 -// @Override
4105 -// public void onResponse(@NonNull Call<ResponseBody> call, @NonNull Response<ResponseBody> responseCouponsets) {
4106 -// if (responseCouponsets.code() == 200 && responseCouponsets.body() != null) {
4107 -// JSONObject jobjCouponsetsResponse = null;
4108 -// try {
4109 -// jobjCouponsetsResponse = new JSONObject(responseCouponsets.body().string());
4110 -// } catch (Exception e) {
4111 -// e.printStackTrace();
4112 -// }
4113 -//
4114 -// if (jobjCouponsetsResponse != null && jobjCouponsetsResponse.has("status") && jobjCouponsetsResponse.optString("status", "2").equals("1")) {
4115 -// LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel();
4116 -// dynatraceEvent.setEventName("custom_success_couponsets_loyalty");
4117 -// EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent));
4118 -//
4119 -// JSONObject finalJobjCouponsetsResponse = jobjCouponsetsResponse;
4120 -// getUserCouponsRetro(service, new Callback<ResponseBody>() {
4121 -// @Override
4122 -// public void onResponse(@NonNull Call<ResponseBody> call, @NonNull Response<ResponseBody> responseCoupons) {
4123 -// if (responseCoupons.code() == 200 && responseCoupons.body() != null) {
4124 -// JSONObject jobjCouponsResponse = null;
4125 -// try {
4126 -// jobjCouponsResponse = new JSONObject(responseCoupons.body().string());
4127 -// } catch (Exception e) {
4128 -// e.printStackTrace();
4129 -// }
4130 -//
4131 -// if (jobjCouponsResponse != null && jobjCouponsResponse.has("status") && jobjCouponsResponse.optInt("status", 2) == 1) {
4132 -// LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel();
4133 -// dynatraceEvent.setEventName("custom_success_user_coupons_loyalty");
4134 -// EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent));
4135 -//
4136 -// JSONObject finalJobjCouponsResponse = jobjCouponsResponse;
4137 -// final ExecutorService executor = Executors.newFixedThreadPool(1);
4138 -// executor.submit(() -> {
4139 -// // COUPONS START //
4140 -// JSONArray jCouponsBody = null;
4141 -// try {
4142 -// jCouponsBody = finalJobjCouponsResponse.optJSONArray("result");
4143 -// } catch (Exception e) {
4144 -// e.printStackTrace();
4145 -// }
4146 -// // COUPONS END //
4147 -//
4148 -// // COUPONSETS START //
4149 -// JSONArray jCouponsetsBody = null;
4150 -// try {
4151 -// jCouponsetsBody = finalJobjCouponsetsResponse.optJSONObject("context").optJSONArray("MAPP_COUPON");
4152 -// } catch (Exception e) {
4153 -// e.printStackTrace();
4154 -// }
4155 -// // COUPONSETS END //
4156 -//
4157 -// if (jCouponsetsBody != null && jCouponsBody != null) {
4158 -// CouponList mCouponList = new CouponList();
4159 -// CouponList mCouponRedeemedList = new CouponList();
4160 -// CouponsetsList mCouponsetList = new CouponsetsList();
4161 -// for (int i = 0; i < jCouponsetsBody.length(); ++i) {
4162 -// Couponset tempCouponset = new Couponset(jCouponsetsBody.optJSONObject(i));
4163 -// mCouponsetList.add(tempCouponset);
4164 -// for (int j = 0; j < jCouponsBody.length(); ++j) {
4165 -// Coupon tempCoupon = new Coupon(jCouponsBody.optJSONObject(j));
4166 -// if (tempCoupon.getCouponsetUuid().equals(tempCouponset.getUuid())) {
4167 -// tempCoupon.setDescription(tempCouponset.getShortDescription());
4168 -// tempCoupon.setImage(tempCouponset.getImgPreview());
4169 -// tempCoupon.setName(tempCouponset.getName());
4170 -// tempCoupon.setMerchantUuid(tempCouponset.getMerchantUuid());
4171 -// tempCoupon.setInnerText(tempCouponset.getInnerText());
4172 -// tempCoupon.setDiscount_type(tempCouponset.getDiscount_type());
4173 -// tempCoupon.setFinal_price(tempCouponset.getFinal_price());
4174 -// mCouponList.add(tempCoupon);
4175 -// }
4176 -// }
4177 -// }
4178 -//
4179 -// for (int j = 0; j < jCouponsBody.length(); ++j) {
4180 -// Coupon tempCoupon = new Coupon(jCouponsBody.optJSONObject(j));
4181 -// if (tempCoupon.getStatus() == 0) {
4182 -// mCouponRedeemedList.add(tempCoupon);
4183 -// }
4184 -// }
4185 -// WarplyManagerHelper.setCouponsets(mCouponsetList);
4186 -// WarplyManagerHelper.setCouponList(mCouponList);
4187 -// WarplyManagerHelper.setCouponRedeemedList(mCouponRedeemedList);
4188 -//
4189 -// CouponList mActiveCouponList = new CouponList();
4190 -// for (Coupon coupon : mCouponList) {
4191 -// if (coupon.getStatus() == 1) {
4192 -// SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm");
4193 -// Date newDate = new Date();
4194 -// try {
4195 -// newDate = simpleDateFormat.parse(coupon.getExpiration());
4196 -// } catch (
4197 -// ParseException e) {
4198 -// e.printStackTrace();
4199 -// }
4200 -// coupon.setExpirationDate(newDate);
4201 -// mActiveCouponList.add(coupon);
4202 -// }
4203 -// }
4204 -//
4205 -// Collections.sort(mActiveCouponList, (coupon1, coupon2) -> coupon1.getExpirationDate().compareTo(coupon2.getExpirationDate()));
4206 -//
4207 -// new Handler(Looper.getMainLooper()).post(() -> receiver.onSuccess(mActiveCouponList));
4208 -// executor.shutdownNow();
4209 -// }
4210 -// });
4211 -// } else {
4212 -// LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel();
4213 -// dynatraceEvent.setEventName("custom_error_user_coupons_loyalty");
4214 -// EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent));
4215 -// receiver.onFailure(2);
4216 -// }
4217 -// } else {
4218 -// LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel();
4219 -// dynatraceEvent.setEventName("custom_error_user_coupons_loyalty");
4220 -// EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent));
4221 -// receiver.onFailure(responseCoupons.code());
4222 -// }
4223 -// }
4224 -//
4225 -// @Override
4226 -// public void onFailure(@NonNull Call<ResponseBody> call, @NonNull Throwable t) {
4227 -// LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel();
4228 -// dynatraceEvent.setEventName("custom_error_user_coupons_loyalty");
4229 -// EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent));
4230 -// receiver.onFailure(2);
4231 -// }
4232 -// });
4233 -//
4234 -// } else {
4235 -// LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel();
4236 -// dynatraceEvent.setEventName("custom_error_couponsets_loyalty");
4237 -// EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent));
4238 -// receiver.onFailure(2);
4239 -// }
4240 -//
4241 -// } else {
4242 -// LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel();
4243 -// dynatraceEvent.setEventName("custom_error_couponsets_loyalty");
4244 -// EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent));
4245 -// receiver.onFailure(responseCouponsets.code());
4246 -// }
4247 -// }
4248 -//
4249 -// @Override
4250 -// public void onFailure(@NonNull Call<ResponseBody> call, @NonNull Throwable t) {
4251 -// LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel();
4252 -// dynatraceEvent.setEventName("custom_error_couponsets_loyalty");
4253 -// EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent));
4254 -// receiver.onFailure(2);
4255 -// }
4256 -// });
4257 -// }
4258 -// } else {
4259 -// LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel();
4260 -// dynatraceEvent.setEventName("custom_error_shops_loyalty");
4261 -// EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent));
4262 -//
4263 -// receiver.onFailure(2);
4264 -// }
4265 -// } else {
4266 -// LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel();
4267 -// dynatraceEvent.setEventName("custom_error_shops_loyalty");
4268 -// EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent));
4269 -//
4270 -// receiver.onFailure(responseMerchants.code());
4271 -// }
4272 -// }
4273 -//
4274 -// @Override
4275 -// public void onFailure(@NonNull Call<ResponseBody> call, @NonNull Throwable t) {
4276 -// LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel();
4277 -// dynatraceEvent.setEventName("custom_error_shops_loyalty");
4278 -// EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent));
4279 -//
4280 -// receiver.onFailure(2);
4281 -// }
4282 -// });
4283 -// }
4284 -
4285 private static /*void*/ ListenableFuture<CouponsetsList> getCouponsetsRetro(ApiService service/*, Callback<ResponseBody> callback*/) { 4046 private static /*void*/ ListenableFuture<CouponsetsList> getCouponsetsRetro(ApiService service/*, Callback<ResponseBody> callback*/) {
4286 SettableFuture<CouponsetsList> future = SettableFuture.create(); 4047 SettableFuture<CouponsetsList> future = SettableFuture.create();
4287 4048
...@@ -5063,6 +4824,7 @@ public class WarplyManager { ...@@ -5063,6 +4824,7 @@ public class WarplyManager {
5063 jsonParams.put("action", "user_coupons"); 4824 jsonParams.put("action", "user_coupons");
5064 JSONArray jArr = new JSONArray(); 4825 JSONArray jArr = new JSONArray();
5065 jArr.put("merchant"); 4826 jArr.put("merchant");
4827 + jArr.put("redemption");
5066 jsonParams.put("details", jArr); 4828 jsonParams.put("details", jArr);
5067 jsonParams.put("language", WarplyProperty.getLanguage(Warply.getWarplyContext())); 4829 jsonParams.put("language", WarplyProperty.getLanguage(Warply.getWarplyContext()));
5068 // JSONObject jPagination= new JSONObject(); 4830 // JSONObject jPagination= new JSONObject();
...@@ -5498,4 +5260,39 @@ public class WarplyManager { ...@@ -5498,4 +5260,39 @@ public class WarplyManager {
5498 } 5260 }
5499 return false; 5261 return false;
5500 } 5262 }
5263 +
5264 + public static void getMarketPassDetails(final CallbackReceiver<MarketPassDetailsModel> receiver) {
5265 + WarpUtils.log("************* WARPLY Market Pass Details Request ********************");
5266 + WarpUtils.log("[WARP Trace] WARPLY Market Pass Details is active");
5267 + WarpUtils.log("**************************************************");
5268 +
5269 + ApiService service = ApiClient.getRetrofitInstance().create(ApiService.class);
5270 + ListeningExecutorService executorService = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(1));
5271 +
5272 + ListenableFuture<MarketPassDetailsModel> futureMarketPassDetails = getMarketPassDetails(service);
5273 +
5274 + ListenableFuture<List<Object>> allResultsFuture = Futures.allAsList(futureMarketPassDetails);
5275 + ListenableFuture<MarketPassDetailsModel> mergedResultFuture = Futures.transformAsync(
5276 + allResultsFuture,
5277 + results -> {
5278 + MarketPassDetailsModel resultMarketPassDetails = (MarketPassDetailsModel) results.get(0);
5279 + return executorService.submit(() -> resultMarketPassDetails);
5280 + },
5281 + executorService
5282 + );
5283 +
5284 + Futures.addCallback(mergedResultFuture, new FutureCallback<MarketPassDetailsModel>() {
5285 + @Override
5286 + public void onSuccess(MarketPassDetailsModel mergedResult) {
5287 + executorService.shutdownNow();
5288 + new Handler(Looper.getMainLooper()).post(() -> receiver.onSuccess(mergedResult));
5289 + }
5290 +
5291 + @Override
5292 + public void onFailure(Throwable throwable) {
5293 + executorService.shutdownNow();
5294 + new Handler(Looper.getMainLooper()).post(() -> receiver.onFailure(2));
5295 + }
5296 + }, executorService);
5297 + }
5501 } 5298 }
......