Skip to content

Commit 1d0ac51

Browse files
committed
fix datatrans payment options
1 parent 6361c6d commit 1d0ac51

File tree

9 files changed

+111
-24
lines changed

9 files changed

+111
-24
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
# Changelog
22
All notable changes to this project will be documented in this file.
33

4+
## [0.37.1]
5+
6+
### Fixed
7+
- TWINT and PostFinance payment methods are now listed in their project specific lists
8+
49
## [0.37.0]
510

611
### Added

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ allprojects {
3131
}
3232

3333
project.ext {
34-
sdkVersion='0.37.0'
34+
sdkVersion='0.37.1'
3535
versionCode=1
3636

3737
compileSdkVersion=30

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,14 +301,16 @@ public static PaymentCredentials fromPaydirekt(PaydirektAuthorizationData author
301301
}
302302

303303
public static PaymentCredentials fromDatatrans(String token, Brand brand, String obfuscatedId,
304-
String expirationMonth, String expirationYear) {
304+
String expirationMonth, String expirationYear,
305+
String projectId) {
305306
if (token == null) {
306307
return null;
307308
}
308309

309310
PaymentCredentials pc = new PaymentCredentials();
310311
pc.generateId();
311312
pc.type = Type.DATATRANS;
313+
pc.projectId = projectId;
312314

313315
List<X509Certificate> certificates = Snabble.getInstance().getPaymentSigningCertificates();
314316
if (certificates.size() == 0) {

ui-integration/src/main/java/io/snabble/sdk/ui/integration/PaymentCredentialsListFragment.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,20 @@ import io.snabble.sdk.Snabble
1111
import io.snabble.sdk.payment.PaymentCredentials
1212
import io.snabble.sdk.ui.payment.CreditCardInputView
1313
import io.snabble.sdk.ui.payment.PaymentCredentialsListView
14+
import java.util.ArrayList
1415

1516
open class PaymentCredentialsListFragment : Fragment() {
1617
companion object {
1718
const val ARG_PAYMENT_TYPE = PaymentCredentialsListView.ARG_PAYMENT_TYPE
1819
const val ARG_PROJECT_ID = PaymentCredentialsListView.ARG_PROJECT_ID
1920
}
2021

21-
var type: PaymentCredentials.Type? = null
22+
var type: ArrayList<PaymentCredentials.Type>? = null
2223
var project: Project? = null
2324

2425
override fun onCreate(savedInstanceState: Bundle?) {
2526
super.onCreate(savedInstanceState)
26-
type = arguments?.getSerializable(ARG_PAYMENT_TYPE) as PaymentCredentials.Type?
27+
type = arguments?.getSerializable(ARG_PAYMENT_TYPE) as ArrayList<PaymentCredentials.Type>?
2728
val projectId = arguments?.getString(ARG_PROJECT_ID)
2829
project = Snabble.getInstance().projects.firstOrNull { it.id == projectId }
2930
}

ui/src/main/java/io/snabble/sdk/ui/payment/Datatrans.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class Datatrans {
5656
val okClient = project.okHttpClient
5757
okClient.newCall(request).enqueue(object : SimpleJsonCallback<DatatransTokenizationResponse>(DatatransTokenizationResponse::class.java), Callback {
5858
override fun success(response: DatatransTokenizationResponse) {
59-
startDatatransTransaction(activity, response, paymentMethod)
59+
startDatatransTransaction(activity, response, paymentMethod, project)
6060
}
6161

6262
override fun error(t: Throwable?) {
@@ -87,7 +87,7 @@ class Datatrans {
8787
}
8888
}
8989

90-
private fun startDatatransTransaction(activity: FragmentActivity, tokenizationResponse: DatatransTokenizationResponse, paymentMethod: PaymentMethod) {
90+
private fun startDatatransTransaction(activity: FragmentActivity, tokenizationResponse: DatatransTokenizationResponse, paymentMethod: PaymentMethod, project: Project) {
9191
val transaction = Transaction(tokenizationResponse.mobileToken)
9292
transaction.listener = object : TransactionListener {
9393
override fun onTransactionSuccess(result: TransactionSuccess) {
@@ -119,7 +119,8 @@ class Datatrans {
119119
PaymentCredentials.Brand.fromPaymentMethod(paymentMethod),
120120
result.paymentMethodToken?.getDisplayTitle(activity),
121121
month,
122-
year
122+
year,
123+
project.id,
123124
)
124125
store.add(credentials)
125126
}

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

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@
1818
import androidx.recyclerview.widget.LinearLayoutManager;
1919
import androidx.recyclerview.widget.RecyclerView;
2020

21-
import java.lang.reflect.Array;
2221
import java.text.SimpleDateFormat;
2322
import java.util.ArrayList;
2423
import java.util.Arrays;
2524
import java.util.List;
2625

26+
import ch.datatrans.payment.paymentmethods.PaymentMethodType;
2727
import io.snabble.sdk.PaymentMethod;
2828
import io.snabble.sdk.Project;
2929
import io.snabble.sdk.Snabble;
@@ -39,12 +39,13 @@
3939

4040
public class PaymentCredentialsListView extends FrameLayout implements PaymentCredentialsStore.Callback {
4141
public static final String ARG_PAYMENT_TYPE = "paymentType";
42+
public static final String ARG_BRAND = "brand";
4243
public static final String ARG_PROJECT_ID = "projectId";
4344

4445
private List<Entry> entries = new ArrayList<>();
4546
private PaymentCredentialsStore paymentCredentialsStore;
4647
private RecyclerView recyclerView;
47-
private PaymentCredentials.Type type;
48+
private List<PaymentCredentials.Type> types;
4849
private Project project;
4950

5051
public PaymentCredentialsListView(Context context) {
@@ -87,10 +88,14 @@ public void click() {
8788
Bundle bundle = new Bundle();
8889
bundle.putString(SelectPaymentMethodFragment.ARG_PROJECT_ID, SnabbleUI.getProject().getId());
8990
ArrayList<PaymentMethod> types;
90-
if (type == null) {
91+
if (PaymentCredentialsListView.this.types == null) {
9192
types = new ArrayList<>(Arrays.asList(PaymentMethod.values()));
9293
} else {
93-
types = new ArrayList<>(type.getPaymentMethods());
94+
ArrayList<PaymentMethod> methodList = new ArrayList<>();
95+
for (PaymentCredentials.Type type : PaymentCredentialsListView.this.types) {
96+
methodList.addAll(type.getPaymentMethods());
97+
}
98+
types = methodList;
9499
}
95100
bundle.putSerializable(SelectPaymentMethodFragment.ARG_PAYMENT_METHOD_LIST, types);
96101
dialogFragment.setArguments(bundle);
@@ -109,8 +114,8 @@ public void click() {
109114
});
110115
}
111116

112-
public void show(PaymentCredentials.Type type, Project project) {
113-
this.type = type;
117+
public void show(List<PaymentCredentials.Type> types, Project project) {
118+
this.types = types;
114119
this.project = project;
115120

116121
entries.clear();
@@ -167,8 +172,8 @@ public void onChanged() {
167172
}
168173

169174
boolean sameTypeOrNull = true;
170-
if (type != null) {
171-
sameTypeOrNull = type.equals(pm.getType());
175+
if (types != null) {
176+
sameTypeOrNull = types.contains(pm.getType());
172177
}
173178

174179
if (pm.isAvailableInCurrentApp() && sameTypeOrNull && sameProjectOrNull) {
@@ -260,7 +265,7 @@ public void onBindViewHolder(final RecyclerView.ViewHolder holder, final int pos
260265
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("MM/yyyy");
261266
String validTo = simpleDateFormat.format(e.paymentCredentials.getValidTo());
262267

263-
if (e.paymentCredentials.getType() == PaymentCredentials.Type.CREDIT_CARD_PSD2) {
268+
if (e.paymentCredentials.getValidTo() != 0) {
264269
vh.validTo.setText(getResources().getString(R.string.Snabble_Payment_CreditCard_expireDate, validTo));
265270
vh.validTo.setVisibility(View.VISIBLE);
266271
} else {

ui/src/main/java/io/snabble/sdk/ui/payment/PaymentOptionsView.kt

Lines changed: 72 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,9 @@ open class PaymentOptionsView @JvmOverloads constructor(
9292
click = {
9393
if (count > 0) {
9494
val args = Bundle()
95-
args.putSerializable(PaymentCredentialsListView.ARG_PAYMENT_TYPE, PaymentCredentials.Type.SEPA)
95+
args.putSerializable(PaymentCredentialsListView.ARG_PAYMENT_TYPE, ArrayList<PaymentCredentials.Type>().apply {
96+
add(PaymentCredentials.Type.SEPA)
97+
})
9698
executeUiAction(SnabbleUI.Action.SHOW_PAYMENT_CREDENTIALS_LIST, args)
9799
} else {
98100
PaymentInputViewHelper.openPaymentInputView(context, PaymentMethod.DE_DIRECT_DEBIT, null)
@@ -122,7 +124,9 @@ open class PaymentOptionsView @JvmOverloads constructor(
122124
click = {
123125
if (count > 0) {
124126
val args = Bundle()
125-
args.putSerializable(PaymentCredentialsListView.ARG_PAYMENT_TYPE, PaymentCredentials.Type.PAYDIREKT)
127+
args.putSerializable(PaymentCredentialsListView.ARG_PAYMENT_TYPE, ArrayList<PaymentCredentials.Type>().apply {
128+
add(PaymentCredentials.Type.PAYDIREKT)
129+
})
126130
executeUiAction(SnabbleUI.Action.SHOW_PAYMENT_CREDENTIALS_LIST, args)
127131
} else {
128132
PaymentInputViewHelper.openPaymentInputView(context, PaymentMethod.PAYDIREKT, null)
@@ -132,6 +136,68 @@ open class PaymentOptionsView @JvmOverloads constructor(
132136
)
133137
}
134138

139+
// if (paymentMethods.contains(PaymentMethod.TWINT)) {
140+
// val count = credentials.count {
141+
// it.appId == Snabble.getInstance().config.appId &&
142+
// it.type == PaymentCredentials.Type.DATATRANS &&
143+
// it.brand == PaymentCredentials.Brand.TWINT
144+
// }
145+
//
146+
// if (globalList.size > 0) {
147+
// globalList.add(
148+
// Entry(isDivider = true)
149+
// )
150+
// }
151+
//
152+
// globalList.add(
153+
// Entry(
154+
// text = "TWINT",
155+
// icon = R.drawable.snabble_ic_payment_select_twint,
156+
// count = count,
157+
// click = {
158+
// if (count > 0) {
159+
// val args = Bundle()
160+
// args.putSerializable(PaymentCredentialsListView.ARG_PAYMENT_TYPE, PaymentCredentials.Type.DATATRANS)
161+
// executeUiAction(SnabbleUI.Action.SHOW_PAYMENT_CREDENTIALS_LIST, args)
162+
// } else {
163+
// PaymentInputViewHelper.openPaymentInputView(context, PaymentMethod.TWINT, null)
164+
// }
165+
// }
166+
// )
167+
// )
168+
// }
169+
//
170+
// if (paymentMethods.contains(PaymentMethod.POST_FINANCE_CARD)) {
171+
// val count = credentials.count {
172+
// it.appId == Snabble.getInstance().config.appId &&
173+
// it.type == PaymentCredentials.Type.DATATRANS &&
174+
// it.brand == PaymentCredentials.Brand.POST_FINANCE_CARD
175+
// }
176+
//
177+
// if (globalList.size > 0) {
178+
// globalList.add(
179+
// Entry(isDivider = true)
180+
// )
181+
// }
182+
//
183+
// globalList.add(
184+
// Entry(
185+
// text = "PostFinance Card",
186+
// icon = R.drawable.snabble_ic_payment_select_postfinance,
187+
// count = count,
188+
// click = {
189+
// if (count > 0) {
190+
// val args = Bundle()
191+
// args.putSerializable(PaymentCredentialsListView.ARG_PAYMENT_TYPE, PaymentCredentials.Type.DATATRANS)
192+
// executeUiAction(SnabbleUI.Action.SHOW_PAYMENT_CREDENTIALS_LIST, args)
193+
// } else {
194+
// PaymentInputViewHelper.openPaymentInputView(context, PaymentMethod.POST_FINANCE_CARD, null)
195+
// }
196+
// }
197+
// )
198+
// )
199+
// }
200+
135201
projectList.add(
136202
Entry(
137203
isSectionHeader = true,
@@ -162,7 +228,9 @@ open class PaymentOptionsView @JvmOverloads constructor(
162228
click = {
163229
if (count > 0) {
164230
val args = Bundle()
165-
args.putSerializable(PaymentCredentialsListView.ARG_PAYMENT_TYPE, PaymentCredentials.Type.CREDIT_CARD_PSD2)
231+
args.putSerializable(PaymentCredentialsListView.ARG_PAYMENT_TYPE, ArrayList<PaymentCredentials.Type>().apply {
232+
add(PaymentCredentials.Type.CREDIT_CARD_PSD2)
233+
})
166234
args.putSerializable(PaymentCredentialsListView.ARG_PROJECT_ID, project.id)
167235
executeUiAction(SnabbleUI.Action.SHOW_PAYMENT_CREDENTIALS_LIST, args)
168236
} else {
@@ -203,7 +271,7 @@ open class PaymentOptionsView @JvmOverloads constructor(
203271
.forEach { project ->
204272
val count = credentials.count {
205273
it.appId == Snabble.getInstance().config.appId
206-
&& it.type == PaymentCredentials.Type.CREDIT_CARD_PSD2
274+
&& (it.type == PaymentCredentials.Type.CREDIT_CARD_PSD2 || it.type == PaymentCredentials.Type.DATATRANS)
207275
&& it.projectId == project.id }
208276

209277
if (!brands.contains(project.brand)) {

ui/src/main/java/io/snabble/sdk/ui/payment/ProjectPaymentOptionsView.kt

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ open class ProjectPaymentOptionsView @JvmOverloads constructor(
9393

9494
val count = credentials.count {
9595
it.appId == Snabble.getInstance().config.appId &&
96-
it.type == PaymentCredentials.Type.CREDIT_CARD_PSD2 &&
96+
(it.type == PaymentCredentials.Type.CREDIT_CARD_PSD2 || it.type == PaymentCredentials.Type.DATATRANS) &&
9797
it.projectId == project.id
9898
}
9999

@@ -107,7 +107,10 @@ open class ProjectPaymentOptionsView @JvmOverloads constructor(
107107
holder.itemView.setOnClickListener {
108108
if (count > 0) {
109109
val args = Bundle()
110-
args.putSerializable(PaymentCredentialsListView.ARG_PAYMENT_TYPE, PaymentCredentials.Type.CREDIT_CARD_PSD2)
110+
args.putSerializable(PaymentCredentialsListView.ARG_PAYMENT_TYPE, ArrayList<PaymentCredentials.Type>().apply {
111+
add(PaymentCredentials.Type.CREDIT_CARD_PSD2)
112+
add(PaymentCredentials.Type.DATATRANS)
113+
})
111114
args.putString(PaymentCredentialsListView.ARG_PROJECT_ID, project.id)
112115
executeUiAction(SnabbleUI.Action.SHOW_PAYMENT_CREDENTIALS_LIST, args)
113116
} else {
@@ -119,7 +122,9 @@ open class ProjectPaymentOptionsView @JvmOverloads constructor(
119122
args.putSerializable(SelectPaymentMethodFragment.ARG_PAYMENT_METHOD_LIST, ArrayList(listOf(
120123
PaymentMethod.VISA,
121124
PaymentMethod.MASTERCARD,
122-
PaymentMethod.AMEX))
125+
PaymentMethod.AMEX,
126+
PaymentMethod.TWINT,
127+
PaymentMethod.POST_FINANCE_CARD))
123128
)
124129
args.putString(SelectPaymentMethodFragment.ARG_PROJECT_ID, project.id)
125130
dialogFragment.arguments = args

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ public void click() {
135135

136136
if (availablePaymentMethods.contains(PaymentMethod.TWINT)) {
137137
entries.add(new SelectPaymentMethodFragment.Entry(R.drawable.snabble_ic_payment_select_twint,
138-
"Twint",
138+
"TWINT",
139139
getUsableAtText(PaymentMethod.TWINT), new OneShotClickListener() {
140140
@Override
141141
public void click() {

0 commit comments

Comments
 (0)