Skip to content

Commit 2a3d96b

Browse files
authored
Add feature deposit return voucher (#230)
1 parent f2b6180 commit 2a3d96b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+863
-177
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,15 @@ All notable changes to this project will be documented in this file.
33

44
## UNRELEASED
55
### Added
6+
* ui: Add UI for deposit return vouchers (APPS-1643)
7+
* core: Handle invalid items (APPS-2039)
8+
* ui/core: Integrate new states for deposit return vouchers into the checkout process and handle them
69
### Changed
10+
* ui: Change button message for a total price of zero and price text color for a negative total price (APPS-1939)
11+
* core: Handle only a set of pre defined violations (APPS-2049)
712
### Removed
13+
* ui/core: Remove everything related to the old deposit return voucher feature
14+
* core: Remove handling an empty list of payment methods in the checkout info as error (APPS-2049)
815
### Fixed
916

1017
## [0.80.3]

core/src/main/java/io/snabble/sdk/Product.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,7 @@ public enum Type {
4343
* A product that needs to be user weighed. The price from {@link Product#getListPrice()}
4444
* is a base price of 1000g
4545
*/
46-
UserWeighed(2),
47-
48-
/**
49-
* A product that is used for deposit return voucher's
50-
*/
51-
DepositReturnVoucher(3);
46+
UserWeighed(2);
5247

5348
private final int databaseValue;
5449

@@ -656,4 +651,4 @@ public Product build() {
656651
return product;
657652
}
658653
}
659-
}
654+
}

core/src/main/java/io/snabble/sdk/ProductApi.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,7 @@ private enum ApiProductType {
5858
@SerializedName("weighable")
5959
WEIGHABLE,
6060
@SerializedName("deposit")
61-
DEPOSIT,
62-
@SerializedName("depositReturnVoucher")
63-
DEPOSIT_RETURN_VOUCHER
61+
DEPOSIT
6462
}
6563

6664
private static class ApiScannableCode {
@@ -281,8 +279,6 @@ private Product toProduct(ApiProduct apiProduct) {
281279
} else {
282280
builder.setType(Product.Type.PreWeighed);
283281
}
284-
} else if (apiProduct.productType == ApiProductType.DEPOSIT_RETURN_VOUCHER) {
285-
builder.setType(Product.Type.DepositReturnVoucher);
286282
} else {
287283
builder.setType(Product.Type.Article);
288284
}
@@ -306,4 +302,4 @@ private Product toProduct(ApiProduct apiProduct) {
306302

307303
return builder.build();
308304
}
309-
}
305+
}

