Skip to content

Commit 5d12a28

Browse files
committed
add support for encodedCodesIKEA payment method
1 parent 8d7b7cf commit 5d12a28

File tree

5 files changed

+35
-6
lines changed

5 files changed

+35
-6
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ All notable changes to this project will be documented in this file.
55

66
### Added
77
- Support for maximum size of encoded code qr code display
8+
- Support for encodedCodesIKEA payment method
89

910
### Fixed
1011
- Race condition when updating product database and shopping cart prices at the same time

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,10 @@ public boolean isAvailable() {
176176
}
177177

178178
private PaymentMethod getFallbackPaymentMethod() {
179-
if(project.getEncodedCodesOptions() != null) {
179+
// TODO remove project id hack when metadata contains explicit fallback method
180+
if(project.getEncodedCodesOptions() != null
181+
&& !project.getId().contains("ikea")
182+
&& !project.getId().contains("globus")) {
180183
return PaymentMethod.ENCODED_CODES;
181184
}
182185

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ public enum PaymentMethod {
99
ENCODED_CODES(true, false),
1010
@SerializedName("encodedCodesCSV")
1111
ENCODED_CODES_CSV(true, false),
12+
@SerializedName("encodedCodesIKEA")
13+
ENCODED_CODES_IKEA(true, false),
1214
@SerializedName("deDirectDebit")
1315
DE_DIRECT_DEBIT(false, true);
1416

core/src/main/java/io/snabble/sdk/encodedcodes/EncodedCodesGenerator.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,14 @@ public ArrayList<String> generate() {
4949
}
5050

5151
finishCode();
52-
ArrayList<String> ret = encodedCodes;
52+
53+
ArrayList<String> ret = new ArrayList<>();
54+
for (int i=0; i<encodedCodes.size(); i++) {
55+
String code = encodedCodes.get(i);
56+
code = code.replace("{qrCodeCount}", String.valueOf(encodedCodes.size()));
57+
ret.add(code);
58+
}
59+
5360
clear();
5461
return ret;
5562
}
@@ -211,6 +218,7 @@ public int compare(ProductInfo p1, ProductInfo p2) {
211218
private void finishCode() {
212219
stringBuilder.append(options.suffix);
213220
String code = stringBuilder.toString();
221+
code = code.replace("{count}", String.valueOf(codeCount));
214222
encodedCodes.add(code);
215223
stringBuilder = new StringBuilder();
216224
codeCount = 0;

ui/src/main/java/io/snabble/sdk/ui/checkout/CheckoutView.java

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import android.widget.ViewAnimator;
1616

1717
import io.snabble.sdk.Checkout;
18+
import io.snabble.sdk.Project;
1819
import io.snabble.sdk.encodedcodes.EncodedCodesOptions;
1920
import io.snabble.sdk.ui.R;
2021
import io.snabble.sdk.ui.SnabbleUI;
@@ -106,6 +107,7 @@ public void onStateChanged(Checkout.State state) {
106107
}
107108

108109
private void displayPaymentView() {
110+
Project project = SnabbleUI.getProject();
109111
switch (checkout.getSelectedPaymentMethod()) {
110112
case DE_DIRECT_DEBIT:
111113
displayView(new CheckoutStatusView(getContext()));
@@ -119,16 +121,29 @@ private void displayPaymentView() {
119121
displayView(new CheckoutEncodedCodesView(getContext()));
120122
break;
121123
case ENCODED_CODES_CSV:
122-
EncodedCodesOptions options = new EncodedCodesOptions.Builder(SnabbleUI.getProject())
124+
displayView(new CheckoutEncodedCodesView(getContext(),
125+
new EncodedCodesOptions.Builder(project)
123126
.prefix("snabble;\n")
124127
.separator("\n")
125128
.suffix("")
126129
.repeatCodes(false)
127130
.countSeparator(";")
128131
.maxCodes(100)
129-
.build();
130-
131-
displayView(new CheckoutEncodedCodesView(getContext(), options));
132+
.build()));
133+
break;
134+
case ENCODED_CODES_IKEA:
135+
EncodedCodesOptions options = project.getEncodedCodesOptions();
136+
int maxCodes = 45;
137+
if (options != null) {
138+
maxCodes = options.maxCodes;
139+
}
140+
displayView(new CheckoutEncodedCodesView(getContext(),
141+
new EncodedCodesOptions.Builder(project)
142+
.prefix("9100003\u001d100{qrCodeCount}\u001d92" + project.getCustomerCardId() + "\u001d240")
143+
.separator("\u001d240")
144+
.suffix("")
145+
.maxCodes(maxCodes)
146+
.build()));
132147
break;
133148
}
134149
}

0 commit comments

Comments
 (0)