Skip to content

Commit 5969006

Browse files
cmaierFabtron
andauthored
Add PAYONE SEPA as payment method (#91)
PAYONE's SEPA payment is now supported. Co-authored-by: Fabian Bender <[email protected]>
1 parent e0625ac commit 5969006

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+1333
-114
lines changed

CHANGELOG.md

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

44
## UNRELEASED
5+
### Added
6+
* Added payment method PAYONE SEPA
57

68
## [0.69.1-beta07]
79
### Fixed

build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ allprojects {
4040
sdkVersion = '0.69.1-beta07'
4141
versionCode = 1
4242

43-
compileSdkVersion = 31
43+
compileSdkVersion = 33
4444
minSdkVersion = 21
45-
targetSdkVersion = 31
45+
targetSdkVersion = 33
4646

4747
okhttpVersion = '4.10.0'
4848
desugarVersion = '1.1.5'

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

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ enum class PaymentMethod(
3232
*/
3333
val needsAbortConfirmation: Boolean,
3434
) {
35+
3536
@SerializedName("qrCodePOS")
3637
QRCODE_POS(
3738
id = "qrCodePOS",
@@ -40,6 +41,7 @@ enum class PaymentMethod(
4041
isShowOnlyIfCredentialsArePresent = false,
4142
needsAbortConfirmation = false
4243
),
44+
4345
@SerializedName("qrCodeOffline")
4446
QRCODE_OFFLINE(
4547
id = "qrCodeOffline",
@@ -48,6 +50,7 @@ enum class PaymentMethod(
4850
isShowOnlyIfCredentialsArePresent = false,
4951
needsAbortConfirmation = false
5052
),
53+
5154
@SerializedName("deDirectDebit")
5255
DE_DIRECT_DEBIT(
5356
id = "deDirectDebit",
@@ -56,6 +59,7 @@ enum class PaymentMethod(
5659
isShowOnlyIfCredentialsArePresent = false,
5760
needsAbortConfirmation = true
5861
),
62+
5963
@SerializedName("creditCardVisa")
6064
VISA(
6165
id = "creditCardVisa",
@@ -64,6 +68,7 @@ enum class PaymentMethod(
6468
isShowOnlyIfCredentialsArePresent = false,
6569
needsAbortConfirmation = true
6670
),
71+
6772
@SerializedName("creditCardMastercard")
6873
MASTERCARD(
6974
id = "creditCardMastercard",
@@ -72,6 +77,7 @@ enum class PaymentMethod(
7277
isShowOnlyIfCredentialsArePresent = false,
7378
needsAbortConfirmation = true
7479
),
80+
7581
@SerializedName("creditCardAmericanExpress")
7682
AMEX(
7783
id = "creditCardAmericanExpress",
@@ -80,14 +86,16 @@ enum class PaymentMethod(
8086
isShowOnlyIfCredentialsArePresent = false,
8187
needsAbortConfirmation = true
8288
),
89+
8390
@SerializedName("externalBilling")
84-
TEGUT_EMPLOYEE_CARD
85-
(id = "externalBilling",
91+
TEGUT_EMPLOYEE_CARD(
92+
id = "externalBilling",
8693
isOfflineMethod = false,
8794
isRequiringCredentials = true,
8895
isShowOnlyIfCredentialsArePresent = true,
8996
needsAbortConfirmation = true
9097
),
98+
9199
@SerializedName("externalBilling")
92100
LEINWEBER_CUSTOMER_ID(
93101
id = "externalBilling",
@@ -96,6 +104,7 @@ enum class PaymentMethod(
96104
isShowOnlyIfCredentialsArePresent = true,
97105
needsAbortConfirmation = true
98106
),
107+
99108
@SerializedName("customerCardPOS")
100109
CUSTOMERCARD_POS(
101110
id = "customerCardPOS",
@@ -104,6 +113,7 @@ enum class PaymentMethod(
104113
isShowOnlyIfCredentialsArePresent = false,
105114
needsAbortConfirmation = false
106115
),
116+
107117
@SerializedName("gatekeeperTerminal")
108118
GATEKEEPER_TERMINAL(
109119
id = "gatekeeperTerminal",
@@ -112,6 +122,7 @@ enum class PaymentMethod(
112122
isShowOnlyIfCredentialsArePresent = false,
113123
needsAbortConfirmation = false
114124
),
125+
115126
@SerializedName("paydirektOneKlick")
116127
PAYDIREKT(
117128
id = "paydirektOneKlick",
@@ -120,6 +131,7 @@ enum class PaymentMethod(
120131
isShowOnlyIfCredentialsArePresent = false,
121132
needsAbortConfirmation = true
122133
),
134+
123135
@SerializedName("postFinanceCard")
124136
POST_FINANCE_CARD(
125137
id = "postFinanceCard",
@@ -128,6 +140,7 @@ enum class PaymentMethod(
128140
isShowOnlyIfCredentialsArePresent = false,
129141
needsAbortConfirmation = true
130142
),
143+
131144
@SerializedName("twint")
132145
TWINT(
133146
id = "twint",
@@ -136,16 +149,27 @@ enum class PaymentMethod(
136149
isShowOnlyIfCredentialsArePresent = false,
137150
needsAbortConfirmation = true
138151
),
152+
139153
@SerializedName("googlePay")
140154
GOOGLE_PAY(
141155
id = "googlePay",
142156
isOfflineMethod = false,
143157
isRequiringCredentials = false,
144158
isShowOnlyIfCredentialsArePresent = false,
145159
needsAbortConfirmation = false
160+
),
161+
162+
@SerializedName("deDirectDebit")
163+
PAYONE_SEPA(
164+
id = "deDirectDebit",
165+
isOfflineMethod = false,
166+
isRequiringCredentials = true,
167+
isShowOnlyIfCredentialsArePresent = false,
168+
needsAbortConfirmation = true
146169
);
147170

148171
companion object {
172+
149173
/**
150174
* Converts a payment method from its string representation.
151175
*/
@@ -173,11 +197,17 @@ enum class PaymentMethod(
173197
"tegutEmployeeID" -> return TEGUT_EMPLOYEE_CARD
174198
"leinweberCustomerID" -> return LEINWEBER_CUSTOMER_ID
175199
}
200+
} else if (pm.id == id && pm.id == PAYONE_SEPA.id) {
201+
//needed for deserialization
202+
return when (origin[0]) {
203+
"payoneSepaData" -> PAYONE_SEPA
204+
else -> DE_DIRECT_DEBIT
205+
}
176206
} else if (pm.id == id) {
177207
return pm
178208
}
179209
}
180210
return null
181211
}
182212
}
183-
}
213+
}

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

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ class Checkout @JvmOverloads constructor(
1919
project, shoppingCart
2020
)
2121
) {
22+
2223
companion object {
24+
2325
const val INVALID_PRICE = -1
2426
}
2527

@@ -121,7 +123,8 @@ class Checkout @JvmOverloads constructor(
121123
if (checkoutProcess != null
122124
&& state.value != CheckoutState.PAYMENT_APPROVED
123125
&& state.value != CheckoutState.DENIED_BY_PAYMENT_PROVIDER
124-
&& state.value != CheckoutState.DENIED_BY_SUPERVISOR) {
126+
&& state.value != CheckoutState.DENIED_BY_SUPERVISOR
127+
) {
125128
if (hasAnyFulfillmentAllocationFailed()) {
126129
reset()
127130
return
@@ -148,7 +151,8 @@ class Checkout @JvmOverloads constructor(
148151
notifyStateChanged(CheckoutState.PAYMENT_PROCESSING_ERROR)
149152
} else {
150153
if (state.value != CheckoutState.PAYMENT_PROCESSING
151-
&& state.value != CheckoutState.PAYMENT_APPROVED) {
154+
&& state.value != CheckoutState.PAYMENT_APPROVED
155+
) {
152156
val lastState = state.value
153157

154158
Dispatch.mainThread {
@@ -182,7 +186,8 @@ class Checkout @JvmOverloads constructor(
182186
if (checkoutProcess != null
183187
&& state.value != CheckoutState.PAYMENT_APPROVED
184188
&& state.value != CheckoutState.DENIED_BY_PAYMENT_PROVIDER
185-
&& state.value != CheckoutState.DENIED_BY_SUPERVISOR) {
189+
&& state.value != CheckoutState.DENIED_BY_SUPERVISOR
190+
) {
186191
checkoutApi.abort(checkoutProcess, null)
187192
}
188193
reset()
@@ -205,6 +210,7 @@ class Checkout @JvmOverloads constructor(
205210
private fun cancelOutstandingCalls() {
206211
checkoutApi.cancel()
207212
}
213+
208214
/**
209215
* Returns true of the checkout is currently available, or false if checkout is disabled
210216
* for this project
@@ -248,7 +254,8 @@ class Checkout @JvmOverloads constructor(
248254
}
249255

250256
val backendCart = shoppingCart.toBackendCart()
251-
checkoutApi.createCheckoutInfo(backendCart,
257+
checkoutApi.createCheckoutInfo(
258+
backendCart,
252259
object : CheckoutInfoResult {
253260
override fun onSuccess(
254261
signedCheckoutInfo: SignedCheckoutInfo,
@@ -401,7 +408,7 @@ class Checkout @JvmOverloads constructor(
401408
private fun hasAnyFulfillmentAllocationFailed(): Boolean {
402409
return checkoutProcess?.fulfillments?.any {
403410
it.state == FulfillmentState.ALLOCATION_FAILED
404-
|| it.state == FulfillmentState.ALLOCATION_TIMED_OUT
411+
|| it.state == FulfillmentState.ALLOCATION_TIMED_OUT
405412
} ?: false
406413
}
407414

@@ -465,7 +472,9 @@ class Checkout @JvmOverloads constructor(
465472
|| state == CheckoutState.VERIFYING_PAYMENT_METHOD
466473
|| state == CheckoutState.REQUEST_PAYMENT_AUTHORIZATION_TOKEN
467474
|| state == CheckoutState.PAYMENT_PROCESSING
468-
|| (state == CheckoutState.PAYMENT_APPROVED && !areAllFulfillmentsClosed())) {
475+
|| (state == CheckoutState.PAYMENT_APPROVED && !areAllFulfillmentsClosed())
476+
|| state == CheckoutState.PAYONE_SEPA_MANDATE_REQUIRED
477+
) {
469478
scheduleNextPoll()
470479
}
471480
}
@@ -497,6 +506,12 @@ class Checkout @JvmOverloads constructor(
497506
return false
498507
}
499508

509+
if (isPayoneSepaMandateRequired(checkoutProcess)) {
510+
Logger.d("Waiting for PAYONE SEPA mandate")
511+
notifyStateChanged(CheckoutState.PAYONE_SEPA_MANDATE_REQUIRED)
512+
return false
513+
}
514+
500515
val authorizePaymentUrl = checkoutProcess.authorizePaymentLink
501516
if (authorizePaymentUrl != null) {
502517
if (authorizePaymentRequestFailed) {
@@ -548,7 +563,8 @@ class Checkout @JvmOverloads constructor(
548563
}
549564
CheckState.FAILED -> {
550565
if (checkoutProcess.paymentResult?.failureCause != null
551-
&& checkoutProcess.paymentResult.failureCause == "terminalAbort") {
566+
&& checkoutProcess.paymentResult.failureCause == "terminalAbort"
567+
) {
552568
Logger.d("Payment aborted by terminal")
553569
notifyStateChanged(CheckoutState.PAYMENT_ABORTED)
554570
} else {
@@ -566,6 +582,11 @@ class Checkout @JvmOverloads constructor(
566582
return false
567583
}
568584

585+
private fun isPayoneSepaMandateRequired(checkoutProcess: CheckoutProcessResponse) =
586+
checkoutProcess.paymentState == CheckState.UNAUTHORIZED &&
587+
checkoutProcess.paymentMethod == PaymentMethod.PAYONE_SEPA &&
588+
checkoutProcess.routingTarget != RoutingTarget.SUPERVISOR
589+
569590
private fun approve() {
570591
Logger.d("dddd approve checkout " + System.identityHashCode(this))
571592

@@ -684,4 +705,4 @@ class Checkout @JvmOverloads constructor(
684705
persistentState.fulfillmentState = checkoutProcess?.fulfillments
685706
persistentState.save()
686707
}
687-
}
708+
}

core/src/main/java/io/snabble/sdk/checkout/CheckoutState.kt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,5 +117,10 @@ enum class CheckoutState {
117117
/**
118118
* No shop was selected
119119
*/
120-
NO_SHOP
121-
}
120+
NO_SHOP,
121+
122+
/**
123+
* SEPA mandate for PAYONE is needed
124+
*/
125+
PAYONE_SEPA_MANDATE_REQUIRED,
126+
}

0 commit comments

Comments
 (0)