Skip to content

Commit 2631724

Browse files
authored
Receive origin type from paymentMethodDescriptor (Apps-888) (#235)
1 parent ca54706 commit 2631724

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ All notable changes to this project will be documented in this file.
44
## UNRELEASED
55
### Added
66
* ui: Add listener to `SelfScanningFragment` to react to camera permission changes
7+
* core: Receive origin type from `PaymentMethodDesricptor` in case it is not set by default
78
### Changed
89
### Removed
910
### Fixed

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

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import okhttp3.*
1111
import okhttp3.MediaType.Companion.toMediaType
1212
import okhttp3.RequestBody.Companion.toRequestBody
1313
import java.io.IOException
14-
import java.lang.Exception
1514
import java.net.HttpURLConnection.HTTP_CONFLICT
1615
import java.net.HttpURLConnection.HTTP_FORBIDDEN
1716
import java.net.HttpURLConnection.HTTP_NOT_FOUND
@@ -209,6 +208,9 @@ class DefaultCheckoutApi(private val project: Project,
209208
}
210209
}
211210

211+
val originType = paymentCredentials?.type?.originType
212+
?: getOriginTypeFromPaymentMethodDescriptor(paymentMethod = paymentMethod)
213+
212214
val checkoutProcessRequest = CheckoutProcessRequest(
213215
paymentMethod = paymentMethod,
214216
signedCheckoutInfo = signedCheckoutInfo,
@@ -217,22 +219,24 @@ class DefaultCheckoutApi(private val project: Project,
217219
paymentInformation = when (paymentCredentials?.type) {
218220
PaymentCredentials.Type.EXTERNAL_BILLING -> {
219221
PaymentInformation(
220-
originType = paymentCredentials.type?.originType,
222+
originType = originType,
221223
encryptedOrigin = paymentCredentials.encryptedData,
222224
subject = paymentCredentials.additionalData["subject"]
223225
)
224226
}
227+
225228
PaymentCredentials.Type.CREDIT_CARD_PSD2 -> {
226229
PaymentInformation(
227-
originType = paymentCredentials.type?.originType,
230+
originType = originType,
228231
encryptedOrigin = paymentCredentials.encryptedData,
229232
validUntil = SimpleDateFormat("yyyy/MM/dd").format(Date(paymentCredentials.validTo)),
230233
cardNumber = paymentCredentials.obfuscatedId,
231234
)
232235
}
236+
233237
PaymentCredentials.Type.GIROPAY -> {
234238
PaymentInformation(
235-
originType = paymentCredentials.type?.originType,
239+
originType = originType,
236240
encryptedOrigin = paymentCredentials.encryptedData,
237241
deviceID = paymentCredentials.additionalData["deviceID"],
238242
deviceName = paymentCredentials.additionalData["deviceName"],
@@ -243,7 +247,7 @@ class DefaultCheckoutApi(private val project: Project,
243247
null -> null
244248
else -> {
245249
PaymentInformation(
246-
originType = paymentCredentials.type?.originType,
250+
originType = originType,
247251
encryptedOrigin = paymentCredentials.encryptedData
248252
)
249253
}
@@ -320,7 +324,14 @@ class DefaultCheckoutApi(private val project: Project,
320324
})
321325
}
322326

327+
private fun getOriginTypeFromPaymentMethodDescriptor(paymentMethod: PaymentMethod): String? =
328+
project.paymentMethodDescriptors
329+
.firstOrNull { it.paymentMethod == paymentMethod }
330+
?.acceptedOriginTypes
331+
?.get(0)
332+
323333
companion object {
334+
324335
private val JSON: MediaType = "application/json".toMediaType()
325336
}
326337
}

0 commit comments

Comments
 (0)