Kotlin - Dwolla Developer Portal
Getting Started
Installation
To begin using this SDK, you will first need to download it to your machine. You can use Maven or Gradle to do so, depending on which build tool your project is using.
Maven
Add this to your project’s POM:
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
<dependency>
<groupId>com.github.Dwolla</groupId>
<artifactId>dwolla-v2-kotlin</artifactId>
<version>0.6.1</version>
</dependency>
Gradle
Add this to your project’s build file:
repositories {
// ...
maven(url = "https://jitpack.io") {
name = "jitpack"
}
}
dependencies {
implementation("com.github.Dwolla:dwolla-v2-kotlin:0.6.1")
}
Initialization
Before any API requests can be made, you must first determine which environment you will be using, as well as fetch the application key and secret. To fetch your application key and secret, please visit one of the following links:
- Production: https://dashboard.dwolla.com/applications
- Sandbox: https://dashboard-sandbox.dwolla.com/applications
Finally, you can create an instance of Dwolla with key and secret replaced with the application key and secret that you fetched from one of the aforementioned links, respectively.
Kotlin
import com.dwolla.Dwolla
import com.dwolla.DwollaEnvironment
val dwolla = Dwolla(
key = "YOUR_APP_KEY",
secret = "YOUR_APP_SECRET",
environment = DwollaEnvironment.SANDBOX // defaults to PRODUCTION
)
Java
import com.dwolla.Dwolla;
import com.dwolla.DwollaEnvironment;
Dwolla dwolla = new Dwolla(
"YOUR_APP_KEY",
"YOUR_APP_SECRET",
DwollaEnvironment.SANDBOX // defaults to PRODUCTION
);
Making Requests
The Dwolla client provides high-level and low-level methods for interacting with the Dwolla API.
High-Level Requests
While the low-level methods are all you need, high-level methods exist to make things easier. They embed information you would typically refer to the docs for in the SDK itself such as endpoints, request parameters, and response parameters. As of now, a subset of the Dwolla API has high-level methods available:
-
dwolla.accounts.* -
dwolla.beneficialOwners.* -
dwolla.businessClassifications.* -
dwolla.customers.* -
dwolla.documents.* -
dwolla.fundingSources.* -
dwolla.fundingSourcesTokens.* -
dwolla.root.* -
dwolla.events.* -
dwolla.labels.* -
dwolla.massPayments.* -
dwolla.transfers.* -
dwolla.webhooks.* -
dwolla.webhookSubscriptions.*
Low-Level Requests
To make low-level HTTP requests, you can use the get(), post(), and delete() methods.
dwolla.getdwolla.postdwolla.delete
Examples:
Handling errors
Dwolla V2 Kotlin has 3 types of exceptions:
DwollaException
├── DwollaApiException
└── DwollaAuthException
DwollaApiException: Thrown when the Dwolla API returns an error response. This could occur for a variety of reasons such as invalid request parameters.DwollaAuthException: Thrown when an error occurs obtaining authenticating with the API. You should not encounter this exception unless yourDwollakey/secret are incorrect.DwollaException: The base class other exceptions inherit from.
Kotlin
try {
dwolla.customers.list()
} catch (e: DwollaApiException) {
e.message // String
e.statusCode // Int
e.headers // Headers
e.error // DwollaError
} catch (e: DwollaAuthException) {
e.message // String
e.statusCode // Int
e.headers // Headers
e.error // OAuthError
} catch (e: DwollaException) {
e.message // String
e.cause // Throwable?
}
Java
try {
dwolla.customers.list();
} catch (DwollaApiException e) {
String message = e.message;
Integer statusCode = e.statusCode;
Headers headers = e.headers;
DwollaError error = e.error;
} catch (DwollaAuthException e) {
String message = e.message;
Integer statusCode = e.statusCode;
Headers headers = e.headers;
OAuthError error = e.error;
} catch (DwollaAuthException e) {
String message = e.message;
Throwable cause = e.cause;
}
Community
- If you have any feedback, please reach out to us on our forums or by creating a GitHub issue.
- If you would like to contribute to this library, bug reports and pull requests are always appreciated!
Docker
If you prefer to use Docker to run dwolla-v2-kotlin locally, a Dockerfile file is included in the root directory. You can either build the Docker image with your API key and secret (by passing the values via CLI), or you can specify the values for the app_key and app_secret build arguments in Dockerfile. Finally, you will need to build and run the Docker image. More information on this topic can be found on Docker’s website, or you can find some example commands below.
Building Docker Container
# Building container by specifying build arguments.
# In this configuration, you will not need to modify Dockerfile. All of the
# necessary arguments are passed via Docker's `--build-arg` option.
$ docker build \
--build-arg app_key=YOUR_API_KEY \
--build-arg app_secret=YOUR_APP_SECRET \
-t dwolla/kotlin:latest .
# Building container without specifying build arguments.
# In this configuration, you will need to specify your account API key and
# secret (retrieved from Dwolla) in the Dockerfile file.
$ docker build -t dwolla/kotlin:latest .