Bleumi Pay SDK for Java
The Bleumi Pay SDK helps you integrate Algo, Algorand Standard Asset, Ethereum, ERC-20, RSK, RSK ERC-20 & xDai payments and payouts into your business or application. The SDK bundles Bleumi Pay API into one SDK to ease implementation and support.
bleumi-pay-sdk-java is a Java library that provides an interface between your Java application and Bleumi Pay API. This tutorial covers the basics, including examples, needed to use the SDK.
Getting Started
Pre-requisites
Development Environment
- Java 1.8+
- Maven/Gradle
Obtain An API Key
Bleumi Pay SDK uses API keys to authenticate requests. You can obtain an API key through the Bleumi Dashboard.
Install Package
Using Maven
Add the following XML code to the dependencies section of your pom.xml file:
<dependency>
<groupId>com.github.bleumi</groupId>
<artifactId>bleumi-pay-sdk-java</artifactId>
<version>1.0.14</version>
</dependency>
Using Gradle
Add this dependency to your project's build file:
compile "com.github.bleumi:bleumi-pay-sdk-java:1.0.14"
Run Sample Code
The following code generates an unique checkout URL to accept payment from the buyer:
// Import classes:
import com.bleumi.pay.ApiClient;
import com.bleumi.pay.ApiException;
import com.bleumi.pay.Configuration;
import com.bleumi.pay.auth.*;
import com.bleumi.pay.model.*;
import com.bleumi.pay.api.HostedCheckoutsApi;
public class HostedCheckoutsApiExample {
public static void main(String[] args) {
ApiClient defaultClient = Configuration.getDefaultApiClient();
// Configure API key authorization: ApiKeyAuth
ApiKeyAuth ApiKeyAuth = (ApiKeyAuth) defaultClient.getAuthentication("ApiKeyAuth");
ApiKeyAuth.setApiKey("<Your API Key>");
HostedCheckoutsApi apiInstance = new HostedCheckoutsApi();
CreateCheckoutUrlRequest body = new CreateCheckoutUrlRequest(); // CreateCheckoutUrlRequest | Request body - used to specify checkout URL creation parameters.
try {
body.setId("<ID>"); //Eg. "1"
body.setCurrency("<CURRENCY>"); // Eg. "USD"
body.setAmount("<AMOUT>"); // Eg. "10"
body.setSuccessUrl("<SUCCESS_URL>"); // Eg. "https://demo.store/api/completeOrder"
body.setCancelUrl("<CANCEL_URL>"); // Eg. "https://demo.store/api/cancelOrder"
body.setToken("<TOKEN>"); //Optional; Replace <TOKEN> by anyone of the following values: 'ETH' or 'XDAI' or 'XDAIT' or ECR-20 Contract Address or 'RBTC' or RSK ECR-20 Contract Address or 'Asset ID' of Algorand Standard Asset.
body.setChain(Chain.GOERLI); //Optional; Replace Chain.GOERLI with appropriate chain as required.
CreateCheckoutUrlResponse result = apiInstance.createCheckoutUrl(body);
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling HostedCheckoutsApi#createCheckoutUrl");
e.printStackTrace();
}
}
}
More examples can be found under each method in SDK Classes section.
SDK Classes
Class | Method | HTTP request | Description |
---|---|---|---|
HostedCheckoutsApi | createCheckoutUrl | POST /v1/payment/hc | Generate a unique checkout URL to accept payment. |
HostedCheckoutsApi | listTokens | GET /v1/payment/hc/tokens | Retrieve all tokens configured for the Hosted Checkout in your account in the Bleumi Pay Dashboard. |
HostedCheckoutsApi | validateCheckoutPayment | POST /v1/payment/hc/validate | Validate the GET parameters passed by Hosted Checkout in successUrl upon successfully completing payment. |
PaymentsApi | getPayment | GET /v1/payment/{id} | Retrieve the wallet addresses & token balances for a given payment |
PaymentsApi | listPayments | GET /v1/payment | Retrieve all payments created. |
PaymentsApi | settlePayment | POST /v1/payment/{id}/settle | Settle a specific amount of a token for a given payment to the transferAddress and remaining balance (if any) will be refunded to the buyerAddress |
PaymentsApi | refundPayment | POST /v1/payment/{id}/refund | Refund the balance of a token for a given payment to the buyerAddress |
PaymentsApi | getPaymentOperation | GET /v1/payment/{id}/operation/{txid} | Retrieve a payment operation for a specific payment. |
PaymentsApi | listPaymentOperations | GET /v1/payment/{id}/operation | Retrieve all payment operations for a specific payment. |
PayoutsApi | createPayout | POST /v1/payout | Create a payout. |
PayoutsApi | listPayouts | GET /v1/payout | Returns a list of payouts |
Documentation for Models
- AlgorandAddress
- AlgorandBalance
- AlgorandWalletAddress
- AlgorandWalletInputs
- BadRequest
- Chain
- CheckoutToken
- CreateCheckoutUrlRequest
- CreateCheckoutUrlResponse
- CreatePayoutRequest
- CreatePayoutResponse
- EthereumAddress
- EthereumBalance
- EthereumWalletAddress
- EthereumWalletInputs
- PaginatedPaymentOperations
- PaginatedPayments
- PaginatedPayoutItems
- Payment
- PaymentAddresses
- PaymentBalances
- PaymentOperation
- PaymentOperationInputs
- PaymentOperationResponse
- PaymentRefundRequest
- PaymentSettleRequest
- Payout
- PayoutItem
- PayoutItemInputs
- RskAddress
- RskBalance
- ValidateCheckoutRequest
- ValidateCheckoutResponse
- WalletBalance
Limitations
Recommendation
It's recommended to create an instance of ApiClient
per thread in a multi-threaded environment to avoid any potential issues.
License
Copyright 2020 Bleumi, Inc.
Code licensed under the MIT License.