Panagiotis Triantafyllou

customer state model

......@@ -2,7 +2,7 @@ apply plugin: 'com.android.library'
ext {
PUBLISH_GROUP_ID = 'ly.warp'
PUBLISH_VERSION = '4.5.4-cosbeta33'
PUBLISH_VERSION = '4.5.4-cosbeta34'
PUBLISH_ARTIFACT_ID = 'warply-android-sdk'
}
......
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 15-July-22.
*/
public class CosmoteSubmitOrderRequest {
// ===========================================================
// Constants
// ===========================================================
private final String KEY_MAPP = "wallet";
private final String KEY_ACTION = "action";
private final String KEY_ACTION_VALUE = "add_product";
private final String KEY_PRODUCT_UUID = "product_uuid";
private final String KEY_PRODUCT_UUID_VALUE = "011d21908d984e3cbecbdfd2920a5d3b";
private final String KEY_COMMUNICATION_UUID = "communication_uuid";
private final String KEY_EXTRA_DATA = "extra_data";
private final String KEY_USER_MSISDN = "user_msisdn";
private final String KEY_BUSINESS_SERVICE = "businessService";
private final String KEY_OFFER_NAME = "offerName";
private final String KEY_PRODUCT_TYPE = "productType";
private final String KEY_PROV_DURATION = "provDuration";
private final String KEY_NO_OF_RECURRANCE = "noOfRecurrance";
private final String KEY_PRICE = "price";
private final String KEY_DISCOUNT = "discount";
private final String KEY_VOICE_CATEGORY = "voiceCategory";
private final String KEY_DATA_CATEGORY = "dataCategory";
private final String KEY_MINS_VALUE = "minsValue";
private final String KEY_DATA_VALUE = "dataValue";
private final String KEY_PROV_STEP_VALUE_MINS = "provStepValueMins";
// ===========================================================
// Fields
// ===========================================================
private HashMap<String, String> mFilters;
private long mCacheUpdateInterval = 0;
private String mCommunicationUuid = "";
private String mUserMsisdn = "";
private String mBusinessService = "";
private String mOfferName = "";
private String mProductType = "";
private String mProvDuration = "";
private String mNoOfRecurrance = "";
private String mPrice = "";
private String mDiscount = "";
private String mVoiceCategory = "";
private String mDataCategory = "";
private String mMinsValue = "";
private String mDataValue = "";
private String mProvStepValueMins = "";
// ===========================================================
// Constructor
// ===========================================================
/**
* Default constructor of CosmoteSharingRequest, initializes an empty filters HashMap
*/
public CosmoteSubmitOrderRequest() {
mFilters = new HashMap<>();
}
public CosmoteSubmitOrderRequest(CosmoteSubmitOrderRequest 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 CosmoteSubmitOrderRequest) {
CosmoteSubmitOrderRequest other = (CosmoteSubmitOrderRequest) 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 CosmoteSubmitOrderRequest setCommunicationUuid(String communicationUuid) {
mCommunicationUuid = communicationUuid;
return this;
}
public CosmoteSubmitOrderRequest setUserMsisdn(String userMsisdn) {
mUserMsisdn = userMsisdn;
return this;
}
public CosmoteSubmitOrderRequest setBusinessService(String businessService) {
mBusinessService = businessService;
return this;
}
public CosmoteSubmitOrderRequest setOfferName(String offerName) {
mOfferName = offerName;
return this;
}
public CosmoteSubmitOrderRequest setProductType(String productType) {
mProductType = productType;
return this;
}
public CosmoteSubmitOrderRequest setProvDuration(String provDuration) {
mProvDuration = provDuration;
return this;
}
public CosmoteSubmitOrderRequest setNoOfRecurrance(String noOfRecurrance) {
mNoOfRecurrance = noOfRecurrance;
return this;
}
public CosmoteSubmitOrderRequest setPrice(String price) {
mPrice = price;
return this;
}
public CosmoteSubmitOrderRequest setDiscount(String discount) {
mDiscount = discount;
return this;
}
public CosmoteSubmitOrderRequest setVoiceCategory(String voiceCategory) {
mVoiceCategory = voiceCategory;
return this;
}
public CosmoteSubmitOrderRequest setDataCategory(String dataCategory) {
mDataCategory = dataCategory;
return this;
}
public CosmoteSubmitOrderRequest setMinsValue(String minsValue) {
mMinsValue = minsValue;
return this;
}
public CosmoteSubmitOrderRequest setDataValue(String dataValue) {
mDataValue = dataValue;
return this;
}
public CosmoteSubmitOrderRequest setProvStepValueMins(String provStepValueMins) {
mProvStepValueMins = provStepValueMins;
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 CosmoteSharingRequest
*/
public CosmoteSubmitOrderRequest 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 CosmoteSharingRequest
*/
public CosmoteSubmitOrderRequest 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 {
JSONObject extraJson = new JSONObject();
extraJson.putOpt(KEY_ACTION, KEY_ACTION_VALUE);
extraJson.putOpt(KEY_PRODUCT_UUID, KEY_PRODUCT_UUID_VALUE);
bodyJsonObject.putOpt(KEY_MAPP, extraJson);
} 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_cosmote_sharing_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;
}
}
......@@ -38,10 +38,10 @@ public class WarplyIntegrationRequest {
private HashMap<String, String> mFilters;
private long mCacheUpdateInterval = 0;
private boolean isNonTelco = false;
private boolean hasAcceptedConsent = false;
private String guid = "";
private ArrayList<String> phoneList = new ArrayList<>();
private boolean mIsNonTelco = false;
private boolean mHasAcceptedConsent = false;
private String mGuid = "";
private ArrayList<String> mPhoneList = new ArrayList<>();
// ===========================================================
// Constructor
......@@ -51,7 +51,11 @@ public class WarplyIntegrationRequest {
* Default constructor of WarplyIntegrationRequest, initializes an empty filters HashMap
*/
public WarplyIntegrationRequest() {
mFilters = new HashMap<>();
this.mFilters = new HashMap<>();
this.mIsNonTelco = false;
this.mHasAcceptedConsent = false;
this.mGuid = "";
this.mPhoneList = new ArrayList<>();
}
public WarplyIntegrationRequest(WarplyIntegrationRequest copy) {
......@@ -88,22 +92,22 @@ public class WarplyIntegrationRequest {
// ===========================================================
public WarplyIntegrationRequest setIsNoTelco(boolean isNonTelco) {
isNonTelco = isNonTelco;
this.mIsNonTelco = isNonTelco;
return this;
}
public WarplyIntegrationRequest setHasAcceptedConsent(boolean hasAcceptedConsent) {
hasAcceptedConsent = hasAcceptedConsent;
this.mHasAcceptedConsent = hasAcceptedConsent;
return this;
}
public WarplyIntegrationRequest setMsisdnList(ArrayList<String> phoneList) {
phoneList = phoneList;
this.mPhoneList = phoneList;
return this;
}
public WarplyIntegrationRequest setGuid(String guid) {
guid = guid;
this.mGuid = guid;
return this;
}
......@@ -171,10 +175,10 @@ public class WarplyIntegrationRequest {
extraJson.putOpt(KEY_ACTION, KEY_ACTION_VALUE);
extraJson.putOpt(KEY_METHOD, KEY_METHOD_VALUE);
JSONObject data = new JSONObject();
data.putOpt("nonTelco", isNonTelco);
data.putOpt("acceptedConsent", hasAcceptedConsent);
data.putOpt("msisdnList", new JSONArray(phoneList));
data.putOpt("guid", guid);
data.putOpt("nonTelco", mIsNonTelco);
data.putOpt("acceptedConsent", mHasAcceptedConsent);
data.putOpt("msisdnList", new JSONArray(mPhoneList));
data.putOpt("guid", mGuid);
extraJson.putOpt(KEY_DATA, data);
bodyJsonObject.putOpt(KEY_MAPP, extraJson);
......
......@@ -579,10 +579,10 @@ public class WarplyManagerHelper {
mCustomerStateModel = customerState;
WarplyIntegrationRequest request = new WarplyIntegrationRequest();
request.setIsNoTelco(customerState.isNonTelco());
request.setHasAcceptedConsent(customerState.isAcceptedConsent());
request.setGuid(customerState.getGuid());
request.setMsisdnList(customerState.getMsisdnList());
request.setIsNoTelco(customerState.isNonTelco())
.setHasAcceptedConsent(customerState.isAcceptedConsent())
.setGuid(customerState.getGuid())
.setMsisdnList(customerState.getMsisdnList());
WarplyManager.consumerIntegration(request, new CallbackReceiver<JSONObject>() {
@Override
public void onSuccess(JSONObject result) {
......
......@@ -75,6 +75,7 @@ import ly.warp.sdk.io.models.TransactionsList;
import ly.warp.sdk.io.request.CosmoteCouponSharingRequest;
import ly.warp.sdk.io.request.CosmoteRetrieveSharingRequest;
import ly.warp.sdk.io.request.CosmoteSharingRequest;
import ly.warp.sdk.io.request.CosmoteSubmitOrderRequest;
import ly.warp.sdk.io.request.PacingDetailsRequest;
import ly.warp.sdk.io.request.WarplyAddAddressRequest;
import ly.warp.sdk.io.request.WarplyAddCardRequest;
......@@ -2244,4 +2245,26 @@ public class WarplyManager {
}
});
}
public static void submitOrder(CosmoteSubmitOrderRequest request, final CallbackReceiver<JSONObject> receiver) {
WarpUtils.log("************* WARPLY Submit Order Request ********************");
WarpUtils.log("[WARP Trace] WARPLY Submit Order Request is active");
WarpUtils.log("**************************************************");
Warply.postReceiveMicroappData(true, "context", request.toJson(), new CallbackReceiver<JSONObject>() {
@Override
public void onSuccess(JSONObject result) {
int status = result.optInt("status", 2);
if (status == 1) {
} else
receiver.onFailure(status);
}
@Override
public void onFailure(int errorCode) {
receiver.onFailure(errorCode);
}
});
}
}
......