Skip to content

Commit 9121e2f

Browse files
committed
filter payment methods by appId
1 parent fe7edf0 commit 9121e2f

File tree

5 files changed

+43
-17
lines changed

5 files changed

+43
-17
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ All notable changes to this project will be documented in this file.
88
- A short Checkout-ID is now visible while in payment
99
- Hide bundles of products without a price
1010
- Removed restriction to german IBAN's
11+
- Filter payment methods by appId
1112

1213
### New String Keys
1314
- Snabble.Payment.cancelError.title

core/src/main/java/io/snabble/sdk/payment/PaymentCredentials.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ private static class CreditCardData {
6363
private long validTo;
6464
private Type type;
6565
private Brand brand;
66+
private String appId;
6667

6768
private PaymentCredentials() {
6869

@@ -97,6 +98,7 @@ public static PaymentCredentials fromSEPA(String name, String iban) {
9798
pc.encrypt();
9899
pc.signature = pc.sha256Signature(certificate);
99100
pc.brand = Brand.UNKNOWN;
101+
pc.appId = Snabble.getInstance().getConfig().appId;
100102

101103
if (pc.encryptedData == null) {
102104
return null;
@@ -144,6 +146,7 @@ public static PaymentCredentials fromCreditCardData(String name, Brand brand, St
144146
pc.encrypt();
145147
pc.signature = pc.sha256Signature(certificate);
146148
pc.brand = brand;
149+
pc.appId = Snabble.getInstance().getConfig().appId;
147150

148151
try {
149152
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("MM/yyyy");
@@ -181,6 +184,10 @@ public Brand getBrand() {
181184
return brand;
182185
}
183186

187+
public String getAppId() {
188+
return appId;
189+
}
190+
184191
private String obfuscate(String s) {
185192
int numCharsStart = 4;
186193
int numCharsEnd = 2;
@@ -330,6 +337,15 @@ public boolean validate() {
330337
return false;
331338
}
332339

340+
boolean checkAppId() {
341+
if (appId == null) {
342+
appId = Snabble.getInstance().getConfig().appId;
343+
return true;
344+
}
345+
346+
return false;
347+
}
348+
333349
public long getValidTo() {
334350
return validTo;
335351
}

core/src/main/java/io/snabble/sdk/payment/PaymentCredentialsStore.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,12 @@ private void validate() {
173173
if (!credentials.validate()) {
174174
data.credentialsList.remove(credentials);
175175
changed = true;
176+
} else {
177+
// app id's were not stored in old versions, if its not there assume the
178+
// current app id was the app id in which the payment method was created
179+
if (credentials.checkAppId()) {
180+
changed = true;
181+
}
176182
}
177183
}
178184

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,8 @@ private List<PaymentCredentials> getPaymentCredentials(PaymentMethod pm) {
214214

215215
List<PaymentCredentials> paymentCredentials = paymentCredentialsStore.getAll();
216216
for (PaymentCredentials pc : paymentCredentials) {
217-
if (pc.getType() == getType(pm) && pc.getBrand() == getBrand(pm)) {
217+
if (pc.getType() == getType(pm) && pc.getBrand() == getBrand(pm)
218+
&& Snabble.getInstance().getConfig().appId.equals(pc.getAppId())) {
218219
list.add(pc);
219220
}
220221
}

ui/src/main/java/io/snabble/sdk/ui/payment/PaymentCredentialsListView.java

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -138,24 +138,26 @@ public void onChanged() {
138138
List<PaymentCredentials> paymentCredentials = paymentCredentialsStore.getAll();
139139

140140
for (PaymentCredentials pm : paymentCredentials) {
141-
if (pm.getType() == PaymentCredentials.Type.SEPA) {
142-
entries.add(new Entry(pm, R.drawable.snabble_ic_sepa_small, pm.getObfuscatedId()));
143-
} else if (pm.getType() == PaymentCredentials.Type.CREDIT_CARD) {
144-
PaymentCredentials.Brand ccBrand = pm.getBrand();
145-
146-
int drawableResId = 0;
147-
if (ccBrand != null) {
148-
switch (ccBrand) {
149-
case VISA:
150-
drawableResId = R.drawable.snabble_ic_visa;
151-
break;
152-
case MASTERCARD:
153-
drawableResId = R.drawable.snabble_ic_mastercard;
154-
break;
141+
if (Snabble.getInstance().getConfig().appId.equals(pm.getAppId())) {
142+
if (pm.getType() == PaymentCredentials.Type.SEPA) {
143+
entries.add(new Entry(pm, R.drawable.snabble_ic_sepa_small, pm.getObfuscatedId()));
144+
} else if (pm.getType() == PaymentCredentials.Type.CREDIT_CARD) {
145+
PaymentCredentials.Brand ccBrand = pm.getBrand();
146+
147+
int drawableResId = 0;
148+
if (ccBrand != null) {
149+
switch (ccBrand) {
150+
case VISA:
151+
drawableResId = R.drawable.snabble_ic_visa;
152+
break;
153+
case MASTERCARD:
154+
drawableResId = R.drawable.snabble_ic_mastercard;
155+
break;
156+
}
155157
}
156-
}
157158

158-
entries.add(new Entry(pm, drawableResId, pm.getObfuscatedId()));
159+
entries.add(new Entry(pm, drawableResId, pm.getObfuscatedId()));
160+
}
159161
}
160162
}
161163

0 commit comments

Comments
 (0)