StripeTextUtils Android

1

Good afternoon! I am starting to develop in android in which they passed me a project, in the comes with a StripeText library and in one of the methods it marks me an error that can not use private classes from the aforementioned library.

The library that is used.

import com.stripe.android.StripeTextUtils;

This is my code where the error marks it in hasAnyPrefix

public String getType(String number) {
    if (!StripeTextUtils.isBlank(number)) {
        if (StripeTextUtils.hasAnyPrefix(number, PREFIXES_AMERICAN_EXPRESS)) {
            return AMERICAN_EXPRESS;
        } else if (StripeTextUtils.hasAnyPrefix(number, PREFIXES_DISCOVER)) {
            return DISCOVER;
        } else if (StripeTextUtils.hasAnyPrefix(number, PREFIXES_JCB)) {
            return JCB;
        } else if (StripeTextUtils.hasAnyPrefix(number, PREFIXES_DINERS_CLUB)) {
            return DINERS_CLUB;
        } else if (StripeTextUtils.hasAnyPrefix(number, PREFIXES_VISA)) {
            return VISA;
        } else if (StripeTextUtils.hasAnyPrefix(number, PREFIXES_MASTERCARD)) {
            return MASTERCARD;
        } else {
            return UNKNOWN;
        }
    }
    return UNKNOWN;
}

Error marking

Error:(332, 32) error: hasAnyPrefix(String,String...) is not public in StripeTextUtils; cannot be accessed from outside package

I hope you can help me or give me some idea of how to solve it, thank you very much!

    
asked by Ulises Díaz 18.09.2017 в 00:45
source

2 answers

0

The hasAnyPrefix method is not public, therefore it is not designed to be consumed from outside the library.

Stripe contains a public method getPossibleCardType of class CardUtils that receives a number and returns the possible type of card. This method calls the function hasAnyPrefix internally.

You can use it like this:

String posibleTipoDeTarjeta = CardUtils.getPossibleCardType(number);

If you want to review the logic that implements the getPossibleCardType method internally, you can find it on GitHub at source code of the file.

    
answered by 18.09.2017 / 01:33
source
0

you may be missing load / compile the StripeText library. For this you must the gradle file (corresponding to the app) put the following line:

compile 'com.stripe:stripe-android:5.0.0'

This will cause that gradle to load this library in the part of dependencies and possibly your problem is solved.

Ex: (part of the gradle file)

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:26.+'
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    testCompile 'junit:junit:4.12'
    compile 'com.stripe:stripe-android:5.0.0'
}

If the problem lies, maybe you should ask yourself to use that library and find another one or do your "calculations" by hand.

I attached a link to the library project. StripeText

    
answered by 18.09.2017 в 01:02