Skip to content

Commit f35a124

Browse files
authored
Add address and email to PAYONE form (#167)
1 parent 97084e4 commit f35a124

File tree

13 files changed

+1157
-127
lines changed

13 files changed

+1157
-127
lines changed

CHANGELOG.md

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

44
## UNRELEASED
55
### Added
6+
* Address and email input fields for credit cards via PAYONE
7+
68
### Changed
79
### Removed
810
### Fixed

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

Lines changed: 35 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
import io.snabble.sdk.Snabble;
4141
import io.snabble.sdk.payment.data.GiropayAuthorizationData;
4242
import io.snabble.sdk.payment.data.GiropayData;
43+
import io.snabble.sdk.payment.data.PayoneData;
4344
import io.snabble.sdk.payment.externalbilling.data.ExternalBillingPaymentCredentials;
4445
import io.snabble.sdk.payment.payone.sepa.PayoneSepaData;
4546
import io.snabble.sdk.utils.GsonHolder;
@@ -153,18 +154,6 @@ private static class DatatransData {
153154
private String expiryYear;
154155
}
155156

156-
private static class PayoneData {
157-
PayoneData(String pseudoCardPAN, String name, String userID) {
158-
this.pseudoCardPAN = pseudoCardPAN;
159-
this.name = name;
160-
this.userID = userID;
161-
}
162-
163-
private final String pseudoCardPAN;
164-
private final String name;
165-
private final String userID;
166-
}
167-
168157
private static class TegutEmployeeCard {
169158
private String cardNumber;
170159
}
@@ -470,18 +459,23 @@ public static PaymentCredentials fromDatatrans(String token, Brand brand, String
470459
/**
471460
* Encrypts and stores a payone pseudo card pan.
472461
*/
473-
public static PaymentCredentials fromPayone(String pseudocardpan,
474-
String truncatedcardpan,
475-
PaymentCredentials.Brand brand,
476-
String cardexpiredate,
477-
String lastname,
478-
String userId,
479-
String projectId) {
480-
if (pseudocardpan == null) {
481-
return null;
482-
}
483-
484-
PaymentCredentials pc = new PaymentCredentials();
462+
@Nullable
463+
public static PaymentCredentials fromPayone(
464+
@NonNull final String pseudoCardPan,
465+
@NonNull final String truncatedCardPan,
466+
@NonNull final PaymentCredentials.Brand brand,
467+
@NonNull final String cardExpiryDate,
468+
@NonNull final String lastname,
469+
@NonNull final String street,
470+
@NonNull final String zip,
471+
@NonNull final String city,
472+
@NonNull final String country,
473+
@Nullable final String state,
474+
@NonNull final String email,
475+
@Nullable final String userId,
476+
@NonNull final String projectId
477+
) {
478+
final PaymentCredentials pc = new PaymentCredentials();
485479
pc.generateId();
486480
if (brand == Brand.MASTERCARD || brand == Brand.AMEX || brand == Brand.VISA) {
487481
pc.type = Type.PAYONE_CREDITCARD;
@@ -490,22 +484,32 @@ public static PaymentCredentials fromPayone(String pseudocardpan,
490484
}
491485
pc.projectId = projectId;
492486

493-
List<X509Certificate> certificates = Snabble.getInstance().getPaymentCertificates();
494-
if (certificates.size() == 0) {
487+
final List<X509Certificate> certificates = Snabble.getInstance().getPaymentCertificates();
488+
if (certificates == null || certificates.isEmpty()) {
495489
return null;
496490
}
497491

498-
PayoneData payoneData = new PayoneData(pseudocardpan, lastname, userId);
492+
final PayoneData payoneData = new PayoneData(
493+
pseudoCardPan,
494+
lastname,
495+
email,
496+
street,
497+
zip,
498+
city,
499+
country,
500+
state,
501+
userId
502+
);
499503

500-
String json = GsonHolder.get().toJson(payoneData, PayoneData.class);
504+
final String json = GsonHolder.get().toJson(payoneData, PayoneData.class);
501505

502-
X509Certificate certificate = certificates.get(0);
506+
final X509Certificate certificate = certificates.get(0);
503507
pc.rsaEncryptedData = pc.rsaEncrypt(certificate, json.getBytes());
504508
pc.signature = pc.sha256Signature(certificate);
505509
pc.appId = Snabble.getInstance().getConfig().appId;
506510
pc.brand = brand;
507-
pc.obfuscatedId = truncatedcardpan;
508-
pc.validTo = parseValidTo("yyMM", cardexpiredate);
511+
pc.obfuscatedId = truncatedCardPan;
512+
pc.validTo = parseValidTo("yyMM", cardExpiryDate);
509513

510514
if (pc.rsaEncryptedData == null) {
511515
return null;
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package io.snabble.sdk.payment.data
2+
3+
import com.google.gson.annotations.SerializedName
4+
5+
@Suppress(
6+
"LongParameterList",
7+
"unused", // Fields are used for serialization
8+
)
9+
internal class PayoneData internal constructor(
10+
@SerializedName("pseudoCardPAN") private val pseudoCardPan: String,
11+
@SerializedName("name") private val name: String,
12+
@SerializedName("email") private val email: String,
13+
street: String,
14+
zip: String,
15+
city: String,
16+
country: String,
17+
state: String?,
18+
@SerializedName("userID") private val userId: String?
19+
) {
20+
21+
@SerializedName("address")
22+
private val address: Address
23+
24+
init {
25+
address = Address(street, zip, city, country, state)
26+
}
27+
28+
private class Address(
29+
@SerializedName("street") val street: String,
30+
@SerializedName("zip") val zip: String,
31+
@SerializedName("city") val city: String,
32+
@SerializedName("country") val country: String,
33+
@SerializedName("state") val state: String?
34+
)
35+
}

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

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@ import android.os.Bundle
44
import android.os.Parcelable
55
import android.widget.Toast
66
import androidx.fragment.app.FragmentActivity
7+
import com.google.gson.annotations.SerializedName
78
import io.snabble.sdk.PaymentMethod
89
import io.snabble.sdk.Project
910
import io.snabble.sdk.Snabble
1011
import io.snabble.sdk.ui.R
1112
import io.snabble.sdk.ui.SnabbleUI
13+
import io.snabble.sdk.ui.payment.creditcard.data.CreditCardInfo
1214
import io.snabble.sdk.utils.Dispatch
1315
import io.snabble.sdk.utils.Logger
1416
import io.snabble.sdk.utils.SimpleJsonCallback
@@ -41,9 +43,20 @@ object Payone {
4143
) : Parcelable
4244

4345
data class PreAuthRequest(
44-
val pseudoCardPAN: String,
45-
val lastname: String,
46-
)
46+
@SerializedName("pseudoCardPAN") val pseudoCardPan: String,
47+
@SerializedName("lastName") val name: String,
48+
@SerializedName("email") val email: String,
49+
@SerializedName("address") val address: Address
50+
) {
51+
52+
data class Address(
53+
@SerializedName("street") val street: String,
54+
@SerializedName("zip") val zip: String,
55+
@SerializedName("city") val city: String,
56+
@SerializedName("country") val country: String,
57+
@SerializedName("state") val state: String?,
58+
)
59+
}
4760

4861
data class PreAuthResponse(
4962
val status: AuthStatus,

0 commit comments

Comments
 (0)