Panagiotis Triantafyllou

version 4.5.1

......@@ -33,8 +33,8 @@ PushIcon=ic_notify
# If the device packages need to be send to the engage server
SendPackages=false
# The language for some requests in case of multi language support
Language=el
# The app language
#Language=el
# The merchant id for some requests
MerchantId=20113
......
......@@ -2,7 +2,7 @@ apply plugin: 'com.android.library'
ext {
PUBLISH_GROUP_ID = 'ly.warp'
PUBLISH_VERSION = '4.5.0'
PUBLISH_VERSION = '4.5.1'
PUBLISH_ARTIFACT_ID = 'warply-android-sdk'
}
......
/*
* Copyright 2010-2013 Warply Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, without modification, are
* permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE WARPLY LTD ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
* EVENT SHALL WARPLY LTD OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package ly.warp.sdk.io.callbacks;
import org.json.JSONArray;
import org.json.JSONObject;
import ly.warp.sdk.io.models.CouponsetsList;
/**
* Created by Panagiotis Triantafyllou on 04-Feb-22.
*/
public class CouponsetsHook implements CallbackReceiver<JSONObject> {
private final String JSON_KEY_MAPP = "MAPP_COUPON";
private final String JSON_KEY_CONTEXT = "context";
private final CallbackReceiver<CouponsetsList> mListener;
private final String mRequestSignature;
public CouponsetsHook(CallbackReceiver<CouponsetsList> listener, String requestSignature) {
this.mListener = listener;
this.mRequestSignature = requestSignature;
}
@Override
public void onSuccess(JSONObject result) {
if (mListener != null) {
int status = result.optInt("status", 2);
if (status == 1) {
JSONObject couponsetsJSONObject = result.optJSONObject(JSON_KEY_CONTEXT);
if (couponsetsJSONObject != null) {
JSONArray jArrayResult = couponsetsJSONObject.optJSONArray(JSON_KEY_MAPP);
if (jArrayResult == null) {
mListener.onFailure(2);
return;
}
mListener.onSuccess(new CouponsetsList(couponsetsJSONObject, mRequestSignature));
}
} else
mListener.onFailure(status);
}
}
@Override
public void onFailure(int errorCode) {
if (mListener != null)
mListener.onFailure(errorCode);
}
}
......@@ -58,6 +58,8 @@ public class Coupon implements Parcelable, Serializable {
private static final String STATUS = "status";
private static final String TRANSACTION_DATE = "transaction_date";
private static final String TRANSACTION_UUID = "transaction_uuid";
private static final String CHANGES_DATES = "changes_dates";
private static final String COUPONSET_UUID = "couponset_uuid";
/* Member variables of the Campaign object */
......@@ -73,6 +75,8 @@ public class Coupon implements Parcelable, Serializable {
private int status = 0;
private String transactionDate = "";
private String transactionUuid = "";
private JSONObject changesDates = new JSONObject();
private String couponsetUuid = "";
/**
* Basic constructor used to create an object from a String, representing a
......@@ -104,6 +108,8 @@ public class Coupon implements Parcelable, Serializable {
this.status = json.optInt(STATUS);
this.transactionDate = json.optString(TRANSACTION_DATE);
this.transactionUuid = json.optString(TRANSACTION_UUID);
this.changesDates = json.optJSONObject(CHANGES_DATES);
this.couponsetUuid = json.optString(COUPONSET_UUID);
}
}
......@@ -120,6 +126,7 @@ public class Coupon implements Parcelable, Serializable {
this.status = source.readInt();
this.transactionDate = source.readString();
this.transactionUuid = source.readString();
this.couponsetUuid = source.readString();
}
@Override
......@@ -136,6 +143,7 @@ public class Coupon implements Parcelable, Serializable {
dest.writeInt(this.status);
dest.writeString(this.transactionDate);
dest.writeString(this.transactionUuid);
dest.writeString(this.couponsetUuid);
}
/**
......@@ -158,6 +166,8 @@ public class Coupon implements Parcelable, Serializable {
jObj.putOpt(STATUS, this.status);
jObj.putOpt(TRANSACTION_DATE, this.transactionDate);
jObj.putOpt(TRANSACTION_UUID, this.transactionUuid);
jObj.putOpt(CHANGES_DATES, this.changesDates);
jObj.putOpt(COUPONSET_UUID, this.couponsetUuid);
} catch (JSONException e) {
if (WarpConstants.DEBUG) {
e.printStackTrace();
......@@ -245,6 +255,14 @@ public class Coupon implements Parcelable, Serializable {
return transactionUuid;
}
public JSONObject getChangesDates() {
return changesDates;
}
public String getCouponsetUuid() {
return couponsetUuid;
}
@Override
public int describeContents() {
return 0;
......
/*
* Copyright 2010-2013 Warply Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, without modification, are
* permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE WARPLY LTD ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
* EVENT SHALL WARPLY LTD OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package ly.warp.sdk.io.models;
import androidx.annotation.NonNull;
import org.json.JSONArray;
import org.json.JSONObject;
import java.util.ArrayList;
/**
* Created by Panagiotis Triantafyllou on 04-Feb-22.
*/
public class CouponsetsList extends ArrayList<Couponset> {
/**
* Generated for serialized class
*/
private static final long serialVersionUID = -188843583823948267L;
private static final String JSON_KEY_COUPON = "MAPP_COUPON";
private String mRequestSignature = "";
private CouponsetsList(String requestSignature) {
this.mRequestSignature = requestSignature;
}
public CouponsetsList() {
super();
}
/**
* Constructor used to create the CouponsetsList from a JSON Object.
*
* @param addressListJSONObject The JSON Object, used to create the CouponsetsList
*/
public CouponsetsList(JSONObject addressListJSONObject, String requestSignature) {
this(requestSignature);
if (addressListJSONObject == null)
return;
JSONArray jArray = addressListJSONObject.optJSONArray(JSON_KEY_COUPON);
if (jArray != null && jArray.length() > 0) {
for (int i = 0, lim = jArray.length(); i < lim; ++i) {
add(new Couponset(jArray.optJSONObject(i)));
}
}
}
@NonNull
public String getRequestSignature() {
return mRequestSignature;
}
}
......@@ -13,8 +13,6 @@ import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.HashMap;
import ly.warp.sdk.Warply;
import ly.warp.sdk.utils.WarplyProperty;
import ly.warp.sdk.utils.constants.WarpConstants;
/**
......@@ -42,6 +40,7 @@ public class WarplyContentRequest {
private long mCacheUpdateInterval = 0;
private String mContentCategory = "";
private ArrayList<String> mTags = new ArrayList<>();
private String mLanguage = "";
// ===========================================================
// Constructor
......@@ -97,6 +96,11 @@ public class WarplyContentRequest {
return this;
}
public WarplyContentRequest setLanguage(String lan) {
mLanguage = lan;
return this;
}
/**
* Call this to get how often the cached data will be updated.
*
......@@ -159,7 +163,7 @@ public class WarplyContentRequest {
try {
bodyJsonObject.putOpt(KEY_ACTION, KEY_ACTION_VALUE);
bodyJsonObject.putOpt(KEY_ACTIVE, true);
bodyJsonObject.putOpt(KEY_LANGUAGE, WarplyProperty.getLanguage(Warply.getWarplyContext()));
bodyJsonObject.putOpt(KEY_LANGUAGE, mLanguage);
bodyJsonObject.putOpt(KEY_CATEGORY, TextUtils.isEmpty(mContentCategory) ? JSONObject.NULL : mContentCategory);
JSONArray jsArray = new JSONArray(mTags);
bodyJsonObject.putOpt(KEY_TAGS, jsArray.length() == 0 ? JSONObject.NULL : jsArray);
......
package ly.warp.sdk.io.request;
import android.util.Base64;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.HashMap;
import ly.warp.sdk.utils.constants.WarpConstants;
/**
* Created by Panagiotis Triantafyllou on 04-Feb-22.
*/
public class WarplyGetCouponsetsRequest {
// ===========================================================
// Constants
// ===========================================================
private final String KEY_ACTION = "action";
private final String KEY_ACTION_VALUE = "retrieve_multilingual";
private final String KEY_ACTIVE = "active";
private final String KEY_VISIBLE = "visible";
private final String KEY_LANGUAGE = "language";
private final String KEY_UUIDS = "uuids";
// ===========================================================
// Fields
// ===========================================================
private HashMap<String, String> mFilters;
private long mCacheUpdateInterval = 0;
private boolean mActive = true;
private boolean mVisible = true;
private ArrayList<String> mUuids = new ArrayList<>();
private String mLanguage = "";
// ===========================================================
// Constructor
// ===========================================================
/**
* Default constructor of WarplyGetCouponsetsRequest, initializes an empty filters HashMap
*/
public WarplyGetCouponsetsRequest() {
mFilters = new HashMap<>();
}
public WarplyGetCouponsetsRequest(WarplyGetCouponsetsRequest copy) {
if (copy != null) {
this.mFilters = copy.mFilters;
this.mCacheUpdateInterval = copy.mCacheUpdateInterval;
}
}
// ===========================================================
// Methods for/from SuperClass/Interfaces
// ===========================================================
@Override
public boolean equals(Object object) {
if (object instanceof WarplyGetCouponsetsRequest) {
WarplyGetCouponsetsRequest other = (WarplyGetCouponsetsRequest) object;
return other == this || (this.mFilters == other.mFilters || (this.mFilters != null && this.mFilters.equals(other.mFilters)));
}
return false;
}
@Override
public int hashCode() {
return mFilters.hashCode();
}
// ===========================================================
// Methods
// ===========================================================
// ===========================================================
// Getter & Setter
// ===========================================================
public WarplyGetCouponsetsRequest setActive(boolean active) {
mActive = active;
return this;
}
public WarplyGetCouponsetsRequest setVisible(boolean visible) {
mVisible = visible;
return this;
}
public WarplyGetCouponsetsRequest setUuids(ArrayList<String> uuids) {
mUuids = uuids;
return this;
}
public WarplyGetCouponsetsRequest setLanguage(String language) {
mLanguage = language;
return this;
}
/**
* Call this to get how often the cached data will be updated.
*
* @return mCacheUpdateInterval
*/
public long getCacheUpdateInterval() {
return mCacheUpdateInterval;
}
/**
* Call this to set how often the cached data will be updated.
*
* @param updateInterval The time that data will be cached
* @return WarplyGetCouponsetsRequest
*/
public WarplyGetCouponsetsRequest setCacheUpdateInterval(long updateInterval) {
this.mCacheUpdateInterval = updateInterval;
if (mCacheUpdateInterval < 0) {
mCacheUpdateInterval = 0;
}
return this;
}
/**
* Call this to check if the Application uses Cache
*
* @return <p>true - the Application is using Cache</p>
* <p>false - the Application is not using Cache</p>
*/
public boolean isUseCache() {
return mCacheUpdateInterval > 0;
}
/**
* Call this to check whether the cached data need to be updated
*
* @param useCache <p>true - the Application is using Cache</p>
* <p>false - the Application is not using Cache</p>
* @return WarplyGetCouponsetsRequest
*/
public WarplyGetCouponsetsRequest setUseCache(boolean useCache) {
if (useCache) {
mCacheUpdateInterval = mCacheUpdateInterval > 0 ? mCacheUpdateInterval
: WarpConstants.INBOX_UPDATE_INTERVAL;
} else {
mCacheUpdateInterval = 0;
}
return this;
}
/**
* Call this to build the couponsets Json object
*
* @return bodyJsonObject
*/
public JSONObject toJson() {
JSONObject bodyJsonObject = new JSONObject();
try {
bodyJsonObject.putOpt(KEY_ACTION, KEY_ACTION_VALUE);
bodyJsonObject.putOpt(KEY_ACTIVE, mActive);
bodyJsonObject.putOpt(KEY_VISIBLE, mVisible);
bodyJsonObject.putOpt(KEY_LANGUAGE, mLanguage);
if (mUuids != null && mUuids.size() > 0)
bodyJsonObject.putOpt(KEY_UUIDS, new JSONArray(mUuids));
} catch (JSONException e) {
if (WarpConstants.DEBUG)
e.printStackTrace();
}
return bodyJsonObject;
}
public String getSignature() {
String signature = mFilters != null && mFilters.size() > 0 ? String.valueOf(mFilters.hashCode()) : "default_get_couponsets_request";
try {
byte[] hash = MessageDigest.getInstance("SHA-256").digest(signature.getBytes("UTF-8"));
signature = Base64.encodeToString(hash, Base64.NO_WRAP);
} catch (NullPointerException | NoSuchAlgorithmException
| UnsupportedEncodingException e) {
e.printStackTrace();
}
return signature;
}
}
......@@ -10,8 +10,6 @@ import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.HashMap;
import ly.warp.sdk.Warply;
import ly.warp.sdk.utils.WarplyProperty;
import ly.warp.sdk.utils.constants.WarpConstants;
/**
......@@ -34,6 +32,7 @@ public class WarplyMerchantCategoriesRequest {
private HashMap<String, String> mFilters;
private long mCacheUpdateInterval = 0;
private String mLanguage = "";
// ===========================================================
// Constructor
......@@ -79,6 +78,11 @@ public class WarplyMerchantCategoriesRequest {
// Getter & Setter
// ===========================================================
public WarplyMerchantCategoriesRequest setLanguage(String lan) {
mLanguage = lan;
return this;
}
/**
* Call this to get how often the cached data will be updated.
*
......@@ -140,7 +144,7 @@ public class WarplyMerchantCategoriesRequest {
JSONObject bodyJsonObject = new JSONObject();
try {
bodyJsonObject.putOpt(KEY_ACTION, KEY_ACTION_VALUE);
bodyJsonObject.putOpt(KEY_LANGUAGE, WarplyProperty.getLanguage(Warply.getWarplyContext()));
bodyJsonObject.putOpt(KEY_LANGUAGE, mLanguage);
} catch (JSONException e) {
if (WarpConstants.DEBUG)
e.printStackTrace();
......
......@@ -13,8 +13,6 @@ import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.HashMap;
import ly.warp.sdk.Warply;
import ly.warp.sdk.utils.WarplyProperty;
import ly.warp.sdk.utils.constants.WarpConstants;
/**
......@@ -53,6 +51,7 @@ public class WarplyMerchantsRequest {
private String mUuid = "";
private int mDistance = 0;
private ArrayList<Double> mCenter = new ArrayList<>();
private String mLanguage = "";
// ===========================================================
// Constructor
......@@ -133,6 +132,11 @@ public class WarplyMerchantsRequest {
return this;
}
public WarplyMerchantsRequest setLanguage(String lan) {
mLanguage = lan;
return this;
}
/**
* Call this to get how often the cached data will be updated.
*
......@@ -198,7 +202,7 @@ public class WarplyMerchantsRequest {
bodyJsonObject.putOpt(KEY_ACTIVE, true);
bodyJsonObject.putOpt(KEY_CATEGORIES, new JSONArray(mCategories));
bodyJsonObject.putOpt(KEY_DEFAULT_SHOWN, mDefaultShown ? mDefaultShown : JSONObject.NULL);
bodyJsonObject.putOpt(KEY_LANGUAGE, WarplyProperty.getLanguage(Warply.getWarplyContext()));
bodyJsonObject.putOpt(KEY_LANGUAGE, mLanguage);
if (mDistance != 0 && mCenter != null && mCenter.size() > 0) {
JSONObject locObj = new JSONObject();
locObj.putOpt(KEY_CENTER, mCenter);
......
......@@ -3,7 +3,6 @@ package ly.warp.sdk.io.request;
import android.text.TextUtils;
import android.util.Base64;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
......@@ -11,7 +10,6 @@ import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.HashMap;
import java.util.Map;
import ly.warp.sdk.Warply;
import ly.warp.sdk.utils.WarplyProperty;
......@@ -41,6 +39,7 @@ public class WarplyProductsRequest {
private HashMap<String, String> mFilters;
private long mCacheUpdateInterval = 0;
private String mProductsCategory = "";
private String mLanguage = "";
// ===========================================================
// Constructor
......@@ -91,6 +90,11 @@ public class WarplyProductsRequest {
return this;
}
public WarplyProductsRequest setLanguage(String lan) {
mLanguage = lan;
return this;
}
/**
* Call this to get how often the cached data will be updated.
*
......@@ -152,7 +156,7 @@ public class WarplyProductsRequest {
JSONObject bodyJsonObject = new JSONObject();
try {
bodyJsonObject.putOpt(KEY_ACTION, KEY_ACTION_VALUE);
bodyJsonObject.putOpt(KEY_LANGUAGE, WarplyProperty.getLanguage(Warply.getWarplyContext()));
bodyJsonObject.putOpt(KEY_LANGUAGE, mLanguage);
bodyJsonObject.putOpt(KEY_MERCHANT_ID, WarplyProperty.getMerchantId(Warply.getWarplyContext()));
JSONObject extraJson = new JSONObject();
extraJson.put(KEY_CATEGORY_NAME, TextUtils.isEmpty(mProductsCategory) ? JSONObject.NULL : mProductsCategory);
......
......@@ -10,12 +10,10 @@ import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.HashMap;
import ly.warp.sdk.Warply;
import ly.warp.sdk.utils.WarplyProperty;
import ly.warp.sdk.utils.constants.WarpConstants;
/**
* Created by Panagiotis Triantafyllou on 18-Jan-22.
* Created by Panagiotis Triantafyllou on 04-Feb-22.
*/
public class WarplyRedeemCouponRequest {
......@@ -25,12 +23,8 @@ public class WarplyRedeemCouponRequest {
// ===========================================================
private final String KEY_ACTION = "action";
private final String KEY_ACTION_VALUE = "vcurrency_purchase";
private final String KEY_MERCHANT_ID = "merchant_id";
private final String KEY_PRODUCT_ID = "product_id";
private final String KEY_PRODUCT_UUID = "product_uuid";
private final String KEY_CAUSE = "cause";
private final String KEY_CAUSE_VALUE = "coupon";
private final String KEY_ACTION_VALUE = "retrieve_coupon";
private final String KEY_COUPONSET = "coupon_set";
// ===========================================================
// Fields
......@@ -38,8 +32,7 @@ public class WarplyRedeemCouponRequest {
private HashMap<String, String> mFilters;
private long mCacheUpdateInterval = 0;
private String mId = "";
private String mUuid = "";
private String mCouponsetUuid = "";
// ===========================================================
// Constructor
......@@ -85,13 +78,8 @@ public class WarplyRedeemCouponRequest {
// Getter & Setter
// ===========================================================
public WarplyRedeemCouponRequest setSku(String sku) {
mId = sku;
return this;
}
public WarplyRedeemCouponRequest setUuid(String uuid) {
mUuid = uuid;
public WarplyRedeemCouponRequest setCouponsetUuid(String uuid) {
mCouponsetUuid = uuid;
return this;
}
......@@ -148,7 +136,7 @@ public class WarplyRedeemCouponRequest {
}
/**
* Call this to build the offers Json object
* Call this to build the redeem coupon Json object
*
* @return bodyJsonObject
*/
......@@ -156,10 +144,7 @@ public class WarplyRedeemCouponRequest {
JSONObject bodyJsonObject = new JSONObject();
try {
bodyJsonObject.putOpt(KEY_ACTION, KEY_ACTION_VALUE);
bodyJsonObject.putOpt(KEY_MERCHANT_ID, WarplyProperty.getMerchantId(Warply.getWarplyContext()));
bodyJsonObject.putOpt(KEY_PRODUCT_ID, mId);
bodyJsonObject.putOpt(KEY_PRODUCT_UUID, mUuid);
bodyJsonObject.putOpt(KEY_CAUSE, KEY_CAUSE_VALUE);
bodyJsonObject.putOpt(KEY_COUPONSET, mCouponsetUuid);
} catch (JSONException e) {
if (WarpConstants.DEBUG)
e.printStackTrace();
......
package ly.warp.sdk.io.request;
import android.util.Base64;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.HashMap;
import ly.warp.sdk.Warply;
import ly.warp.sdk.utils.WarplyProperty;
import ly.warp.sdk.utils.constants.WarpConstants;
/**
* Created by Panagiotis Triantafyllou on 18-Jan-22.
*/
public class WarplyRedeemProductRequest {
// ===========================================================
// Constants
// ===========================================================
private final String KEY_ACTION = "action";
private final String KEY_ACTION_VALUE = "vcurrency_purchase";
private final String KEY_MERCHANT_ID = "merchant_id";
private final String KEY_PRODUCT_ID = "product_id";
private final String KEY_PRODUCT_UUID = "product_uuid";
private final String KEY_CAUSE = "cause";
private final String KEY_CAUSE_VALUE = "coupon";
// ===========================================================
// Fields
// ===========================================================
private HashMap<String, String> mFilters;
private long mCacheUpdateInterval = 0;
private String mId = "";
private String mUuid = "";
// ===========================================================
// Constructor
// ===========================================================
/**
* Default constructor of WarplyRedeemCouponRequest, initializes an empty filters HashMap
*/
public WarplyRedeemProductRequest() {
mFilters = new HashMap<>();
}
public WarplyRedeemProductRequest(WarplyRedeemProductRequest copy) {
if (copy != null) {
this.mFilters = copy.mFilters;
this.mCacheUpdateInterval = copy.mCacheUpdateInterval;
}
}
// ===========================================================
// Methods for/from SuperClass/Interfaces
// ===========================================================
@Override
public boolean equals(Object object) {
if (object instanceof WarplyRedeemProductRequest) {
WarplyRedeemProductRequest other = (WarplyRedeemProductRequest) object;
return other == this || (this.mFilters == other.mFilters || (this.mFilters != null && this.mFilters.equals(other.mFilters)));
}
return false;
}
@Override
public int hashCode() {
return mFilters.hashCode();
}
// ===========================================================
// Methods
// ===========================================================
// ===========================================================
// Getter & Setter
// ===========================================================
public WarplyRedeemProductRequest setSku(String sku) {
mId = sku;
return this;
}
public WarplyRedeemProductRequest setUuid(String uuid) {
mUuid = uuid;
return this;
}
/**
* Call this to get how often the cached data will be updated.
*
* @return mCacheUpdateInterval
*/
public long getCacheUpdateInterval() {
return mCacheUpdateInterval;
}
/**
* Call this to set how often the cached data will be updated.
*
* @param updateInterval The time that data will be cached
* @return WarplyRedeemCouponRequest
*/
public WarplyRedeemProductRequest setCacheUpdateInterval(long updateInterval) {
this.mCacheUpdateInterval = updateInterval;
if (mCacheUpdateInterval < 0) {
mCacheUpdateInterval = 0;
}
return this;
}
/**
* Call this to check if the Application uses Cache
*
* @return <p>true - the Application is using Cache</p>
* <p>false - the Application is not using Cache</p>
*/
public boolean isUseCache() {
return mCacheUpdateInterval > 0;
}
/**
* Call this to check whether the cached data need to be updated
*
* @param useCache <p>true - the Application is using Cache</p>
* <p>false - the Application is not using Cache</p>
* @return WarplyRedeemCouponRequest
*/
public WarplyRedeemProductRequest setUseCache(boolean useCache) {
if (useCache) {
mCacheUpdateInterval = mCacheUpdateInterval > 0 ? mCacheUpdateInterval
: WarpConstants.INBOX_UPDATE_INTERVAL;
} else {
mCacheUpdateInterval = 0;
}
return this;
}
/**
* Call this to build the offers Json object
*
* @return bodyJsonObject
*/
public JSONObject toJson() {
JSONObject bodyJsonObject = new JSONObject();
try {
bodyJsonObject.putOpt(KEY_ACTION, KEY_ACTION_VALUE);
bodyJsonObject.putOpt(KEY_MERCHANT_ID, WarplyProperty.getMerchantId(Warply.getWarplyContext()));
bodyJsonObject.putOpt(KEY_PRODUCT_ID, mId);
bodyJsonObject.putOpt(KEY_PRODUCT_UUID, mUuid);
bodyJsonObject.putOpt(KEY_CAUSE, KEY_CAUSE_VALUE);
} catch (JSONException e) {
if (WarpConstants.DEBUG)
e.printStackTrace();
}
return bodyJsonObject;
}
public String getSignature() {
String signature = mFilters != null && mFilters.size() > 0 ? String.valueOf(mFilters.hashCode()) : "default_redeem_product_request";
try {
byte[] hash = MessageDigest.getInstance("SHA-256").digest(signature.getBytes("UTF-8"));
signature = Base64.encodeToString(hash, Base64.NO_WRAP);
} catch (NullPointerException | NoSuchAlgorithmException
| UnsupportedEncodingException e) {
e.printStackTrace();
}
return signature;
}
}
......@@ -10,8 +10,6 @@ import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.HashMap;
import ly.warp.sdk.Warply;
import ly.warp.sdk.utils.WarplyProperty;
import ly.warp.sdk.utils.constants.WarpConstants;
/**
......@@ -35,6 +33,7 @@ public class WarplyTagsCategoriesRequest {
private HashMap<String, String> mFilters;
private long mCacheUpdateInterval = 0;
private String mLanguage = "";
// ===========================================================
// Constructor
......@@ -80,6 +79,11 @@ public class WarplyTagsCategoriesRequest {
// Getter & Setter
// ===========================================================
public WarplyTagsCategoriesRequest setLanguage(String lan) {
mLanguage = lan;
return this;
}
/**
* Call this to get how often the cached data will be updated.
*
......@@ -141,7 +145,7 @@ public class WarplyTagsCategoriesRequest {
JSONObject bodyJsonObject = new JSONObject();
try {
bodyJsonObject.putOpt(KEY_ACTION, KEY_ACTION_VALUE);
bodyJsonObject.putOpt(KEY_LANGUAGE, WarplyProperty.getLanguage(Warply.getWarplyContext()));
bodyJsonObject.putOpt(KEY_LANGUAGE, mLanguage);
bodyJsonObject.putOpt(KEY_ACTIVE, true);
} catch (JSONException e) {
if (WarpConstants.DEBUG)
......
......@@ -10,8 +10,6 @@ import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.HashMap;
import ly.warp.sdk.Warply;
import ly.warp.sdk.utils.WarplyProperty;
import ly.warp.sdk.utils.constants.WarpConstants;
/**
......@@ -35,6 +33,7 @@ public class WarplyTagsRequest {
private HashMap<String, String> mFilters;
private long mCacheUpdateInterval = 0;
private String mLanguage = "";
// ===========================================================
// Constructor
......@@ -80,6 +79,11 @@ public class WarplyTagsRequest {
// Getter & Setter
// ===========================================================
public WarplyTagsRequest setLanguage(String lan) {
mLanguage = lan;
return this;
}
/**
* Call this to get how often the cached data will be updated.
*
......@@ -141,7 +145,7 @@ public class WarplyTagsRequest {
JSONObject bodyJsonObject = new JSONObject();
try {
bodyJsonObject.putOpt(KEY_ACTION, KEY_ACTION_VALUE);
bodyJsonObject.putOpt(KEY_LANGUAGE, WarplyProperty.getLanguage(Warply.getWarplyContext()));
bodyJsonObject.putOpt(KEY_LANGUAGE, mLanguage);
bodyJsonObject.putOpt(KEY_ACTIVE, true);
} catch (JSONException e) {
if (WarpConstants.DEBUG)
......
package ly.warp.sdk.io.request;
import android.util.Base64;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.HashMap;
import ly.warp.sdk.utils.constants.WarpConstants;
/**
* Created by Panagiotis Triantafyllou on 04-Feb-22.
*/
public class WarplyValidateCouponRequest {
// ===========================================================
// Constants
// ===========================================================
private final String KEY_ACTION = "action";
private final String KEY_ACTION_VALUE = "validate";
private final String KEY_COUPON = "coupon";
// ===========================================================
// Fields
// ===========================================================
private HashMap<String, String> mFilters;
private long mCacheUpdateInterval = 0;
private String mCoupon = "";
// ===========================================================
// Constructor
// ===========================================================
/**
* Default constructor of WarplyValidateCouponRequest, initializes an empty filters HashMap
*/
public WarplyValidateCouponRequest() {
mFilters = new HashMap<>();
}
public WarplyValidateCouponRequest(WarplyValidateCouponRequest copy) {
if (copy != null) {
this.mFilters = copy.mFilters;
this.mCacheUpdateInterval = copy.mCacheUpdateInterval;
}
}
// ===========================================================
// Methods for/from SuperClass/Interfaces
// ===========================================================
@Override
public boolean equals(Object object) {
if (object instanceof WarplyValidateCouponRequest) {
WarplyValidateCouponRequest other = (WarplyValidateCouponRequest) object;
return other == this || (this.mFilters == other.mFilters || (this.mFilters != null && this.mFilters.equals(other.mFilters)));
}
return false;
}
@Override
public int hashCode() {
return mFilters.hashCode();
}
// ===========================================================
// Methods
// ===========================================================
// ===========================================================
// Getter & Setter
// ===========================================================
public WarplyValidateCouponRequest setCoupon(String code) {
mCoupon = code;
return this;
}
/**
* Call this to get how often the cached data will be updated.
*
* @return mCacheUpdateInterval
*/
public long getCacheUpdateInterval() {
return mCacheUpdateInterval;
}
/**
* Call this to set how often the cached data will be updated.
*
* @param updateInterval The time that data will be cached
* @return WarplyValidateCouponRequest
*/
public WarplyValidateCouponRequest setCacheUpdateInterval(long updateInterval) {
this.mCacheUpdateInterval = updateInterval;
if (mCacheUpdateInterval < 0) {
mCacheUpdateInterval = 0;
}
return this;
}
/**
* Call this to check if the Application uses Cache
*
* @return <p>true - the Application is using Cache</p>
* <p>false - the Application is not using Cache</p>
*/
public boolean isUseCache() {
return mCacheUpdateInterval > 0;
}
/**
* Call this to check whether the cached data need to be updated
*
* @param useCache <p>true - the Application is using Cache</p>
* <p>false - the Application is not using Cache</p>
* @return WarplyValidateCouponRequest
*/
public WarplyValidateCouponRequest setUseCache(boolean useCache) {
if (useCache) {
mCacheUpdateInterval = mCacheUpdateInterval > 0 ? mCacheUpdateInterval
: WarpConstants.INBOX_UPDATE_INTERVAL;
} else {
mCacheUpdateInterval = 0;
}
return this;
}
/**
* Call this to build the validate coupon Json object
*
* @return bodyJsonObject
*/
public JSONObject toJson() {
JSONObject bodyJsonObject = new JSONObject();
try {
bodyJsonObject.putOpt(KEY_ACTION, KEY_ACTION_VALUE);
bodyJsonObject.putOpt(KEY_COUPON, mCoupon);
} catch (JSONException e) {
if (WarpConstants.DEBUG)
e.printStackTrace();
}
return bodyJsonObject;
}
public String getSignature() {
String signature = mFilters != null && mFilters.size() > 0 ? String.valueOf(mFilters.hashCode()) : "default_validate_coupon_request";
try {
byte[] hash = MessageDigest.getInstance("SHA-256").digest(signature.getBytes("UTF-8"));
signature = Base64.encodeToString(hash, Base64.NO_WRAP);
} catch (NullPointerException | NoSuchAlgorithmException
| UnsupportedEncodingException e) {
e.printStackTrace();
}
return signature;
}
}
......@@ -30,7 +30,7 @@ public class WarpConstants {
/**
* The version of the SDK installed in the device
*/
public static final String SDK_VERSION = "4.5.0";
public static final String SDK_VERSION = "4.5.1";
/**
* The URL of the server where it should ping
......
......@@ -36,6 +36,7 @@ import ly.warp.sdk.io.callbacks.CardsHook;
import ly.warp.sdk.io.callbacks.ContactHook;
import ly.warp.sdk.io.callbacks.ContentHook;
import ly.warp.sdk.io.callbacks.CouponsHook;
import ly.warp.sdk.io.callbacks.CouponsetsHook;
import ly.warp.sdk.io.callbacks.MerchantCategoriesHook;
import ly.warp.sdk.io.callbacks.MerchantsHook;
import ly.warp.sdk.io.callbacks.PointsHook;
......@@ -49,6 +50,7 @@ import ly.warp.sdk.io.models.CardList;
import ly.warp.sdk.io.models.Consumer;
import ly.warp.sdk.io.models.ContentList;
import ly.warp.sdk.io.models.CouponList;
import ly.warp.sdk.io.models.CouponsetsList;
import ly.warp.sdk.io.models.MerchantCategoriesList;
import ly.warp.sdk.io.models.MerchantList;
import ly.warp.sdk.io.models.PointsList;
......@@ -70,12 +72,14 @@ import ly.warp.sdk.io.request.WarplyEditConsumerRequest;
import ly.warp.sdk.io.request.WarplyForgotPasswordRequest;
import ly.warp.sdk.io.request.WarplyGetAddressRequest;
import ly.warp.sdk.io.request.WarplyGetCardsRequest;
import ly.warp.sdk.io.request.WarplyGetCouponsetsRequest;
import ly.warp.sdk.io.request.WarplyLoginRequest;
import ly.warp.sdk.io.request.WarplyMerchantCategoriesRequest;
import ly.warp.sdk.io.request.WarplyMerchantsRequest;
import ly.warp.sdk.io.request.WarplyPointHistoryRequest;
import ly.warp.sdk.io.request.WarplyProductsRequest;
import ly.warp.sdk.io.request.WarplyRedeemCouponRequest;
import ly.warp.sdk.io.request.WarplyRedeemProductRequest;
import ly.warp.sdk.io.request.WarplyRefreshTokenRequest;
import ly.warp.sdk.io.request.WarplyRegisterRequest;
import ly.warp.sdk.io.request.WarplyRequestOTPRequest;
......@@ -86,6 +90,7 @@ import ly.warp.sdk.io.request.WarplyTokenAuthorizeRequest;
import ly.warp.sdk.io.request.WarplyTransactionHistoryRequest;
import ly.warp.sdk.io.request.WarplyUploadConsumerPhotoRequest;
import ly.warp.sdk.io.request.WarplyUserCouponsRequest;
import ly.warp.sdk.io.request.WarplyValidateCouponRequest;
import ly.warp.sdk.io.request.WarplyVerifyOTPRequest;
import ly.warp.sdk.io.request.WarplyVerifyTicketRequest;
import ly.warp.sdk.utils.WarpUtils;
......@@ -1031,9 +1036,9 @@ public class WarplyManager {
});
}
public static void redeemCoupon(WarplyRedeemCouponRequest request, final CallbackReceiver<JSONObject> receiver) {
WarpUtils.log("************* WARPLY Redeem Coupons Request ********************");
WarpUtils.log("[WARP Trace] WARPLY Redeem Coupons Request is active");
public static void redeemProduct(WarplyRedeemProductRequest request, final CallbackReceiver<JSONObject> receiver) {
WarpUtils.log("************* WARPLY Redeem Product Request ********************");
WarpUtils.log("[WARP Trace] WARPLY Redeem Product Request is active");
WarpUtils.log("**************************************************");
Warply.postReceiveMicroappData(WarpConstants.MICROAPP_TRANSACTIONS, true, "context", request.toJson(), new CallbackReceiver<JSONObject>() {
......@@ -1050,7 +1055,7 @@ public class WarplyManager {
public void onSuccess(JSONObject result) {
int status = result.optInt("status", 2);
if (status == 1)
redeemCoupon(request, receiver);
redeemProduct(request, receiver);
else
receiver.onFailure(status);
}
......@@ -1173,4 +1178,93 @@ public class WarplyManager {
Warply.postReceiveMicroappData(WarpConstants.MICROAPP_SHOPS, request.toJson(),
new MerchantsHook(receiver, request.getSignature()));
}
public static void getCouponsets(WarplyGetCouponsetsRequest request, final CallbackReceiver<CouponsetsList> receiver) {
WarpUtils.log("************* WARPLY Get Couponsets Request ********************");
WarpUtils.log("[WARP Trace] WARPLY Get Couponsets Request is active");
WarpUtils.log("**************************************************");
Warply.postReceiveMicroappData(WarpConstants.MICROAPP_COUPONS, request.toJson(), new CouponsetsHook(new CallbackReceiver<CouponsetsList>() {
@Override
public void onSuccess(CouponsetsList result) {
receiver.onSuccess(result);
}
@Override
public void onFailure(int errorCode) {
receiver.onFailure(errorCode);
}
},
request.getSignature()));
}
public static void redeemCoupon(WarplyRedeemCouponRequest request, final CallbackReceiver<JSONObject> receiver) {
WarpUtils.log("************* WARPLY Redeem Coupon Request ********************");
WarpUtils.log("[WARP Trace] WARPLY Redeem Coupon Request is active");
WarpUtils.log("**************************************************");
Warply.postReceiveMicroappData(WarpConstants.MICROAPP_COUPONS, true, "context", request.toJson(), new CallbackReceiver<JSONObject>() {
@Override
public void onSuccess(JSONObject result) {
receiver.onSuccess(result);
}
@Override
public void onFailure(int errorCode) {
if (errorCode == 401) {
refreshToken(new WarplyRefreshTokenRequest(), new CallbackReceiver<JSONObject>() {
@Override
public void onSuccess(JSONObject result) {
int status = result.optInt("status", 2);
if (status == 1)
redeemCoupon(request, receiver);
else
receiver.onFailure(status);
}
@Override
public void onFailure(int errorCode) {
receiver.onFailure(errorCode);
}
});
} else
receiver.onFailure(errorCode);
}
});
}
public static void validateCoupon(WarplyValidateCouponRequest request, final CallbackReceiver<JSONObject> receiver) {
WarpUtils.log("************* WARPLY Validate Coupon Request ********************");
WarpUtils.log("[WARP Trace] WARPLY Validate Coupon Request is active");
WarpUtils.log("**************************************************");
Warply.postReceiveMicroappData(WarpConstants.MICROAPP_COUPONS, true, "context", request.toJson(), new CallbackReceiver<JSONObject>() {
@Override
public void onSuccess(JSONObject result) {
receiver.onSuccess(result);
}
@Override
public void onFailure(int errorCode) {
if (errorCode == 401) {
refreshToken(new WarplyRefreshTokenRequest(), new CallbackReceiver<JSONObject>() {
@Override
public void onSuccess(JSONObject result) {
int status = result.optInt("status", 2);
if (status == 1)
validateCoupon(request, receiver);
else
receiver.onFailure(status);
}
@Override
public void onFailure(int errorCode) {
receiver.onFailure(errorCode);
}
});
} else
receiver.onFailure(errorCode);
}
});
}
}
......