Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: added custom order parameters #14

Merged
merged 1 commit into from
May 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions personalizatio-sdk/src/main/java/com/personalizatio/Params.java
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,24 @@ public Item set(COLUMN column, boolean value) {
}
}

final public static class CustomOrderParameters {
private final HashMap<String, String> parameters = new HashMap<>();

public CustomOrderParameters set(@NonNull String name, @NonNull String value) {
parameters.put(name, value);
return this;
}
public CustomOrderParameters set(@NonNull String name, int value) {
return set(name, String.valueOf(value));
}
public CustomOrderParameters set(@NonNull String name, double value) {
return set(name, String.valueOf(value));
}
public CustomOrderParameters set(@NonNull String name, boolean value) {
return set(name, value ? "1" : "0");
}
}

public enum TrackEvent {
VIEW("view"),
CATEGORY("category"),
Expand Down Expand Up @@ -178,6 +196,24 @@ public Params put(Item item) {
return this;
}

/**
* Вставка свойст заказа
*/
public Params put(CustomOrderParameters customOrderParameter) {
try {
JSONObject object = new JSONObject();
for (var entry : customOrderParameter.parameters.entrySet()) {
object.put(entry.getKey(), entry.getValue());
}

params.put("custom", object);
} catch(JSONException e) {
Log.e(SDK.TAG, e.getMessage(), e);
}

return this;
}

//---------------Private---------->

enum InternalParameter implements ParamInterface {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,9 @@ protected void onCreate(Bundle savedInstanceState) {
// purchase
// .put(new Params.Item("37").set(Params.Item.COLUMN.AMOUNT, 2).set(Params.Item.COLUMN.PRICE, 10.5))
// .put(new Params.Item("38").set(Params.Item.COLUMN.AMOUNT, 2))
// .put(new Params.CustomOrderParameters()
// .set("tour_class", "lux")
// .set("children_count", 1))
// .put(Params.Parameter.ORDER_ID, "100234")
// .put(Params.Parameter.ORDER_PRICE, 100500)
// .put(new Params.RecommendedBy(Params.RecommendedBy.TYPE.RECOMMENDATION, "e9ddb9cdc66285fac40c7a897760582a"));
Expand Down
Loading