Skip to content

Commit

Permalink
Merge pull request #92 from Tinkoff/2.5.7
Browse files Browse the repository at this point in the history
Added option to disable validation of card expiry date
  • Loading branch information
IlnarH authored Jun 6, 2022
2 parents ffae269 + bac8e53 commit ba29900
Show file tree
Hide file tree
Showing 16 changed files with 50 additions and 6 deletions.
7 changes: 7 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## 2.5.7

#### Fixed
#### Changes
Added option to disable validation of card expiry date; expiry date is not validated by default
#### Additions

## 2.5.6

#### Fixed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,12 @@ internal object CardValidator {
} catch (e: NumberFormatException) {
return false
}

if (month in 1..12) {
return true
}

// disable expiration validation
/*if (month in 1..12) {
val c = Calendar.getInstance()
val currentYearStr = c.get(Calendar.YEAR).toString().substring(2)
val currentMonth = c.get(Calendar.MONTH) + 1
Expand All @@ -81,7 +85,7 @@ internal object CardValidator {
if (year > currentYear && year <= currentYear + 20) {
return true
}
}
}*/

return false
}
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VERSION_NAME=2.5.6
VERSION_NAME=2.5.7
VERSION_CODE=15
GROUP=ru.tinkoff.acquiring

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ class MainActivity : AppCompatActivity(), BooksListAdapter.BookDetailsClickListe
}
featuresOptions {
useSecureKeyboard = settings.isCustomKeyboardEnabled
validateExpiryDate = settings.validateExpiryDate
cameraCardScanner = settings.cameraScanner
darkThemeMode = settings.resolveDarkThemeMode()
theme = settings.resolveAttachCardStyle()
Expand Down Expand Up @@ -230,6 +231,7 @@ class MainActivity : AppCompatActivity(), BooksListAdapter.BookDetailsClickListe
}
featuresOptions {
useSecureKeyboard = settings.isCustomKeyboardEnabled
validateExpiryDate = settings.validateExpiryDate
cameraCardScanner = settings.cameraScanner
darkThemeMode = settings.resolveDarkThemeMode()
theme = settings.resolveAttachCardStyle()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ open class PayableActivity : AppCompatActivity() {
localizationSource = AsdkSource(Language.RU)
handleCardListErrorInSdk = settings.handleCardListErrorInSdk
useSecureKeyboard = settings.isCustomKeyboardEnabled
validateExpiryDate = settings.validateExpiryDate
cameraCardScanner = settings.cameraScanner
fpsEnabled = settings.isFpsEnabled
tinkoffPayEnabled = settings.isTinkoffPayEnabled
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ object PaymentNotificationManager {
featuresOptions {
localizationSource = AsdkSource(Language.RU)
useSecureKeyboard = settings.isCustomKeyboardEnabled
validateExpiryDate = settings.validateExpiryDate
cameraCardScanner = settings.cameraScanner
fpsEnabled = settings.isFpsEnabled
tinkoffPayEnabled = settings.isTinkoffPayEnabled
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ class SettingsSdkManager(private val context: Context) {
return !preferences.getBoolean(key, false)
}

val validateExpiryDate: Boolean
get() = preferences.getBoolean(context.getString(R.string.acq_sp_validate_expiry_date), false)

val terminalKey: String
get() {
val key = context.getString(R.string.acq_sp_terminal_id)
Expand All @@ -60,7 +63,8 @@ class SettingsSdkManager(private val context: Context) {
val checkType: String
get() {
val defaultCheckType = context.getString(R.string.acq_sp_check_type_no)
return preferences.getString(context.getString(R.string.acq_sp_check_type_id), defaultCheckType) ?: defaultCheckType
return preferences.getString(context.getString(R.string.acq_sp_check_type_id), defaultCheckType)
?: defaultCheckType
}

val cameraScanner: CameraCardScanner
Expand Down
1 change: 1 addition & 0 deletions sample/src/main/res/values-ru/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
<string name="cart_list_item_count_format">"%1$d шт. "</string>

<string name="settings_title_use_system_keyboard">Использовать системную клавиатуру</string>
<string name="settings_title_validate_expiry_date">Валидировать срок действия карты</string>
<string name="settings_title_recurrent_payment">Рекуррентный платёж</string>
<string name="settings_title_handle_cards_list_error">Обработать ошибки получения списка карт в SDK</string>
<string name="settings_title_google_pay">GooglePay</string>
Expand Down
1 change: 1 addition & 0 deletions sample/src/main/res/values/preferences_keys.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<resources>

<string name="acq_sp_use_system_keyboard" translatable="false">acq_sp_use_system_keyboard</string>
<string name="acq_sp_validate_expiry_date" translatable="false">acq_sp_validate_expiry_date</string>
<string name="acq_sp_recurrent_payment" translatable="false">acq_sp_recurrent_payment</string>
<string name="acq_sp_terminal_id" translatable="false">acq_sp_terminal_id</string>
<string name="acq_sp_android_pay" translatable="false">acq_sp_android_pay</string>
Expand Down
1 change: 1 addition & 0 deletions sample/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
<string name="cart_list_item_count_format">"%1$d Qty "</string>

<string name="settings_title_use_system_keyboard">Use system keyboard</string>
<string name="settings_title_validate_expiry_date">Validate expiry date</string>
<string name="settings_title_recurrent_payment">Recurrent payment</string>
<string name="settings_title_handle_cards_list_error">Handle cards list error in SDK</string>
<string name="settings_title_google_pay">GooglePay</string>
Expand Down
5 changes: 5 additions & 0 deletions sample/src/main/res/xml/settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@
android:title="@string/settings_title_use_system_keyboard"
app:iconSpaceReserved="false" />

<SwitchPreference
android:key="@string/acq_sp_validate_expiry_date"
android:title="@string/settings_title_validate_expiry_date"
app:iconSpaceReserved="false" />

<SwitchPreference
android:key="@string/acq_sp_recurrent_payment"
android:title="@string/settings_title_recurrent_payment"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ internal class CardsViewPagerAdapter(
scanButtonClickListener = scanButtonListener
isScanButtonVisible = canScanCard
useSecureKeyboard = options.features.useSecureKeyboard
validateNotExpired = options.features.validateExpiryDate

val localization = AsdkLocalization.resources
cardNumberHint = localization.payCardPanHint ?: ""
Expand Down Expand Up @@ -157,6 +158,7 @@ internal class CardsViewPagerAdapter(

useSecureKeyboard = options.features.useSecureKeyboard
isScanButtonVisible = false
validateNotExpired = options.features.validateExpiryDate

if (rejectedItem == position) {
setMode(EditCard.EditCardMode.EDIT_CVC_ONLY)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,14 @@ class FeaturesOptions() : Options(), Parcelable {
*/
var emailRequired: Boolean = true

/**
* Следует ли при валидации данных карты показывать пользователю ошибку, если введенная
* им срок действия карты уже истек.
* Если установить в true - пользователь не сможет добавить или провести оплату с помощью
* карты с истекшим сроком действия.
*/
var validateExpiryDate: Boolean = false

private constructor(parcel: Parcel) : this() {
parcel.run {
theme = readInt()
Expand All @@ -126,6 +134,7 @@ class FeaturesOptions() : Options(), Parcelable {
emailRequired = readByte().toInt() != 0
userCanSelectCard = readByte().toInt() != 0
showOnlyRecurrentCards = readByte().toInt() != 0
validateExpiryDate = readByte().toInt() != 0
}
}

Expand All @@ -143,6 +152,7 @@ class FeaturesOptions() : Options(), Parcelable {
writeByte((if (emailRequired) 1 else 0).toByte())
writeByte((if (userCanSelectCard) 1 else 0).toByte())
writeByte((if (showOnlyRecurrentCards) 1 else 0).toByte())
writeByte((if (validateExpiryDate) 1 else 0).toByte())
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,8 @@ internal class EditCard @JvmOverloads constructor(
invalidate()
}

var validateNotExpired: Boolean = false

private var cursorPosition: Int = 0
private var editableField: EditCardField = CARD_NUMBER
private var viewState: Int = FULL_CARD_NUMBER_STATE
Expand Down Expand Up @@ -919,7 +921,7 @@ internal class EditCard @JvmOverloads constructor(
private fun isValid(field: EditCardField): Boolean {
return when (field) {
CARD_NUMBER -> CardValidator.validateCardNumber(cardNumber) || checkFlags(FLAG_MASKED_NUMBER)
EXPIRE_DATE -> CardValidator.validateExpireDate(cardDate)
EXPIRE_DATE -> CardValidator.validateExpireDate(cardDate, validateNotExpired)
SECURE_CODE -> CardValidator.validateSecurityCode(cardCvc)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ internal object CardValidator {
return lengthAllowed && validateWithLuhnAlgorithm(cardNumber)
}

fun validateExpireDate(expiryDate: String): Boolean {
fun validateExpireDate(expiryDate: String, validateNotExpired: Boolean): Boolean {
if (expiryDate.isEmpty() || expiryDate.isBlank() || expiryDate.length != MAX_DATE_LENGTH) {
return false
}
Expand All @@ -63,6 +63,8 @@ internal object CardValidator {
}

if (month in 1..12) {
if (!validateNotExpired) return true

val c = Calendar.getInstance()
val currentYearStr = c.get(Calendar.YEAR).toString().substring(2)
val currentMonth = c.get(Calendar.MONTH) + 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ internal class AttachCardFragment : BaseAcquiringFragment(), EditCardScanButtonC
cardCvcHint = localization.payCardCvcHint ?: ""
useSecureKeyboard = attachCardOptions.features.useSecureKeyboard
isScanButtonVisible = cardScanner.cardScanAvailable
validateNotExpired = attachCardOptions.features.validateExpiryDate
requestFocus()
}

Expand Down

0 comments on commit ba29900

Please sign in to comment.