Panagiotis Triantafyllou

cosmote pass requests

......@@ -97,6 +97,7 @@ public class Coupon implements Parcelable, Serializable {
private String terms = "";
private Couponset couponsetDetails = new Couponset(true);
private Merchant merchantDetails = new Merchant(true);
private RedeemMerchantDetails redeemDetails = new RedeemMerchantDetails();
public Coupon() {
this.barcode = "";
......@@ -121,6 +122,7 @@ public class Coupon implements Parcelable, Serializable {
this.final_price = 0.0d;
this.short_description = "";
this.terms = "";
this.redeemDetails = new RedeemMerchantDetails();
}
public Coupon(boolean isUniversal) {
......@@ -135,6 +137,7 @@ public class Coupon implements Parcelable, Serializable {
this.redeemDate = new Date();
this.couponsetDetails = new Couponset(isUniversal);
this.merchantDetails = new Merchant(isUniversal);
this.redeemDetails = new RedeemMerchantDetails();
}
/**
......@@ -189,6 +192,10 @@ public class Coupon implements Parcelable, Serializable {
this.final_price = json.optDouble(FINAL_PRICE);
this.short_description = json.optString(SHORT_DESCRIPTION);
this.terms = json.optString(TERMS);
JSONObject tempRedeemDetails = json.optJSONObject("redeemed_merchant_details");
if (tempRedeemDetails != null) {
this.redeemDetails = new RedeemMerchantDetails(tempRedeemDetails);
}
}
}
......@@ -224,6 +231,10 @@ public class Coupon implements Parcelable, Serializable {
if (tempMerchantDetails != null) {
this.merchantDetails = new Merchant(tempMerchantDetails, isUniversal);
}
JSONObject tempRedeemDetails = json.optJSONObject("redeemed_merchant_details");
if (tempRedeemDetails != null) {
this.redeemDetails = new RedeemMerchantDetails(tempRedeemDetails);
}
// this.category = json.optString(CATEGORY);
// this.created = json.optString(CREATED);
......@@ -240,6 +251,75 @@ public class Coupon implements Parcelable, Serializable {
}
}
public class RedeemMerchantDetails {
private static final String IMG_PREVIEW = "img_preview";
private static final String NAME = "name";
private static final String UUID = "uuid";
private static final String REDEEMED_DATE = "redeemed_date";
private String imgPreview = "";
private String name = "";
private String uuid = "";
private String redeemedDate = "";
public RedeemMerchantDetails() {
this.imgPreview = "";
this.name = "";
this.uuid = "";
this.redeemedDate = "";
}
public RedeemMerchantDetails(JSONObject json) {
if (json != null) {
if (json.optJSONObject(IMG_PREVIEW) != null) {
this.imgPreview = json.optString(IMG_PREVIEW);
}
if (json.optJSONObject(NAME) != null) {
this.name = json.optString(NAME);
}
if (json.optJSONObject(UUID) != null) {
this.uuid = json.optString(UUID);
}
if (json.optJSONObject(REDEEMED_DATE) != null) {
this.redeemedDate = json.optString(REDEEMED_DATE);
}
}
}
public String getImgPreview() {
return imgPreview;
}
public void setImgPreview(String imgPreview) {
this.imgPreview = imgPreview;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getUuid() {
return uuid;
}
public void setUuid(String uuid) {
this.uuid = uuid;
}
public String getRedeemedDate() {
return redeemedDate;
}
public void setRedeemedDate(String redeemedDate) {
this.redeemedDate = redeemedDate;
}
}
public Coupon(Parcel source) {
this.barcode = source.readString();
this.category = source.readString();
......@@ -544,6 +624,14 @@ public class Coupon implements Parcelable, Serializable {
this.merchantDetails = merchantDetails;
}
public RedeemMerchantDetails getRedeemDetails() {
return redeemDetails;
}
public void setRedeemDetails(RedeemMerchantDetails redeemDetails) {
this.redeemDetails = redeemDetails;
}
@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 org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.ArrayList;
import ly.warp.sdk.utils.WarpUtils;
import ly.warp.sdk.utils.constants.WarpConstants;
/**
* Created by Panagiotis Triantafyllou on 20-Jan-25.
*/
public class MarketPassDetailsModel {
private static final String BARCODE = "barcode";
private static final String SUPERMARKETS = "supermarkets";
private static final String TOTAL_DISCOUNT = "total_available_discount";
private ArrayList<Supermarkets> supermarkets = new ArrayList<Supermarkets>();
private String barcode = "";
private double totalDiscount = 0.0d;
public MarketPassDetailsModel() {
this.supermarkets = new ArrayList<Supermarkets>();
this.barcode = "";
this.totalDiscount = 0.0d;
}
/**
* Basic constructor used to create an object from a String, representing a
* JSON Object
*
* @param json The String, representing the JSON Object
* @throws JSONException Thrown if the String cannot be converted to JSON
*/
public MarketPassDetailsModel(String json) throws JSONException {
this(new JSONObject(json));
}
/**
* Constructor used to create an Object from a given JSON Object
*
* @param json JSON Object used to create the Campaign
*/
public MarketPassDetailsModel(JSONObject json) {
if (json != null) {
if (json.optJSONArray(SUPERMARKETS) != null) {
JSONArray tempSupermarkets = json.optJSONArray(SUPERMARKETS);
if (tempSupermarkets != null && tempSupermarkets.length() > 0) {
for (int i = 0, lim = tempSupermarkets.length(); i < lim; ++i) {
this.supermarkets.add(new Supermarkets(tempSupermarkets.optJSONObject(i)));
}
}
}
this.barcode = json.optString(BARCODE);
this.totalDiscount = json.optDouble(TOTAL_DISCOUNT);
}
}
/**
* Converts the Campaign into a JSON Object
*
* @return The JSON Object created from this campaign
*/
public JSONObject toJSONObject() {
JSONObject jObj = new JSONObject();
try {
jObj.putOpt(BARCODE, this.barcode);
jObj.putOpt(TOTAL_DISCOUNT, this.totalDiscount);
jObj.putOpt(SUPERMARKETS, this.supermarkets);
} catch (JSONException e) {
if (WarpConstants.DEBUG) {
e.printStackTrace();
}
}
return jObj;
}
/**
* String representation of the Campaign, as a JSON object
*
* @return A String representation of JSON object
*/
public String toString() {
if (toJSONObject() != null)
return toJSONObject().toString();
return null;
}
/**
* String representation of the Campaign, as a human readable JSON object
*
* @return A human readable String representation of JSON object
*/
public String toHumanReadableString() {
String humanReadableString = null;
try {
humanReadableString = toJSONObject().toString(2);
} catch (JSONException e) {
WarpUtils.warn("Failed converting Campaign JSON object to String",
e);
}
return humanReadableString;
}
public class Supermarkets {
private static final String LOGO = "logo";
private static final String NAME = "name";
private static final String UUID = "uuid";
private String logo = "";
private String name = "";
private String uuid = "";
public Supermarkets() {
this.logo = "";
this.name = "";
this.uuid = "";
}
public Supermarkets(JSONObject json) {
if (json != null) {
if (json.optJSONObject(LOGO) != null) {
this.logo = json.optString(LOGO);
}
if (json.optJSONObject(NAME) != null) {
this.name = json.optString(NAME);
}
if (json.optJSONObject(UUID) != null) {
this.uuid = json.optString(UUID);
}
}
}
public String getLogo() {
return logo;
}
public void setLogo(String logo) {
this.logo = logo;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getUuid() {
return uuid;
}
public void setUuid(String uuid) {
this.uuid = uuid;
}
}
// ================================================================================
// Getters
// ================================================================================
public ArrayList<Supermarkets> getSupermarkets() {
return supermarkets;
}
public void setSupermarkets(ArrayList<Supermarkets> supermarkets) {
this.supermarkets = supermarkets;
}
public String getBarcode() {
return barcode;
}
public void setBarcode(String barcode) {
this.barcode = barcode;
}
public double getTotalDiscount() {
return totalDiscount;
}
public void setTotalDiscount(double totalDiscount) {
this.totalDiscount = totalDiscount;
}
}
......@@ -174,6 +174,18 @@ public interface ApiService {
@Headers("Content-Type: application/json")
@POST("/oauth/{appUuid}/context")
Call<ResponseBody> getMarketPassDetails(@Path("appUuid") String appUuid,
@Body RequestBody request,
@Header(WarpConstants.HEADER_DATE) String timeStamp,
@Header(WarpConstants.HEADER_LOYALTY_BUNDLE_ID) String bundleId,
@Header(WarpConstants.HEADER_UNIQUE_DEVICE_ID) String deviceId,
@Header(WarpConstants.HEADER_CHANNEL) String channel,
@Header(WarpConstants.HEADER_WEB_ID) String webId,
@Header(WarpConstants.HEADER_SIGNATURE) String signature,
@Header(WarpConstants.HEADER_AUTHORIZATION) String bearer);
@Headers("Content-Type: application/json")
@POST("/oauth/{appUuid}/context")
Call<ResponseBody> sendTelematicsData(@Path("appUuid") String appUuid,
@Body RequestBody request,
@Header(WarpConstants.HEADER_DATE) String timeStamp,
......