core/src/main/java/io/snabble/sdk/ProductDatabase.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1405,7 +1405,6 @@ public Cursor searchByFoldedName(String searchString, CancellationSignal cancell
14051405
return productQuery("JOIN searchByName ns ON ns.sku = p.sku " +
14061406
"WHERE ns.foldedName MATCH ? " +
14071407
"AND p.weighing != " + Product.Type.PreWeighed.getDatabaseValue() + " " +
1408-
"AND p.weighing != " + Product.Type.DepositReturnVoucher.getDatabaseValue() + " " +
14091408
"AND p.isDeposit = 0 " +
14101409
"AND availability != 2 " +
14111410
"LIMIT 100", new String[]{
@@ -1439,8 +1438,6 @@ public Cursor searchByCode(String searchString, CancellationSignal cancellationS
14391438

14401439
sb.append(") AND p.weighing != ");
14411440
sb.append(Product.Type.PreWeighed.getDatabaseValue());
1442-
sb.append(" AND p.weighing != ");
1443-
sb.append(Product.Type.DepositReturnVoucher.getDatabaseValue());
14441441
sb.append(" AND p.isDeposit = 0 ");
14451442
sb.append(" AND availability != 2");
14461443

core/src/main/java/io/snabble/sdk/Project.kt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import io.snabble.sdk.auth.SnabbleAuthorizationInterceptor
99
import io.snabble.sdk.checkout.Checkout
1010
import io.snabble.sdk.codes.templates.CodeTemplate
1111
import io.snabble.sdk.codes.templates.PriceOverrideTemplate
12+
import io.snabble.sdk.codes.templates.depositReturnVoucher.DepositReturnVoucherProvider
1213
import io.snabble.sdk.coupons.Coupon
1314
import io.snabble.sdk.coupons.CouponSource
1415
import io.snabble.sdk.coupons.Coupons
@@ -193,6 +194,13 @@ class Project internal constructor(
193194
var codeTemplates = emptyList<CodeTemplate>()
194195
private set
195196

197+
/**
198+
* List of providers for deposit return vouchers.
199+
* Each provider contains an id and a list of code templates used for parsing return voucher specific barcodes.
200+
*/
201+
var depositReturnVoucherProviders = emptyList<DepositReturnVoucherProvider>()
202+
private set
203+
196204
/**
197205
* List of code templates that are used when supplying an existing Product with a different
198206
* barcode which contains a reduced price
@@ -468,6 +476,13 @@ class Project internal constructor(
468476
}
469477
this.codeTemplates = codeTemplates
470478

479+
val dvrProvider: JsonElement? = jsonObject["depositReturnVoucherProviders"]
480+
481+
if (dvrProvider?.isJsonArray == true) {
482+
depositReturnVoucherProviders =
483+
dvrProvider.asJsonArray.mapNotNull { drv -> DepositReturnVoucherProvider.fromJsonElement(drv) }
484+
}
485+
471486
val priceOverrideTemplates = mutableListOf<PriceOverrideTemplate>()
472487
jsonObject["priceOverrideCodes"]?.asJsonArray?.forEach {
473488
val priceOverride = it.asJsonObject
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package io.snabble.sdk
22

3+
import io.snabble.sdk.checkout.ViolationType
4+
35
/**
46
* A notification that a violation occurred
57
*/
@@ -9,9 +11,9 @@ data class ViolationNotification(
911
/** The local generated uuid of the affected item **/
1012
val refersTo: String?,
1113
/** The type of the violation **/
12-
val type: String? = null,
14+
val type: ViolationType? = null,
1315
/** Non-localized message of the backend which sould be displayed
1416
* if no localized message is available
1517
*/
1618
val fallbackMessage: String? = null,
17-
)
19+
)

core/src/main/java/io/snabble/sdk/checkout/Checkout.kt

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,13 @@ class Checkout @JvmOverloads constructor(
8282
persistentState.save()
8383
}
8484

85+
var invalidItems: List<ShoppingCart.Item>?
86+
get() = persistentState.invalidItems
87+
private set(value) {
88+
persistentState.invalidItems = value
89+
persistentState.save()
90+
}
91+
8592
/**
8693
* List of coupons that were redeemed during this checkout
8794
*/
@@ -303,12 +310,13 @@ class Checkout @JvmOverloads constructor(
303310
notifyStateChanged(CheckoutState.INVALID_PRODUCTS)
304311
}
305312

306-
override fun onNoAvailablePaymentMethodFound() {
307-
notifyStateChanged(CheckoutState.NO_PAYMENT_METHOD_AVAILABLE)
313+
override fun onInvalidItems(itemIds: List<String>) {
314+
invalidItems = shoppingCart.filterNotNull().filter { it.id in itemIds }
315+
notifyStateChanged(CheckoutState.INVALID_ITEMS)
308316
}
309317

310-
override fun onInvalidDepositReturnVoucher() {
311-
notifyStateChanged(CheckoutState.CONNECTION_ERROR)
318+
override fun onNoAvailablePaymentMethodFound() {
319+
notifyStateChanged(CheckoutState.NO_PAYMENT_METHOD_AVAILABLE)
312320
}
313321

314322
override fun onUnknownError() {
@@ -445,6 +453,15 @@ class Checkout @JvmOverloads constructor(
445453
notifyStateChanged(CheckoutState.PAYMENT_ABORTED)
446454
return
447455
}
456+
val hasAnyFailedDrvRedemptions =
457+
checkoutProcess?.depositReturnVouchers
458+
?.any { it.state == DepositReturnVoucherState.REDEEMING_FAILED }
459+
?: false
460+
461+
if (hasAnyFailedDrvRedemptions) {
462+
notifyStateChanged(CheckoutState.DEPOSIT_RETURN_REDEMPTION_FAILED)
463+
return
464+
}
448465

449466
Logger.d("Polling for approval state...")
450467
Logger.d("RoutingTarget = $routingTarget")

core/src/main/java/io/snabble/sdk/checkout/CheckoutApi.kt

Lines changed: 52 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,14 @@ import com.google.gson.Gson
44
import com.google.gson.JsonObject
55
import com.google.gson.annotations.SerializedName
66
import com.google.gson.reflect.TypeToken
7-
import io.snabble.sdk.payment.PaymentCredentials
8-
import io.snabble.sdk.Product
9-
import io.snabble.sdk.coupons.Coupon
107
import io.snabble.sdk.FulfillmentState
118
import io.snabble.sdk.PaymentMethod
9+
import io.snabble.sdk.Product
10+
import io.snabble.sdk.coupons.Coupon
11+
import io.snabble.sdk.payment.PaymentCredentials
1212
import io.snabble.sdk.shoppingcart.data.cart.BackendCart
1313
import java.io.Serializable
14-
import java.lang.Exception
15-
import java.util.*
14+
import java.util.Date
1615

1716
/**
1817
* Interface for the snabble Checkout API
@@ -90,8 +89,8 @@ interface CheckoutInfoResult {
9089

9190
fun onNoShopFound()
9291
fun onInvalidProducts(products: List<Product>)
92+
fun onInvalidItems(itemIds: List<String>)
9393
fun onNoAvailablePaymentMethodFound()
94-
fun onInvalidDepositReturnVoucher()
9594
fun onUnknownError()
9695
fun onConnectionError()
9796
}
@@ -111,7 +110,9 @@ enum class LineItemType {
111110
@SerializedName("default") DEFAULT,
112111
@SerializedName("deposit") DEPOSIT,
113112
@SerializedName("discount") DISCOUNT,
114-
@SerializedName("coupon") COUPON
113+
@SerializedName("coupon") COUPON,
114+
@SerializedName("depositReturnVoucher") DEPOSIT_RETURN_VOUCHER,
115+
@SerializedName("depositReturn") DEPOSIT_RETURN
115116
}
116117

117118
enum class CheckState {
@@ -213,11 +214,28 @@ data class CheckoutInfo(
213214
)
214215

215216
data class Violation(
216-
val type: String? = null,
217+
val type: ViolationType? = null,
217218
val refersTo: String? = null,
218219
val message: String? = null,
219220
)
220221

222+
enum class ViolationType {
223+
@SerializedName("deposit_return_voucher_already_redeemed")
224+
DEPOSIT_RETURN_ALREADY_REDEEMED,
225+
226+
@SerializedName("deposit_return_voucher_duplicate")
227+
DEPOSIT_RETURN_DUPLICATED,
228+
229+
@SerializedName("coupon_already_voided")
230+
COUPON_ALREADY_VOIDED,
231+
232+
@SerializedName("coupon_currently_not_valid")
233+
COUPON_CURRENTLY_NOT_VALID,
234+
235+
@SerializedName("coupon_invalid")
236+
COUPON_INVALID,
237+
}
238+
221239
data class LineItem(
222240
val id: String? = null,
223241
val amount: Int = 0,
@@ -317,11 +335,37 @@ data class Fulfillment(
317335
get() = links?.get("self")?.href
318336
}
319337

338+
data class DepositReturnVoucher(
339+
@SerializedName("refersTo")
340+
val refersTo: String,
341+
@SerializedName("state")
342+
val state: DepositReturnVoucherState
343+
)
344+
345+
enum class DepositReturnVoucherState {
346+
@SerializedName("pending")
347+
PENDING,
348+
349+
@SerializedName("redeemed")
350+
REDEEMED,
351+
352+
@SerializedName("redeemingFailed")
353+
REDEEMING_FAILED,
354+
355+
@SerializedName("rolledback")
356+
ROLLED_BACK,
357+
358+
@SerializedName("rollbackFailed")
359+
ROLLBACK_FAILED
360+
}
361+
320362
data class CheckoutProcessResponse(
321363
val links: Map<String, Href>? = null,
322364
val checks: List<Check> = emptyList(),
323365
@SerializedName("orderID")
324366
val orderId: String? = null,
367+
@SerializedName("depositReturnVouchers")
368+
val depositReturnVouchers: List<DepositReturnVoucher>? = null,
325369
val aborted: Boolean = false,
326370
val paymentMethod: PaymentMethod? = null,
327371
val paymentInformation: PaymentInformation? = null,

core/src/main/java/io/snabble/sdk/checkout/CheckoutRetryer.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,11 +143,11 @@ internal class CheckoutRetryer(project: Project, fallbackPaymentMethod: PaymentM
143143
fail()
144144
}
145145

146-
override fun onNoAvailablePaymentMethodFound() {
146+
override fun onInvalidItems(itemIds: List<String>) {
147147
fail()
148148
}
149149

150-
override fun onInvalidDepositReturnVoucher() {
150+
override fun onNoAvailablePaymentMethodFound() {
151151
fail()
152152
}
153153

core/src/main/java/io/snabble/sdk/checkout/CheckoutState.kt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,11 @@ enum class CheckoutState {
109109
*/
110110
INVALID_PRODUCTS,
111111

112+
/**
113+
* Invalid items detected. For example if an item can't be found
114+
*/
115+
INVALID_ITEMS,
116+
112117
/**
113118
* No payment method available
114119
*/
@@ -129,4 +134,9 @@ enum class CheckoutState {
129134
* will not be communicated
130135
*/
131136
PAYMENT_TRANSFERRED,
137+
138+
/**
139+
* One of the deposit return vouchers added couldn't be redeemed
140+
*/
141+
DEPOSIT_RETURN_REDEMPTION_FAILED
132142
}

0 commit comments

Comments
 (0)