Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package eu.pretix.libpretixsync.models.db

import eu.pretix.libpretixsync.sqldelight.OrderPosition
import eu.pretix.libpretixsync.sqldelight.SafeOffsetDateTimeMapper
import eu.pretix.libpretixsync.utils.JSONUtils
import org.json.JSONArray
import org.json.JSONException
import org.json.JSONObject
Expand All @@ -21,15 +22,15 @@ fun OrderPosition.toModel(): OrderPositionModel {
subEventServerId = this.subevent_id,
variationServerId = parseVariationId(json),
attendeeNameParts = json.optJSONObject("attendee_name_parts"),
city = json.optString("city", null),
company = json.optString("company", null),
country = json.optString("country", null),
email = json.optString("email", null),
street = json.optString("street", null),
zipcode = json.optString("zipcode", null),
city = JSONUtils.optString(json, "city"),
company = JSONUtils.optString(json, "company"),
country = JSONUtils.optString(json, "country"),
email = JSONUtils.optString(json, "email"),
street = JSONUtils.optString(json, "street"),
zipcode = JSONUtils.optString(json, "zipcode"),
price = parsePrice(json),
taxRate = parseTaxRate(json),
taxCode = parseTaxCode(json),
taxCode = JSONUtils.optString(json, "tax_code"),
taxValue = parseTaxValue(json),
seatName = parseSeatName(json),
addonToServerId = parseAddonToServerId(json),
Expand Down Expand Up @@ -65,18 +66,6 @@ private fun parsePrice(json: JSONObject): BigDecimal? {
}
}

private fun parseTaxCode(json: JSONObject): String? {
try {
if (json.isNull("tax_code")) {
return null
}
return json.optString("tax_code", null)
} catch (e: JSONException) {
e.printStackTrace()
return null
}
}

private fun parseTaxRate(json: JSONObject): BigDecimal? {
try {
return BigDecimal(json.getString("tax_rate"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,22 @@ of first software and associated documentation files (the "Software"), to deal


import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;

public class JSONUtils {

public static String optString(JSONObject object, String key) throws JSONException {
if (object.has(key) && !object.isNull(key)) {
return object.getString(key);
}
return null;
}

private static Set<String> setFromIterable(Iterator<String> it) {
HashSet<String> set = new HashSet<String>();
while (it.hasNext()) {
Expand Down
Loading