Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ All notable changes to this project will be documented in this file.
## UNRELEASED
### Added
* ui: Add listener to `SelfScanningFragment` to react to camera permission changes
* core: Receive origin type from `PaymentMethodDesricptor` in case it is not set by default
### Changed
### Removed
### Fixed
Expand Down
21 changes: 16 additions & 5 deletions core/src/main/java/io/snabble/sdk/checkout/DefaultCheckoutApi.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import okhttp3.*
import okhttp3.MediaType.Companion.toMediaType
import okhttp3.RequestBody.Companion.toRequestBody
import java.io.IOException
import java.lang.Exception
import java.net.HttpURLConnection.HTTP_CONFLICT
import java.net.HttpURLConnection.HTTP_FORBIDDEN
import java.net.HttpURLConnection.HTTP_NOT_FOUND
Expand Down Expand Up @@ -209,6 +208,9 @@ class DefaultCheckoutApi(private val project: Project,
}
}

val originType = paymentCredentials?.type?.originType
?: getOriginTypeFromPaymentMethodDescriptor(paymentMethod = paymentMethod)

val checkoutProcessRequest = CheckoutProcessRequest(
paymentMethod = paymentMethod,
signedCheckoutInfo = signedCheckoutInfo,
Expand All @@ -217,22 +219,24 @@ class DefaultCheckoutApi(private val project: Project,
paymentInformation = when (paymentCredentials?.type) {
PaymentCredentials.Type.EXTERNAL_BILLING -> {
PaymentInformation(
originType = paymentCredentials.type?.originType,
originType = originType,
encryptedOrigin = paymentCredentials.encryptedData,
subject = paymentCredentials.additionalData["subject"]
)
}

PaymentCredentials.Type.CREDIT_CARD_PSD2 -> {
PaymentInformation(
originType = paymentCredentials.type?.originType,
originType = originType,
encryptedOrigin = paymentCredentials.encryptedData,
validUntil = SimpleDateFormat("yyyy/MM/dd").format(Date(paymentCredentials.validTo)),
cardNumber = paymentCredentials.obfuscatedId,
)
}

PaymentCredentials.Type.GIROPAY -> {
PaymentInformation(
originType = paymentCredentials.type?.originType,
originType = originType,
encryptedOrigin = paymentCredentials.encryptedData,
deviceID = paymentCredentials.additionalData["deviceID"],
deviceName = paymentCredentials.additionalData["deviceName"],
Expand All @@ -243,7 +247,7 @@ class DefaultCheckoutApi(private val project: Project,
null -> null
else -> {
PaymentInformation(
originType = paymentCredentials.type?.originType,
originType = originType,
encryptedOrigin = paymentCredentials.encryptedData
)
}
Expand Down Expand Up @@ -320,7 +324,14 @@ class DefaultCheckoutApi(private val project: Project,
})
}

private fun getOriginTypeFromPaymentMethodDescriptor(paymentMethod: PaymentMethod): String? =
project.paymentMethodDescriptors
.firstOrNull { it.paymentMethod == paymentMethod }
?.acceptedOriginTypes
?.get(0)

companion object {

private val JSON: MediaType = "application/json".toMediaType()
}
}
Loading