-
Notifications
You must be signed in to change notification settings - Fork 662
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Link Cvc & Expiry recollection VM (#9882)
- Loading branch information
1 parent
1faaf8d
commit 4270a65
Showing
10 changed files
with
595 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
payments-ui-core/src/main/java/com/stripe/android/ui/core/elements/CardDetailsUtil.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package com.stripe.android.ui.core.elements | ||
|
||
import androidx.annotation.RestrictTo | ||
import com.stripe.android.uicore.elements.IdentifierSpec | ||
import com.stripe.android.uicore.elements.convertTo4DigitDate | ||
import com.stripe.android.uicore.forms.FormFieldEntry | ||
|
||
@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) | ||
object CardDetailsUtil { | ||
@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) | ||
fun createExpiryDateFormFieldValues(entry: FormFieldEntry): Map<IdentifierSpec, FormFieldEntry> { | ||
return mapOf( | ||
IdentifierSpec.CardExpMonth to getExpiryMonthFormFieldEntry(entry), | ||
IdentifierSpec.CardExpYear to getExpiryYearFormFieldEntry(entry) | ||
) | ||
} | ||
|
||
@SuppressWarnings("MagicNumber") | ||
internal fun getExpiryMonthFormFieldEntry(entry: FormFieldEntry): FormFieldEntry { | ||
var month = -1 | ||
entry.value?.let { date -> | ||
val newString = convertTo4DigitDate(date) | ||
if (newString.length == 4) { | ||
month = requireNotNull(newString.take(2).toIntOrNull()) | ||
} | ||
} | ||
|
||
return entry.copy( | ||
value = month.toString().padStart(length = 2, padChar = '0') | ||
) | ||
} | ||
|
||
@SuppressWarnings("MagicNumber") | ||
internal fun getExpiryYearFormFieldEntry(entry: FormFieldEntry): FormFieldEntry { | ||
var year = -1 | ||
entry.value?.let { date -> | ||
val newString = convertTo4DigitDate(date) | ||
if (newString.length == 4) { | ||
year = requireNotNull(newString.takeLast(2).toIntOrNull()) + 2000 | ||
} | ||
} | ||
|
||
return entry.copy( | ||
value = year.toString() | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.