Showing
4 changed files
with
822 additions
and
301 deletions
| ... | @@ -50,8 +50,8 @@ public class BaseFragmentActivity extends FragmentActivity implements Navigation | ... | @@ -50,8 +50,8 @@ public class BaseFragmentActivity extends FragmentActivity implements Navigation |
| 50 | mBottomNavigationView = findViewById(R.id.bt_tabs); | 50 | mBottomNavigationView = findViewById(R.id.bt_tabs); |
| 51 | 51 | ||
| 52 | WarplyManager.getUserCouponsWithCouponsets(mUserCouponsReceiver); | 52 | WarplyManager.getUserCouponsWithCouponsets(mUserCouponsReceiver); |
| 53 | - WarplyManager.getCampaigns(mCampaignsCallback); | 53 | +// WarplyManager.getCampaigns(mCampaignsCallback); |
| 54 | - WarplyManager.getUnifiedCouponsDeals(mUnifiedCallback); | 54 | +// WarplyManager.getUnifiedCouponsDeals(mUnifiedCallback); |
| 55 | } | 55 | } |
| 56 | 56 | ||
| 57 | @Override | 57 | @Override | ... | ... |
| ... | @@ -95,6 +95,7 @@ public class Coupon implements Parcelable, Serializable { | ... | @@ -95,6 +95,7 @@ public class Coupon implements Parcelable, Serializable { |
| 95 | private double final_price = 0.0d; | 95 | private double final_price = 0.0d; |
| 96 | private String short_description = ""; | 96 | private String short_description = ""; |
| 97 | private String terms = ""; | 97 | private String terms = ""; |
| 98 | + private Couponset couponsetDetails = new Couponset(true); | ||
| 98 | 99 | ||
| 99 | public Coupon() { | 100 | public Coupon() { |
| 100 | this.barcode = ""; | 101 | this.barcode = ""; |
| ... | @@ -121,6 +122,19 @@ public class Coupon implements Parcelable, Serializable { | ... | @@ -121,6 +122,19 @@ public class Coupon implements Parcelable, Serializable { |
| 121 | this.terms = ""; | 122 | this.terms = ""; |
| 122 | } | 123 | } |
| 123 | 124 | ||
| 125 | + public Coupon(boolean isUniversal) { | ||
| 126 | + this.barcode = ""; | ||
| 127 | + this.coupon = ""; | ||
| 128 | + this.discount = ""; | ||
| 129 | + this.expiration = ""; | ||
| 130 | + this.status = 0; | ||
| 131 | + this.changesDates = new JSONObject(); | ||
| 132 | + this.couponsetUuid = ""; | ||
| 133 | + this.merchantUuid = ""; | ||
| 134 | + this.redeemDate = new Date(); | ||
| 135 | + this.couponsetDetails = new Couponset(isUniversal); | ||
| 136 | + } | ||
| 137 | + | ||
| 124 | /** | 138 | /** |
| 125 | * Basic constructor used to create an object from a String, representing a | 139 | * Basic constructor used to create an object from a String, representing a |
| 126 | * JSON Object | 140 | * JSON Object |
| ... | @@ -176,6 +190,50 @@ public class Coupon implements Parcelable, Serializable { | ... | @@ -176,6 +190,50 @@ public class Coupon implements Parcelable, Serializable { |
| 176 | } | 190 | } |
| 177 | } | 191 | } |
| 178 | 192 | ||
| 193 | + public Coupon(JSONObject json, boolean isUniversal) { | ||
| 194 | + if (json != null) { | ||
| 195 | + this.barcode = json.optString(BARCODE); | ||
| 196 | + this.changesDates = json.optJSONObject(CHANGES_DATES); | ||
| 197 | + if (this.changesDates != null) { | ||
| 198 | + SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm"); | ||
| 199 | + Date newDate = new Date(); | ||
| 200 | + String tempRedeemDate = this.changesDates.optString("redeemed"); | ||
| 201 | + try { | ||
| 202 | + newDate = simpleDateFormat.parse(tempRedeemDate); | ||
| 203 | + this.redeemDate = newDate; | ||
| 204 | + } catch (ParseException e) { | ||
| 205 | + e.printStackTrace(); | ||
| 206 | + } | ||
| 207 | + } | ||
| 208 | + this.coupon = json.optString(COUPON); | ||
| 209 | + this.couponsetUuid = json.optString(COUPONSET_UUID); | ||
| 210 | + this.discount = json.optString(DISCOUNT); | ||
| 211 | + if (this.discount.contains(",")) { | ||
| 212 | + this.discount = this.discount.replace(",", "."); | ||
| 213 | + } | ||
| 214 | + this.expiration = json.optString(EXPIRATION); | ||
| 215 | + this.merchantUuid = json.optString(MERCHANT_UUID); | ||
| 216 | + this.status = json.optInt(STATUS); | ||
| 217 | + JSONObject tempCouponsetDetails = json.optJSONObject("couponset_details"); | ||
| 218 | + if (tempCouponsetDetails != null) { | ||
| 219 | + this.couponsetDetails = new Couponset(tempCouponsetDetails, isUniversal); | ||
| 220 | + } | ||
| 221 | + | ||
| 222 | +// this.category = json.optString(CATEGORY); | ||
| 223 | +// this.created = json.optString(CREATED); | ||
| 224 | +// this.description = json.optString(DESCRIPTION); | ||
| 225 | +// this.image = json.optString(IMAGE); | ||
| 226 | +// this.name = json.optString(NAME); | ||
| 227 | +// this.transactionDate = json.optString(TRANSACTION_DATE); | ||
| 228 | +// this.transactionUuid = json.optString(TRANSACTION_UUID); | ||
| 229 | +// this.innerText = json.optString(INNER_TEXT); | ||
| 230 | +// this.discount_type = json.isNull(DISCOUNT_TYPE) ? "" : json.optString(DISCOUNT_TYPE); | ||
| 231 | +// this.final_price = json.optDouble(FINAL_PRICE); | ||
| 232 | +// this.short_description = json.optString(SHORT_DESCRIPTION); | ||
| 233 | +// this.terms = json.optString(TERMS); | ||
| 234 | + } | ||
| 235 | + } | ||
| 236 | + | ||
| 179 | public Coupon(Parcel source) { | 237 | public Coupon(Parcel source) { |
| 180 | this.barcode = source.readString(); | 238 | this.barcode = source.readString(); |
| 181 | this.category = source.readString(); | 239 | this.category = source.readString(); | ... | ... |
| ... | @@ -33,6 +33,9 @@ import org.json.JSONException; | ... | @@ -33,6 +33,9 @@ import org.json.JSONException; |
| 33 | import org.json.JSONObject; | 33 | import org.json.JSONObject; |
| 34 | 34 | ||
| 35 | import java.io.Serializable; | 35 | import java.io.Serializable; |
| 36 | +import java.text.ParseException; | ||
| 37 | +import java.text.SimpleDateFormat; | ||
| 38 | +import java.util.Date; | ||
| 36 | 39 | ||
| 37 | import ly.warp.sdk.utils.WarpUtils; | 40 | import ly.warp.sdk.utils.WarpUtils; |
| 38 | import ly.warp.sdk.utils.constants.WarpConstants; | 41 | import ly.warp.sdk.utils.constants.WarpConstants; |
| ... | @@ -108,6 +111,7 @@ public class Couponset implements Parcelable, Serializable { | ... | @@ -108,6 +111,7 @@ public class Couponset implements Parcelable, Serializable { |
| 108 | private String innerText = ""; | 111 | private String innerText = ""; |
| 109 | private String discount_type = ""; | 112 | private String discount_type = ""; |
| 110 | private double final_price = 0.0d; | 113 | private double final_price = 0.0d; |
| 114 | + private Date endDate = new Date(); | ||
| 111 | 115 | ||
| 112 | public Couponset() { | 116 | public Couponset() { |
| 113 | this.uuid = ""; | 117 | this.uuid = ""; |
| ... | @@ -140,6 +144,23 @@ public class Couponset implements Parcelable, Serializable { | ... | @@ -140,6 +144,23 @@ public class Couponset implements Parcelable, Serializable { |
| 140 | this.final_price = 0.0d; | 144 | this.final_price = 0.0d; |
| 141 | } | 145 | } |
| 142 | 146 | ||
| 147 | + public Couponset(boolean isUniversal) { | ||
| 148 | + this.admin_name = ""; | ||
| 149 | + this.active = false; | ||
| 150 | + this.buyable = false; | ||
| 151 | + this.category = ""; | ||
| 152 | + this.created = ""; | ||
| 153 | + this.discount = ""; | ||
| 154 | + this.discount_type = ""; | ||
| 155 | + this.name = ""; | ||
| 156 | + this.img = new JSONArray(); | ||
| 157 | + this.short_description = ""; | ||
| 158 | + this.terms = ""; | ||
| 159 | + this.updated = ""; | ||
| 160 | + this.uuid = ""; | ||
| 161 | +// this.endDate = new Date(); | ||
| 162 | + } | ||
| 163 | + | ||
| 143 | /** | 164 | /** |
| 144 | * Basic constructor used to create an object from a String, representing a | 165 | * Basic constructor used to create an object from a String, representing a |
| 145 | * JSON Object | 166 | * JSON Object |
| ... | @@ -196,6 +217,56 @@ public class Couponset implements Parcelable, Serializable { | ... | @@ -196,6 +217,56 @@ public class Couponset implements Parcelable, Serializable { |
| 196 | } | 217 | } |
| 197 | } | 218 | } |
| 198 | 219 | ||
| 220 | + public Couponset(JSONObject json, boolean isUniversal) { | ||
| 221 | + if (json != null) { | ||
| 222 | + this.uuid = json.optString(UUID); | ||
| 223 | + this.admin_name = json.optString(ADMIN_NAME); | ||
| 224 | + this.created = json.optString(CREATED); | ||
| 225 | + this.updated = json.optString(UPDATED); | ||
| 226 | + this.img = json.optJSONArray(IMG); | ||
| 227 | + this.active = json.optBoolean(ACTIVE); | ||
| 228 | + this.buyable = json.optBoolean(BUYABLE); | ||
| 229 | + this.name = json.optString(NAME); | ||
| 230 | + this.short_description = json.optString(SHORT_DESCRIPTION); | ||
| 231 | + this.discount = json.optString(DISCOUNT); | ||
| 232 | + this.category = json.optString(CATEGORY); | ||
| 233 | + this.terms = json.optString(TERMS); | ||
| 234 | + this.discount_type = json.isNull(DISCOUNT_TYPE) ? "" : json.optString(DISCOUNT_TYPE); | ||
| 235 | +// SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm"); | ||
| 236 | +// Date newDate = new Date(); | ||
| 237 | +// String tempRedeemDate = json.optString("end_date"); | ||
| 238 | +// try { | ||
| 239 | +// newDate = simpleDateFormat.parse(tempRedeemDate); | ||
| 240 | +// this.endDate = newDate; | ||
| 241 | +// } catch (ParseException e) { | ||
| 242 | +// e.printStackTrace(); | ||
| 243 | +// } | ||
| 244 | + | ||
| 245 | +// this.app_uuid = json.optString(APP_UUID); | ||
| 246 | +// this.img_preview = json.optString(IMG_PREVIEW); | ||
| 247 | +// this.sorting = json.optInt(SORTING); | ||
| 248 | +// this.visible = json.optBoolean(VISIBLE); | ||
| 249 | +// this.user_generated = json.optBoolean(USER_GENERATED); | ||
| 250 | +// this.limits = json.optJSONObject(LIMITS); | ||
| 251 | +// this.points = json.optInt(POINTS); | ||
| 252 | +// this.points_cause = json.optString(POINTS_CAUSE); | ||
| 253 | +// JSONObject exp = null; | ||
| 254 | +// try { | ||
| 255 | +// exp = new JSONObject(json.optString(EXPIRATION)); | ||
| 256 | +// this.expiration = exp.optString(VALUE); | ||
| 257 | +// } catch (JSONException e) { | ||
| 258 | +// e.printStackTrace(); | ||
| 259 | +// this.expiration = ""; | ||
| 260 | +// } | ||
| 261 | +// this.third_party_service = json.optBoolean(THIRD_PARTY_SERVICE); | ||
| 262 | +// this.description = json.optString(DESCRIPTION); | ||
| 263 | +// this.availability = json.optInt(AVAILABILITY); | ||
| 264 | +// this.merchantUuid = json.optString(MERCHANT_UUID); | ||
| 265 | +// this.innerText = json.optString(INNER_TEXT); | ||
| 266 | +// this.final_price = json.isNull(FINAL_PRICE) ? 0.0d : json.optDouble(FINAL_PRICE); | ||
| 267 | + } | ||
| 268 | + } | ||
| 269 | + | ||
| 199 | public Couponset(Parcel source) { | 270 | public Couponset(Parcel source) { |
| 200 | this.uuid = source.readString(); | 271 | this.uuid = source.readString(); |
| 201 | this.admin_name = source.readString(); | 272 | this.admin_name = source.readString(); | ... | ... |
| ... | @@ -1501,76 +1501,6 @@ public class WarplyManager { | ... | @@ -1501,76 +1501,6 @@ public class WarplyManager { |
| 1501 | }); | 1501 | }); |
| 1502 | } | 1502 | } |
| 1503 | 1503 | ||
| 1504 | - public static void getCampaigns(WarplyGetCampaignsRequest request, final CallbackReceiver<ArrayList<Campaign>> receiver) { | ||
| 1505 | - WarpUtils.log("************* WARPLY Get Campaigns Request ********************"); | ||
| 1506 | - WarpUtils.log("[WARP Trace] WARPLY Get Campaigns Request is active"); | ||
| 1507 | - WarpUtils.log("**************************************************"); | ||
| 1508 | - | ||
| 1509 | - Warply.postReceiveMicroappData(WarpConstants.MICROAPP_NEW_CAMPAIGNS, false, "campaigns", request.toJson(), new NewCampaignsHook(new CallbackReceiver<ArrayList<Campaign>>() { | ||
| 1510 | - @Override | ||
| 1511 | - public void onSuccess(ArrayList<Campaign> result) { | ||
| 1512 | - LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel(); | ||
| 1513 | - dynatraceEvent.setEventName("custom_success_campaigns_loyalty"); | ||
| 1514 | - EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent)); | ||
| 1515 | - | ||
| 1516 | - getCampaignsPersonalized(request, new CallbackReceiver<ArrayList<Campaign>>() { | ||
| 1517 | - @Override | ||
| 1518 | - public void onSuccess(ArrayList<Campaign> resultPersonalized) { | ||
| 1519 | - ArrayList<Campaign> newCampaignList = new ArrayList<Campaign>(); | ||
| 1520 | - newCampaignList.clear(); | ||
| 1521 | - newCampaignList.addAll(result); | ||
| 1522 | - newCampaignList.addAll(resultPersonalized); | ||
| 1523 | - Collections.sort(newCampaignList, (obj1, obj2) -> Integer.compare(obj1.getSorting(), obj2.getSorting())); | ||
| 1524 | - WarplyManagerHelper.setCampaignList(newCampaignList); | ||
| 1525 | - ArrayList<Campaign> campaignLoyaltyList = new ArrayList<>(); | ||
| 1526 | - campaignLoyaltyList.clear(); | ||
| 1527 | - ArrayList<Campaign> campaignCarouselList = new ArrayList<>(); | ||
| 1528 | - campaignCarouselList.clear(); | ||
| 1529 | - for (Campaign camp : newCampaignList) { | ||
| 1530 | - JSONObject campMetadata = WarpJSONParser.getJSONFromString(camp.getExtraFields()); | ||
| 1531 | - if (campMetadata != null) { | ||
| 1532 | - if (campMetadata.has("carousel")) { | ||
| 1533 | - campaignCarouselList.add(camp); | ||
| 1534 | - } | ||
| 1535 | - } | ||
| 1536 | - | ||
| 1537 | - try { | ||
| 1538 | - JSONObject extraFields = WarpJSONParser.getJSONFromString(camp.getExtraFields()); | ||
| 1539 | - if (extraFields != null) { | ||
| 1540 | - if (extraFields.length() == 0 || !(extraFields.has("ccms_offer") || extraFields.has("type"))) { | ||
| 1541 | - campaignLoyaltyList.add(camp); | ||
| 1542 | - } | ||
| 1543 | - } | ||
| 1544 | - } catch (Exception exception) { | ||
| 1545 | - campaignLoyaltyList.add(camp); | ||
| 1546 | - } | ||
| 1547 | - } | ||
| 1548 | - WarplyManagerHelper.setCarouselList(campaignCarouselList); | ||
| 1549 | - | ||
| 1550 | - Set<Campaign> set = new LinkedHashSet<>(campaignLoyaltyList); | ||
| 1551 | - campaignLoyaltyList.clear(); | ||
| 1552 | - campaignLoyaltyList.addAll(set); | ||
| 1553 | - receiver.onSuccess(campaignLoyaltyList); //resultPersonalized | ||
| 1554 | - } | ||
| 1555 | - | ||
| 1556 | - @Override | ||
| 1557 | - public void onFailure(int errorCode) { | ||
| 1558 | - receiver.onFailure(errorCode); | ||
| 1559 | - } | ||
| 1560 | - }); | ||
| 1561 | - } | ||
| 1562 | - | ||
| 1563 | - @Override | ||
| 1564 | - public void onFailure(int errorCode) { | ||
| 1565 | - LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel(); | ||
| 1566 | - dynatraceEvent.setEventName("custom_error_campaigns_loyalty"); | ||
| 1567 | - EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent)); | ||
| 1568 | - receiver.onFailure(errorCode); | ||
| 1569 | - } | ||
| 1570 | - }, | ||
| 1571 | - request.getSignature())); | ||
| 1572 | - } | ||
| 1573 | - | ||
| 1574 | private static ArrayList<Campaign> mergeCampaignResults(ArrayList<Campaign> resultCampaigns, ArrayList<Campaign> resultPersonalizedCampaigns, JSONObject resultCampaignsAvailability) { | 1504 | private static ArrayList<Campaign> mergeCampaignResults(ArrayList<Campaign> resultCampaigns, ArrayList<Campaign> resultPersonalizedCampaigns, JSONObject resultCampaignsAvailability) { |
| 1575 | ArrayList<Campaign> newCampaignList = new ArrayList<Campaign>(); | 1505 | ArrayList<Campaign> newCampaignList = new ArrayList<Campaign>(); |
| 1576 | ArrayList<Campaign> campaignLoyaltyList = new ArrayList<>(); | 1506 | ArrayList<Campaign> campaignLoyaltyList = new ArrayList<>(); |
| ... | @@ -1627,6 +1557,237 @@ public class WarplyManager { | ... | @@ -1627,6 +1557,237 @@ public class WarplyManager { |
| 1627 | return campaignLoyaltyList; | 1557 | return campaignLoyaltyList; |
| 1628 | } | 1558 | } |
| 1629 | 1559 | ||
| 1560 | + public static void getUserCouponsWithCouponsets(final CallbackReceiver<CouponList> receiver) { | ||
| 1561 | + WarpUtils.log("************* WARPLY User Coupons Request ********************"); | ||
| 1562 | + WarpUtils.log("[WARP Trace] WARPLY User Coupons Request is active"); | ||
| 1563 | + WarpUtils.log("**************************************************"); | ||
| 1564 | + | ||
| 1565 | + ApiService service = ApiClient.getRetrofitInstance().create(ApiService.class); | ||
| 1566 | + ListeningExecutorService executorService = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(3)); | ||
| 1567 | + | ||
| 1568 | + //TODO: check to see if we need merchants global else delete request | ||
| 1569 | + ListenableFuture<MerchantList> futureMerchants = getMerchantsRetro(service); | ||
| 1570 | + ListenableFuture<CouponsetsList> futureCouponsets = getCouponsetsRetro(service); | ||
| 1571 | + ListenableFuture<CouponList> futureCoupons = getCouponsUniversalRetro(service); | ||
| 1572 | + | ||
| 1573 | +// getMerchantsRetro(service, new Callback<ResponseBody>() { | ||
| 1574 | +// @Override | ||
| 1575 | +// public void onResponse(@NonNull Call<ResponseBody> call, @NonNull Response<ResponseBody> responseMerchants) { | ||
| 1576 | +// if (responseMerchants.code() == 200 && responseMerchants.body() != null) { | ||
| 1577 | +// JSONObject jobjMerchantsResponse = null; | ||
| 1578 | +// try { | ||
| 1579 | +// jobjMerchantsResponse = new JSONObject(responseMerchants.body().string()); | ||
| 1580 | +// } catch (Exception e) { | ||
| 1581 | +// e.printStackTrace(); | ||
| 1582 | +// } | ||
| 1583 | +// | ||
| 1584 | +// if (jobjMerchantsResponse != null && jobjMerchantsResponse.has("status") && jobjMerchantsResponse.optString("status", "2").equals("1")) { | ||
| 1585 | +// LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel(); | ||
| 1586 | +// dynatraceEvent.setEventName("custom_success_shops_loyalty"); | ||
| 1587 | +// EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent)); | ||
| 1588 | +// | ||
| 1589 | +// JSONArray jMerchantsBody = null; | ||
| 1590 | +// try { | ||
| 1591 | +// jMerchantsBody = jobjMerchantsResponse.optJSONObject("context").optJSONObject("MAPP_SHOPS").optJSONArray("result"); | ||
| 1592 | +// } catch (Exception e) { | ||
| 1593 | +// e.printStackTrace(); | ||
| 1594 | +// } | ||
| 1595 | +// | ||
| 1596 | +// if (jMerchantsBody != null) { | ||
| 1597 | +// MerchantList mMerchantList = new MerchantList(); | ||
| 1598 | +// | ||
| 1599 | +// final ExecutorService executorShops = Executors.newFixedThreadPool(1); | ||
| 1600 | +// JSONArray finalMerchantsJBody = jMerchantsBody; | ||
| 1601 | +// executorShops.submit(() -> { | ||
| 1602 | +// for (int i = 0; i < finalMerchantsJBody.length(); ++i) { | ||
| 1603 | +// mMerchantList.add(new Merchant(finalMerchantsJBody.optJSONObject(i))); | ||
| 1604 | +// } | ||
| 1605 | +// WarplyManagerHelper.setMerchantList(mMerchantList); | ||
| 1606 | +// executorShops.shutdownNow(); | ||
| 1607 | +// }); | ||
| 1608 | +// | ||
| 1609 | +// getCouponsetsRetro(service, new Callback<ResponseBody>() { | ||
| 1610 | +// @Override | ||
| 1611 | +// public void onResponse(@NonNull Call<ResponseBody> call, @NonNull Response<ResponseBody> responseCouponsets) { | ||
| 1612 | +// if (responseCouponsets.code() == 200 && responseCouponsets.body() != null) { | ||
| 1613 | +// JSONObject jobjCouponsetsResponse = null; | ||
| 1614 | +// try { | ||
| 1615 | +// jobjCouponsetsResponse = new JSONObject(responseCouponsets.body().string()); | ||
| 1616 | +// } catch (Exception e) { | ||
| 1617 | +// e.printStackTrace(); | ||
| 1618 | +// } | ||
| 1619 | +// | ||
| 1620 | +// if (jobjCouponsetsResponse != null && jobjCouponsetsResponse.has("status") && jobjCouponsetsResponse.optString("status", "2").equals("1")) { | ||
| 1621 | +// LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel(); | ||
| 1622 | +// dynatraceEvent.setEventName("custom_success_couponsets_loyalty"); | ||
| 1623 | +// EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent)); | ||
| 1624 | +// | ||
| 1625 | +// JSONObject finalJobjCouponsetsResponse = jobjCouponsetsResponse; | ||
| 1626 | +// getUserCouponsRetro(service, new Callback<ResponseBody>() { | ||
| 1627 | +// @Override | ||
| 1628 | +// public void onResponse(@NonNull Call<ResponseBody> call, @NonNull Response<ResponseBody> responseCoupons) { | ||
| 1629 | +// if (responseCoupons.code() == 200 && responseCoupons.body() != null) { | ||
| 1630 | +// JSONObject jobjCouponsResponse = null; | ||
| 1631 | +// try { | ||
| 1632 | +// jobjCouponsResponse = new JSONObject(responseCoupons.body().string()); | ||
| 1633 | +// } catch (Exception e) { | ||
| 1634 | +// e.printStackTrace(); | ||
| 1635 | +// } | ||
| 1636 | +// | ||
| 1637 | +// if (jobjCouponsResponse != null && jobjCouponsResponse.has("status") && jobjCouponsResponse.optInt("status", 2) == 1) { | ||
| 1638 | +// LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel(); | ||
| 1639 | +// dynatraceEvent.setEventName("custom_success_user_coupons_loyalty"); | ||
| 1640 | +// EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent)); | ||
| 1641 | +// | ||
| 1642 | +// JSONObject finalJobjCouponsResponse = jobjCouponsResponse; | ||
| 1643 | +// final ExecutorService executor = Executors.newFixedThreadPool(1); | ||
| 1644 | +// executor.submit(() -> { | ||
| 1645 | +// // COUPONS START // | ||
| 1646 | +// JSONArray jCouponsBody = null; | ||
| 1647 | +// try { | ||
| 1648 | +// jCouponsBody = finalJobjCouponsResponse.optJSONArray("result"); | ||
| 1649 | +// } catch (Exception e) { | ||
| 1650 | +// e.printStackTrace(); | ||
| 1651 | +// } | ||
| 1652 | +// // COUPONS END // | ||
| 1653 | +// | ||
| 1654 | +// // COUPONSETS START // | ||
| 1655 | +// JSONArray jCouponsetsBody = null; | ||
| 1656 | +// try { | ||
| 1657 | +// jCouponsetsBody = finalJobjCouponsetsResponse.optJSONObject("context").optJSONArray("MAPP_COUPON"); | ||
| 1658 | +// } catch (Exception e) { | ||
| 1659 | +// e.printStackTrace(); | ||
| 1660 | +// } | ||
| 1661 | +// // COUPONSETS END // | ||
| 1662 | +// | ||
| 1663 | +// if (jCouponsetsBody != null && jCouponsBody != null) { | ||
| 1664 | +// CouponList mCouponList = new CouponList(); | ||
| 1665 | +// CouponList mCouponRedeemedList = new CouponList(); | ||
| 1666 | +// CouponsetsList mCouponsetList = new CouponsetsList(); | ||
| 1667 | +// for (int i = 0; i < jCouponsetsBody.length(); ++i) { | ||
| 1668 | +// Couponset tempCouponset = new Couponset(jCouponsetsBody.optJSONObject(i)); | ||
| 1669 | +// mCouponsetList.add(tempCouponset); | ||
| 1670 | +// for (int j = 0; j < jCouponsBody.length(); ++j) { | ||
| 1671 | +// Coupon tempCoupon = new Coupon(jCouponsBody.optJSONObject(j)); | ||
| 1672 | +// if (tempCoupon.getCouponsetUuid().equals(tempCouponset.getUuid())) { | ||
| 1673 | +// tempCoupon.setDescription(tempCouponset.getShortDescription()); | ||
| 1674 | +// tempCoupon.setImage(tempCouponset.getImgPreview()); | ||
| 1675 | +// tempCoupon.setName(tempCouponset.getName()); | ||
| 1676 | +// tempCoupon.setMerchantUuid(tempCouponset.getMerchantUuid()); | ||
| 1677 | +// tempCoupon.setInnerText(tempCouponset.getInnerText()); | ||
| 1678 | +// tempCoupon.setDiscount_type(tempCouponset.getDiscount_type()); | ||
| 1679 | +// tempCoupon.setFinal_price(tempCouponset.getFinal_price()); | ||
| 1680 | +// mCouponList.add(tempCoupon); | ||
| 1681 | +// } | ||
| 1682 | +// } | ||
| 1683 | +// } | ||
| 1684 | +// | ||
| 1685 | +// for (int j = 0; j < jCouponsBody.length(); ++j) { | ||
| 1686 | +// Coupon tempCoupon = new Coupon(jCouponsBody.optJSONObject(j)); | ||
| 1687 | +// if (tempCoupon.getStatus() == 0) { | ||
| 1688 | +// mCouponRedeemedList.add(tempCoupon); | ||
| 1689 | +// } | ||
| 1690 | +// } | ||
| 1691 | +// WarplyManagerHelper.setCouponsets(mCouponsetList); | ||
| 1692 | +// WarplyManagerHelper.setCouponList(mCouponList); | ||
| 1693 | +// WarplyManagerHelper.setCouponRedeemedList(mCouponRedeemedList); | ||
| 1694 | +// | ||
| 1695 | +// CouponList mActiveCouponList = new CouponList(); | ||
| 1696 | +// for (Coupon coupon : mCouponList) { | ||
| 1697 | +// if (coupon.getStatus() == 1) { | ||
| 1698 | +// SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm"); | ||
| 1699 | +// Date newDate = new Date(); | ||
| 1700 | +// try { | ||
| 1701 | +// newDate = simpleDateFormat.parse(coupon.getExpiration()); | ||
| 1702 | +// } catch ( | ||
| 1703 | +// ParseException e) { | ||
| 1704 | +// e.printStackTrace(); | ||
| 1705 | +// } | ||
| 1706 | +// coupon.setExpirationDate(newDate); | ||
| 1707 | +// mActiveCouponList.add(coupon); | ||
| 1708 | +// } | ||
| 1709 | +// } | ||
| 1710 | +// | ||
| 1711 | +// Collections.sort(mActiveCouponList, (coupon1, coupon2) -> coupon1.getExpirationDate().compareTo(coupon2.getExpirationDate())); | ||
| 1712 | +// | ||
| 1713 | +// new Handler(Looper.getMainLooper()).post(() -> receiver.onSuccess(mActiveCouponList)); | ||
| 1714 | +// executor.shutdownNow(); | ||
| 1715 | +// } | ||
| 1716 | +// }); | ||
| 1717 | +// } else { | ||
| 1718 | +// LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel(); | ||
| 1719 | +// dynatraceEvent.setEventName("custom_error_user_coupons_loyalty"); | ||
| 1720 | +// EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent)); | ||
| 1721 | +// receiver.onFailure(2); | ||
| 1722 | +// } | ||
| 1723 | +// } else { | ||
| 1724 | +// LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel(); | ||
| 1725 | +// dynatraceEvent.setEventName("custom_error_user_coupons_loyalty"); | ||
| 1726 | +// EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent)); | ||
| 1727 | +// receiver.onFailure(responseCoupons.code()); | ||
| 1728 | +// } | ||
| 1729 | +// } | ||
| 1730 | +// | ||
| 1731 | +// @Override | ||
| 1732 | +// public void onFailure(@NonNull Call<ResponseBody> call, @NonNull Throwable t) { | ||
| 1733 | +// LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel(); | ||
| 1734 | +// dynatraceEvent.setEventName("custom_error_user_coupons_loyalty"); | ||
| 1735 | +// EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent)); | ||
| 1736 | +// receiver.onFailure(2); | ||
| 1737 | +// } | ||
| 1738 | +// }); | ||
| 1739 | +// | ||
| 1740 | +// } else { | ||
| 1741 | +// LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel(); | ||
| 1742 | +// dynatraceEvent.setEventName("custom_error_couponsets_loyalty"); | ||
| 1743 | +// EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent)); | ||
| 1744 | +// receiver.onFailure(2); | ||
| 1745 | +// } | ||
| 1746 | +// | ||
| 1747 | +// } else { | ||
| 1748 | +// LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel(); | ||
| 1749 | +// dynatraceEvent.setEventName("custom_error_couponsets_loyalty"); | ||
| 1750 | +// EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent)); | ||
| 1751 | +// receiver.onFailure(responseCouponsets.code()); | ||
| 1752 | +// } | ||
| 1753 | +// } | ||
| 1754 | +// | ||
| 1755 | +// @Override | ||
| 1756 | +// public void onFailure(@NonNull Call<ResponseBody> call, @NonNull Throwable t) { | ||
| 1757 | +// LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel(); | ||
| 1758 | +// dynatraceEvent.setEventName("custom_error_couponsets_loyalty"); | ||
| 1759 | +// EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent)); | ||
| 1760 | +// receiver.onFailure(2); | ||
| 1761 | +// } | ||
| 1762 | +// }); | ||
| 1763 | +// } | ||
| 1764 | +// } else { | ||
| 1765 | +// LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel(); | ||
| 1766 | +// dynatraceEvent.setEventName("custom_error_shops_loyalty"); | ||
| 1767 | +// EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent)); | ||
| 1768 | +// | ||
| 1769 | +// receiver.onFailure(2); | ||
| 1770 | +// } | ||
| 1771 | +// } else { | ||
| 1772 | +// LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel(); | ||
| 1773 | +// dynatraceEvent.setEventName("custom_error_shops_loyalty"); | ||
| 1774 | +// EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent)); | ||
| 1775 | +// | ||
| 1776 | +// receiver.onFailure(responseMerchants.code()); | ||
| 1777 | +// } | ||
| 1778 | +// } | ||
| 1779 | +// | ||
| 1780 | +// @Override | ||
| 1781 | +// public void onFailure(@NonNull Call<ResponseBody> call, @NonNull Throwable t) { | ||
| 1782 | +// LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel(); | ||
| 1783 | +// dynatraceEvent.setEventName("custom_error_shops_loyalty"); | ||
| 1784 | +// EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent)); | ||
| 1785 | +// | ||
| 1786 | +// receiver.onFailure(2); | ||
| 1787 | +// } | ||
| 1788 | +// }); | ||
| 1789 | + } | ||
| 1790 | + | ||
| 1630 | public static void getCampaigns(final CallbackReceiver<ArrayList<Campaign>> receiver) { | 1791 | public static void getCampaigns(final CallbackReceiver<ArrayList<Campaign>> receiver) { |
| 1631 | WarpUtils.log("************* WARPLY Get Campaigns Request ********************"); | 1792 | WarpUtils.log("************* WARPLY Get Campaigns Request ********************"); |
| 1632 | WarpUtils.log("[WARP Trace] WARPLY Get Campaigns Request is active"); | 1793 | WarpUtils.log("[WARP Trace] WARPLY Get Campaigns Request is active"); |
| ... | @@ -3322,232 +3483,234 @@ public class WarplyManager { | ... | @@ -3322,232 +3483,234 @@ public class WarplyManager { |
| 3322 | }); | 3483 | }); |
| 3323 | } | 3484 | } |
| 3324 | 3485 | ||
| 3325 | - public static void getUserCouponsWithCouponsets(final CallbackReceiver<CouponList> receiver) { | 3486 | +// public static void getUserCouponsWithCouponsets(final CallbackReceiver<CouponList> receiver) { |
| 3326 | - WarpUtils.log("************* WARPLY User Coupons Request ********************"); | 3487 | +// WarpUtils.log("************* WARPLY User Coupons Request ********************"); |
| 3327 | - WarpUtils.log("[WARP Trace] WARPLY User Coupons Request is active"); | 3488 | +// WarpUtils.log("[WARP Trace] WARPLY User Coupons Request is active"); |
| 3328 | - WarpUtils.log("**************************************************"); | 3489 | +// WarpUtils.log("**************************************************"); |
| 3329 | - | 3490 | +// |
| 3330 | - ApiService service = ApiClient.getRetrofitInstance().create(ApiService.class); | 3491 | +// ApiService service = ApiClient.getRetrofitInstance().create(ApiService.class); |
| 3331 | - | 3492 | +// |
| 3332 | - getMerchantsRetro(service, new Callback<ResponseBody>() { | 3493 | +// getMerchantsRetro(service, new Callback<ResponseBody>() { |
| 3333 | - @Override | 3494 | +// @Override |
| 3334 | - public void onResponse(@NonNull Call<ResponseBody> call, @NonNull Response<ResponseBody> responseMerchants) { | 3495 | +// public void onResponse(@NonNull Call<ResponseBody> call, @NonNull Response<ResponseBody> responseMerchants) { |
| 3335 | - if (responseMerchants.code() == 200 && responseMerchants.body() != null) { | 3496 | +// if (responseMerchants.code() == 200 && responseMerchants.body() != null) { |
| 3336 | - JSONObject jobjMerchantsResponse = null; | 3497 | +// JSONObject jobjMerchantsResponse = null; |
| 3337 | - try { | 3498 | +// try { |
| 3338 | - jobjMerchantsResponse = new JSONObject(responseMerchants.body().string()); | 3499 | +// jobjMerchantsResponse = new JSONObject(responseMerchants.body().string()); |
| 3339 | - } catch (Exception e) { | 3500 | +// } catch (Exception e) { |
| 3340 | - e.printStackTrace(); | 3501 | +// e.printStackTrace(); |
| 3341 | - } | 3502 | +// } |
| 3342 | - | 3503 | +// |
| 3343 | - if (jobjMerchantsResponse != null && jobjMerchantsResponse.has("status") && jobjMerchantsResponse.optString("status", "2").equals("1")) { | 3504 | +// if (jobjMerchantsResponse != null && jobjMerchantsResponse.has("status") && jobjMerchantsResponse.optString("status", "2").equals("1")) { |
| 3344 | - LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel(); | 3505 | +// LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel(); |
| 3345 | - dynatraceEvent.setEventName("custom_success_shops_loyalty"); | 3506 | +// dynatraceEvent.setEventName("custom_success_shops_loyalty"); |
| 3346 | - EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent)); | 3507 | +// EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent)); |
| 3347 | - | 3508 | +// |
| 3348 | - JSONArray jMerchantsBody = null; | 3509 | +// JSONArray jMerchantsBody = null; |
| 3349 | - try { | 3510 | +// try { |
| 3350 | - jMerchantsBody = jobjMerchantsResponse.optJSONObject("context").optJSONObject("MAPP_SHOPS").optJSONArray("result"); | 3511 | +// jMerchantsBody = jobjMerchantsResponse.optJSONObject("context").optJSONObject("MAPP_SHOPS").optJSONArray("result"); |
| 3351 | - } catch (Exception e) { | 3512 | +// } catch (Exception e) { |
| 3352 | - e.printStackTrace(); | 3513 | +// e.printStackTrace(); |
| 3353 | - } | 3514 | +// } |
| 3354 | - | 3515 | +// |
| 3355 | - if (jMerchantsBody != null) { | 3516 | +// if (jMerchantsBody != null) { |
| 3356 | - MerchantList mMerchantList = new MerchantList(); | 3517 | +// MerchantList mMerchantList = new MerchantList(); |
| 3357 | - | 3518 | +// |
| 3358 | - final ExecutorService executorShops = Executors.newFixedThreadPool(1); | 3519 | +// final ExecutorService executorShops = Executors.newFixedThreadPool(1); |
| 3359 | - JSONArray finalMerchantsJBody = jMerchantsBody; | 3520 | +// JSONArray finalMerchantsJBody = jMerchantsBody; |
| 3360 | - executorShops.submit(() -> { | 3521 | +// executorShops.submit(() -> { |
| 3361 | - for (int i = 0; i < finalMerchantsJBody.length(); ++i) { | 3522 | +// for (int i = 0; i < finalMerchantsJBody.length(); ++i) { |
| 3362 | - mMerchantList.add(new Merchant(finalMerchantsJBody.optJSONObject(i))); | 3523 | +// mMerchantList.add(new Merchant(finalMerchantsJBody.optJSONObject(i))); |
| 3363 | - } | 3524 | +// } |
| 3364 | - WarplyManagerHelper.setMerchantList(mMerchantList); | 3525 | +// WarplyManagerHelper.setMerchantList(mMerchantList); |
| 3365 | - executorShops.shutdownNow(); | 3526 | +// executorShops.shutdownNow(); |
| 3366 | - }); | 3527 | +// }); |
| 3367 | - | 3528 | +// |
| 3368 | - getCouponsetsRetro(service, new Callback<ResponseBody>() { | 3529 | +// getCouponsetsRetro(service, new Callback<ResponseBody>() { |
| 3369 | - @Override | 3530 | +// @Override |
| 3370 | - public void onResponse(@NonNull Call<ResponseBody> call, @NonNull Response<ResponseBody> responseCouponsets) { | 3531 | +// public void onResponse(@NonNull Call<ResponseBody> call, @NonNull Response<ResponseBody> responseCouponsets) { |
| 3371 | - if (responseCouponsets.code() == 200 && responseCouponsets.body() != null) { | 3532 | +// if (responseCouponsets.code() == 200 && responseCouponsets.body() != null) { |
| 3372 | - JSONObject jobjCouponsetsResponse = null; | 3533 | +// JSONObject jobjCouponsetsResponse = null; |
| 3373 | - try { | 3534 | +// try { |
| 3374 | - jobjCouponsetsResponse = new JSONObject(responseCouponsets.body().string()); | 3535 | +// jobjCouponsetsResponse = new JSONObject(responseCouponsets.body().string()); |
| 3375 | - } catch (Exception e) { | 3536 | +// } catch (Exception e) { |
| 3376 | - e.printStackTrace(); | 3537 | +// e.printStackTrace(); |
| 3377 | - } | 3538 | +// } |
| 3378 | - | 3539 | +// |
| 3379 | - if (jobjCouponsetsResponse != null && jobjCouponsetsResponse.has("status") && jobjCouponsetsResponse.optString("status", "2").equals("1")) { | 3540 | +// if (jobjCouponsetsResponse != null && jobjCouponsetsResponse.has("status") && jobjCouponsetsResponse.optString("status", "2").equals("1")) { |
| 3380 | - LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel(); | 3541 | +// LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel(); |
| 3381 | - dynatraceEvent.setEventName("custom_success_couponsets_loyalty"); | 3542 | +// dynatraceEvent.setEventName("custom_success_couponsets_loyalty"); |
| 3382 | - EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent)); | 3543 | +// EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent)); |
| 3383 | - | 3544 | +// |
| 3384 | - JSONObject finalJobjCouponsetsResponse = jobjCouponsetsResponse; | 3545 | +// JSONObject finalJobjCouponsetsResponse = jobjCouponsetsResponse; |
| 3385 | - getUserCouponsRetro(service, new Callback<ResponseBody>() { | 3546 | +// getUserCouponsRetro(service, new Callback<ResponseBody>() { |
| 3386 | - @Override | 3547 | +// @Override |
| 3387 | - public void onResponse(@NonNull Call<ResponseBody> call, @NonNull Response<ResponseBody> responseCoupons) { | 3548 | +// public void onResponse(@NonNull Call<ResponseBody> call, @NonNull Response<ResponseBody> responseCoupons) { |
| 3388 | - if (responseCoupons.code() == 200 && responseCoupons.body() != null) { | 3549 | +// if (responseCoupons.code() == 200 && responseCoupons.body() != null) { |
| 3389 | - JSONObject jobjCouponsResponse = null; | 3550 | +// JSONObject jobjCouponsResponse = null; |
| 3390 | - try { | 3551 | +// try { |
| 3391 | - jobjCouponsResponse = new JSONObject(responseCoupons.body().string()); | 3552 | +// jobjCouponsResponse = new JSONObject(responseCoupons.body().string()); |
| 3392 | - } catch (Exception e) { | 3553 | +// } catch (Exception e) { |
| 3393 | - e.printStackTrace(); | 3554 | +// e.printStackTrace(); |
| 3394 | - } | 3555 | +// } |
| 3395 | - | 3556 | +// |
| 3396 | - if (jobjCouponsResponse != null && jobjCouponsResponse.has("status") && jobjCouponsResponse.optInt("status", 2) == 1) { | 3557 | +// if (jobjCouponsResponse != null && jobjCouponsResponse.has("status") && jobjCouponsResponse.optInt("status", 2) == 1) { |
| 3397 | - LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel(); | 3558 | +// LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel(); |
| 3398 | - dynatraceEvent.setEventName("custom_success_user_coupons_loyalty"); | 3559 | +// dynatraceEvent.setEventName("custom_success_user_coupons_loyalty"); |
| 3399 | - EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent)); | 3560 | +// EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent)); |
| 3400 | - | 3561 | +// |
| 3401 | - JSONObject finalJobjCouponsResponse = jobjCouponsResponse; | 3562 | +// JSONObject finalJobjCouponsResponse = jobjCouponsResponse; |
| 3402 | - final ExecutorService executor = Executors.newFixedThreadPool(1); | 3563 | +// final ExecutorService executor = Executors.newFixedThreadPool(1); |
| 3403 | - executor.submit(() -> { | 3564 | +// executor.submit(() -> { |
| 3404 | - // COUPONS START // | 3565 | +// // COUPONS START // |
| 3405 | - JSONArray jCouponsBody = null; | 3566 | +// JSONArray jCouponsBody = null; |
| 3406 | - try { | 3567 | +// try { |
| 3407 | - jCouponsBody = finalJobjCouponsResponse.optJSONArray("result"); | 3568 | +// jCouponsBody = finalJobjCouponsResponse.optJSONArray("result"); |
| 3408 | - } catch (Exception e) { | 3569 | +// } catch (Exception e) { |
| 3409 | - e.printStackTrace(); | 3570 | +// e.printStackTrace(); |
| 3410 | - } | 3571 | +// } |
| 3411 | - // COUPONS END // | 3572 | +// // COUPONS END // |
| 3412 | - | 3573 | +// |
| 3413 | - // COUPONSETS START // | 3574 | +// // COUPONSETS START // |
| 3414 | - JSONArray jCouponsetsBody = null; | 3575 | +// JSONArray jCouponsetsBody = null; |
| 3415 | - try { | 3576 | +// try { |
| 3416 | - jCouponsetsBody = finalJobjCouponsetsResponse.optJSONObject("context").optJSONArray("MAPP_COUPON"); | 3577 | +// jCouponsetsBody = finalJobjCouponsetsResponse.optJSONObject("context").optJSONArray("MAPP_COUPON"); |
| 3417 | - } catch (Exception e) { | 3578 | +// } catch (Exception e) { |
| 3418 | - e.printStackTrace(); | 3579 | +// e.printStackTrace(); |
| 3419 | - } | 3580 | +// } |
| 3420 | - // COUPONSETS END // | 3581 | +// // COUPONSETS END // |
| 3421 | - | 3582 | +// |
| 3422 | - if (jCouponsetsBody != null && jCouponsBody != null) { | 3583 | +// if (jCouponsetsBody != null && jCouponsBody != null) { |
| 3423 | - CouponList mCouponList = new CouponList(); | 3584 | +// CouponList mCouponList = new CouponList(); |
| 3424 | - CouponList mCouponRedeemedList = new CouponList(); | 3585 | +// CouponList mCouponRedeemedList = new CouponList(); |
| 3425 | - CouponsetsList mCouponsetList = new CouponsetsList(); | 3586 | +// CouponsetsList mCouponsetList = new CouponsetsList(); |
| 3426 | - for (int i = 0; i < jCouponsetsBody.length(); ++i) { | 3587 | +// for (int i = 0; i < jCouponsetsBody.length(); ++i) { |
| 3427 | - Couponset tempCouponset = new Couponset(jCouponsetsBody.optJSONObject(i)); | 3588 | +// Couponset tempCouponset = new Couponset(jCouponsetsBody.optJSONObject(i)); |
| 3428 | - mCouponsetList.add(tempCouponset); | 3589 | +// mCouponsetList.add(tempCouponset); |
| 3429 | - for (int j = 0; j < jCouponsBody.length(); ++j) { | 3590 | +// for (int j = 0; j < jCouponsBody.length(); ++j) { |
| 3430 | - Coupon tempCoupon = new Coupon(jCouponsBody.optJSONObject(j)); | 3591 | +// Coupon tempCoupon = new Coupon(jCouponsBody.optJSONObject(j)); |
| 3431 | - if (tempCoupon.getCouponsetUuid().equals(tempCouponset.getUuid())) { | 3592 | +// if (tempCoupon.getCouponsetUuid().equals(tempCouponset.getUuid())) { |
| 3432 | - tempCoupon.setDescription(tempCouponset.getShortDescription()); | 3593 | +// tempCoupon.setDescription(tempCouponset.getShortDescription()); |
| 3433 | - tempCoupon.setImage(tempCouponset.getImgPreview()); | 3594 | +// tempCoupon.setImage(tempCouponset.getImgPreview()); |
| 3434 | - tempCoupon.setName(tempCouponset.getName()); | 3595 | +// tempCoupon.setName(tempCouponset.getName()); |
| 3435 | - tempCoupon.setMerchantUuid(tempCouponset.getMerchantUuid()); | 3596 | +// tempCoupon.setMerchantUuid(tempCouponset.getMerchantUuid()); |
| 3436 | - tempCoupon.setInnerText(tempCouponset.getInnerText()); | 3597 | +// tempCoupon.setInnerText(tempCouponset.getInnerText()); |
| 3437 | - tempCoupon.setDiscount_type(tempCouponset.getDiscount_type()); | 3598 | +// tempCoupon.setDiscount_type(tempCouponset.getDiscount_type()); |
| 3438 | - tempCoupon.setFinal_price(tempCouponset.getFinal_price()); | 3599 | +// tempCoupon.setFinal_price(tempCouponset.getFinal_price()); |
| 3439 | - mCouponList.add(tempCoupon); | 3600 | +// mCouponList.add(tempCoupon); |
| 3440 | - } | 3601 | +// } |
| 3441 | - } | 3602 | +// } |
| 3442 | - } | 3603 | +// } |
| 3443 | - | 3604 | +// |
| 3444 | - for (int j = 0; j < jCouponsBody.length(); ++j) { | 3605 | +// for (int j = 0; j < jCouponsBody.length(); ++j) { |
| 3445 | - Coupon tempCoupon = new Coupon(jCouponsBody.optJSONObject(j)); | 3606 | +// Coupon tempCoupon = new Coupon(jCouponsBody.optJSONObject(j)); |
| 3446 | - if (tempCoupon.getStatus() == 0) { | 3607 | +// if (tempCoupon.getStatus() == 0) { |
| 3447 | - mCouponRedeemedList.add(tempCoupon); | 3608 | +// mCouponRedeemedList.add(tempCoupon); |
| 3448 | - } | 3609 | +// } |
| 3449 | - } | 3610 | +// } |
| 3450 | - WarplyManagerHelper.setCouponsets(mCouponsetList); | 3611 | +// WarplyManagerHelper.setCouponsets(mCouponsetList); |
| 3451 | - WarplyManagerHelper.setCouponList(mCouponList); | 3612 | +// WarplyManagerHelper.setCouponList(mCouponList); |
| 3452 | - WarplyManagerHelper.setCouponRedeemedList(mCouponRedeemedList); | 3613 | +// WarplyManagerHelper.setCouponRedeemedList(mCouponRedeemedList); |
| 3453 | - | 3614 | +// |
| 3454 | - CouponList mActiveCouponList = new CouponList(); | 3615 | +// CouponList mActiveCouponList = new CouponList(); |
| 3455 | - for (Coupon coupon : mCouponList) { | 3616 | +// for (Coupon coupon : mCouponList) { |
| 3456 | - if (coupon.getStatus() == 1) { | 3617 | +// if (coupon.getStatus() == 1) { |
| 3457 | - SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm"); | 3618 | +// SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm"); |
| 3458 | - Date newDate = new Date(); | 3619 | +// Date newDate = new Date(); |
| 3459 | - try { | 3620 | +// try { |
| 3460 | - newDate = simpleDateFormat.parse(coupon.getExpiration()); | 3621 | +// newDate = simpleDateFormat.parse(coupon.getExpiration()); |
| 3461 | - } catch ( | 3622 | +// } catch ( |
| 3462 | - ParseException e) { | 3623 | +// ParseException e) { |
| 3463 | - e.printStackTrace(); | 3624 | +// e.printStackTrace(); |
| 3464 | - } | 3625 | +// } |
| 3465 | - coupon.setExpirationDate(newDate); | 3626 | +// coupon.setExpirationDate(newDate); |
| 3466 | - mActiveCouponList.add(coupon); | 3627 | +// mActiveCouponList.add(coupon); |
| 3467 | - } | 3628 | +// } |
| 3468 | - } | 3629 | +// } |
| 3469 | - | 3630 | +// |
| 3470 | - Collections.sort(mActiveCouponList, (coupon1, coupon2) -> coupon1.getExpirationDate().compareTo(coupon2.getExpirationDate())); | 3631 | +// Collections.sort(mActiveCouponList, (coupon1, coupon2) -> coupon1.getExpirationDate().compareTo(coupon2.getExpirationDate())); |
| 3471 | - | 3632 | +// |
| 3472 | - new Handler(Looper.getMainLooper()).post(() -> receiver.onSuccess(mActiveCouponList)); | 3633 | +// new Handler(Looper.getMainLooper()).post(() -> receiver.onSuccess(mActiveCouponList)); |
| 3473 | - executor.shutdownNow(); | 3634 | +// executor.shutdownNow(); |
| 3474 | - } | 3635 | +// } |
| 3475 | - }); | 3636 | +// }); |
| 3476 | - } else { | 3637 | +// } else { |
| 3477 | - LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel(); | 3638 | +// LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel(); |
| 3478 | - dynatraceEvent.setEventName("custom_error_user_coupons_loyalty"); | 3639 | +// dynatraceEvent.setEventName("custom_error_user_coupons_loyalty"); |
| 3479 | - EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent)); | 3640 | +// EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent)); |
| 3480 | - receiver.onFailure(2); | 3641 | +// receiver.onFailure(2); |
| 3481 | - } | 3642 | +// } |
| 3482 | - } else { | 3643 | +// } else { |
| 3483 | - LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel(); | 3644 | +// LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel(); |
| 3484 | - dynatraceEvent.setEventName("custom_error_user_coupons_loyalty"); | 3645 | +// dynatraceEvent.setEventName("custom_error_user_coupons_loyalty"); |
| 3485 | - EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent)); | 3646 | +// EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent)); |
| 3486 | - receiver.onFailure(responseCoupons.code()); | 3647 | +// receiver.onFailure(responseCoupons.code()); |
| 3487 | - } | 3648 | +// } |
| 3488 | - } | 3649 | +// } |
| 3489 | - | 3650 | +// |
| 3490 | - @Override | 3651 | +// @Override |
| 3491 | - public void onFailure(@NonNull Call<ResponseBody> call, @NonNull Throwable t) { | 3652 | +// public void onFailure(@NonNull Call<ResponseBody> call, @NonNull Throwable t) { |
| 3492 | - LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel(); | 3653 | +// LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel(); |
| 3493 | - dynatraceEvent.setEventName("custom_error_user_coupons_loyalty"); | 3654 | +// dynatraceEvent.setEventName("custom_error_user_coupons_loyalty"); |
| 3494 | - EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent)); | 3655 | +// EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent)); |
| 3495 | - receiver.onFailure(2); | 3656 | +// receiver.onFailure(2); |
| 3496 | - } | 3657 | +// } |
| 3497 | - }); | 3658 | +// }); |
| 3498 | - | 3659 | +// |
| 3499 | - } else { | 3660 | +// } else { |
| 3500 | - LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel(); | 3661 | +// LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel(); |
| 3501 | - dynatraceEvent.setEventName("custom_error_couponsets_loyalty"); | 3662 | +// dynatraceEvent.setEventName("custom_error_couponsets_loyalty"); |
| 3502 | - EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent)); | 3663 | +// EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent)); |
| 3503 | - receiver.onFailure(2); | 3664 | +// receiver.onFailure(2); |
| 3504 | - } | 3665 | +// } |
| 3505 | - | 3666 | +// |
| 3506 | - } else { | 3667 | +// } else { |
| 3507 | - LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel(); | 3668 | +// LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel(); |
| 3508 | - dynatraceEvent.setEventName("custom_error_couponsets_loyalty"); | 3669 | +// dynatraceEvent.setEventName("custom_error_couponsets_loyalty"); |
| 3509 | - EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent)); | 3670 | +// EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent)); |
| 3510 | - receiver.onFailure(responseCouponsets.code()); | 3671 | +// receiver.onFailure(responseCouponsets.code()); |
| 3511 | - } | 3672 | +// } |
| 3512 | - } | 3673 | +// } |
| 3513 | - | 3674 | +// |
| 3514 | - @Override | 3675 | +// @Override |
| 3515 | - public void onFailure(@NonNull Call<ResponseBody> call, @NonNull Throwable t) { | 3676 | +// public void onFailure(@NonNull Call<ResponseBody> call, @NonNull Throwable t) { |
| 3516 | - LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel(); | 3677 | +// LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel(); |
| 3517 | - dynatraceEvent.setEventName("custom_error_couponsets_loyalty"); | 3678 | +// dynatraceEvent.setEventName("custom_error_couponsets_loyalty"); |
| 3518 | - EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent)); | 3679 | +// EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent)); |
| 3519 | - receiver.onFailure(2); | 3680 | +// receiver.onFailure(2); |
| 3520 | - } | 3681 | +// } |
| 3521 | - }); | 3682 | +// }); |
| 3522 | - } | 3683 | +// } |
| 3523 | - } else { | 3684 | +// } else { |
| 3524 | - LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel(); | 3685 | +// LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel(); |
| 3525 | - dynatraceEvent.setEventName("custom_error_shops_loyalty"); | 3686 | +// dynatraceEvent.setEventName("custom_error_shops_loyalty"); |
| 3526 | - EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent)); | 3687 | +// EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent)); |
| 3527 | - | 3688 | +// |
| 3528 | - receiver.onFailure(2); | 3689 | +// receiver.onFailure(2); |
| 3529 | - } | 3690 | +// } |
| 3530 | - } else { | 3691 | +// } else { |
| 3531 | - LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel(); | 3692 | +// LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel(); |
| 3532 | - dynatraceEvent.setEventName("custom_error_shops_loyalty"); | 3693 | +// dynatraceEvent.setEventName("custom_error_shops_loyalty"); |
| 3533 | - EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent)); | 3694 | +// EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent)); |
| 3534 | - | 3695 | +// |
| 3535 | - receiver.onFailure(responseMerchants.code()); | 3696 | +// receiver.onFailure(responseMerchants.code()); |
| 3536 | - } | 3697 | +// } |
| 3537 | - } | 3698 | +// } |
| 3538 | - | 3699 | +// |
| 3539 | - @Override | 3700 | +// @Override |
| 3540 | - public void onFailure(@NonNull Call<ResponseBody> call, @NonNull Throwable t) { | 3701 | +// public void onFailure(@NonNull Call<ResponseBody> call, @NonNull Throwable t) { |
| 3541 | - LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel(); | 3702 | +// LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel(); |
| 3542 | - dynatraceEvent.setEventName("custom_error_shops_loyalty"); | 3703 | +// dynatraceEvent.setEventName("custom_error_shops_loyalty"); |
| 3543 | - EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent)); | 3704 | +// EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent)); |
| 3705 | +// | ||
| 3706 | +// receiver.onFailure(2); | ||
| 3707 | +// } | ||
| 3708 | +// }); | ||
| 3709 | +// } | ||
| 3544 | 3710 | ||
| 3545 | - receiver.onFailure(2); | 3711 | + private static /*void*/ ListenableFuture<CouponsetsList> getCouponsetsRetro(ApiService service/*, Callback<ResponseBody> callback*/) { |
| 3546 | - } | 3712 | + SettableFuture<CouponsetsList> future = SettableFuture.create(); |
| 3547 | - }); | ||
| 3548 | - } | ||
| 3549 | 3713 | ||
| 3550 | - private static void getCouponsetsRetro(ApiService service, Callback<ResponseBody> callback) { | ||
| 3551 | String timeStamp = DateFormat.format("yyyy-MM-dd hh:mm:ss", System.currentTimeMillis()).toString(); | 3714 | String timeStamp = DateFormat.format("yyyy-MM-dd hh:mm:ss", System.currentTimeMillis()).toString(); |
| 3552 | String apiKey = WarpUtils.getApiKey(Warply.getWarplyContext()); | 3715 | String apiKey = WarpUtils.getApiKey(Warply.getWarplyContext()); |
| 3553 | String webId = WarpUtils.getWebId(Warply.getWarplyContext()); | 3716 | String webId = WarpUtils.getWebId(Warply.getWarplyContext()); |
| ... | @@ -3584,14 +3747,68 @@ public class WarplyManager { | ... | @@ -3584,14 +3747,68 @@ public class WarplyManager { |
| 3584 | couponsetsCall.enqueue(new Callback<ResponseBody>() { | 3747 | couponsetsCall.enqueue(new Callback<ResponseBody>() { |
| 3585 | @Override | 3748 | @Override |
| 3586 | public void onResponse(@NonNull Call<ResponseBody> call, @NonNull Response<ResponseBody> response) { | 3749 | public void onResponse(@NonNull Call<ResponseBody> call, @NonNull Response<ResponseBody> response) { |
| 3587 | - callback.onResponse(call, response); | 3750 | + if (response.code() == 200 && response.body() != null) { |
| 3751 | + JSONObject jobjCouponsetsResponse = null; | ||
| 3752 | + try { | ||
| 3753 | + jobjCouponsetsResponse = new JSONObject(response.body().string()); | ||
| 3754 | + } catch (Exception e) { | ||
| 3755 | + e.printStackTrace(); | ||
| 3756 | + } | ||
| 3757 | + | ||
| 3758 | + if (jobjCouponsetsResponse != null && jobjCouponsetsResponse.has("status") && jobjCouponsetsResponse.optString("status", "2").equals("1")) { | ||
| 3759 | + LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel(); | ||
| 3760 | + dynatraceEvent.setEventName("custom_success_couponsets_loyalty"); | ||
| 3761 | + EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent)); | ||
| 3762 | + | ||
| 3763 | + JSONArray jCouponsetsBody = null; | ||
| 3764 | + try { | ||
| 3765 | + jCouponsetsBody = jobjCouponsetsResponse.optJSONObject("context").optJSONArray("MAPP_COUPON"); | ||
| 3766 | + } catch (Exception e) { | ||
| 3767 | + e.printStackTrace(); | ||
| 3768 | + } | ||
| 3769 | + | ||
| 3770 | + if (jCouponsetsBody != null) { | ||
| 3771 | + CouponsetsList mCouponsetList = new CouponsetsList(); | ||
| 3772 | + | ||
| 3773 | + final ExecutorService executorCouponsets = Executors.newFixedThreadPool(1); | ||
| 3774 | + JSONArray finalJCouponsetsBody = jCouponsetsBody; | ||
| 3775 | + executorCouponsets.submit(() -> { | ||
| 3776 | + for (int i = 0; i < finalJCouponsetsBody.length(); ++i) { | ||
| 3777 | + Couponset tempCouponset = new Couponset(finalJCouponsetsBody.optJSONObject(i)); | ||
| 3778 | + mCouponsetList.add(tempCouponset); | ||
| 3779 | + } | ||
| 3780 | + | ||
| 3781 | + WarplyManagerHelper.setCouponsets(mCouponsetList); | ||
| 3782 | + executorCouponsets.shutdownNow(); | ||
| 3783 | + | ||
| 3784 | + future.set(mCouponsetList); | ||
| 3785 | + }); | ||
| 3786 | + } | ||
| 3787 | + } else { | ||
| 3788 | + LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel(); | ||
| 3789 | + dynatraceEvent.setEventName("custom_error_couponsets_loyalty"); | ||
| 3790 | + EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent)); | ||
| 3791 | + future.set(new CouponsetsList()); | ||
| 3792 | + } | ||
| 3793 | + | ||
| 3794 | + } else { | ||
| 3795 | + LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel(); | ||
| 3796 | + dynatraceEvent.setEventName("custom_error_couponsets_loyalty"); | ||
| 3797 | + EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent)); | ||
| 3798 | + future.set(new CouponsetsList()); | ||
| 3799 | + } | ||
| 3588 | } | 3800 | } |
| 3589 | 3801 | ||
| 3590 | @Override | 3802 | @Override |
| 3591 | public void onFailure(@NonNull Call<ResponseBody> call, @NonNull Throwable t) { | 3803 | public void onFailure(@NonNull Call<ResponseBody> call, @NonNull Throwable t) { |
| 3592 | - callback.onFailure(call, t); | 3804 | + LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel(); |
| 3805 | + dynatraceEvent.setEventName("custom_error_couponsets_loyalty"); | ||
| 3806 | + EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent)); | ||
| 3807 | + future.set(new CouponsetsList()); | ||
| 3593 | } | 3808 | } |
| 3594 | }); | 3809 | }); |
| 3810 | + | ||
| 3811 | + return future; | ||
| 3595 | } | 3812 | } |
| 3596 | 3813 | ||
| 3597 | private static void getCouponsetsRetro(ApiService service, boolean isFiltered, Callback<ResponseBody> callback) { | 3814 | private static void getCouponsetsRetro(ApiService service, boolean isFiltered, Callback<ResponseBody> callback) { |
| ... | @@ -4017,7 +4234,9 @@ public class WarplyManager { | ... | @@ -4017,7 +4234,9 @@ public class WarplyManager { |
| 4017 | }); | 4234 | }); |
| 4018 | } | 4235 | } |
| 4019 | 4236 | ||
| 4020 | - private static void getMerchantsRetro(ApiService service, Callback<ResponseBody> callback) { | 4237 | + private static /*void*/ ListenableFuture<MerchantList> getMerchantsRetro(ApiService service/*, Callback<ResponseBody> callback*/) { |
| 4238 | + SettableFuture<MerchantList> future = SettableFuture.create(); | ||
| 4239 | + | ||
| 4021 | String timeStamp = DateFormat.format("yyyy-MM-dd hh:mm:ss", System.currentTimeMillis()).toString(); | 4240 | String timeStamp = DateFormat.format("yyyy-MM-dd hh:mm:ss", System.currentTimeMillis()).toString(); |
| 4022 | String apiKey = WarpUtils.getApiKey(Warply.getWarplyContext()); | 4241 | String apiKey = WarpUtils.getApiKey(Warply.getWarplyContext()); |
| 4023 | String webId = WarpUtils.getWebId(Warply.getWarplyContext()); | 4242 | String webId = WarpUtils.getWebId(Warply.getWarplyContext()); |
| ... | @@ -4050,14 +4269,65 @@ public class WarplyManager { | ... | @@ -4050,14 +4269,65 @@ public class WarplyManager { |
| 4050 | merchantsCall.enqueue(new Callback<ResponseBody>() { | 4269 | merchantsCall.enqueue(new Callback<ResponseBody>() { |
| 4051 | @Override | 4270 | @Override |
| 4052 | public void onResponse(@NonNull Call<ResponseBody> call, @NonNull Response<ResponseBody> response) { | 4271 | public void onResponse(@NonNull Call<ResponseBody> call, @NonNull Response<ResponseBody> response) { |
| 4053 | - callback.onResponse(call, response); | 4272 | + if (response.code() == 200 && response.body() != null) { |
| 4273 | + JSONObject jobjMerchantsResponse = null; | ||
| 4274 | + try { | ||
| 4275 | + jobjMerchantsResponse = new JSONObject(response.body().string()); | ||
| 4276 | + } catch (Exception e) { | ||
| 4277 | + e.printStackTrace(); | ||
| 4278 | + } | ||
| 4279 | + | ||
| 4280 | + if (jobjMerchantsResponse != null && jobjMerchantsResponse.has("status") && jobjMerchantsResponse.optString("status", "2").equals("1")) { | ||
| 4281 | + LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel(); | ||
| 4282 | + dynatraceEvent.setEventName("custom_success_shops_loyalty"); | ||
| 4283 | + EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent)); | ||
| 4284 | + | ||
| 4285 | + JSONArray jMerchantsBody = null; | ||
| 4286 | + try { | ||
| 4287 | + jMerchantsBody = jobjMerchantsResponse.optJSONObject("context").optJSONObject("MAPP_SHOPS").optJSONArray("result"); | ||
| 4288 | + } catch (Exception e) { | ||
| 4289 | + e.printStackTrace(); | ||
| 4290 | + } | ||
| 4291 | + | ||
| 4292 | + if (jMerchantsBody != null) { | ||
| 4293 | + MerchantList mMerchantList = new MerchantList(); | ||
| 4294 | + | ||
| 4295 | + final ExecutorService executorShops = Executors.newFixedThreadPool(1); | ||
| 4296 | + JSONArray finalMerchantsJBody = jMerchantsBody; | ||
| 4297 | + executorShops.submit(() -> { | ||
| 4298 | + for (int i = 0; i < finalMerchantsJBody.length(); ++i) { | ||
| 4299 | + mMerchantList.add(new Merchant(finalMerchantsJBody.optJSONObject(i))); | ||
| 4300 | + } | ||
| 4301 | + WarplyManagerHelper.setMerchantList(mMerchantList); | ||
| 4302 | + executorShops.shutdownNow(); | ||
| 4303 | + | ||
| 4304 | + future.set(mMerchantList); | ||
| 4305 | + }); | ||
| 4306 | + } | ||
| 4307 | + } else { | ||
| 4308 | + LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel(); | ||
| 4309 | + dynatraceEvent.setEventName("custom_error_shops_loyalty"); | ||
| 4310 | + EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent)); | ||
| 4311 | + future.set(new MerchantList()); | ||
| 4312 | + } | ||
| 4313 | + } else { | ||
| 4314 | + LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel(); | ||
| 4315 | + dynatraceEvent.setEventName("custom_error_shops_loyalty"); | ||
| 4316 | + EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent)); | ||
| 4317 | + future.set(new MerchantList()); | ||
| 4318 | + } | ||
| 4054 | } | 4319 | } |
| 4055 | 4320 | ||
| 4056 | @Override | 4321 | @Override |
| 4057 | public void onFailure(@NonNull Call<ResponseBody> call, @NonNull Throwable t) { | 4322 | public void onFailure(@NonNull Call<ResponseBody> call, @NonNull Throwable t) { |
| 4058 | - callback.onFailure(call, t); | 4323 | + LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel(); |
| 4324 | + dynatraceEvent.setEventName("custom_error_shops_loyalty"); | ||
| 4325 | + EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent)); | ||
| 4326 | + future.set(new MerchantList()); | ||
| 4059 | } | 4327 | } |
| 4060 | }); | 4328 | }); |
| 4329 | + | ||
| 4330 | + return future; | ||
| 4061 | } | 4331 | } |
| 4062 | 4332 | ||
| 4063 | private static void getMerchantsRetro(ApiService service, ArrayList<String> catuuids, Callback<ResponseBody> callback) { | 4333 | private static void getMerchantsRetro(ApiService service, ArrayList<String> catuuids, Callback<ResponseBody> callback) { |
| ... | @@ -4205,6 +4475,128 @@ public class WarplyManager { | ... | @@ -4205,6 +4475,128 @@ public class WarplyManager { |
| 4205 | }); | 4475 | }); |
| 4206 | } | 4476 | } |
| 4207 | 4477 | ||
| 4478 | + private static ListenableFuture<CouponList> getCouponsUniversalRetro(ApiService service) { | ||
| 4479 | + SettableFuture<CouponList> future = SettableFuture.create(); | ||
| 4480 | + | ||
| 4481 | + String timeStamp = DateFormat.format("yyyy-MM-dd hh:mm:ss", System.currentTimeMillis()).toString(); | ||
| 4482 | + String apiKey = WarpUtils.getApiKey(Warply.getWarplyContext()); | ||
| 4483 | + String webId = WarpUtils.getWebId(Warply.getWarplyContext()); | ||
| 4484 | + | ||
| 4485 | + Map<String, Object> jsonParamsCoupons = new ArrayMap<>(); | ||
| 4486 | + Map<String, Object> jsonParams = new ArrayMap<>(); | ||
| 4487 | + jsonParams.put("action", "user_coupons"); | ||
| 4488 | + JSONArray jArr = new JSONArray(); | ||
| 4489 | + jArr.put("merchant"); | ||
| 4490 | + jsonParams.put("details", jArr); | ||
| 4491 | + jsonParams.put("language", WarplyProperty.getLanguage(Warply.getWarplyContext())); | ||
| 4492 | +// JSONObject jPagination= new JSONObject(); | ||
| 4493 | +// try { | ||
| 4494 | +// jPagination.putOpt("page",1); | ||
| 4495 | +// jPagination.putOpt("per_page", 10); | ||
| 4496 | +// } catch (JSONException e) { | ||
| 4497 | +// throw new RuntimeException(e); | ||
| 4498 | +// } | ||
| 4499 | +// jsonParams.put("pagination", jPagination); | ||
| 4500 | + | ||
| 4501 | + jsonParamsCoupons.put("coupon", jsonParams); | ||
| 4502 | + RequestBody couponsRequest = RequestBody.create(MediaType.get("application/json; charset=utf-8"), (new JSONObject(jsonParamsCoupons)).toString()); | ||
| 4503 | + | ||
| 4504 | + Call<ResponseBody> couponsCall = service.getUserCoupons( | ||
| 4505 | + WarplyProperty.getAppUuid(Warply.getWarplyContext()), | ||
| 4506 | + couponsRequest, | ||
| 4507 | + timeStamp, | ||
| 4508 | + "android:" + Warply.getWarplyContext().getPackageName(), | ||
| 4509 | + new WarplyDeviceInfoCollector(Warply.getWarplyContext()).getUniqueDeviceId(), | ||
| 4510 | + "mobile", | ||
| 4511 | + webId, | ||
| 4512 | + WarpUtils.produceSignature(apiKey + timeStamp), | ||
| 4513 | + "Bearer " + WarplyDBHelper.getInstance(Warply.getWarplyContext()).getAuthValue("access_token") | ||
| 4514 | + ); | ||
| 4515 | + | ||
| 4516 | + couponsCall.enqueue(new Callback<ResponseBody>() { | ||
| 4517 | + @Override | ||
| 4518 | + public void onResponse(@NonNull Call<ResponseBody> call, @NonNull Response<ResponseBody> response) { | ||
| 4519 | + if (response.code() == 200 && response.body() != null) { | ||
| 4520 | + JSONObject jobjCouponsResponse = null; | ||
| 4521 | + try { | ||
| 4522 | + jobjCouponsResponse = new JSONObject(response.body().string()); | ||
| 4523 | + } catch (Exception e) { | ||
| 4524 | + e.printStackTrace(); | ||
| 4525 | + } | ||
| 4526 | + | ||
| 4527 | + if (jobjCouponsResponse != null && jobjCouponsResponse.has("status") && jobjCouponsResponse.optString("status", "2").equals("1")) { | ||
| 4528 | + LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel(); | ||
| 4529 | + dynatraceEvent.setEventName("custom_success_user_coupons_loyalty"); | ||
| 4530 | + EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent)); | ||
| 4531 | + | ||
| 4532 | + JSONArray jCouponsBody = null; | ||
| 4533 | + try { | ||
| 4534 | + jCouponsBody = jobjCouponsResponse.optJSONArray("result"); | ||
| 4535 | + } catch (Exception e) { | ||
| 4536 | + e.printStackTrace(); | ||
| 4537 | + } | ||
| 4538 | + | ||
| 4539 | + if (jCouponsBody != null) { | ||
| 4540 | + CouponList mCouponsList = new CouponList(); | ||
| 4541 | +// | ||
| 4542 | + final ExecutorService executorCoupons = Executors.newFixedThreadPool(1); | ||
| 4543 | + JSONArray finalJCouponsBody = jCouponsBody; | ||
| 4544 | + executorCoupons.submit(() -> { | ||
| 4545 | + for (int i = 0; i < finalJCouponsBody.length(); ++i) { | ||
| 4546 | + Coupon tempCoupon = new Coupon(finalJCouponsBody.optJSONObject(i), true); | ||
| 4547 | + mCouponsList.add(tempCoupon); | ||
| 4548 | + } | ||
| 4549 | + | ||
| 4550 | +// WarplyManagerHelper.setCouponsets(mCouponsetList); | ||
| 4551 | + executorCoupons.shutdownNow(); | ||
| 4552 | + | ||
| 4553 | + future.set(mCouponsList); | ||
| 4554 | + }); | ||
| 4555 | + } | ||
| 4556 | + } else { | ||
| 4557 | + LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel(); | ||
| 4558 | + dynatraceEvent.setEventName("custom_error_user_coupons_loyalty"); | ||
| 4559 | + EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent)); | ||
| 4560 | + future.set(new CouponList()); | ||
| 4561 | + } | ||
| 4562 | + } else if (response.code() == 401) { | ||
| 4563 | +// refreshToken(new WarplyRefreshTokenRequest(), new CallbackReceiver<JSONObject>() { | ||
| 4564 | +// @Override | ||
| 4565 | +// public void onSuccess(JSONObject result) { | ||
| 4566 | +// int status = result.optInt("status", 2); | ||
| 4567 | +// if (status == 1) | ||
| 4568 | +// getCouponsUniversalRetro(service, callback); | ||
| 4569 | +// else | ||
| 4570 | +// callback.onFailure(call, new Throwable()); | ||
| 4571 | +// } | ||
| 4572 | +// | ||
| 4573 | +// @Override | ||
| 4574 | +// public void onFailure(int errorCode) { | ||
| 4575 | +// callback.onFailure(call, new Throwable()); | ||
| 4576 | +// } | ||
| 4577 | +// }); | ||
| 4578 | + } else { | ||
| 4579 | + LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel(); | ||
| 4580 | + dynatraceEvent.setEventName("custom_error_user_coupons_loyalty"); | ||
| 4581 | + EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent)); | ||
| 4582 | + future.set(new CouponList()); | ||
| 4583 | + } | ||
| 4584 | + | ||
| 4585 | + future.set(new CouponList()); | ||
| 4586 | + } | ||
| 4587 | + | ||
| 4588 | + @Override | ||
| 4589 | + public void onFailure(@NonNull Call<ResponseBody> call, @NonNull Throwable t) { | ||
| 4590 | + LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel(); | ||
| 4591 | + dynatraceEvent.setEventName("custom_error_user_coupons_loyalty"); | ||
| 4592 | + EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent)); | ||
| 4593 | + future.set(new CouponList()); | ||
| 4594 | + } | ||
| 4595 | + }); | ||
| 4596 | + | ||
| 4597 | + return future; | ||
| 4598 | + } | ||
| 4599 | + | ||
| 4208 | public static void getCosmoteUser(WarplyCosmoteUserRequest request, final CallbackReceiver<JSONObject> receiver) { | 4600 | public static void getCosmoteUser(WarplyCosmoteUserRequest request, final CallbackReceiver<JSONObject> receiver) { |
| 4209 | WarpUtils.log("************* WARPLY Cosmote User Request ********************"); | 4601 | WarpUtils.log("************* WARPLY Cosmote User Request ********************"); |
| 4210 | WarpUtils.log("[WARP Trace] WARPLY Cosmote User Request is active"); | 4602 | WarpUtils.log("[WARP Trace] WARPLY Cosmote User Request is active"); | ... | ... |
-
Please register or login to post a comment