Showing
8 changed files
with
351 additions
and
217 deletions
1 | <?xml version="1.0" encoding="UTF-8"?> | 1 | <?xml version="1.0" encoding="UTF-8"?> |
2 | <project version="4"> | 2 | <project version="4"> |
3 | <component name="CompilerConfiguration"> | 3 | <component name="CompilerConfiguration"> |
4 | - <bytecodeTargetLevel target="21" /> | 4 | + <bytecodeTargetLevel target="17" /> |
5 | </component> | 5 | </component> |
6 | </project> | 6 | </project> |
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
.idea/migrations.xml
0 → 100644
1 | +<?xml version="1.0" encoding="UTF-8"?> | ||
2 | +<project version="4"> | ||
3 | + <component name="ProjectMigrations"> | ||
4 | + <option name="MigrateToGradleLocalJavaHome"> | ||
5 | + <set> | ||
6 | + <option value="$PROJECT_DIR$" /> | ||
7 | + </set> | ||
8 | + </option> | ||
9 | + </component> | ||
10 | +</project> | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
... | @@ -184,7 +184,7 @@ | ... | @@ -184,7 +184,7 @@ |
184 | </map> | 184 | </map> |
185 | </option> | 185 | </option> |
186 | </component> | 186 | </component> |
187 | - <component name="ProjectRootManager" version="2" languageLevel="JDK_21" default="true" project-jdk-name="jbr-21" project-jdk-type="JavaSDK"> | 187 | + <component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="zulu-17" project-jdk-type="JavaSDK"> |
188 | <output url="file://$PROJECT_DIR$/build/classes" /> | 188 | <output url="file://$PROJECT_DIR$/build/classes" /> |
189 | </component> | 189 | </component> |
190 | <component name="ProjectType"> | 190 | <component name="ProjectType"> | ... | ... |
... | @@ -5,7 +5,7 @@ android.buildFeatures.buildConfig = true | ... | @@ -5,7 +5,7 @@ android.buildFeatures.buildConfig = true |
5 | 5 | ||
6 | ext { | 6 | ext { |
7 | PUBLISH_GROUP_ID = 'ly.warp' | 7 | PUBLISH_GROUP_ID = 'ly.warp' |
8 | - PUBLISH_VERSION = '4.5.5.4r46' | 8 | + PUBLISH_VERSION = '4.5.5.4m1' |
9 | PUBLISH_ARTIFACT_ID = 'warply-android-sdk' | 9 | PUBLISH_ARTIFACT_ID = 'warply-android-sdk' |
10 | } | 10 | } |
11 | 11 | ... | ... |
... | @@ -23,6 +23,7 @@ import ly.warp.sdk.db.WarplyDBHelper; | ... | @@ -23,6 +23,7 @@ import ly.warp.sdk.db.WarplyDBHelper; |
23 | import ly.warp.sdk.fragments.HomeFragment; | 23 | import ly.warp.sdk.fragments.HomeFragment; |
24 | import ly.warp.sdk.io.callbacks.CallbackReceiver; | 24 | import ly.warp.sdk.io.callbacks.CallbackReceiver; |
25 | import ly.warp.sdk.io.models.Campaign; | 25 | import ly.warp.sdk.io.models.Campaign; |
26 | +import ly.warp.sdk.io.models.RedeemedSMHistoryModel; | ||
26 | import ly.warp.sdk.utils.managers.WarplyManager; | 27 | import ly.warp.sdk.utils.managers.WarplyManager; |
27 | 28 | ||
28 | public class BaseFragmentActivity extends FragmentActivity implements NavigationBarView.OnItemSelectedListener { | 29 | public class BaseFragmentActivity extends FragmentActivity implements NavigationBarView.OnItemSelectedListener { |
... | @@ -52,6 +53,7 @@ public class BaseFragmentActivity extends FragmentActivity implements Navigation | ... | @@ -52,6 +53,7 @@ public class BaseFragmentActivity extends FragmentActivity implements Navigation |
52 | 53 | ||
53 | if (WarplyDBHelper.getInstance(this).isTableNotEmpty("auth")) { | 54 | if (WarplyDBHelper.getInstance(this).isTableNotEmpty("auth")) { |
54 | WarplyManager.getSupermarketCampaign(mCampaignsCallback); | 55 | WarplyManager.getSupermarketCampaign(mCampaignsCallback); |
56 | + WarplyManager.getRedeemedSMHistory(mSMHistoryReceiver); | ||
55 | } | 57 | } |
56 | 58 | ||
57 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { | 59 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { |
... | @@ -147,4 +149,16 @@ public class BaseFragmentActivity extends FragmentActivity implements Navigation | ... | @@ -147,4 +149,16 @@ public class BaseFragmentActivity extends FragmentActivity implements Navigation |
147 | Toast.makeText(BaseFragmentActivity.this, "Campaigns Error", Toast.LENGTH_SHORT).show(); | 149 | Toast.makeText(BaseFragmentActivity.this, "Campaigns Error", Toast.LENGTH_SHORT).show(); |
148 | } | 150 | } |
149 | }; | 151 | }; |
152 | + | ||
153 | + private final CallbackReceiver<RedeemedSMHistoryModel> mSMHistoryReceiver = new CallbackReceiver<RedeemedSMHistoryModel>() { | ||
154 | + @Override | ||
155 | + public void onSuccess(RedeemedSMHistoryModel result) { | ||
156 | + Toast.makeText(BaseFragmentActivity.this, "SM HISTORY SUCCESS", Toast.LENGTH_SHORT).show(); | ||
157 | + } | ||
158 | + | ||
159 | + @Override | ||
160 | + public void onFailure(int errorCode) { | ||
161 | + Toast.makeText(BaseFragmentActivity.this, "SM HISTORY ERROR", Toast.LENGTH_SHORT).show(); | ||
162 | + } | ||
163 | + }; | ||
150 | } | 164 | } | ... | ... |
... | @@ -23,6 +23,7 @@ import ly.warp.sdk.R; | ... | @@ -23,6 +23,7 @@ import ly.warp.sdk.R; |
23 | import ly.warp.sdk.db.WarplyDBHelper; | 23 | import ly.warp.sdk.db.WarplyDBHelper; |
24 | import ly.warp.sdk.io.callbacks.CallbackReceiver; | 24 | import ly.warp.sdk.io.callbacks.CallbackReceiver; |
25 | import ly.warp.sdk.io.models.Campaign; | 25 | import ly.warp.sdk.io.models.Campaign; |
26 | +import ly.warp.sdk.io.models.RedeemedSMHistoryModel; | ||
26 | import ly.warp.sdk.utils.WarplyManagerHelper; | 27 | import ly.warp.sdk.utils.WarplyManagerHelper; |
27 | import ly.warp.sdk.utils.managers.WarplyManager; | 28 | import ly.warp.sdk.utils.managers.WarplyManager; |
28 | 29 | ||
... | @@ -100,6 +101,7 @@ public class HomeFragment extends Fragment implements View.OnClickListener, Swip | ... | @@ -100,6 +101,7 @@ public class HomeFragment extends Fragment implements View.OnClickListener, Swip |
100 | public void onRefresh() { | 101 | public void onRefresh() { |
101 | if (WarplyDBHelper.getInstance(getActivity()).isTableNotEmpty("auth")) { | 102 | if (WarplyDBHelper.getInstance(getActivity()).isTableNotEmpty("auth")) { |
102 | WarplyManager.getSupermarketCampaign(mCampaignsCallback); | 103 | WarplyManager.getSupermarketCampaign(mCampaignsCallback); |
104 | + WarplyManager.getRedeemedSMHistory(mSMHistoryReceiver); | ||
103 | mSwipeRefresh.setRefreshing(false); | 105 | mSwipeRefresh.setRefreshing(false); |
104 | } else { | 106 | } else { |
105 | mSwipeRefresh.setRefreshing(false); | 107 | mSwipeRefresh.setRefreshing(false); |
... | @@ -182,6 +184,7 @@ public class HomeFragment extends Fragment implements View.OnClickListener, Swip | ... | @@ -182,6 +184,7 @@ public class HomeFragment extends Fragment implements View.OnClickListener, Swip |
182 | // } | 184 | // } |
183 | 185 | ||
184 | WarplyManager.getSupermarketCampaign(mCampaignsCallback); | 186 | WarplyManager.getSupermarketCampaign(mCampaignsCallback); |
187 | + WarplyManager.getRedeemedSMHistory(mSMHistoryReceiver); | ||
185 | } | 188 | } |
186 | 189 | ||
187 | @Override | 190 | @Override |
... | @@ -190,4 +193,16 @@ public class HomeFragment extends Fragment implements View.OnClickListener, Swip | ... | @@ -190,4 +193,16 @@ public class HomeFragment extends Fragment implements View.OnClickListener, Swip |
190 | Toast.makeText(getActivity(), "LOGIN ERROR", Toast.LENGTH_SHORT).show(); | 193 | Toast.makeText(getActivity(), "LOGIN ERROR", Toast.LENGTH_SHORT).show(); |
191 | } | 194 | } |
192 | }; | 195 | }; |
196 | + | ||
197 | + private final CallbackReceiver<RedeemedSMHistoryModel> mSMHistoryReceiver = new CallbackReceiver<RedeemedSMHistoryModel>() { | ||
198 | + @Override | ||
199 | + public void onSuccess(RedeemedSMHistoryModel result) { | ||
200 | + Toast.makeText(getActivity(), "SM HISTORY SUCCESS", Toast.LENGTH_SHORT).show(); | ||
201 | + } | ||
202 | + | ||
203 | + @Override | ||
204 | + public void onFailure(int errorCode) { | ||
205 | + Toast.makeText(getActivity(), "SM HISTORY ERROR", Toast.LENGTH_SHORT).show(); | ||
206 | + } | ||
207 | + }; | ||
193 | } | 208 | } |
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
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 | +/** | ||
29 | + * Created by Panagiotis Triantafyllou on 05-Mar-25. | ||
30 | + */ | ||
31 | + | ||
32 | +public class RedeemedSMHistoryModel { | ||
33 | + private CouponList redeemedCouponList = new CouponList(); | ||
34 | + private float totalRedeemedValue = 0.0f; | ||
35 | + | ||
36 | + public RedeemedSMHistoryModel() { | ||
37 | + this.redeemedCouponList = new CouponList(); | ||
38 | + this.totalRedeemedValue = 0.0f; | ||
39 | + } | ||
40 | + | ||
41 | + // ================================================================================ | ||
42 | + // Getters | ||
43 | + // ================================================================================ | ||
44 | + | ||
45 | + | ||
46 | + public CouponList getRedeemedCouponList() { | ||
47 | + return redeemedCouponList; | ||
48 | + } | ||
49 | + | ||
50 | + public void setRedeemedCouponList(CouponList redeemedCouponList) { | ||
51 | + this.redeemedCouponList = redeemedCouponList; | ||
52 | + } | ||
53 | + | ||
54 | + public float getTotalRedeemedValue() { | ||
55 | + return totalRedeemedValue; | ||
56 | + } | ||
57 | + | ||
58 | + public void setTotalRedeemedValue(float totalRedeemedValue) { | ||
59 | + this.totalRedeemedValue = totalRedeemedValue; | ||
60 | + } | ||
61 | +} |
... | @@ -65,6 +65,7 @@ import ly.warp.sdk.io.models.CouponList; | ... | @@ -65,6 +65,7 @@ import ly.warp.sdk.io.models.CouponList; |
65 | import ly.warp.sdk.io.models.LoyaltySDKDynatraceEventModel; | 65 | import ly.warp.sdk.io.models.LoyaltySDKDynatraceEventModel; |
66 | import ly.warp.sdk.io.models.MarketPassDetailsModel; | 66 | import ly.warp.sdk.io.models.MarketPassDetailsModel; |
67 | import ly.warp.sdk.io.models.NewCampaign; | 67 | import ly.warp.sdk.io.models.NewCampaign; |
68 | +import ly.warp.sdk.io.models.RedeemedSMHistoryModel; | ||
68 | import ly.warp.sdk.io.request.WarplyRefreshTokenRequest; | 69 | import ly.warp.sdk.io.request.WarplyRefreshTokenRequest; |
69 | import ly.warp.sdk.io.volley.ApiClient; | 70 | import ly.warp.sdk.io.volley.ApiClient; |
70 | import ly.warp.sdk.io.volley.ApiService; | 71 | import ly.warp.sdk.io.volley.ApiService; |
... | @@ -94,53 +95,49 @@ public class WarplyManager { | ... | @@ -94,53 +95,49 @@ public class WarplyManager { |
94 | WarpUtils.log("[WARP Trace] WARPLY Refresh Authorize Request is active"); | 95 | WarpUtils.log("[WARP Trace] WARPLY Refresh Authorize Request is active"); |
95 | WarpUtils.log("**************************************************"); | 96 | WarpUtils.log("**************************************************"); |
96 | 97 | ||
97 | - Warply.postReceiveMicroappData(false, "token", request.toJson(), | 98 | + Warply.postReceiveMicroappData(false, "token", request.toJson(), new CallbackReceiver<JSONObject>() { |
98 | - new CallbackReceiver<JSONObject>() { | 99 | + @Override |
99 | - @Override | 100 | + public void onSuccess(JSONObject result) { |
100 | - public void onSuccess(JSONObject result) { | 101 | + if (result.has("token_type")) { |
101 | - if (result.has("token_type")) { | 102 | + WarplyDBHelper.getInstance(Warply.getWarplyContext()).saveAuthAccess(result.optString("access_token", ""), result.optString("refresh_token", "")); |
102 | - WarplyDBHelper.getInstance(Warply.getWarplyContext()).saveAuthAccess( | ||
103 | - result.optString("access_token", ""), | ||
104 | - result.optString("refresh_token", "") | ||
105 | - ); | ||
106 | - | ||
107 | - JSONObject newResult = new JSONObject(); | ||
108 | - try { | ||
109 | - newResult.putOpt("status", 1); | ||
110 | - newResult.putOpt("message", "Success"); | ||
111 | 103 | ||
112 | - LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel(); | 104 | + JSONObject newResult = new JSONObject(); |
113 | - dynatraceEvent.setEventName("custom_success_refresh_token_loyalty"); | 105 | + try { |
114 | - EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent)); | 106 | + newResult.putOpt("status", 1); |
107 | + newResult.putOpt("message", "Success"); | ||
115 | 108 | ||
116 | - receiver.onSuccess(newResult); | 109 | + LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel(); |
117 | - } catch (JSONException e) { | 110 | + dynatraceEvent.setEventName("custom_success_refresh_token_loyalty"); |
118 | - e.printStackTrace(); | 111 | + EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent)); |
119 | - LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel(); | ||
120 | - dynatraceEvent.setEventName("custom_error_refresh_token_loyalty"); | ||
121 | - EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent)); | ||
122 | - receiver.onFailure(2); | ||
123 | - } | ||
124 | - } else { | ||
125 | - LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel(); | ||
126 | - dynatraceEvent.setEventName("custom_error_refresh_token_loyalty"); | ||
127 | - EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent)); | ||
128 | - receiver.onFailure(2); | ||
129 | - } | ||
130 | - } | ||
131 | 112 | ||
132 | - @Override | 113 | + receiver.onSuccess(newResult); |
133 | - public void onFailure(int errorCode) { | 114 | + } catch (JSONException e) { |
115 | + e.printStackTrace(); | ||
134 | LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel(); | 116 | LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel(); |
135 | dynatraceEvent.setEventName("custom_error_refresh_token_loyalty"); | 117 | dynatraceEvent.setEventName("custom_error_refresh_token_loyalty"); |
136 | EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent)); | 118 | EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent)); |
137 | - if (errorCode == 401) { | 119 | + receiver.onFailure(2); |
138 | - WarplyDBHelper.getInstance(Warply.getWarplyContext()).deleteAuth(); | ||
139 | - WarplyDBHelper.getInstance(Warply.getWarplyContext()).deleteClient(); | ||
140 | - receiver.onFailure(errorCode); | ||
141 | - } | ||
142 | } | 120 | } |
143 | - }); | 121 | + } else { |
122 | + LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel(); | ||
123 | + dynatraceEvent.setEventName("custom_error_refresh_token_loyalty"); | ||
124 | + EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent)); | ||
125 | + receiver.onFailure(2); | ||
126 | + } | ||
127 | + } | ||
128 | + | ||
129 | + @Override | ||
130 | + public void onFailure(int errorCode) { | ||
131 | + LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel(); | ||
132 | + dynatraceEvent.setEventName("custom_error_refresh_token_loyalty"); | ||
133 | + EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent)); | ||
134 | + if (errorCode == 401) { | ||
135 | + WarplyDBHelper.getInstance(Warply.getWarplyContext()).deleteAuth(); | ||
136 | + WarplyDBHelper.getInstance(Warply.getWarplyContext()).deleteClient(); | ||
137 | + receiver.onFailure(errorCode); | ||
138 | + } | ||
139 | + } | ||
140 | + }); | ||
144 | } | 141 | } |
145 | 142 | ||
146 | public static void logout(final CallbackReceiver<JSONObject> receiver) { | 143 | public static void logout(final CallbackReceiver<JSONObject> receiver) { |
... | @@ -166,28 +163,7 @@ public class WarplyManager { | ... | @@ -166,28 +163,7 @@ public class WarplyManager { |
166 | 163 | ||
167 | RequestBody loginRequest = RequestBody.create(MediaType.get("application/json; charset=utf-8"), (new JSONObject(jsonParams)).toString()); | 164 | RequestBody loginRequest = RequestBody.create(MediaType.get("application/json; charset=utf-8"), (new JSONObject(jsonParams)).toString()); |
168 | 165 | ||
169 | - Call<ResponseBody> logoutCall = WarpUtils.isJWTEnabled(Warply.getWarplyContext()) ? | 166 | + Call<ResponseBody> logoutCall = WarpUtils.isJWTEnabled(Warply.getWarplyContext()) ? service.logoutUserJwt(WarplyProperty.getAppUuid(Warply.getWarplyContext()), loginRequest, timeStamp, "android:" + Warply.getWarplyContext().getPackageName(), new WarplyDeviceInfoCollector(Warply.getWarplyContext()).getUniqueDeviceId(), "mobile", webId, WarpUtils.produceSignature(apiKey + timeStamp)) : service.logoutUser(WarplyProperty.getAppUuid(Warply.getWarplyContext()), loginRequest, timeStamp, "android:" + Warply.getWarplyContext().getPackageName(), new WarplyDeviceInfoCollector(Warply.getWarplyContext()).getUniqueDeviceId(), "mobile", webId, WarpUtils.produceSignature(apiKey + timeStamp)); |
170 | - service.logoutUserJwt( | ||
171 | - WarplyProperty.getAppUuid(Warply.getWarplyContext()), | ||
172 | - loginRequest, | ||
173 | - timeStamp, | ||
174 | - "android:" + Warply.getWarplyContext().getPackageName(), | ||
175 | - new WarplyDeviceInfoCollector(Warply.getWarplyContext()).getUniqueDeviceId(), | ||
176 | - "mobile", | ||
177 | - webId, | ||
178 | - WarpUtils.produceSignature(apiKey + timeStamp) | ||
179 | - ) | ||
180 | - : | ||
181 | - service.logoutUser( | ||
182 | - WarplyProperty.getAppUuid(Warply.getWarplyContext()), | ||
183 | - loginRequest, | ||
184 | - timeStamp, | ||
185 | - "android:" + Warply.getWarplyContext().getPackageName(), | ||
186 | - new WarplyDeviceInfoCollector(Warply.getWarplyContext()).getUniqueDeviceId(), | ||
187 | - "mobile", | ||
188 | - webId, | ||
189 | - WarpUtils.produceSignature(apiKey + timeStamp) | ||
190 | - ); | ||
191 | 167 | ||
192 | logoutCall.enqueue(new Callback<ResponseBody>() { | 168 | logoutCall.enqueue(new Callback<ResponseBody>() { |
193 | @Override | 169 | @Override |
... | @@ -261,17 +237,7 @@ public class WarplyManager { | ... | @@ -261,17 +237,7 @@ public class WarplyManager { |
261 | 237 | ||
262 | RequestBody loginRequest = RequestBody.create(MediaType.get("application/json; charset=utf-8"), (new JSONObject(jsonParams)).toString()); | 238 | RequestBody loginRequest = RequestBody.create(MediaType.get("application/json; charset=utf-8"), (new JSONObject(jsonParams)).toString()); |
263 | 239 | ||
264 | - Call<ResponseBody> loginCall = service.cosmoteUser( | 240 | + Call<ResponseBody> loginCall = service.cosmoteUser(WarplyProperty.getAppUuid(Warply.getWarplyContext()), loginRequest, timeStamp, "android:" + Warply.getWarplyContext().getPackageName(), new WarplyDeviceInfoCollector(Warply.getWarplyContext()).getUniqueDeviceId(), "mobile", webId, WarpUtils.produceSignature(apiKey + timeStamp), "Basic MVBQNFhCQzhFYTJBaUdCNkJWZGFGUERlTTNLQ3kzMjU6YzViMzAyZDY5N2FiNGY3NzhiNThhMTg0YzBkZWRmNGU="); |
265 | - WarplyProperty.getAppUuid(Warply.getWarplyContext()), | ||
266 | - loginRequest, | ||
267 | - timeStamp, | ||
268 | - "android:" + Warply.getWarplyContext().getPackageName(), | ||
269 | - new WarplyDeviceInfoCollector(Warply.getWarplyContext()).getUniqueDeviceId(), | ||
270 | - "mobile", | ||
271 | - webId, | ||
272 | - WarpUtils.produceSignature(apiKey + timeStamp), | ||
273 | - "Basic MVBQNFhCQzhFYTJBaUdCNkJWZGFGUERlTTNLQ3kzMjU6YzViMzAyZDY5N2FiNGY3NzhiNThhMTg0YzBkZWRmNGU=" | ||
274 | - ); | ||
275 | 241 | ||
276 | loginCall.enqueue(new Callback<ResponseBody>() { | 242 | loginCall.enqueue(new Callback<ResponseBody>() { |
277 | @Override | 243 | @Override |
... | @@ -287,15 +253,9 @@ public class WarplyManager { | ... | @@ -287,15 +253,9 @@ public class WarplyManager { |
287 | if (jobjLoginResponse != null && jobjLoginResponse.has("status") && jobjLoginResponse.optString("status", "2").equals("1")) { | 253 | if (jobjLoginResponse != null && jobjLoginResponse.has("status") && jobjLoginResponse.optString("status", "2").equals("1")) { |
288 | JSONObject tokens = jobjLoginResponse.optJSONObject("result"); | 254 | JSONObject tokens = jobjLoginResponse.optJSONObject("result"); |
289 | if (tokens != null) { | 255 | if (tokens != null) { |
290 | - WarplyDBHelper.getInstance(Warply.getWarplyContext()).saveClientAccess( | 256 | + WarplyDBHelper.getInstance(Warply.getWarplyContext()).saveClientAccess(tokens.optString("client_id", ""), tokens.optString("client_secret", "")); |
291 | - tokens.optString("client_id", ""), | ||
292 | - tokens.optString("client_secret", "") | ||
293 | - ); | ||
294 | 257 | ||
295 | - WarplyDBHelper.getInstance(Warply.getWarplyContext()).saveAuthAccess( | 258 | + WarplyDBHelper.getInstance(Warply.getWarplyContext()).saveAuthAccess(tokens.optString("access_token", ""), tokens.optString("refresh_token", "")); |
296 | - tokens.optString("access_token", ""), | ||
297 | - tokens.optString("refresh_token", "") | ||
298 | - ); | ||
299 | 259 | ||
300 | JSONObject newResult = new JSONObject(); | 260 | JSONObject newResult = new JSONObject(); |
301 | try { | 261 | try { |
... | @@ -306,8 +266,7 @@ public class WarplyManager { | ... | @@ -306,8 +266,7 @@ public class WarplyManager { |
306 | e.printStackTrace(); | 266 | e.printStackTrace(); |
307 | receiver.onFailure(2); | 267 | receiver.onFailure(2); |
308 | } | 268 | } |
309 | - } else | 269 | + } else receiver.onFailure(2); |
310 | - receiver.onFailure(2); | ||
311 | } else { | 270 | } else { |
312 | receiver.onFailure(2); | 271 | receiver.onFailure(2); |
313 | } | 272 | } |
... | @@ -364,15 +323,7 @@ public class WarplyManager { | ... | @@ -364,15 +323,7 @@ public class WarplyManager { |
364 | 323 | ||
365 | RequestBody loginRequest = RequestBody.create(MediaType.get("application/json; charset=utf-8"), (new JSONObject(jsonParams)).toString()); | 324 | RequestBody loginRequest = RequestBody.create(MediaType.get("application/json; charset=utf-8"), (new JSONObject(jsonParams)).toString()); |
366 | 325 | ||
367 | - Call<ResponseBody> loginCall = service.verifyUser( | 326 | + Call<ResponseBody> loginCall = service.verifyUser(loginRequest, timeStamp, "android:" + Warply.getWarplyContext().getPackageName(), new WarplyDeviceInfoCollector(Warply.getWarplyContext()).getUniqueDeviceId(), "mobile", webId, WarpUtils.produceSignature(apiKey + timeStamp)); |
368 | - loginRequest, | ||
369 | - timeStamp, | ||
370 | - "android:" + Warply.getWarplyContext().getPackageName(), | ||
371 | - new WarplyDeviceInfoCollector(Warply.getWarplyContext()).getUniqueDeviceId(), | ||
372 | - "mobile", | ||
373 | - webId, | ||
374 | - WarpUtils.produceSignature(apiKey + timeStamp) | ||
375 | - ); | ||
376 | 327 | ||
377 | loginCall.enqueue(new Callback<ResponseBody>() { | 328 | loginCall.enqueue(new Callback<ResponseBody>() { |
378 | @Override | 329 | @Override |
... | @@ -388,15 +339,9 @@ public class WarplyManager { | ... | @@ -388,15 +339,9 @@ public class WarplyManager { |
388 | if (jobjLoginResponse != null && jobjLoginResponse.has("result") && jobjLoginResponse.optString("result", "2").equals("1")) { | 339 | if (jobjLoginResponse != null && jobjLoginResponse.has("result") && jobjLoginResponse.optString("result", "2").equals("1")) { |
389 | JSONObject tokens = jobjLoginResponse.optJSONObject("tokens"); | 340 | JSONObject tokens = jobjLoginResponse.optJSONObject("tokens"); |
390 | if (tokens != null) { | 341 | if (tokens != null) { |
391 | - WarplyDBHelper.getInstance(Warply.getWarplyContext()).saveClientAccess( | 342 | + WarplyDBHelper.getInstance(Warply.getWarplyContext()).saveClientAccess(tokens.optString("client_id", ""), tokens.optString("client_secret", "")); |
392 | - tokens.optString("client_id", ""), | ||
393 | - tokens.optString("client_secret", "") | ||
394 | - ); | ||
395 | 343 | ||
396 | - WarplyDBHelper.getInstance(Warply.getWarplyContext()).saveAuthAccess( | 344 | + WarplyDBHelper.getInstance(Warply.getWarplyContext()).saveAuthAccess(tokens.optString("access_token", ""), tokens.optString("refresh_token", "")); |
397 | - tokens.optString("access_token", ""), | ||
398 | - tokens.optString("refresh_token", "") | ||
399 | - ); | ||
400 | 345 | ||
401 | JSONObject newResult = new JSONObject(); | 346 | JSONObject newResult = new JSONObject(); |
402 | try { | 347 | try { |
... | @@ -504,14 +449,10 @@ public class WarplyManager { | ... | @@ -504,14 +449,10 @@ public class WarplyManager { |
504 | ListenableFuture<CouponList> futureCoupons = getCouponsUniversalRetro(service, 0, futureUniversal); | 449 | ListenableFuture<CouponList> futureCoupons = getCouponsUniversalRetro(service, 0, futureUniversal); |
505 | 450 | ||
506 | ListenableFuture<List<Object>> allResultsFuture = Futures.allAsList(futureCoupons); | 451 | ListenableFuture<List<Object>> allResultsFuture = Futures.allAsList(futureCoupons); |
507 | - ListenableFuture<CouponList> mergedResultFuture = Futures.transformAsync( | 452 | + ListenableFuture<CouponList> mergedResultFuture = Futures.transformAsync(allResultsFuture, results -> { |
508 | - allResultsFuture, | 453 | + CouponList resultCoupons = (CouponList) results.get(0); |
509 | - results -> { | 454 | + return executorService.submit(() -> resultCoupons); |
510 | - CouponList resultCoupons = (CouponList) results.get(0); | 455 | + }, executorService); |
511 | - return executorService.submit(() -> resultCoupons); | ||
512 | - }, | ||
513 | - executorService | ||
514 | - ); | ||
515 | 456 | ||
516 | Futures.addCallback(mergedResultFuture, new FutureCallback<CouponList>() { | 457 | Futures.addCallback(mergedResultFuture, new FutureCallback<CouponList>() { |
517 | @Override | 458 | @Override |
... | @@ -542,16 +483,12 @@ public class WarplyManager { | ... | @@ -542,16 +483,12 @@ public class WarplyManager { |
542 | ListenableFuture<JSONObject> futureCampaignAvailability = getCampaignAvailability(service); | 483 | ListenableFuture<JSONObject> futureCampaignAvailability = getCampaignAvailability(service); |
543 | 484 | ||
544 | ListenableFuture<List<Object>> allResultsFuture = Futures.allAsList(futureCampaigns, futurePersonalizedCampaigns, futureCampaignAvailability); | 485 | ListenableFuture<List<Object>> allResultsFuture = Futures.allAsList(futureCampaigns, futurePersonalizedCampaigns, futureCampaignAvailability); |
545 | - ListenableFuture<ArrayList<Campaign>> mergedResultFuture = Futures.transformAsync( | 486 | + ListenableFuture<ArrayList<Campaign>> mergedResultFuture = Futures.transformAsync(allResultsFuture, results -> { |
546 | - allResultsFuture, | 487 | + ArrayList<Campaign> resultCampaigns = (ArrayList<Campaign>) results.get(0); |
547 | - results -> { | 488 | + ArrayList<Campaign> resultPersonalizedCampaigns = (ArrayList<Campaign>) results.get(1); |
548 | - ArrayList<Campaign> resultCampaigns = (ArrayList<Campaign>) results.get(0); | 489 | + JSONObject resultCampaignsAvailability = (JSONObject) results.get(2); |
549 | - ArrayList<Campaign> resultPersonalizedCampaigns = (ArrayList<Campaign>) results.get(1); | 490 | + return executorService.submit(() -> mergeCampaignResults(resultCampaigns, resultPersonalizedCampaigns, resultCampaignsAvailability)); |
550 | - JSONObject resultCampaignsAvailability = (JSONObject) results.get(2); | 491 | + }, executorService); |
551 | - return executorService.submit(() -> mergeCampaignResults(resultCampaigns, resultPersonalizedCampaigns, resultCampaignsAvailability)); | ||
552 | - }, | ||
553 | - executorService | ||
554 | - ); | ||
555 | 492 | ||
556 | Futures.addCallback(mergedResultFuture, new FutureCallback<ArrayList<Campaign>>() { | 493 | Futures.addCallback(mergedResultFuture, new FutureCallback<ArrayList<Campaign>>() { |
557 | @Override | 494 | @Override |
... | @@ -584,16 +521,7 @@ public class WarplyManager { | ... | @@ -584,16 +521,7 @@ public class WarplyManager { |
584 | jsonParamsCampaigns.put("campaigns", jsonParams); | 521 | jsonParamsCampaigns.put("campaigns", jsonParams); |
585 | RequestBody campaignsRequest = RequestBody.create(MediaType.get("application/json; charset=utf-8"), (new JSONObject(jsonParamsCampaigns)).toString()); | 522 | RequestBody campaignsRequest = RequestBody.create(MediaType.get("application/json; charset=utf-8"), (new JSONObject(jsonParamsCampaigns)).toString()); |
586 | 523 | ||
587 | - Call<ResponseBody> campaignsCall = service.getCampaigns( | 524 | + Call<ResponseBody> campaignsCall = service.getCampaigns(WarplyProperty.getAppUuid(Warply.getWarplyContext()), campaignsRequest, timeStamp, "android:" + Warply.getWarplyContext().getPackageName(), new WarplyDeviceInfoCollector(Warply.getWarplyContext()).getUniqueDeviceId(), "mobile", webId, WarpUtils.produceSignature(apiKey + timeStamp)); |
588 | - WarplyProperty.getAppUuid(Warply.getWarplyContext()), | ||
589 | - campaignsRequest, | ||
590 | - timeStamp, | ||
591 | - "android:" + Warply.getWarplyContext().getPackageName(), | ||
592 | - new WarplyDeviceInfoCollector(Warply.getWarplyContext()).getUniqueDeviceId(), | ||
593 | - "mobile", | ||
594 | - webId, | ||
595 | - WarpUtils.produceSignature(apiKey + timeStamp) | ||
596 | - ); | ||
597 | 525 | ||
598 | campaignsCall.enqueue(new Callback<ResponseBody>() { | 526 | campaignsCall.enqueue(new Callback<ResponseBody>() { |
599 | @Override | 527 | @Override |
... | @@ -732,17 +660,7 @@ public class WarplyManager { | ... | @@ -732,17 +660,7 @@ public class WarplyManager { |
732 | jsonParamsCampaigns.put("campaigns", jsonParams); | 660 | jsonParamsCampaigns.put("campaigns", jsonParams); |
733 | RequestBody campaignsPersonalizedRequest = RequestBody.create(MediaType.get("application/json; charset=utf-8"), (new JSONObject(jsonParamsCampaigns)).toString()); | 661 | RequestBody campaignsPersonalizedRequest = RequestBody.create(MediaType.get("application/json; charset=utf-8"), (new JSONObject(jsonParamsCampaigns)).toString()); |
734 | 662 | ||
735 | - Call<ResponseBody> campaignsPersonalizedCall = service.getCampaignsPersonalized( | 663 | + Call<ResponseBody> campaignsPersonalizedCall = service.getCampaignsPersonalized(WarplyProperty.getAppUuid(Warply.getWarplyContext()), campaignsPersonalizedRequest, timeStamp, "android:" + Warply.getWarplyContext().getPackageName(), new WarplyDeviceInfoCollector(Warply.getWarplyContext()).getUniqueDeviceId(), "mobile", webId, WarpUtils.produceSignature(apiKey + timeStamp), "Bearer " + WarplyDBHelper.getInstance(Warply.getWarplyContext()).getAuthValue("access_token")); |
736 | - WarplyProperty.getAppUuid(Warply.getWarplyContext()), | ||
737 | - campaignsPersonalizedRequest, | ||
738 | - timeStamp, | ||
739 | - "android:" + Warply.getWarplyContext().getPackageName(), | ||
740 | - new WarplyDeviceInfoCollector(Warply.getWarplyContext()).getUniqueDeviceId(), | ||
741 | - "mobile", | ||
742 | - webId, | ||
743 | - WarpUtils.produceSignature(apiKey + timeStamp), | ||
744 | - "Bearer " + WarplyDBHelper.getInstance(Warply.getWarplyContext()).getAuthValue("access_token") | ||
745 | - ); | ||
746 | 664 | ||
747 | campaignsPersonalizedCall.enqueue(new Callback<ResponseBody>() { | 665 | campaignsPersonalizedCall.enqueue(new Callback<ResponseBody>() { |
748 | @Override | 666 | @Override |
... | @@ -914,16 +832,7 @@ public class WarplyManager { | ... | @@ -914,16 +832,7 @@ public class WarplyManager { |
914 | jsonParamsCampaignsAvailability.put("coupon", jsonParams); | 832 | jsonParamsCampaignsAvailability.put("coupon", jsonParams); |
915 | RequestBody campaignsAvailabilityRequest = RequestBody.create(MediaType.get("application/json; charset=utf-8"), (new JSONObject(jsonParamsCampaignsAvailability)).toString()); | 833 | RequestBody campaignsAvailabilityRequest = RequestBody.create(MediaType.get("application/json; charset=utf-8"), (new JSONObject(jsonParamsCampaignsAvailability)).toString()); |
916 | 834 | ||
917 | - Call<ResponseBody> campaignsAvailabilityCall = service.getCampaignsAvailability( | 835 | + Call<ResponseBody> campaignsAvailabilityCall = service.getCampaignsAvailability(WarplyProperty.getAppUuid(Warply.getWarplyContext()), campaignsAvailabilityRequest, timeStamp, "android:" + Warply.getWarplyContext().getPackageName(), new WarplyDeviceInfoCollector(Warply.getWarplyContext()).getUniqueDeviceId(), "mobile", webId, WarpUtils.produceSignature(apiKey + timeStamp)); |
918 | - WarplyProperty.getAppUuid(Warply.getWarplyContext()), | ||
919 | - campaignsAvailabilityRequest, | ||
920 | - timeStamp, | ||
921 | - "android:" + Warply.getWarplyContext().getPackageName(), | ||
922 | - new WarplyDeviceInfoCollector(Warply.getWarplyContext()).getUniqueDeviceId(), | ||
923 | - "mobile", | ||
924 | - webId, | ||
925 | - WarpUtils.produceSignature(apiKey + timeStamp) | ||
926 | - ); | ||
927 | 836 | ||
928 | campaignsAvailabilityCall.enqueue(new Callback<ResponseBody>() { | 837 | campaignsAvailabilityCall.enqueue(new Callback<ResponseBody>() { |
929 | @Override | 838 | @Override |
... | @@ -999,17 +908,7 @@ public class WarplyManager { | ... | @@ -999,17 +908,7 @@ public class WarplyManager { |
999 | jsonParamsMarketPassDetails.put("consumer_data", jsonParams); | 908 | jsonParamsMarketPassDetails.put("consumer_data", jsonParams); |
1000 | RequestBody marketPassDetailsRequest = RequestBody.create(MediaType.get("application/json; charset=utf-8"), (new JSONObject(jsonParamsMarketPassDetails)).toString()); | 909 | RequestBody marketPassDetailsRequest = RequestBody.create(MediaType.get("application/json; charset=utf-8"), (new JSONObject(jsonParamsMarketPassDetails)).toString()); |
1001 | 910 | ||
1002 | - Call<ResponseBody> marketPassDetailsCall = service.getMarketPassDetails( | 911 | + Call<ResponseBody> marketPassDetailsCall = service.getMarketPassDetails(WarplyProperty.getAppUuid(Warply.getWarplyContext()), marketPassDetailsRequest, timeStamp, "android:" + Warply.getWarplyContext().getPackageName(), new WarplyDeviceInfoCollector(Warply.getWarplyContext()).getUniqueDeviceId(), "mobile", webId, WarpUtils.produceSignature(apiKey + timeStamp), "Bearer " + WarplyDBHelper.getInstance(Warply.getWarplyContext()).getAuthValue("access_token")); |
1003 | - WarplyProperty.getAppUuid(Warply.getWarplyContext()), | ||
1004 | - marketPassDetailsRequest, | ||
1005 | - timeStamp, | ||
1006 | - "android:" + Warply.getWarplyContext().getPackageName(), | ||
1007 | - new WarplyDeviceInfoCollector(Warply.getWarplyContext()).getUniqueDeviceId(), | ||
1008 | - "mobile", | ||
1009 | - webId, | ||
1010 | - WarpUtils.produceSignature(apiKey + timeStamp), | ||
1011 | - "Bearer " + WarplyDBHelper.getInstance(Warply.getWarplyContext()).getAuthValue("access_token") | ||
1012 | - ); | ||
1013 | 912 | ||
1014 | marketPassDetailsCall.enqueue(new Callback<ResponseBody>() { | 913 | marketPassDetailsCall.enqueue(new Callback<ResponseBody>() { |
1015 | @Override | 914 | @Override |
... | @@ -1076,6 +975,132 @@ public class WarplyManager { | ... | @@ -1076,6 +975,132 @@ public class WarplyManager { |
1076 | return future; | 975 | return future; |
1077 | } | 976 | } |
1078 | 977 | ||
978 | + private static ListenableFuture<RedeemedSMHistoryModel> getSMCouponsUniversalRetro(ApiService service, int tries, SettableFuture<RedeemedSMHistoryModel> future) { | ||
979 | + String timeStamp = DateFormat.format("yyyy-MM-dd hh:mm:ss", System.currentTimeMillis()).toString(); | ||
980 | + String apiKey = WarpUtils.getApiKey(Warply.getWarplyContext()); | ||
981 | + String webId = WarpUtils.getWebId(Warply.getWarplyContext()); | ||
982 | + | ||
983 | + Map<String, Object> jsonParamsCoupons = new ArrayMap<>(); | ||
984 | + Map<String, Object> jsonParams = new ArrayMap<>(); | ||
985 | + jsonParams.put("action", "user_coupons"); | ||
986 | + JSONArray jArr = new JSONArray(); | ||
987 | + jArr.put("merchant"); | ||
988 | + jArr.put("redemption"); | ||
989 | + jsonParams.put("details", jArr); | ||
990 | + jsonParams.put("language", WarplyProperty.getLanguage(Warply.getWarplyContext())); | ||
991 | + jsonParams.put("couponset_types", new JSONArray().put("supermarket")); | ||
992 | + | ||
993 | + jsonParamsCoupons.put("coupon", jsonParams); | ||
994 | + RequestBody couponsRequest = RequestBody.create(MediaType.get("application/json; charset=utf-8"), (new JSONObject(jsonParamsCoupons)).toString()); | ||
995 | + | ||
996 | + Call<ResponseBody> couponsCall = service.getUserCoupons(WarplyProperty.getAppUuid(Warply.getWarplyContext()), couponsRequest, timeStamp, "android:" + Warply.getWarplyContext().getPackageName(), new WarplyDeviceInfoCollector(Warply.getWarplyContext()).getUniqueDeviceId(), "mobile", webId, WarpUtils.produceSignature(apiKey + timeStamp), "Bearer " + WarplyDBHelper.getInstance(Warply.getWarplyContext()).getAuthValue("access_token")); | ||
997 | + | ||
998 | + couponsCall.enqueue(new Callback<ResponseBody>() { | ||
999 | + @Override | ||
1000 | + public void onResponse(@NonNull Call<ResponseBody> call, @NonNull Response<ResponseBody> response) { | ||
1001 | + if (response.code() == 200 && response.body() != null) { | ||
1002 | + JSONObject jobjCouponsResponse = null; | ||
1003 | + try { | ||
1004 | + jobjCouponsResponse = new JSONObject(response.body().string()); | ||
1005 | + } catch (Exception e) { | ||
1006 | + e.printStackTrace(); | ||
1007 | + } | ||
1008 | + if (jobjCouponsResponse != null && jobjCouponsResponse.has("status") && jobjCouponsResponse.optString("status", "2").equals("1")) { | ||
1009 | + LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel(); | ||
1010 | + dynatraceEvent.setEventName("custom_success_user_sm_coupons_loyalty"); | ||
1011 | + EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent)); | ||
1012 | + JSONArray jCouponsBody = null; | ||
1013 | + try { | ||
1014 | + jCouponsBody = jobjCouponsResponse.optJSONArray("result"); | ||
1015 | + } catch (Exception e) { | ||
1016 | + e.printStackTrace(); | ||
1017 | + } | ||
1018 | + if (jCouponsBody != null) { | ||
1019 | + RedeemedSMHistoryModel redeemedSMHistoryModel = new RedeemedSMHistoryModel(); | ||
1020 | + CouponList mCouponRedeemedList = new CouponList(); | ||
1021 | + | ||
1022 | + final ExecutorService executorCoupons = Executors.newFixedThreadPool(1); | ||
1023 | + JSONArray finalJCouponsBody = jCouponsBody; | ||
1024 | + executorCoupons.submit(() -> { | ||
1025 | + float couponValue = 0.0f; | ||
1026 | + | ||
1027 | + for (int i = 0; i < finalJCouponsBody.length(); ++i) { | ||
1028 | + Coupon tempCoupon = new Coupon(finalJCouponsBody.optJSONObject(i), true); | ||
1029 | + | ||
1030 | + if (tempCoupon.getStatus() == 0) { | ||
1031 | + mCouponRedeemedList.add(tempCoupon); | ||
1032 | + couponValue += (float) tempCoupon.getCouponsetDetails().getFinal_price(); | ||
1033 | + } | ||
1034 | + } | ||
1035 | + | ||
1036 | + Collections.sort(mCouponRedeemedList, (coupon1, coupon2) -> coupon1.getRedeemDate().compareTo(coupon2.getRedeemDate())); | ||
1037 | + redeemedSMHistoryModel.setTotalRedeemedValue(couponValue); | ||
1038 | + redeemedSMHistoryModel.setRedeemedCouponList(mCouponRedeemedList); | ||
1039 | + executorCoupons.shutdownNow(); | ||
1040 | + future.set(redeemedSMHistoryModel); | ||
1041 | + }); | ||
1042 | + } else { | ||
1043 | + LoyaltySDKDynatraceEventModel dynatraceEventElse = new LoyaltySDKDynatraceEventModel(); | ||
1044 | + dynatraceEventElse.setEventName("custom_error_user_sm_coupons_loyalty"); | ||
1045 | + EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEventElse)); | ||
1046 | + future.set(new RedeemedSMHistoryModel()); | ||
1047 | + } | ||
1048 | + } else { | ||
1049 | + LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel(); | ||
1050 | + dynatraceEvent.setEventName("custom_error_user_sm_coupons_loyalty"); | ||
1051 | + EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent)); | ||
1052 | + future.set(new RedeemedSMHistoryModel()); | ||
1053 | + } | ||
1054 | + } else if (response.code() == 401) { | ||
1055 | + refreshToken(new WarplyRefreshTokenRequest(), new CallbackReceiver<JSONObject>() { | ||
1056 | + @Override | ||
1057 | + public void onSuccess(JSONObject result) { | ||
1058 | + int status = result.optInt("status", 2); | ||
1059 | + if (status == 1) | ||
1060 | + getSMCouponsUniversalRetro(service, tries/*, receiver*/, future); | ||
1061 | + else { | ||
1062 | +// receiver.onFailure(status); | ||
1063 | + if (tries < MAX_RETRIES) { | ||
1064 | + getSMCouponsUniversalRetro(service, (tries + 1), future); | ||
1065 | + } else { | ||
1066 | +// future.set(new CouponList()); | ||
1067 | + future.setException(new Throwable()); | ||
1068 | + } | ||
1069 | + } | ||
1070 | + } | ||
1071 | + | ||
1072 | + @Override | ||
1073 | + public void onFailure(int errorCode) { | ||
1074 | +// receiver.onFailure(errorCode); | ||
1075 | + if (tries < MAX_RETRIES) { | ||
1076 | + getSMCouponsUniversalRetro(service, (tries + 1), future); | ||
1077 | + } else { | ||
1078 | +// future.set(new CouponList()); | ||
1079 | + future.setException(new Throwable()); | ||
1080 | + } | ||
1081 | + } | ||
1082 | + }); | ||
1083 | + } else { | ||
1084 | + LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel(); | ||
1085 | + dynatraceEvent.setEventName("custom_error_user_sm_coupons_loyalty"); | ||
1086 | + EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent)); | ||
1087 | +// future.set(new CouponList()); | ||
1088 | + future.setException(new Throwable()); | ||
1089 | + } | ||
1090 | + } | ||
1091 | + | ||
1092 | + @Override | ||
1093 | + public void onFailure(@NonNull Call<ResponseBody> call, @NonNull Throwable t) { | ||
1094 | + LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel(); | ||
1095 | + dynatraceEvent.setEventName("custom_error_user_sm_coupons_loyalty"); | ||
1096 | + EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent)); | ||
1097 | +// future.set(new CouponList()); | ||
1098 | + future.setException(new Throwable()); | ||
1099 | + } | ||
1100 | + }); | ||
1101 | + return future; | ||
1102 | + } | ||
1103 | + | ||
1079 | private static ListenableFuture<CouponList> getCouponsUniversalRetro(ApiService service, int tries, SettableFuture<CouponList> future) { | 1104 | private static ListenableFuture<CouponList> getCouponsUniversalRetro(ApiService service, int tries, SettableFuture<CouponList> future) { |
1080 | String timeStamp = DateFormat.format("yyyy-MM-dd hh:mm:ss", System.currentTimeMillis()).toString(); | 1105 | String timeStamp = DateFormat.format("yyyy-MM-dd hh:mm:ss", System.currentTimeMillis()).toString(); |
1081 | String apiKey = WarpUtils.getApiKey(Warply.getWarplyContext()); | 1106 | String apiKey = WarpUtils.getApiKey(Warply.getWarplyContext()); |
... | @@ -1101,17 +1126,7 @@ public class WarplyManager { | ... | @@ -1101,17 +1126,7 @@ public class WarplyManager { |
1101 | jsonParamsCoupons.put("coupon", jsonParams); | 1126 | jsonParamsCoupons.put("coupon", jsonParams); |
1102 | RequestBody couponsRequest = RequestBody.create(MediaType.get("application/json; charset=utf-8"), (new JSONObject(jsonParamsCoupons)).toString()); | 1127 | RequestBody couponsRequest = RequestBody.create(MediaType.get("application/json; charset=utf-8"), (new JSONObject(jsonParamsCoupons)).toString()); |
1103 | 1128 | ||
1104 | - Call<ResponseBody> couponsCall = service.getUserCoupons( | 1129 | + Call<ResponseBody> couponsCall = service.getUserCoupons(WarplyProperty.getAppUuid(Warply.getWarplyContext()), couponsRequest, timeStamp, "android:" + Warply.getWarplyContext().getPackageName(), new WarplyDeviceInfoCollector(Warply.getWarplyContext()).getUniqueDeviceId(), "mobile", webId, WarpUtils.produceSignature(apiKey + timeStamp), "Bearer " + WarplyDBHelper.getInstance(Warply.getWarplyContext()).getAuthValue("access_token")); |
1105 | - WarplyProperty.getAppUuid(Warply.getWarplyContext()), | ||
1106 | - couponsRequest, | ||
1107 | - timeStamp, | ||
1108 | - "android:" + Warply.getWarplyContext().getPackageName(), | ||
1109 | - new WarplyDeviceInfoCollector(Warply.getWarplyContext()).getUniqueDeviceId(), | ||
1110 | - "mobile", | ||
1111 | - webId, | ||
1112 | - WarpUtils.produceSignature(apiKey + timeStamp), | ||
1113 | - "Bearer " + WarplyDBHelper.getInstance(Warply.getWarplyContext()).getAuthValue("access_token") | ||
1114 | - ); | ||
1115 | 1130 | ||
1116 | couponsCall.enqueue(new Callback<ResponseBody>() { | 1131 | couponsCall.enqueue(new Callback<ResponseBody>() { |
1117 | @Override | 1132 | @Override |
... | @@ -1160,6 +1175,11 @@ public class WarplyManager { | ... | @@ -1160,6 +1175,11 @@ public class WarplyManager { |
1160 | 1175 | ||
1161 | future.set(mCouponRedeemedList); | 1176 | future.set(mCouponRedeemedList); |
1162 | }); | 1177 | }); |
1178 | + } else { | ||
1179 | + LoyaltySDKDynatraceEventModel dynatraceEventElse = new LoyaltySDKDynatraceEventModel(); | ||
1180 | + dynatraceEventElse.setEventName("custom_error_user_coupons_loyalty"); | ||
1181 | + EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEventElse)); | ||
1182 | + future.set(new CouponList()); | ||
1163 | } | 1183 | } |
1164 | } else { | 1184 | } else { |
1165 | LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel(); | 1185 | LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel(); |
... | @@ -1225,24 +1245,23 @@ public class WarplyManager { | ... | @@ -1225,24 +1245,23 @@ public class WarplyManager { |
1225 | 1245 | ||
1226 | String url = WarplyProperty.getBaseUrl(Warply.getWarplyContext()) + WarpConstants.BASE_REMOTE_PAGE_URL + sessionUuid; | 1246 | String url = WarplyProperty.getBaseUrl(Warply.getWarplyContext()) + WarpConstants.BASE_REMOTE_PAGE_URL + sessionUuid; |
1227 | 1247 | ||
1228 | - Warply.INSTANCE.getSingleCampaign(null, url, | 1248 | + Warply.INSTANCE.getSingleCampaign(null, url, new CallbackReceiver<JSONObject>() { |
1229 | - new CallbackReceiver<JSONObject>() { | 1249 | + @Override |
1230 | - @Override | 1250 | + public void onSuccess(JSONObject result) { |
1231 | - public void onSuccess(JSONObject result) { | 1251 | + LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel(); |
1232 | - LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel(); | 1252 | + dynatraceEvent.setEventName("custom_success_read_campaign_loyalty"); |
1233 | - dynatraceEvent.setEventName("custom_success_read_campaign_loyalty"); | 1253 | + EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent)); |
1234 | - EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent)); | 1254 | + } |
1235 | - } | ||
1236 | 1255 | ||
1237 | - @Override | 1256 | + @Override |
1238 | - public void onFailure(int errorCode) { | 1257 | + public void onFailure(int errorCode) { |
1239 | - if (errorCode == 301 || errorCode == 302 || errorCode == 307 || errorCode == 308) { | 1258 | + if (errorCode == 301 || errorCode == 302 || errorCode == 307 || errorCode == 308) { |
1240 | - LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel(); | 1259 | + LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel(); |
1241 | - dynatraceEvent.setEventName("custom_success_read_campaign_loyalty"); | 1260 | + dynatraceEvent.setEventName("custom_success_read_campaign_loyalty"); |
1242 | - EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent)); | 1261 | + EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent)); |
1243 | - } | 1262 | + } |
1244 | - } | 1263 | + } |
1245 | - }, null); | 1264 | + }, null); |
1246 | } | 1265 | } |
1247 | 1266 | ||
1248 | public static void getMarketPassDetails(final CallbackReceiver<MarketPassDetailsModel> receiver) { | 1267 | public static void getMarketPassDetails(final CallbackReceiver<MarketPassDetailsModel> receiver) { |
... | @@ -1256,14 +1275,10 @@ public class WarplyManager { | ... | @@ -1256,14 +1275,10 @@ public class WarplyManager { |
1256 | ListenableFuture<MarketPassDetailsModel> futureMarketPassDetails = getMarketPassDetails(service); | 1275 | ListenableFuture<MarketPassDetailsModel> futureMarketPassDetails = getMarketPassDetails(service); |
1257 | 1276 | ||
1258 | ListenableFuture<List<Object>> allResultsFuture = Futures.allAsList(futureMarketPassDetails); | 1277 | ListenableFuture<List<Object>> allResultsFuture = Futures.allAsList(futureMarketPassDetails); |
1259 | - ListenableFuture<MarketPassDetailsModel> mergedResultFuture = Futures.transformAsync( | 1278 | + ListenableFuture<MarketPassDetailsModel> mergedResultFuture = Futures.transformAsync(allResultsFuture, results -> { |
1260 | - allResultsFuture, | 1279 | + MarketPassDetailsModel resultMarketPassDetails = (MarketPassDetailsModel) results.get(0); |
1261 | - results -> { | 1280 | + return executorService.submit(() -> resultMarketPassDetails); |
1262 | - MarketPassDetailsModel resultMarketPassDetails = (MarketPassDetailsModel) results.get(0); | 1281 | + }, executorService); |
1263 | - return executorService.submit(() -> resultMarketPassDetails); | ||
1264 | - }, | ||
1265 | - executorService | ||
1266 | - ); | ||
1267 | 1282 | ||
1268 | Futures.addCallback(mergedResultFuture, new FutureCallback<MarketPassDetailsModel>() { | 1283 | Futures.addCallback(mergedResultFuture, new FutureCallback<MarketPassDetailsModel>() { |
1269 | @Override | 1284 | @Override |
... | @@ -1306,16 +1321,7 @@ public class WarplyManager { | ... | @@ -1306,16 +1321,7 @@ public class WarplyManager { |
1306 | jsonParamsCampaigns.put("campaigns", jsonParams); | 1321 | jsonParamsCampaigns.put("campaigns", jsonParams); |
1307 | RequestBody campaignsRequest = RequestBody.create(MediaType.get("application/json; charset=utf-8"), (new JSONObject(jsonParamsCampaigns)).toString()); | 1322 | RequestBody campaignsRequest = RequestBody.create(MediaType.get("application/json; charset=utf-8"), (new JSONObject(jsonParamsCampaigns)).toString()); |
1308 | 1323 | ||
1309 | - Call<ResponseBody> campaignsCall = service.getCampaigns( | 1324 | + Call<ResponseBody> campaignsCall = service.getCampaigns(WarplyProperty.getAppUuid(Warply.getWarplyContext()), campaignsRequest, timeStamp, "android:" + Warply.getWarplyContext().getPackageName(), new WarplyDeviceInfoCollector(Warply.getWarplyContext()).getUniqueDeviceId(), "mobile", webId, WarpUtils.produceSignature(apiKey + timeStamp)); |
1310 | - WarplyProperty.getAppUuid(Warply.getWarplyContext()), | ||
1311 | - campaignsRequest, | ||
1312 | - timeStamp, | ||
1313 | - "android:" + Warply.getWarplyContext().getPackageName(), | ||
1314 | - new WarplyDeviceInfoCollector(Warply.getWarplyContext()).getUniqueDeviceId(), | ||
1315 | - "mobile", | ||
1316 | - webId, | ||
1317 | - WarpUtils.produceSignature(apiKey + timeStamp) | ||
1318 | - ); | ||
1319 | 1325 | ||
1320 | campaignsCall.enqueue(new Callback<ResponseBody>() { | 1326 | campaignsCall.enqueue(new Callback<ResponseBody>() { |
1321 | @Override | 1327 | @Override |
... | @@ -1451,14 +1457,10 @@ public class WarplyManager { | ... | @@ -1451,14 +1457,10 @@ public class WarplyManager { |
1451 | ListenableFuture<ArrayList<Campaign>> futureCampaigns = getSupermarketCampaignRetro(service); | 1457 | ListenableFuture<ArrayList<Campaign>> futureCampaigns = getSupermarketCampaignRetro(service); |
1452 | 1458 | ||
1453 | ListenableFuture<List<Object>> allResultsFuture = Futures.allAsList(futureCampaigns); | 1459 | ListenableFuture<List<Object>> allResultsFuture = Futures.allAsList(futureCampaigns); |
1454 | - ListenableFuture<ArrayList<Campaign>> mergedResultFuture = Futures.transformAsync( | 1460 | + ListenableFuture<ArrayList<Campaign>> mergedResultFuture = Futures.transformAsync(allResultsFuture, results -> { |
1455 | - allResultsFuture, | 1461 | + ArrayList<Campaign> resultCampaigns = (ArrayList<Campaign>) results.get(0); |
1456 | - results -> { | 1462 | + return executorService.submit(() -> resultCampaigns); |
1457 | - ArrayList<Campaign> resultCampaigns = (ArrayList<Campaign>) results.get(0); | 1463 | + }, executorService); |
1458 | - return executorService.submit(() -> resultCampaigns); | ||
1459 | - }, | ||
1460 | - executorService | ||
1461 | - ); | ||
1462 | 1464 | ||
1463 | Futures.addCallback(mergedResultFuture, new FutureCallback<ArrayList<Campaign>>() { | 1465 | Futures.addCallback(mergedResultFuture, new FutureCallback<ArrayList<Campaign>>() { |
1464 | @Override | 1466 | @Override |
... | @@ -1475,4 +1477,36 @@ public class WarplyManager { | ... | @@ -1475,4 +1477,36 @@ public class WarplyManager { |
1475 | } | 1477 | } |
1476 | }, executorService); | 1478 | }, executorService); |
1477 | } | 1479 | } |
1480 | + | ||
1481 | + public static void getRedeemedSMHistory(final CallbackReceiver<RedeemedSMHistoryModel> receiver) { | ||
1482 | + WarpUtils.log("************* WARPLY User Redeemed History Request ********************"); | ||
1483 | + WarpUtils.log("[WARP Trace] WARPLY User Redeemed History Request is active"); | ||
1484 | + WarpUtils.log("**************************************************"); | ||
1485 | + | ||
1486 | + ApiService service = ApiClient.getRetrofitInstance().create(ApiService.class); | ||
1487 | + ListeningExecutorService executorService = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(1)); | ||
1488 | + | ||
1489 | + SettableFuture<RedeemedSMHistoryModel> futureUniversal = SettableFuture.create(); | ||
1490 | + ListenableFuture<RedeemedSMHistoryModel> futureCoupons = getSMCouponsUniversalRetro(service, 0, futureUniversal); | ||
1491 | + | ||
1492 | + ListenableFuture<List<Object>> allResultsFuture = Futures.allAsList(futureCoupons); | ||
1493 | + ListenableFuture<RedeemedSMHistoryModel> mergedResultFuture = Futures.transformAsync(allResultsFuture, results -> { | ||
1494 | + RedeemedSMHistoryModel resultCoupons = (RedeemedSMHistoryModel) results.get(0); | ||
1495 | + return executorService.submit(() -> resultCoupons); | ||
1496 | + }, executorService); | ||
1497 | + | ||
1498 | + Futures.addCallback(mergedResultFuture, new FutureCallback<RedeemedSMHistoryModel>() { | ||
1499 | + @Override | ||
1500 | + public void onSuccess(RedeemedSMHistoryModel mergedResult) { | ||
1501 | + executorService.shutdownNow(); | ||
1502 | + new Handler(Looper.getMainLooper()).post(() -> receiver.onSuccess(mergedResult)); | ||
1503 | + } | ||
1504 | + | ||
1505 | + @Override | ||
1506 | + public void onFailure(Throwable throwable) { | ||
1507 | + executorService.shutdownNow(); | ||
1508 | + new Handler(Looper.getMainLooper()).post(() -> receiver.onFailure(2)); | ||
1509 | + } | ||
1510 | + }, executorService); | ||
1511 | + } | ||
1478 | } | 1512 | } | ... | ... |
-
Please register or login to post a comment