Skip to content

Commit 259c202

Browse files
committed
parse available payment methods
1 parent c8aa1f2 commit 259c202

File tree

4 files changed

+40
-1
lines changed

4 files changed

+40
-1
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
### Changed
77
- Added accessor to additional metadata
8+
- Added available payment methods to project
89

910
## [0.14.9]
1011

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ allprojects {
2323
}
2424

2525
project.ext {
26-
sdkVersion='0.14.9'
26+
sdkVersion='0.14.10'
2727
versionCode=1
2828

2929
compileSdkVersion=28

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,27 @@ public boolean isOfflineMethod() {
2929
public boolean isRequiringCredentials() {
3030
return requiresCredentials;
3131
}
32+
33+
public static PaymentMethod fromString(String value) {
34+
PaymentMethod[] values = values();
35+
for (PaymentMethod pm : values) {
36+
try {
37+
SerializedName serializedName = PaymentMethod.class.getField(pm.name()).getAnnotation(SerializedName.class);
38+
if (serializedName != null) {
39+
String name = serializedName.value();
40+
if (name.equals(value)) {
41+
return pm;
42+
}
43+
}
44+
} catch (NoSuchFieldException e) {
45+
e.printStackTrace();
46+
}
47+
}
48+
49+
try {
50+
PaymentMethod pm = valueOf(value);
51+
} catch (Exception ignored) { }
52+
53+
return null;
54+
}
3255
}

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ public class Project {
5252
private Shop checkedInShop;
5353
private CustomerCardInfo[] acceptedCustomerCardInfos;
5454
private CustomerCardInfo requiredCustomerCardInfo;
55+
private PaymentMethod[] availablePaymentMethods;
5556

5657
private Map<String, String> urls;
5758

@@ -186,6 +187,16 @@ void parse(JsonObject jsonObject) {
186187
}
187188
}
188189

190+
List<PaymentMethod> paymentMethodList = new ArrayList<>();
191+
String[] paymentMethods = JsonUtils.getStringArrayOpt(jsonObject, "paymentMethods", new String[0]);
192+
for (String paymentMethod : paymentMethods) {
193+
PaymentMethod pm = PaymentMethod.fromString(paymentMethod);
194+
if (pm != null) {
195+
paymentMethodList.add(pm);
196+
}
197+
}
198+
availablePaymentMethods = paymentMethodList.toArray(new PaymentMethod[paymentMethodList.size()]);
199+
189200
if (jsonObject.has("shops")) {
190201
shops = Shop.fromJson(jsonObject.get("shops"));
191202
}
@@ -441,6 +452,10 @@ public String getCustomerCardId() {
441452
return loyaltyCardId;
442453
}
443454

455+
public PaymentMethod[] getAvailablePaymentMethods() {
456+
return availablePaymentMethods;
457+
}
458+
444459
public CodeTemplate getDefaultCodeTemplate() {
445460
return getCodeTemplate("default");
446461
}

0 commit comments

Comments
 (0)