uphold/uphold-sdk-android

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

Homepage:

Size: 983

Language: Java

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

Uphold SDK for Android Build Status Release

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.

Requirements
Installation

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
}

Basic usage

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.

Authenticate User

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.
}

Get user accounts
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.
}

Get user cards with chaining
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.
}

Get user cards
.getCards().then(new PromiseAction<List<Card>>() {
@Override
public void call(List<Card> cards) {
    // Do something with the list of cards.
}

Create new card
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.
}

Create new card address
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.
}

Get ticker
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.
}

Create and commit a new transaction
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);
Get all public transactions
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.
}

Get reserve status
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.
}

Pagination

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.
}

Uphold SDK sample

Check the sample application to explore a application using the Uphold Android SDK.

Building

To build the sample application you need the Android Studio. Steps to build:

  1. Clone the repository.
  2. Open Android Studio.
  3. Click 'Import project…'.
  4. Open the sample/Uphold-android-sdk-demo directory in the cloned repository.
  5. Build and run the app from inside Android Studio.

The sample application is configured to use the sandbox environment, make sure you use a sandbox account to perform the login.

Contributing & Development
Contributing

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.

Develop

It will be awesome if you can help us evolve uphold-sdk-android. Want to help?

  1. Fork it.
  2. Hack away.
  3. Run the tests.
  4. Create a Pull Request.

This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.