minSdkVersion 16+
- Add it in your root build.gradle at the end of repositories:
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
- Add the dependency:
dependencies {
implementation 'com.github.tranzzo:android-sdk:$version'
}
- Add the JitPack repository to your build file
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
- Add the dependency
<dependency>
<groupId>com.github.tranzzo</groupId>
<artifactId>android-sdk</artifactId>
<version>$version</version>
</dependency>
Tokenization: Simple way to obtain a Tranzzo user card token, generated on our servers. For more information visit our documentation Validation: Use straightforward card utilities to validate, define and format your card input
<com.tranzzo.android.sdk.view.CardNumberEditText
.../>
<com.tranzzo.android.sdk.view.ExpiryDateEditText
.../>
<com.tranzzo.android.sdk.view.CvcEditText
.../>
TranzzoInputListener cardInputListener = new TranzzoInputListener(
etCardNumber,
etExpiration,
etCvc,
() -> btnTokenize.setEnabled(true)
);
private Either<TrzError, Card> collectCard() {
return etCardNumber
.getCardNumber()
.flatMap(cardNumber ->
etExpiration
.getValidDateFields()
.flatMap(expiry ->
etCvc
.getCvc()
.map(cvc -> new Card(cardNumber, expiry, cvc))
)
)
.mapLeft(TrzError::mkInternal);
}
if (cardInputListener.isFormValid()) {
collectCard().consume(
System.out.println(error.message),
c ->
new TokenizeTask().execute(c);
}
);
}
});
class TokenizeTask extends AsyncTask<Card, Void, Either<TrzError, CardToken>> {
@Override
protected Either<TrzError, CardToken> doInBackground(Card... cards) {
return initTranzzo().tokenize(cards[0], getApplicationContext());
}
@Override
protected void onPostExecute(Either<TrzError, CardToken> result) {
result.consume(error->
System.out.println(error.message),
token -> {
System.out.println(token.toString());
});
}
}
}
Copyright 2013 Square, Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.