Name: uphold-sdk-android
Owner: Uphold
Description: Uphold Android SDK
Created: 2015-03-06 11:31:43.0
Updated: 2018-05-22 17:36:11.0
Pushed: 2018-05-22 17:36:20.0
Size: 983
Language: Java
GitHub Committers
User | Most Recent Commit | # Commits |
---|
Other Committers
User | Most Recent Commit | # Commits |
---|
Uphold is a next generation platform that allows anyone to transfer and exchange value for free, instantly and securely.
The Uphold SDK for Android provides an easy way for developers to integrate Android applications with the Uphold API.
Using gradle:
sitories {
// Add the jitpack maven repository url.
maven {
url "https://jitpack.io"
}
ndencies {
// Add the classifier `sandboxRelease`, i.e. `'com.github.uphold:uphold-sdk-android:0.16.0:sandboxRelease@aar'`, to use the sandbox environment.
compile ('com.github.uphold:uphold-sdk-android:0.16.0@aar') {
transitive = true
}
In order to learn more about the Uphold API, please visit the developer website.
To use the SDK you must first register an Application and obtain a unique client_id
and client_secret
combination. We recommend your first app be registered in the Sandbox environment, so you can safely play around during development.
From the application page in your account you can get the Client ID, Client Secret and configure the redirect URI and the desired Scopes.
Before instantiating the Uphold client to start the OAuth authentication flow, you must first initialize it:
ldClient.initialize(MainActivity.this);
Now we can start the authentication process by calling the beginAuthorization
method:
ldClient upholdClient = new UpholdClient();
ldClient.beginAuthorization(MainActivity.this, CLIENT_ID, scopes, state);
To receive an intent for the callback URL it is necessary to register an intent filter for one of your Android activities in order for users to be redirected to your app after the authorization process:
ent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:pathPrefix="/connect/uphold"
android:scheme="uphold-demo" />
tent-filter>
In the Android activity with the intent filter override the onNewIntent
method to receive the redirect code:
rride
ected void onNewIntent(final Intent intent) {
if (intent == null || intent.getAction() == null || !intent.getAction().equals("android.intent.action.VIEW")) {
return;
}
upholdClient.completeAuthorization(intent.getData(), CLIENT_ID, CLIENT_SECRET, "authorization_code", state).then(new PromiseAction<AuthenticationResponse>() {
@Override
public void call(AuthenticationResponse authenticationResponse) {
// Get the user bearer token from the authenticationResponse.
}
}).fail(new PromiseAction<Exception>() {
@Override
public void call(Exception e) {
// Handle the Error.
}
});
To get the current user information, just instantiate the Uphold client with the user bearer token:
ldClient upholdClient = new UpholdClient(bearerToken);
ldClient.getUser().then(new PromiseAction<User>() {
@Override
public void call(User user) {
// The user information is available at the user object.
}
ldClient upholdClient = new UpholdClient(bearerToken);
ldClient.getUser().getAccounts().then(new PromiseAction<List<Account>>() {
@Override
public void call(List<Account> accounts) {
// Do something with the list of accounts.
}
ldClient upholdClient = new UpholdClient(bearerToken);
ldClient.getUser().then(new RepromiseFunction<User, List<Card>>() {
@Override
public Promise<List<Card>> call(User user) {
// Do something with the user.
return user.getCards();
}
hen(new PromiseAction<List<Card>>() {
@Override
public void call(List<Card> cards) {
// Do something with the list of cards.
}
ail(new PromiseAction<Exception>() {
@Override
public void call(Exception e) {
// Do something with the error.
}
.getCards().then(new PromiseAction<List<Card>>() {
@Override
public void call(List<Card> cards) {
// Do something with the list of cards.
}
ou can create a simple card request with just the label and the currency.
Request cardRequest = new CardRequest("label", "USD");
.createCard(cardRequest);
r a card request with the label, currency, position and whether it is starred or not.
Request cardRequest = new CardRequest("label", "USD", new Settings(1, true));
.createCard(cardRequest);
Handling the success and error flow:
.createCard(cardRequest).then(new PromiseAction<Card>() {
@Override
public void call(Card card) {
// Do something with the card created.
}
ail(new PromiseAction<Exception>() {
@Override
public void call(Exception e) {
// Handle the error.
}
n the address request you need to specify the network for the address.
essRequest addressRequest = new AddressRequest("bitcoin");
.createAddress(addressRequest);
Handling the success and error flow:
.createAddress(addressRequest).then(new PromiseAction<Address>() {
@Override
public void call(Address address) {
// Do something with the address created.
}
ail(new PromiseAction<Exception>() {
@Override
public void call(Exception e) {
// Handle the error.
}
nstantiate the client. In this case, we don't need an
UTHORIZATION_TOKEN because the Ticker endpoint is public.
ldClient upholdClient = new UpholdClient();
et tickers.
ldClient.getTicker().then(new PromiseAction<List<Rate>>() {
@Override
public void call(List<Rate> rates) {
// Do something with the rates list.
}
Or you could get a ticker for a specific currency:
et tickers for BTC.
ldClient.getTickersByCurrency("BTC").then(new PromiseAction<List<Rate>>() {
@Override
public void call(List<Rate> rates) {
// Do something with the rates list.
}
sactionDenominationRequest transactionDenominationRequest = new TransactionDenominationRequest("1.0", "BTC");
transaction to a destination (card id, crypto address, email, phone number or username).
sactionTransferRequest transactionTransferRequest = new TransactionTransferRequest(transactionDenominationRequest, "foo@bar.com");
.createTransaction(transactionTransferRequest).then(new PromiseAction<Transaction>() {
@Override
public void call(Transaction transaction) {
// Commit the transaction.
transaction.commit();
}
transaction to a destination (card id, crypto address, email, phone number or username) with reference.
sactionTransferRequest transactionTransferRequest = new TransactionTransferRequest(transactionDenominationRequest, "foo@bar.com", "12345");
.createTransaction(transactionTransferRequest).then(new PromiseAction<Transaction>() {
@Override
public void call(Transaction transaction) {
// Commit the transaction.
transaction.commit();
}
deposit from an ACH or SEPA account.
sactionDepositRequest transactionDepositRequest = new TransactionDepositRequest(transactionDenominationRequest, "accountId");
.createTransaction(transactionDepositRequest).then(new PromiseAction<Transaction>() {
@Override
public void call(Transaction transaction) {
// Commit the transaction.
transaction.commit();
}
deposit from a credit card.
sactionCardDepositRequest transactionCardDepositRequest = new TransactionCardDepositRequest(transactionDenominationRequest, "creditCardId", "1234");
.createTransaction(transactionCardDepositRequest).then(new PromiseAction<Transaction>() {
@Override
public void call(Transaction transaction) {
// Commit the transaction.
transaction.commit();
}
If you want to commit the transaction on the creation process, call the createTransaction
method with the second parameter set to true
.
.createTransaction(transactionRequest, true);
nstantiate the client. In this case, we don't need an
UTHORIZATION_TOKEN because the Ticker endpoint is public.
ldClient upholdClient = new UpholdClient();
nator<Transaction> paginator = upholdClient.getReserve().getTransactions();
et the list of transactions.
nator.getElements().then(new PromiseAction<List<Transaction>>() {
@Override
public void call(List<Transaction> transactions) {
// Do something with the list of transactions.
}
et the next page of transactions.
nator.getNext().then(new PromiseAction<List<Transaction>>() {
@Override
public void call(List<Transaction> transactions) {
// Do something with the list of transactions.
}
Or you could get a specific public transaction:
et one public transaction.
ldClient.getReserve().getTransactionById("a97bb994-6e24-4a89-b653-e0a6d0bcf634").then(new PromiseAction<Transaction>() {
@Override
public void call(Transaction transaction) {
// Do something with the transaction.
}
nstantiate the client. In this case, we don't need an
UTHORIZATION_TOKEN because the Ticker endpoint is public.
ldClient upholdClient = new UpholdClient();
et the reserve summary of all the obligations and assets within it.
ldClient.getReserve().getStatistics().then(new PromiseAction<List<ReserveStatistics>>() {
@Override
public void call(List<ReserveStatistics> reserveStatisticses) {
// Do something with the reserve statistics.
}
Some endpoints will return a paginator. Here are some examples on how to handle it:
et public transactions paginator.
nator<Transaction> paginator = upholdClient.getReserve().getTransactions();
et the first page of transactions.
nator.getElements().then(new PromiseAction<List<Transaction>>() {
@Override
public void call(List<Transaction> transactions) {
// Do something with the list of transactions.
}
heck if the paginator has a valid next page.
nator.hasNext().then(new PromiseAction<Boolean>() {
@Override
public void call(Boolean hasNext) {
// Do something with the hasNext.
}
et the number of paginator elements.
nator.count().then(new PromiseAction<Integer>() {
@Override
public void call(Integer count) {
// Do something with the count.
}
et the next page.
nator.getNext().then(new PromiseAction<List<Transaction>>() {
@Override
public void call(List<Transaction> transactions) {
// Do something with the list of transactions.
}
Check the sample application to explore a application using the Uphold Android SDK.
To build the sample application you need the Android Studio. Steps to build:
sample/Uphold-android-sdk-demo
directory in the cloned repository.The sample application is configured to use the sandbox environment, make sure you use a sandbox account to perform the login.
Have you found a bug or want to suggest something? Please search the issues first and, if it is new, go ahead and submit it.
It will be awesome if you can help us evolve uphold-sdk-android
. Want to help?