From bac8e53f8f1c7643c33af7d7f18dc59e388ca416 Mon Sep 17 00:00:00 2001 From: "i.khafizov" Date: Thu, 2 Jun 2022 17:33:30 +0300 Subject: [PATCH] Added option to disable validation of card expiry date; expiry date is not validated by default --- changelog.md | 7 +++++++ .../ru/tinkoff/acquiring/sdk/utils/CardValidator.kt | 8 ++++++-- gradle.properties | 2 +- .../ru/tinkoff/acquiring/sample/ui/MainActivity.kt | 2 ++ .../ru/tinkoff/acquiring/sample/ui/PayableActivity.kt | 1 + .../sample/utils/PaymentNotificationManager.kt | 1 + .../acquiring/sample/utils/SettingsSdkManager.kt | 6 +++++- sample/src/main/res/values-ru/strings.xml | 1 + sample/src/main/res/values/preferences_keys.xml | 1 + sample/src/main/res/values/strings.xml | 1 + sample/src/main/res/xml/settings.xml | 5 +++++ .../acquiring/sdk/adapters/CardsViewPagerAdapter.kt | 2 ++ .../acquiring/sdk/models/options/FeaturesOptions.kt | 10 ++++++++++ .../acquiring/sdk/ui/customview/editcard/EditCard.kt | 4 +++- .../ui/customview/editcard/validators/CardValidator.kt | 4 +++- .../acquiring/sdk/ui/fragments/AttachCardFragment.kt | 1 + 16 files changed, 50 insertions(+), 6 deletions(-) diff --git a/changelog.md b/changelog.md index 5830b71d..1ae01b00 100644 --- a/changelog.md +++ b/changelog.md @@ -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 diff --git a/core/src/main/java/ru/tinkoff/acquiring/sdk/utils/CardValidator.kt b/core/src/main/java/ru/tinkoff/acquiring/sdk/utils/CardValidator.kt index d5638962..e217c836 100644 --- a/core/src/main/java/ru/tinkoff/acquiring/sdk/utils/CardValidator.kt +++ b/core/src/main/java/ru/tinkoff/acquiring/sdk/utils/CardValidator.kt @@ -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 @@ -81,7 +85,7 @@ internal object CardValidator { if (year > currentYear && year <= currentYear + 20) { return true } - } + }*/ return false } diff --git a/gradle.properties b/gradle.properties index 2fb0125d..7f09e92a 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,4 +1,4 @@ -VERSION_NAME=2.5.6 +VERSION_NAME=2.5.7 VERSION_CODE=15 GROUP=ru.tinkoff.acquiring diff --git a/sample/src/main/java/ru/tinkoff/acquiring/sample/ui/MainActivity.kt b/sample/src/main/java/ru/tinkoff/acquiring/sample/ui/MainActivity.kt index dc55f458..649af92b 100644 --- a/sample/src/main/java/ru/tinkoff/acquiring/sample/ui/MainActivity.kt +++ b/sample/src/main/java/ru/tinkoff/acquiring/sample/ui/MainActivity.kt @@ -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() @@ -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() diff --git a/sample/src/main/java/ru/tinkoff/acquiring/sample/ui/PayableActivity.kt b/sample/src/main/java/ru/tinkoff/acquiring/sample/ui/PayableActivity.kt index a6fab8fc..88f3576a 100644 --- a/sample/src/main/java/ru/tinkoff/acquiring/sample/ui/PayableActivity.kt +++ b/sample/src/main/java/ru/tinkoff/acquiring/sample/ui/PayableActivity.kt @@ -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 diff --git a/sample/src/main/java/ru/tinkoff/acquiring/sample/utils/PaymentNotificationManager.kt b/sample/src/main/java/ru/tinkoff/acquiring/sample/utils/PaymentNotificationManager.kt index 03fca6af..95380ce0 100644 --- a/sample/src/main/java/ru/tinkoff/acquiring/sample/utils/PaymentNotificationManager.kt +++ b/sample/src/main/java/ru/tinkoff/acquiring/sample/utils/PaymentNotificationManager.kt @@ -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 diff --git a/sample/src/main/java/ru/tinkoff/acquiring/sample/utils/SettingsSdkManager.kt b/sample/src/main/java/ru/tinkoff/acquiring/sample/utils/SettingsSdkManager.kt index fb482a98..99a13024 100644 --- a/sample/src/main/java/ru/tinkoff/acquiring/sample/utils/SettingsSdkManager.kt +++ b/sample/src/main/java/ru/tinkoff/acquiring/sample/utils/SettingsSdkManager.kt @@ -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) @@ -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 diff --git a/sample/src/main/res/values-ru/strings.xml b/sample/src/main/res/values-ru/strings.xml index 474cf2b0..8c97f8f1 100644 --- a/sample/src/main/res/values-ru/strings.xml +++ b/sample/src/main/res/values-ru/strings.xml @@ -61,6 +61,7 @@ "%1$d шт. " Использовать системную клавиатуру + Валидировать срок действия карты Рекуррентный платёж Обработать ошибки получения списка карт в SDK GooglePay diff --git a/sample/src/main/res/values/preferences_keys.xml b/sample/src/main/res/values/preferences_keys.xml index f2c5cd40..01bfd0ae 100644 --- a/sample/src/main/res/values/preferences_keys.xml +++ b/sample/src/main/res/values/preferences_keys.xml @@ -18,6 +18,7 @@ acq_sp_use_system_keyboard + acq_sp_validate_expiry_date acq_sp_recurrent_payment acq_sp_terminal_id acq_sp_android_pay diff --git a/sample/src/main/res/values/strings.xml b/sample/src/main/res/values/strings.xml index 1e8692b5..19919ccd 100644 --- a/sample/src/main/res/values/strings.xml +++ b/sample/src/main/res/values/strings.xml @@ -60,6 +60,7 @@ "%1$d Qty " Use system keyboard + Validate expiry date Recurrent payment Handle cards list error in SDK GooglePay diff --git a/sample/src/main/res/xml/settings.xml b/sample/src/main/res/xml/settings.xml index 9624c9ad..61d05444 100644 --- a/sample/src/main/res/xml/settings.xml +++ b/sample/src/main/res/xml/settings.xml @@ -23,6 +23,11 @@ android:title="@string/settings_title_use_system_keyboard" app:iconSpaceReserved="false" /> + + CardValidator.validateCardNumber(cardNumber) || checkFlags(FLAG_MASKED_NUMBER) - EXPIRE_DATE -> CardValidator.validateExpireDate(cardDate) + EXPIRE_DATE -> CardValidator.validateExpireDate(cardDate, validateNotExpired) SECURE_CODE -> CardValidator.validateSecurityCode(cardCvc) } } diff --git a/ui/src/main/java/ru/tinkoff/acquiring/sdk/ui/customview/editcard/validators/CardValidator.kt b/ui/src/main/java/ru/tinkoff/acquiring/sdk/ui/customview/editcard/validators/CardValidator.kt index e0fb218f..8d42c148 100644 --- a/ui/src/main/java/ru/tinkoff/acquiring/sdk/ui/customview/editcard/validators/CardValidator.kt +++ b/ui/src/main/java/ru/tinkoff/acquiring/sdk/ui/customview/editcard/validators/CardValidator.kt @@ -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 } @@ -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 diff --git a/ui/src/main/java/ru/tinkoff/acquiring/sdk/ui/fragments/AttachCardFragment.kt b/ui/src/main/java/ru/tinkoff/acquiring/sdk/ui/fragments/AttachCardFragment.kt index ec90a8fb..5b340ea8 100644 --- a/ui/src/main/java/ru/tinkoff/acquiring/sdk/ui/fragments/AttachCardFragment.kt +++ b/ui/src/main/java/ru/tinkoff/acquiring/sdk/ui/fragments/AttachCardFragment.kt @@ -103,6 +103,7 @@ internal class AttachCardFragment : BaseAcquiringFragment(), EditCardScanButtonC cardCvcHint = localization.payCardCvcHint ?: "" useSecureKeyboard = attachCardOptions.features.useSecureKeyboard isScanButtonVisible = cardScanner.cardScanAvailable + validateNotExpired = attachCardOptions.features.validateExpiryDate requestFocus() }