@Immutable @LevelUpApi(contract=PUBLIC) public abstract class LevelUpCode extends Object
Class to represent a QR code. Note: this is not a representation of the web service model.
The primary goal of this class is to enable the parsing of colors from the QR codes scanned by the merchant. This does not validate codes, it attempts to determine code version for the sole purpose of parsing colors. The server will always be the final validator of codes.
Callers should not instantiate this class, they should just call
parseColor(Resources, String)
and it will return the color parsed or the
default color.
Modifier and Type | Field and Description |
---|---|
protected String |
mData
The QR code data.
|
Modifier | Constructor and Description |
---|---|
protected |
LevelUpCode(String qrData) |
Modifier and Type | Method and Description |
---|---|
protected static int |
decodeColor(int position,
Resources resources) |
static String |
encodeLevelUpCode(String data,
int color,
int tipValue)
Deprecated.
use
encodeLevelUpCode(String, int, Tip) instead. |
static String |
encodeLevelUpCode(String data,
int color,
Tip<?> tip)
Encodes the payment preferences to the end of the QR code string passed.
|
protected abstract int |
getColor(Resources resources)
Get the color from this LevelUp code.
|
static int |
parseColor(Resources resources,
String qrData)
Parse the color parameter from this QR code.
|
protected final String mData
protected LevelUpCode(String qrData)
qrData
- the data read from the QR codepublic static int parseColor(Resources resources, String qrData)
resources
- the resources to use to get color resources.qrData
- the QR code string scanned.public static String encodeLevelUpCode(String data, int color, Tip<?> tip)
data
- the QR code data to append the preferences to.color
- the color to encode. This value is between 0 and 9, indexing into a list of
preset colors.tip
- the tip to encode.@Deprecated public static String encodeLevelUpCode(String data, int color, int tipValue)
encodeLevelUpCode(String, int, Tip)
instead.data
- the QR code data to append the preferences to.color
- the color to encode. This value is between 0 and 9, indexing into a list of
preset colors.tipValue
- the tip value to encode.protected abstract int getColor(Resources resources)
resources
- the resources to use to resolve the color.PaymentPreferences.COLOR_UNKNOWN
if none were found in QR
code.protected static int decodeColor(int position, Resources resources)
position
- the position in the color array that was parsed from the QR code data.resources
- Application resources.colorToDecode
or
PaymentPreferences.COLOR_UNKNOWN
if colorToDecode
couldn't be
decoded.