Skip to content

Commit 1eacfc8

Browse files
committed
Add payments and refunds properties to Order model
1 parent 648e261 commit 1eacfc8

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

libpretixsync/src/main/java/eu/pretix/libpretixsync/models/Order.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package eu.pretix.libpretixsync.models
22

3+
import org.json.JSONArray
34
import java.math.BigDecimal
45

56
class Order(
@@ -15,6 +16,8 @@ class Order(
1516
val validIfPending: Boolean = false,
1617
val total: BigDecimal? = null,
1718
val pendingTotal: BigDecimal? = null,
19+
val payments: JSONArray = JSONArray(),
20+
val refunds: JSONArray = JSONArray(),
1821
) {
1922

2023
val hasValidStatus = when (status) {

libpretixsync/src/main/java/eu/pretix/libpretixsync/models/db/OrderExensions.kt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package eu.pretix.libpretixsync.models.db
22

33
import eu.pretix.libpretixsync.models.Order
44
import eu.pretix.libpretixsync.sqldelight.Orders
5+
import org.json.JSONArray
56
import org.json.JSONException
67
import org.json.JSONObject
78
import java.math.BigDecimal
@@ -22,6 +23,8 @@ fun Orders.toModel(): Order {
2223
validIfPending = this.valid_if_pending ?: false,
2324
total = parseTotal(json),
2425
pendingTotal = parsePendingTotal(json),
26+
payments = parsePayments(json),
27+
refunds = parseRefunds(json),
2528
)
2629
}
2730

@@ -82,3 +85,21 @@ private fun parsePendingTotal(json: JSONObject): BigDecimal? {
8285
return null
8386
}
8487
}
88+
89+
private fun parsePayments(json: JSONObject): JSONArray {
90+
try {
91+
return json.getJSONArray("payments")
92+
} catch (e: JSONException) {
93+
e.printStackTrace()
94+
return JSONArray()
95+
}
96+
}
97+
98+
private fun parseRefunds(json: JSONObject): JSONArray {
99+
try {
100+
return json.getJSONArray("refunds")
101+
} catch (e: JSONException) {
102+
e.printStackTrace()
103+
return JSONArray()
104+
}
105+
}

0 commit comments

Comments
 (0)