Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielluong committed May 18, 2021
1 parent 3126928 commit 0169121
Show file tree
Hide file tree
Showing 8 changed files with 579 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

package mozilla.components.service.sync.autofill

import androidx.annotation.DrawableRes

/**
* Information about a credit card issuer.
*
* @param name The name of the credit card issuer.
* @param icon The icon of the credit card issuer.
* @param start
* @param end
* @param cardNumberMaxLength The maximum card number length for the credit card name.
*/
data class CreditCardIssuer(
val name: String,
@DrawableRes val icon: Int,
val start: Int,
val end: Int,
val cardNumberMaxLength: List<Int>
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

package mozilla.components.service.sync.autofill

import mozilla.components.browser.storage.sync.autofill.R
import kotlin.math.floor
import kotlin.math.log10

/**
*
*/
internal object CreditCardsProvider {

private val creditCardIssuers = listOf(
CreditCardIssuer(
name = CreditCardIssuerType.AMEX.cardName,
icon = R.drawable.ic_cc_logo_visa,
start = 34,
end = 34,
cardNumberMaxLength = listOf(15)
),
CreditCardIssuer(
name = CreditCardIssuerType.DINERS.cardName,
icon = R.drawable.ic_cc_logo_diners,
start = 300,
end = 305,
cardNumberMaxLength = listOf(14)
),
CreditCardIssuer(
name = CreditCardIssuerType.DISCOVER.cardName,
icon = R.drawable.ic_cc_logo_visa,
start = 6011,
end = 6011,
cardNumberMaxLength = listOf(16)
)
// CreditCardIssuerType.JCB.cardName to CreditCardIssuer(
// name = CreditCardIssuerType.JCB.cardName,
// icon = R.drawable.ic_cc_logo_jcb,
// cardNumberMaxLength = listOf(16)
// ),
// CreditCardIssuerType.MASTERCARD.cardName to CreditCardIssuer(
// name = CreditCardIssuerType.MASTERCARD.cardName,
// icon = R.drawable.ic_cc_logo_mastercard,
// cardNumberMaxLength = listOf(16)
// ),
// CreditCardIssuerType.MIR.cardName to CreditCardIssuer(
// name = CreditCardIssuerType.MIR.cardName,
// icon = R.drawable.ic_cc_logo_mir,
// cardNumberMaxLength = listOf(16)
// ),
// CreditCardIssuerType.UNIONPAY.cardName to CreditCardIssuer(
// name = CreditCardIssuerType.UNIONPAY.cardName,
// icon = R.drawable.ic_cc_logo_unionpay,
// cardNumberMaxLength = listOf(19)
// ),
// CreditCardIssuerType.VISA.cardName to CreditCardIssuer(
// name = CreditCardIssuerType.VISA.cardName,
// icon = R.drawable.ic_cc_logo_visa,
// cardNumberMaxLength = listOf(16)
// )
)

/**
* @param cardNumber
*/
fun getCreditCardIssuer(cardNumber: String): CreditCardIssuer? {
for (issuer in creditCardIssuers) {
if (issuer.cardNumberMaxLength.any { cardNumber.length != it }) {
continue
}

val prefixLength = floor(log10(issuer.start.toDouble())) + 1
val prefix = cardNumber.substring(0, prefixLength.toInt()).toInt()

if (prefix >= issuer.start && prefix <= issuer.end) {
return issuer
}
}

return null
}

/**
* Enum of supported credit card issuer types.
*/
enum class CreditCardIssuerType(val cardName: String) {
AMEX("amex"),
DINERS("diners"),
DISCOVER("discover")
// JCB("jcb"),
// MASTERCARD("mastercard"),
// MIR("mir"),
// UNIONPAY("unionpay"),
// VISA("visa")
}
}

fun String.cardType() = CreditCardsProvider.getCreditCardIssuer(this)
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="36dp"
android:height="30dp"
android:viewportWidth="36"
android:viewportHeight="30">
<path
android:pathData="M19.8626,20.068C24.5613,20.0905 28.85,16.2292 28.85,11.5317C28.85,6.3948 24.5613,2.8441 19.8626,2.8458L15.8188,2.8458C11.0638,2.8441 7.15,6.3959 7.15,11.5317C7.15,16.2302 11.0638,20.0905 15.8188,20.068L19.8626,20.068Z"
android:strokeWidth="1"
android:fillColor="#4186CD"
android:fillType="nonZero"
android:strokeColor="#00000000"/>
<path
android:pathData="M15.7604,3.5347C11.3853,3.5361 7.8399,7.0816 7.8389,11.4575C7.8399,15.8326 11.3852,19.3778 15.7604,19.3792C20.1367,19.3778 23.6827,15.8326 23.6833,11.4575C23.6827,7.0816 20.1367,3.5361 15.7604,3.5347ZM10.9389,11.2853C10.9429,9.1633 12.2274,7.3538 14.0389,6.6347L14.0389,15.9347C12.2274,15.2161 10.9428,13.4076 10.9389,11.2853ZM17.4833,15.9347L17.4833,6.6347C19.2943,7.3519 20.58,9.1619 20.5833,11.2844C20.58,13.4075 19.2943,15.2162 17.4833,15.9347Z"
android:strokeWidth="1"
android:fillColor="#FFFFFF"
android:fillType="nonZero"
android:strokeColor="#00000000"/>
<path
android:pathData="M0.6496,22.9249C0.6496,22.2148 0.2754,22.2616 -0.0833,22.2538L-0.0833,22.0486C0.2276,22.0638 0.5463,22.0638 0.8578,22.0638C1.1928,22.0638 1.6475,22.0486 2.238,22.0486C4.3031,22.0486 5.4278,23.414 5.4278,24.8122C5.4278,25.5941 4.9655,27.5597 2.142,27.5597C1.7354,27.5597 1.3601,27.5442 0.9854,27.5442C0.6266,27.5442 0.2754,27.552 -0.0833,27.5597L-0.0833,27.3548C0.3949,27.3071 0.6266,27.2913 0.6495,26.7543L0.6495,22.9249L0.6496,22.9249ZM1.2944,26.5613C1.2944,27.147 1.7309,27.2153 2.1192,27.2153C3.8321,27.2153 4.3944,25.9753 4.3944,24.8418C4.3944,23.4198 3.4429,22.3931 1.9131,22.3931C1.5876,22.3931 1.4381,22.4154 1.2945,22.4235L1.2944,26.5613Z"
android:strokeWidth="1"
android:fillColor="#211E1F"
android:fillType="nonZero"
android:strokeColor="#00000000"/>
<path
android:pathData="M5.4278,27.3638L5.5803,27.3638C5.8053,27.3638 5.9666,27.3638 5.9666,27.1145L5.9666,25.0726C5.9666,24.7414 5.846,24.6953 5.5481,24.5454L5.5481,24.4246C5.9262,24.3183 6.3776,24.1761 6.4092,24.1534C6.466,24.1232 6.514,24.1153 6.5544,24.1153C6.5942,24.1153 6.6109,24.1608 6.6109,24.2213L6.6109,27.1145C6.6109,27.3638 6.7879,27.3638 7.0133,27.3638L7.15,27.3638L7.15,27.5597C6.876,27.5597 6.5942,27.5447 6.305,27.5447C6.0152,27.5447 5.7252,27.5521 5.4278,27.5597L5.4278,27.3638L5.4278,27.3638ZM6.1165,22.7375C5.9335,22.7375 5.7722,22.569 5.7722,22.3864C5.7722,22.2105 5.9409,22.0486 6.1165,22.0486C6.2988,22.0486 6.4611,22.1967 6.4611,22.3864C6.4611,22.5761 6.306,22.7375 6.1165,22.7375Z"
android:strokeWidth="1"
android:fillColor="#211E1F"
android:fillType="nonZero"
android:strokeColor="#00000000"/>
<path
android:pathData="M7.9926,25.1175C7.9926,24.8389 7.9091,24.7638 7.5552,24.6205L7.5552,24.4775C7.8795,24.372 8.1885,24.274 8.551,24.1153C8.5735,24.1153 8.5957,24.1307 8.5957,24.1906L8.5957,24.6808C9.0266,24.372 9.3965,24.1153 9.9028,24.1153C10.5435,24.1153 10.7699,24.5827 10.7699,25.1703L10.7699,27.1145C10.7699,27.3638 10.9359,27.3638 11.1475,27.3638L11.2833,27.3638L11.2833,27.5597C11.0185,27.5597 10.7545,27.5447 10.4834,27.5447C10.2114,27.5447 9.9394,27.5521 9.6681,27.5597L9.6681,27.3638L9.8036,27.3638C10.0155,27.3638 10.1656,27.3638 10.1656,27.1145L10.1656,25.1632C10.1656,24.7331 9.9028,24.5224 9.4719,24.5224C9.2307,24.5224 8.8457,24.7183 8.5956,24.8843L8.5956,27.1144C8.5956,27.3638 8.7625,27.3638 8.9741,27.3638L9.1097,27.3638L9.1097,27.5597C8.8457,27.5597 8.5811,27.5446 8.3095,27.5446C8.0381,27.5446 7.7659,27.552 7.4944,27.5597L7.4944,27.3638L7.6306,27.3638C7.8419,27.3638 7.9925,27.3638 7.9925,27.1144L7.9925,25.1175L7.9926,25.1175Z"
android:strokeWidth="1"
android:fillColor="#211E1F"
android:fillType="nonZero"
android:strokeColor="#00000000"/>
<path
android:pathData="M11.9432,25.5685C11.9261,25.6409 11.9261,25.7611 11.9432,26.0343C11.9918,26.7964 12.496,27.4224 13.1545,27.4224C13.6084,27.4224 13.9637,27.1817 14.2683,26.8849L14.3833,26.9976C14.0038,27.4869 13.534,27.9042 12.8584,27.9042C11.5472,27.9042 11.2833,26.6678 11.2833,26.1545C11.2833,24.581 12.3715,24.1153 12.9483,24.1153C13.6165,24.1153 14.3342,24.5244 14.342,25.3753C14.342,25.4241 14.342,25.4716 14.3342,25.5204L14.2595,25.5685L11.9432,25.5685ZM13.4566,25.1486C13.6693,25.1486 13.6944,25.072 13.6944,25.0016C13.6944,24.7012 13.4302,24.4597 12.9524,24.4597C12.4327,24.4597 12.0745,24.7243 11.9722,25.1486L13.4566,25.1486Z"
android:strokeWidth="1"
android:fillColor="#211E1F"
android:fillType="nonZero"
android:strokeColor="#00000000"/>
<path
android:pathData="M14.3833,27.3638L14.5744,27.3638C14.7717,27.3638 14.9132,27.3638 14.9132,27.1145L14.9132,24.9972C14.9132,24.7638 14.652,24.7183 14.5456,24.658L14.5456,24.5454C15.0618,24.3115 15.3449,24.1153 15.4092,24.1153C15.4511,24.1153 15.4719,24.138 15.4719,24.2136L15.4719,24.8917L15.4868,24.8917C15.6632,24.598 15.9607,24.1153 16.3916,24.1153C16.5684,24.1153 16.7944,24.2432 16.7944,24.5147C16.7944,24.7183 16.6605,24.8997 16.4626,24.8997C16.2425,24.8997 16.2425,24.7183 15.9954,24.7183C15.8751,24.7183 15.4794,24.8917 15.4794,25.3441L15.4794,27.1145C15.4794,27.3638 15.6205,27.3638 15.8187,27.3638L16.2144,27.3638L16.2144,27.5597C15.8254,27.552 15.5295,27.5447 15.2248,27.5447C14.9351,27.5447 14.6379,27.552 14.3834,27.5597L14.3834,27.3638L14.3833,27.3638Z"
android:strokeWidth="1"
android:fillColor="#211E1F"
android:fillType="nonZero"
android:strokeColor="#00000000"/>
<path
android:pathData="M17.2815,26.6677C17.3844,27.1976 17.7003,27.6473 18.2778,27.6473C18.7431,27.6473 18.9173,27.3585 18.9173,27.0774C18.9173,26.1302 17.1944,26.4352 17.1944,25.143C17.1944,24.6934 17.5505,24.1153 18.4198,24.1153C18.6724,24.1153 19.0121,24.188 19.3203,24.3488L19.3764,25.1667L19.1942,25.1667C19.1154,24.6616 18.8389,24.3724 18.3324,24.3724C18.0162,24.3724 17.7161,24.5571 17.7161,24.902C17.7161,25.842 19.55,25.5522 19.55,26.8122C19.55,27.3418 19.1309,27.9042 18.1901,27.9042C17.8739,27.9042 17.5025,27.7918 17.226,27.6316L17.1389,26.7084L17.2815,26.6677Z"
android:strokeWidth="1"
android:fillColor="#211E1F"
android:fillType="nonZero"
android:strokeColor="#00000000"/>
<path
android:pathData="M26.4311,23.6254L26.2389,23.6254C26.0924,22.6849 25.4529,22.3065 24.5903,22.3065C23.7037,22.3065 22.417,22.9254 22.417,24.8555C22.417,26.4812 23.5272,27.6468 24.7133,27.6468C25.4758,27.6468 26.1081,27.1001 26.2621,26.2554L26.4389,26.3034L26.2621,27.4775C25.9386,27.6872 25.0679,27.9042 24.5589,27.9042C22.7565,27.9042 21.6167,26.6896 21.6167,24.8801C21.6167,23.2313 23.0263,22.0486 24.5362,22.0486C25.1601,22.0486 25.761,22.2586 26.3543,22.4758L26.4311,23.6254Z"
android:strokeWidth="1"
android:fillColor="#211E1F"
android:fillType="nonZero"
android:strokeColor="#00000000"/>
<path
android:pathData="M26.7834,27.3605L26.9359,27.3605C27.1616,27.3605 27.3232,27.3605 27.3232,27.1069L27.3232,22.839C27.3232,22.3405 27.2023,22.3252 26.8961,22.2411L26.8961,22.1185C27.2181,22.019 27.5562,21.8808 27.7254,21.7886C27.8132,21.7429 27.8782,21.7042 27.9019,21.7042C27.9511,21.7042 27.9672,21.7505 27.9672,21.812L27.9672,27.1069C27.9672,27.3605 28.144,27.3605 28.3697,27.3605L28.5056,27.3605L28.5056,27.5597C28.233,27.5597 27.9511,27.5444 27.661,27.5444C27.3715,27.5444 27.0817,27.5519 26.7833,27.5597L26.7833,27.3605L26.7834,27.3605Z"
android:strokeWidth="1"
android:fillColor="#211E1F"
android:fillType="nonZero"
android:strokeColor="#00000000"/>
<path
android:pathData="M31.7754,27.0317C31.7754,27.1679 31.8589,27.1753 31.9887,27.1753C32.0806,27.1753 32.1947,27.1679 32.2944,27.1679L32.2944,27.3266C31.9656,27.3564 31.3392,27.5148 31.1939,27.5597L31.1556,27.5369L31.1556,26.927C30.6979,27.2961 30.3459,27.5597 29.8032,27.5597C29.3907,27.5597 28.963,27.2961 28.963,26.6634L28.963,24.7332C28.963,24.5373 28.9327,24.3488 28.5056,24.3113L28.5056,24.1679C28.7809,24.1605 29.3908,24.1153 29.4905,24.1153C29.5752,24.1153 29.5752,24.1679 29.5752,24.3337L29.5752,26.2778C29.5752,26.5045 29.5752,27.1525 30.2393,27.1525C30.499,27.1525 30.8426,26.9566 31.1632,26.6935L31.1632,24.665C31.1632,24.5148 30.7968,24.4321 30.5224,24.3564L30.5224,24.2208C31.209,24.1753 31.6376,24.1153 31.7134,24.1153C31.7753,24.1153 31.7753,24.1679 31.7753,24.2512L31.7753,27.0317L31.7754,27.0317Z"
android:strokeWidth="1"
android:fillColor="#211E1F"
android:fillType="nonZero"
android:strokeColor="#00000000"/>
<path
android:pathData="M33.3716,24.7207C33.6951,24.4502 34.1322,24.1476 34.5779,24.1476C35.5173,24.1476 36.0833,24.9522 36.0833,25.819C36.0833,26.8615 35.3065,27.9042 34.1481,27.9042C33.5493,27.9042 33.2338,27.7129 33.023,27.6258L32.7805,27.8084L32.611,27.7213C32.6828,27.2517 32.724,26.79 32.724,26.3048L32.724,22.8826C32.724,22.365 32.6018,22.3491 32.2944,22.2617L32.2944,22.1344C32.6192,22.0312 32.9582,21.8876 33.1284,21.7918C33.2176,21.7444 33.2821,21.7042 33.3071,21.7042C33.3554,21.7042 33.3716,21.7522 33.3716,21.8162L33.3716,24.7207L33.3716,24.7207L33.3716,24.7207ZM33.3278,26.7525C33.3278,27.0532 33.6193,27.5597 34.1625,27.5597C35.0299,27.5597 35.3944,26.7289 35.3944,26.025C35.3944,25.1712 34.7305,24.4597 34.0979,24.4597C33.7973,24.4597 33.5464,24.6497 33.3278,24.832L33.3278,26.7525L33.3278,26.7525Z"
android:strokeWidth="1"
android:fillColor="#211E1F"
android:fillType="nonZero"
android:strokeColor="#00000000"/>
</vector>
Loading

0 comments on commit 0169121

Please sign in to comment.