Skip to content

Commit

Permalink
0.0.39
Browse files Browse the repository at this point in the history
  • Loading branch information
PaysafeAutoCommitter committed Jul 31, 2024
1 parent 5c5e907 commit afc8316
Show file tree
Hide file tree
Showing 20 changed files with 79 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import com.paysafe.android.tokenization.domain.model.paymentHandle.BillingDetail
import com.paysafe.android.tokenization.domain.model.paymentHandle.MerchantDescriptor
import com.paysafe.android.tokenization.domain.model.paymentHandle.ShippingDetails
import com.paysafe.android.tokenization.domain.model.paymentHandle.ShippingMethod
import com.paysafe.android.tokenization.domain.model.paymentHandle.SimulatorType
import com.paysafe.android.tokenization.domain.model.paymentHandle.TransactionType
import com.paysafe.android.tokenization.domain.model.paymentHandle.profile.DateOfBirth
import com.paysafe.android.tokenization.domain.model.paymentHandle.profile.Gender
Expand Down Expand Up @@ -268,6 +269,7 @@ class FragmentSelectPaymentMethod : Fragment() {
accountId = Consts.CARDS_ACCOUNT_ID,
merchantDescriptor = provideMerchantDescriptor(),
shippingDetails = provideShippingDetails(),
simulator = SimulatorType.INTERNAL,
threeDS = ThreeDS(
merchantUrl = "https://api.qa.paysafe.com/checkout/v2/index.html#/desktop",
process = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@ internal fun PSGooglePayTokenizeOptions.toPaymentHandleRequest(
shippingDetails = shippingDetails,
paymentType = PaymentType.CARD,
googlePayPaymentToken = token,
simulatorType = simulator,
threeDS = threeDS
)
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import com.paysafe.android.tokenization.domain.model.paymentHandle.BillingDetail
import com.paysafe.android.tokenization.domain.model.paymentHandle.MerchantDescriptor
import com.paysafe.android.tokenization.domain.model.paymentHandle.PSTokenizeOptions
import com.paysafe.android.tokenization.domain.model.paymentHandle.ShippingDetails
import com.paysafe.android.tokenization.domain.model.paymentHandle.SimulatorType
import com.paysafe.android.tokenization.domain.model.paymentHandle.TransactionType
import com.paysafe.android.tokenization.domain.model.paymentHandle.profile.Profile
import com.paysafe.android.tokenization.domain.model.paymentHandle.threeds.ThreeDS
Expand Down Expand Up @@ -35,6 +36,8 @@ data class PSGooglePayTokenizeOptions(

override val shippingDetails: ShippingDetails? = null,

override val simulator: SimulatorType = SimulatorType.EXTERNAL,

/** ThreeDS. */
val threeDS: ThreeDS? = null

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import androidx.lifecycle.MutableLiveData
import com.paysafe.android.hostedfields.PSTheme
import com.paysafe.android.hostedfields.R
import com.paysafe.android.hostedfields.model.CardNumberSeparator
import com.paysafe.android.hostedfields.model.DefaultPSCardFieldEventHandler
import com.paysafe.android.hostedfields.model.PSCardFieldEventHandler
import com.paysafe.android.hostedfields.model.PSCardFieldInputEvent
import com.paysafe.android.hostedfields.model.PSCardNumberState
import com.paysafe.android.hostedfields.model.PSCardNumberStateImpl
Expand Down Expand Up @@ -58,7 +60,7 @@ private fun CardNumberBrandIcon(
}
}

private fun getCreditCardIcon(creditCardType: PSCreditCardType) = when (creditCardType) {
fun getCreditCardIcon(creditCardType: PSCreditCardType) = when (creditCardType) {
PSCreditCardType.VISA -> R.drawable.ic_cc_visa
PSCreditCardType.MASTERCARD -> R.drawable.ic_cc_mastercard
PSCreditCardType.AMEX -> R.drawable.ic_cc_amex
Expand All @@ -70,18 +72,18 @@ private fun onCardNumberChange(
cardNumberState: PSCardNumberState,
cardTypeLiveData: MutableLiveData<PSCreditCardType>,
isValidLiveData: MutableLiveData<Boolean>,
onEvent: ((PSCardFieldInputEvent) -> Unit)? = null
): (String) -> Unit = {
val inputData = CardNumberChecks.inputProtection(it, cardNumberState.type, onEvent)
eventHandler: PSCardFieldEventHandler
): (String) -> Unit = { input ->
val inputData = CardNumberChecks.inputProtection(input, cardNumberState.type, eventHandler::handleEvent)

if (cardNumberState.value != inputData.first) { // is new value distinct?
val isValid = CardNumberChecks.validations(inputData.first)
val noInvalidCharacters = inputData.first == it
val noInvalidCharacters = inputData.first == input

// Security check to avoid double trigger for 'onFieldValueChange'; if 'it' contains an
// Security check to avoid double trigger for 'onFieldValueChange'; if 'input' contains an
// invalid character its value would be different from the one returned by 'inputProtection'
if (noInvalidCharacters) onEvent?.invoke(PSCardFieldInputEvent.FIELD_VALUE_CHANGE)
onEvent?.invoke(if (isValid) PSCardFieldInputEvent.VALID else PSCardFieldInputEvent.INVALID)
if (noInvalidCharacters) eventHandler.handleEvent(PSCardFieldInputEvent.FIELD_VALUE_CHANGE)
eventHandler.handleEvent(if (isValid) PSCardFieldInputEvent.VALID else PSCardFieldInputEvent.INVALID)

isValidLiveData.postValue(isValid)
}
Expand All @@ -104,9 +106,9 @@ private fun onDonePressed(
private fun onCardNumberFocusChange(
focusState: FocusState,
cardNumberState: PSCardNumberState,
onEvent: ((PSCardFieldInputEvent) -> Unit)? = null
eventHandler: PSCardFieldEventHandler
) {
if (focusState.isFocused) onEvent?.invoke(PSCardFieldInputEvent.FOCUS)
if (focusState.isFocused) eventHandler.handleEvent(PSCardFieldInputEvent.FOCUS)
val isInactive = !focusState.isFocused
cardNumberState.isFocused = focusState.isFocused
if (isInactive && cardNumberState.alreadyShown) {
Expand All @@ -126,13 +128,13 @@ internal fun PSCardNumber(
cardNumberLiveData: PSCardNumberLiveData,
psTheme: PSTheme,
separator: CardNumberSeparator,
onEvent: ((PSCardFieldInputEvent) -> Unit)? = null,
eventHandler: PSCardFieldEventHandler,
) {
val onValueChange: (String) -> Unit = onCardNumberChange(
state,
cardNumberLiveData.cardTypeLiveData,
cardNumberLiveData.isValidLiveData,
onEvent
eventHandler::handleEvent
)
val keyboardController = LocalSoftwareKeyboardController.current
val keyboardImeAction: ImeAction = ImeAction.Done
Expand Down Expand Up @@ -170,7 +172,7 @@ internal fun PSCardNumber(
isError = !state.isValidInUi,
modifier = cardNumberModifier.modifier
.testTag(PS_CARD_NUMBER_TEST_TAG)
.onFocusChanged { onCardNumberFocusChange(it, state, onEvent) },
.onFocusChanged { onCardNumberFocusChange(it, state, eventHandler) },
colors = textFieldColorsWithPSTheme(psTheme),
shape = roundedCornerShapeWithPSTheme(psTheme),
textStyle = textStyleWithPSTheme(psTheme)
Expand Down Expand Up @@ -247,6 +249,7 @@ internal fun PreviewPSCardNumber(
cardNumber: PSCardNumberState = PSCardNumberStateImpl(),
separator: CardNumberSeparator = CardNumberSeparator.WHITESPACE
) {
val eventHandler = DefaultPSCardFieldEventHandler(MutableLiveData(false))
PSCardNumber(
state = cardNumber,
cardNumberModifier = PSCardNumberModifier(
Expand All @@ -262,7 +265,8 @@ internal fun PreviewPSCardNumber(
isValidLiveData = MutableLiveData(false)
),
psTheme = provideDefaultPSTheme(),
separator = separator
separator = separator,
eventHandler = eventHandler
)
}
//endregion
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import androidx.compose.ui.semantics.testTagsAsResourceId
import com.paysafe.android.hostedfields.PSTheme
import com.paysafe.android.hostedfields.cvv.PSCvvView
import com.paysafe.android.hostedfields.model.CardNumberSeparator
import com.paysafe.android.hostedfields.model.PSCardFieldEventHandler
import com.paysafe.android.hostedfields.model.PSCardFieldInputEvent
import com.paysafe.android.hostedfields.model.PSCardNumberState
import com.paysafe.android.hostedfields.util.PS_CARD_NUMBER_NO_ANIM_LABEL_TEST_TAG
Expand Down Expand Up @@ -49,7 +50,7 @@ fun PSCardNumberField(
cardNumberLiveData: PSCardNumberLiveData,
psTheme: PSTheme,
separator: CardNumberSeparator,
onEvent: ((PSCardFieldInputEvent) -> Unit)? = null
eventHandler: PSCardFieldEventHandler
) {
CompositionLocalProvider(
LocalTextToolbar provides WrapperToAvoidPaste,
Expand All @@ -67,7 +68,7 @@ fun PSCardNumberField(
cardNumberLiveData = cardNumberLiveData,
psTheme = psTheme,
separator = separator,
onEvent = onEvent
eventHandler = eventHandler
)
if (cardNumberState.showLabelWithoutAnimation(animateTopLabelText, labelText)) {
TextLabelReplacement(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.distinctUntilChanged
import com.paysafe.android.hostedfields.R
import com.paysafe.android.hostedfields.model.CardNumberSeparator
import com.paysafe.android.hostedfields.model.DefaultPSCardFieldEventHandler
import com.paysafe.android.hostedfields.model.PSCardNumberStateImpl
import com.paysafe.android.hostedfields.valid.CardNumberChecks
import com.paysafe.android.hostedfields.view.PSCardView
Expand Down Expand Up @@ -73,7 +74,7 @@ class PSCardNumberView @JvmOverloads constructor(
),
psTheme = psTheme,
separator = separator,
onEvent = onEvent
eventHandler = eventHandler ?: DefaultPSCardFieldEventHandler(_isValidLiveData)
)

private fun provideSeparator(attrs: AttributeSet?): CardNumberSeparator {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@ internal fun PSCardTokenizeOptions.toPaymentHandleRequest() = PaymentHandleReque
singleUseCustomerToken = singleUseCustomerToken,
paymentHandleTokenFrom = paymentHandleTokenFrom,
renderType = renderType,
simulatorType = simulator,
threeDS = threeDS
)
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import com.paysafe.android.tokenization.domain.model.paymentHandle.MerchantDescr
import com.paysafe.android.tokenization.domain.model.paymentHandle.PSTokenizeOptions
import com.paysafe.android.tokenization.domain.model.paymentHandle.RenderType
import com.paysafe.android.tokenization.domain.model.paymentHandle.ShippingDetails
import com.paysafe.android.tokenization.domain.model.paymentHandle.SimulatorType
import com.paysafe.android.tokenization.domain.model.paymentHandle.TransactionType
import com.paysafe.android.tokenization.domain.model.paymentHandle.profile.Profile
import com.paysafe.android.tokenization.domain.model.paymentHandle.threeds.ThreeDS
Expand Down Expand Up @@ -45,6 +46,8 @@ data class PSCardTokenizeOptions(
/** Payment handle token. */
val paymentHandleTokenFrom: String? = null,

override val simulator: SimulatorType = SimulatorType.EXTERNAL,

/** Render type to display specific payment challenges. */
val renderType: RenderType? = null

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

package com.paysafe.android.core.data.entity

import com.paysafe.android.core.data.service.SimulatorType

/**
* Model for generic data required for each Paysafe request.
*/
Expand All @@ -22,6 +24,9 @@ data class PSApiRequest(

/** Body for api call. */
var body: String? = null,

/** SimulatorType for api call. */
var simulator: SimulatorType = SimulatorType.EXTERNAL
)

/** Http request types supported, GET and POST. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ private const val SDK_VERSION_HEADER = "X-App-Version"
private const val SDK_SOURCE_HEADER = "X-TransactionSource"
private const val SDK_SOURCE_ANDROID = "AndroidSDKV2"
private const val CALL_TIMEOUT = 15L
const val SIMULATOR_HEADER = "Simulator"

/**
* Paysafe api client.
Expand Down Expand Up @@ -249,7 +250,8 @@ class PSApiClient internal constructor(
private fun prepareHeaders(apiRequest: PSApiRequest) = apiRequest.headers + mapOf(
CORRELATION_ID_HEADER to correlationId,
SDK_VERSION_HEADER to BuildConfig.APP_VERSION,
SDK_SOURCE_HEADER to (customSDKSource ?: SDK_SOURCE_ANDROID)
SDK_SOURCE_HEADER to (customSDKSource ?: SDK_SOURCE_ANDROID),
SIMULATOR_HEADER to apiRequest.simulator.toString()
)

private fun createUrl(httpUrl: HttpUrl, apiRequest: PSApiRequest) =
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.paysafe.android.core.data.service

enum class SimulatorType {
EXTERNAL, INTERNAL
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ import com.paysafe.android.tokenization.data.entity.paymentHandle.PaymentHandleR
import com.paysafe.android.tokenization.data.entity.paymentHandle.PaymentHandleResponseSerializable
import com.paysafe.android.tokenization.data.entity.paymentHandle.PaymentHandleStatusRequest
import com.paysafe.android.tokenization.data.entity.paymentHandle.PaymentHandleStatusResponse
import com.paysafe.android.tokenization.domain.model.paymentHandle.SimulatorType
import com.paysafe.android.tokenization.domain.repository.UniversallyUniqueId

private const val INVOCATION_ID_HEADER = "invocationId"
private const val SIMULATOR_HEADER = "Simulator"
private const val SIMULATOR_HEADER_EXTERNAL = "EXTERNAL"

/**
* Structure to organize API calls to payment hub endpoints.
Expand All @@ -37,6 +37,7 @@ internal class PaymentHubApi(
*/
suspend fun requestPaymentHandle(
requestBody: PaymentHandleRequestSerializable,
simulatorType: SimulatorType = SimulatorType.EXTERNAL,
doBeforeRequest: (String) -> Unit
): PSResult<PaymentHandleResponseSerializable?> {
val invocationId = invocationId.generate()
Expand All @@ -47,8 +48,9 @@ internal class PaymentHubApi(
path = "paymenthub/v1/singleusepaymenthandles",
headers = mapOf(
INVOCATION_ID_HEADER to invocationId,
SIMULATOR_HEADER to SIMULATOR_HEADER_EXTERNAL
)
SIMULATOR_HEADER to simulatorType.toString()
),
simulator = simulatorType.toCoreModuleSimulatorType()
).withBody(requestBody, PaymentHandleRequestSerializable.serializer())
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ internal class PaymentHubRepositoryImpl(
doBeforeRequest: (String, String) -> Unit
): PSResult<PaymentHandle> {
val requestSerializable = paymentHandleRequest.toData(cardRequest)
val response = paymentHubApi.requestPaymentHandle(requestSerializable) { invocationId ->
val response = paymentHubApi.requestPaymentHandle(requestSerializable, simulatorType = paymentHandleRequest.simulatorType) { invocationId ->
doBeforeRequest(
Json.encodeToString(requestSerializable), invocationId
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,8 @@ interface PSTokenizeOptions {
/** Shipping details. */
val shippingDetails: ShippingDetails?

/** Simulator details. */
val simulator: SimulatorType
get() = SimulatorType.EXTERNAL

}
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ data class PaymentHandleRequest(
/** Venmo additinal data */
val venmoRequest: VenmoRequest ? = null,

/** Venmo additinal data */
val simulatorType: SimulatorType = SimulatorType.EXTERNAL,

/** List of return links information for payment. */
val returnLinks: List<PaymentHandleReturnLink>? = null

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.paysafe.android.tokenization.domain.model.paymentHandle

enum class SimulatorType {
EXTERNAL, INTERNAL;

fun toCoreModuleSimulatorType(): com.paysafe.android.core.data.service.SimulatorType {
return when (this) {
EXTERNAL -> com.paysafe.android.core.data.service.SimulatorType.EXTERNAL
INTERNAL -> com.paysafe.android.core.data.service.SimulatorType.INTERNAL
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@ internal fun PSVenmoTokenizeOptions.toPaymentHandleRequest(
shippingDetails = shippingDetails,
paymentType = PaymentType.VENMO,
venmoRequest = venmoRequest,
simulatorType = simulator,
returnLinks = returnLinks,
)
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import com.paysafe.android.tokenization.domain.model.paymentHandle.BillingDetail
import com.paysafe.android.tokenization.domain.model.paymentHandle.MerchantDescriptor
import com.paysafe.android.tokenization.domain.model.paymentHandle.PSTokenizeOptions
import com.paysafe.android.tokenization.domain.model.paymentHandle.ShippingDetails
import com.paysafe.android.tokenization.domain.model.paymentHandle.SimulatorType
import com.paysafe.android.tokenization.domain.model.paymentHandle.TransactionType
import com.paysafe.android.tokenization.domain.model.paymentHandle.profile.Profile
import com.paysafe.android.tokenization.domain.model.paymentHandle.venmo.VenmoRequest
Expand Down Expand Up @@ -35,6 +36,8 @@ data class PSVenmoTokenizeOptions(

override val shippingDetails: ShippingDetails? = null,

override val simulator: SimulatorType = SimulatorType.EXTERNAL,

/** The details of the Venmo account used for the transaction. */
val venmoRequest: VenmoRequest? = null,

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import com.paysafe.android.tokenization.domain.model.paymentHandle.MerchantDescr
import com.paysafe.android.tokenization.domain.model.paymentHandle.PaymentHandleReturnLink
import com.paysafe.android.tokenization.domain.model.paymentHandle.PaymentType
import com.paysafe.android.tokenization.domain.model.paymentHandle.ShippingDetails
import com.paysafe.android.tokenization.domain.model.paymentHandle.SimulatorType
import com.paysafe.android.tokenization.domain.model.paymentHandle.TransactionType
import com.paysafe.android.tokenization.domain.model.paymentHandle.profile.Profile
import com.paysafe.android.tokenization.domain.model.paymentHandle.venmo.VenmoRequest
Expand All @@ -26,6 +27,7 @@ class PSVenmoTokenizeOptionsMapperTest {
private val consumerIdInput = "consumerIdInput"
private val profileId = "profileId"
private val recipientDescriptionInput = "recipientDescriptionInput"
private val simulator = SimulatorType.INTERNAL

@Test
fun `IF venmo tokenization options contains data THEN toTokenizationOptions RETURNS PSTokenizeOptions with data`() {
Expand All @@ -40,6 +42,7 @@ class PSVenmoTokenizeOptionsMapperTest {
accountIdInput,
merchantDescriptorInput,
shippingDetailsInput,
simulator,
VenmoRequest(
consumerIdInput,
recipientDescriptionInput,
Expand Down
2 changes: 1 addition & 1 deletion version.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
# Copyright (c) 2024 Paysafe Group
#

VERSION=0.0.38
VERSION=0.0.39

0 comments on commit afc8316

Please sign in to comment.