Skip to content

Commit 4e7d539

Browse files
raphaelmrobbi5
authored andcommitted
Support for CheckResult.locale and check(useOrderLocale)
1 parent c5e1aad commit 4e7d539

10 files changed

Lines changed: 38 additions & 12 deletions

File tree

libpretixsync/src/main/java/eu/pretix/libpretixsync/api/PretixApi.kt

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,16 @@ open class PretixApi(url: String, key: String, orgaSlug: String, version: Int, h
4343
inner class ApiResponse(val data: JSONObject?, val response: Response)
4444

4545
@Throws(ApiException::class, JSONException::class)
46-
fun redeem(eventSlug: String, secret: String, datetime: Date?, force: Boolean, nonce: String?, answers: List<Answer>?, listId: Long, ignore_unpaid: Boolean, pdf_data: Boolean, type: String?, source_type: String?, callTimeout: Long? = null, questions_supported: Boolean = true): ApiResponse {
46+
fun redeem(eventSlug: String, secret: String, datetime: Date?, force: Boolean, nonce: String?, answers: List<Answer>?, listId: Long, ignore_unpaid: Boolean, pdf_data: Boolean, type: String?, source_type: String?, callTimeout: Long? = null, questions_supported: Boolean = true, use_order_locale: Boolean = false): ApiResponse {
4747
var dt: String? = null
4848
if (datetime != null) {
4949
dt = QueuedCheckIn.formatDatetime(datetime)
5050
}
51-
return redeem(eventSlug, secret, dt, force, nonce, answers, listId, ignore_unpaid, pdf_data, type, source_type, callTimeout, questions_supported)
51+
return redeem(eventSlug, secret, dt, force, nonce, answers, listId, ignore_unpaid, pdf_data, type, source_type, callTimeout, questions_supported, use_order_locale)
5252
}
5353

5454
@Throws(ApiException::class, JSONException::class)
55-
open fun redeem(eventSlug: String, secret: String, datetime: String?, force: Boolean, nonce: String?, answers: List<Answer>?, listId: Long, ignore_unpaid: Boolean, pdf_data: Boolean, type: String?, source_type: String?, callTimeout: Long? = null, questions_supported: Boolean=true): ApiResponse {
55+
open fun redeem(eventSlug: String, secret: String, datetime: String?, force: Boolean, nonce: String?, answers: List<Answer>?, listId: Long, ignore_unpaid: Boolean, pdf_data: Boolean, type: String?, source_type: String?, callTimeout: Long? = null, questions_supported: Boolean = true, use_order_locale: Boolean = false): ApiResponse {
5656
val body = JSONObject()
5757
if (datetime != null) {
5858
body.put("datetime", datetime)
@@ -82,6 +82,7 @@ open class PretixApi(url: String, key: String, orgaSlug: String, version: Int, h
8282
body.put("answers", answerbody)
8383
body.put("questions_supported", questions_supported)
8484
body.put("canceled_supported", true)
85+
body.put("use_order_locale", use_order_locale)
8586
var pd = ""
8687
if (pdf_data) {
8788
pd = "?pdf_data=true"
@@ -90,7 +91,7 @@ open class PretixApi(url: String, key: String, orgaSlug: String, version: Int, h
9091
}
9192

9293
@Throws(ApiException::class, JSONException::class)
93-
fun redeem(lists: List<Long>, secret: String, datetime: Date?, force: Boolean, nonce: String?, answers: List<Answer>?, ignore_unpaid: Boolean, pdf_data: Boolean, type: String?, source_type: String?, callTimeout: Long? = null, questions_supported: Boolean = true): ApiResponse {
94+
fun redeem(lists: List<Long>, secret: String, datetime: Date?, force: Boolean, nonce: String?, answers: List<Answer>?, ignore_unpaid: Boolean, pdf_data: Boolean, type: String?, source_type: String?, callTimeout: Long? = null, questions_supported: Boolean = true, use_order_locale: Boolean = false): ApiResponse {
9495
var dt: String? = null
9596
if (datetime != null) {
9697
dt = QueuedCheckIn.formatDatetime(datetime)
@@ -99,7 +100,7 @@ open class PretixApi(url: String, key: String, orgaSlug: String, version: Int, h
99100
}
100101

101102
@Throws(ApiException::class, JSONException::class)
102-
open fun redeem(lists: List<Long>, secret: String, datetime: String?, force: Boolean, nonce: String?, answers: List<Answer>?, ignore_unpaid: Boolean, pdf_data: Boolean, type: String?, source_type: String?, callTimeout: Long? = null, questions_supported: Boolean = true): ApiResponse {
103+
open fun redeem(lists: List<Long>, secret: String, datetime: String?, force: Boolean, nonce: String?, answers: List<Answer>?, ignore_unpaid: Boolean, pdf_data: Boolean, type: String?, source_type: String?, callTimeout: Long? = null, questions_supported: Boolean = true, use_order_locale: Boolean = false): ApiResponse {
103104
val body = JSONObject()
104105
if (datetime != null) {
105106
body.put("datetime", datetime)
@@ -129,6 +130,7 @@ open class PretixApi(url: String, key: String, orgaSlug: String, version: Int, h
129130
body.put("answers", answerbody)
130131
body.put("questions_supported", questions_supported)
131132
body.put("canceled_supported", true)
133+
body.put("use_order_locale", use_order_locale)
132134
body.put("secret", secret)
133135
val jlists = JSONArray()
134136
for (l in lists) {

libpretixsync/src/main/java/eu/pretix/libpretixsync/api/ProxyApi.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ data class MultiCheckInput(
2525

2626
// TODO: Check unused values
2727
val allowQuestions: Boolean,
28+
val useOrderLocale: Boolean,
2829
val nonce: String?
2930
)
3031

libpretixsync/src/main/java/eu/pretix/libpretixsync/check/AsyncCheckProvider.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -544,6 +544,7 @@ class AsyncCheckProvider(private val config: ConfigStore, private val db: SyncDa
544544
type: TicketCheckProvider.CheckInType,
545545
nonce: String?,
546546
allowQuestions: Boolean,
547+
useOrderLocale: Boolean
547548
): TicketCheckProvider.CheckResult {
548549
val ticketid_cleaned = cleanInput(ticketid, source_type)
549550

@@ -697,6 +698,7 @@ class AsyncCheckProvider(private val config: ConfigStore, private val db: SyncDa
697698
res.variation = variation.stringValue
698699
}
699700

701+
res.locale = order.locale
700702
res.attendee_name = position.attendeeName
701703
res.seat = position.seatName
702704
res.orderCode = order.code

libpretixsync/src/main/java/eu/pretix/libpretixsync/check/OnlineCheckProvider.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ class OnlineCheckProvider(
4747
with_badge_data: Boolean,
4848
type: TicketCheckProvider.CheckInType,
4949
nonce: String?,
50-
allowQuestions: Boolean
50+
allowQuestions: Boolean,
51+
useOrderLocale: Boolean
5152
): TicketCheckProvider.CheckResult {
5253
val ticketid_cleaned = cleanInput(ticketid, source_type)
5354
val nonce_cleaned = nonce ?: NonceGenerator.nextNonce()
@@ -70,6 +71,7 @@ class OnlineCheckProvider(
7071
source_type,
7172
callTimeout = if (fallback != null) fallbackTimeout.toLong() else null,
7273
questions_supported = allowQuestions,
74+
use_order_locale = useOrderLocale,
7375
)
7476
} else {
7577
if (eventsAndCheckinLists.size != 1) throw CheckException("Multi-event scan not supported by server.")
@@ -188,6 +190,9 @@ class OnlineCheckProvider(
188190
}
189191
res.orderCode = posjson.optString("order")
190192
res.positionId = posjson.optLong("positionid")
193+
if (posjson.has("order__locale")) {
194+
res.locale = posjson.getString("order__locale")
195+
}
191196
res.position = posjson
192197
val checkins = posjson.getJSONArray("checkins")
193198
for (i in 0 until checkins.length()) {

libpretixsync/src/main/java/eu/pretix/libpretixsync/check/ProxyCheckProvider.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,8 @@ class ProxyCheckProvider(private val config: ConfigStore, httpClientFactory: Htt
109109
with_badge_data: Boolean,
110110
type: TicketCheckProvider.CheckInType,
111111
nonce: String?,
112-
allowQuestions: Boolean
112+
allowQuestions: Boolean,
113+
useOrderLocale: Boolean
113114
): TicketCheckProvider.CheckResult {
114115
val answersInput = answers?.map {
115116
val questionModel = it.question as Question // TODO: Can we avoid the cast?
@@ -129,6 +130,7 @@ class ProxyCheckProvider(private val config: ConfigStore, httpClientFactory: Htt
129130
source_type = source_type,
130131
type = type.name,
131132
allowQuestions = allowQuestions,
133+
useOrderLocale = useOrderLocale,
132134
nonce = nonce,
133135
)
134136

libpretixsync/src/main/java/eu/pretix/libpretixsync/check/TicketCheckProvider.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ interface TicketCheckProvider {
8080
var position: JSONObject? = null
8181
var eventSlug: String? = null
8282
var offline: Boolean = false
83+
var locale: String? = null
8384

8485
constructor(type: Type?, message: String?, offline: Boolean = false) {
8586
this.type = type
@@ -157,7 +158,7 @@ interface TicketCheckProvider {
157158
class StatusResult(var eventName: String?, var totalTickets: Int, var alreadyScanned: Int, var currentlyInside: Int?, var items: List<StatusResultItem>?) {
158159
}
159160

160-
fun check(eventsAndCheckinLists: Map<String, Long>, ticketid: String, source_type: String, answers: List<Answer>?, ignore_unpaid: Boolean, with_badge_data: Boolean, type: CheckInType, nonce: String? = null, allowQuestions: Boolean = true): CheckResult
161+
fun check(eventsAndCheckinLists: Map<String, Long>, ticketid: String, source_type: String, answers: List<Answer>?, ignore_unpaid: Boolean, with_badge_data: Boolean, type: CheckInType, nonce: String? = null, allowQuestions: Boolean = true, useOrderLocale: Boolean = false): CheckResult
161162
fun check(eventsAndCheckinLists: Map<String, Long>, ticketid: String): CheckResult
162163
@Throws(CheckException::class)
163164
fun search(eventsAndCheckinLists: Map<String, Long>, query: String, page: Int): List<SearchResult>

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ class Order(
1818
val pendingTotal: BigDecimal? = null,
1919
val payments: JSONArray = JSONArray(),
2020
val refunds: JSONArray = JSONArray(),
21+
val locale: String? = null,
2122
) {
2223

2324
val hasValidStatus = when (status) {

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ fun Orders.toModel(): Order {
2525
pendingTotal = parsePendingTotal(json),
2626
payments = parsePayments(json),
2727
refunds = parseRefunds(json),
28+
locale = parseLocale(json),
2829
)
2930
}
3031

@@ -103,3 +104,12 @@ private fun parseRefunds(json: JSONObject): JSONArray {
103104
return JSONArray()
104105
}
105106
}
107+
108+
private fun parseLocale(json: JSONObject): String? {
109+
try {
110+
return json.getString("locale")
111+
} catch (e: JSONException) {
112+
e.printStackTrace()
113+
return null
114+
}
115+
}

libpretixsync/src/main/java/eu/pretix/libpretixsync/sync/SyncManager.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -728,9 +728,9 @@ protected void uploadCheckins(ProgressFeedback feedback) throws SyncException {
728728
}
729729
if (qci.getDatetime_string() == null || qci.getDatetime_string().equals("")) {
730730
// Backwards compatibility
731-
ar = api.redeem(qci.getEvent_slug(), qci.getSecret(), qci.getDatetime(), true, qci.getNonce(), answers, qci.getCheckinListId(), false, false, qci.getType(), st, null, false);
731+
ar = api.redeem(qci.getEvent_slug(), qci.getSecret(), qci.getDatetime(), true, qci.getNonce(), answers, qci.getCheckinListId(), false, false, qci.getType(), st, null, false, false);
732732
} else {
733-
ar = api.redeem(qci.getEvent_slug(), qci.getSecret(), qci.getDatetime_string(), true, qci.getNonce(), answers, qci.getCheckinListId(), false, false, qci.getType(), st, null, false);
733+
ar = api.redeem(qci.getEvent_slug(), qci.getSecret(), qci.getDatetime_string(), true, qci.getNonce(), answers, qci.getCheckinListId(), false, false, qci.getType(), st, null, false, false);
734734
}
735735
if (connectivityFeedback != null) {
736736
connectivityFeedback.recordSuccess(System.currentTimeMillis() - startedAt);

libpretixsync/src/testFixtures/java/eu/pretix/pretixscan/scanproxy/tests/test/FakePretixApi.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ class FakePretixApi : PretixApi("http://1.1.1.1/", "a", "demo", 1, DefaultHttpCl
4242
type: String?,
4343
source_type: String?,
4444
callTimeout: Long?,
45-
questions_supported: Boolean
45+
questions_supported: Boolean,
46+
use_order_locale: Boolean
4647
): ApiResponse {
4748
redeemRequestSecret = secret
4849
redeemRequestDatetime = datetime
@@ -68,7 +69,8 @@ class FakePretixApi : PretixApi("http://1.1.1.1/", "a", "demo", 1, DefaultHttpCl
6869
type: String?,
6970
source_type: String?,
7071
callTimeout: Long?,
71-
questions_supported: Boolean
72+
questions_supported: Boolean,
73+
use_order_locale: Boolean
7274
): ApiResponse {
7375
redeemRequestSecret = secret
7476
redeemRequestDatetime = datetime

0 commit comments

Comments
 (0)