Skip to content

Latest commit

 

History

History
480 lines (324 loc) · 17.1 KB

File metadata and controls

480 lines (324 loc) · 17.1 KB

chainside

developed with ❤️ by chainside

Introduction

This project is the official SDK library for the integration with the Chainside Pay Platform.

Installation

Follow these steps to install the SDK library into your system. You can install it either using the maven-dependency-plugin, configuring the pom.xml or configuring the gradle.build (for gradle users)

With Maven plugin:

mvn org.apache.maven.plugins:maven-dependency-plugin:2.1:get 
-Dartifact=net.chainside.webpossdk:webpos-sdk-java:1.0.0 
-DrepoUrl=http://central.maven.org/maven2/

In pom.xml:

<dependency>
            <groupId>net.chainside.webpossdk</groupId>
            <artifactId>webpos-sdk-java</artifactId>
            <version>1.0.0</version>
</dependency>

In gradle.build:

compile 'net.chainside.webpossdk:webpos-sdk-java:1.0.0'

Structure

The following sections will describe the high level structure of the SDK library.

Configuration

In order to be able to configure your SDK client you have to set some configuration parameters. Here is the list of the configuration parameters used by the library:

Parameter Type Required Default Description
mode string Yes live The SDK mode, can be sandbox or live
clientId string Yes null Your WebPos client id
secret string Yes null Your WebPos secret

Client

The Library exposes a client object which is instantiated with the system configuration and provides an high-level interface to send requests. Client's instances take care of compiling and sending http request and parse responses into SdkObject instances.

Objects

The library defines an SdkObject class which is extended by actual objects which represent Chainside-Pay API requests and response bodies. Every json object defined in the API has a corresponding SdkObject class which is either the input of a client instance method (for creation) or returned (for reading)

Callbacks

Callbacks are requests sent by the server to your application in order to notify about some events. Every callback is sent only to HTTPS webhooks and will be securely signed by the server in order to be verified.

Usage

The following sections will describe how to use the SDK library and all the detail needed to integrate your business with Chainside Pay.

Instantiate and use the client

In order to communicate with our backend first you need to instantiate the client:

import net.webpossdk.api.ChainsideClient;
import net.webpossdk.object.CallbackList;

HashMap<String, Object> config = new HashMap<>();
config.put("mode", "live");
config.put("clientId", "{webpos_client_id}");
config.put("secret", "{webpos_secret}");

PaymentOrderCreation paymentOrder = new PaymentOrderCreation();
paymentOrder.setAmount("10.00");
paymentOrder.setReference("#1");
paymentOrder.setDetails("#1 details");
paymentOrder.setRequiredConfirmations(3);
PaymentOrderCreationResponse resp = client.createPaymentOrder(paymentOrder);

String btcAddress = resp.address // will output the payment order address

Once the client is instantiated and configured, you can use the following methods to send requests:

Method
clientCredentialsLogin(clientcredentials:ClientCredentials) : ClientCredentialsLoginResponse
getCallbacks(paymentOrderUuid:uuid) : CallbackList
paymentReset(paymentOrderUuid:uuid) : PaymentOrderRetrieval
paymentUpdate(paymentOrderUuid:uuid,paymentupdateobject:PaymentUpdateObject) : None
deletePaymentOrder(paymentOrderUuid:uuid) : PaymentOrderDeletionResponse
getPaymentOrder(paymentOrderUuid:uuid) : PaymentOrderRetrieval
getWebPosPayments(posUuid:uuid,status:string) : PaymentOrderList
createPaymentOrder(paymentordercreation:PaymentOrderCreation) : PaymentOrderCreationResponse

Objects

ClientCredentials

Data required to perform a confidential client login

Attributes

Attribute Type Required Description
grant_type string Yes Oauth2 Authorization's grant type
scope string Yes Oauth2 scope of the client's authorization

ClientCredentialsLoginResponse

Response data for a login performed by a confidential client.

Attributes

Attribute Type Required Description
scope string No Authorization's scope
token_type string Yes Token's type
id_token string Yes Jwt Token containing identity's informations
access_token string Yes User's access token
expires_in integer Yes Token's expiration time

CallbackList

Callback list object

Attributes

Attribute Type Required Description
callbacks [Callback] Yes Valid payment transitions callbacks

Callback

Callback Retrieval object

Attributes

Attribute Type Required Description
name string Yes Namespace of a callback sent after the related payment status' transition

PaymentOrderRetrieval

Payment order retrieval data

Attributes

Attribute Type Required Description
created_at string Yes Creation date of the payment order
uuid string Yes UUID of the payment order
address string Yes Bitcoin address of the payment order
currency CurrencyRetrieval Yes Fiat currency of the payment order
reference string Yes Business' reference for the payment order
rate RateRetrieval Yes Crypto/Fiat rate of the payment order
expires_in integer Yes Expiration time of the payment order
expiration_time string Yes Expiration date of the payment order
amount string Yes Fiat's amount of the payment order
chargeback_date string Yes Time at which either the payment order has been fully paid or is expired
resolved_at string Yes Time at which either the payment order has been fully paid or is expired
created_by PaymentOrderCreator Yes Data of the pos which created the payment order
callback_url string Yes The URL contacted to send callbacks related to payment status changes
required_confirmations integer Yes Required confirmations for transactions paying the payment order
transactions [Transaction] Yes Transactions paying the payment order
dispute_start_date string Yes Time at which either the payment order has been fully paid or is expired
details string Yes Payment order's details
redirect_url string Yes URL where to redirect the user to perform the payment
uri string Yes Bitcoin uri
btc_amount integer Yes Bitcoin amount of the payment order
state PaymentOrderState Yes Current payment state of the payment order

CurrencyRetrieval

Currency Data

Attributes

Attribute Type Required Description
type string Yes Currency's type (fiat/crypto)
name string Yes Name of the currency
uuid string Yes UUID of the currency

RateRetrieval

Rate Data

Attributes

Attribute Type Required Description
source string Yes Exchange providing the rate
created_at string Yes Creation's date of the rate
value string Yes Value of the rate

PaymentOrderCreator

Data of payment order's creator

Attributes

Attribute Type Required Description
type string Yes Payment order creator's type
name string Yes Payment order creator's name
deposit_account DepositAccountLite Yes Deposit account associated to the payment order's creator
uuid string Yes Payment order creator's uuid

DepositAccountLite

Deposit account lite object when sent nested in other api objects

Attributes

Attribute Type Required Description
type string Yes Deposit account's type
name string Yes Deposit account's name
uuid string Yes Deposit account's uuid

Transaction

Bitcoin transaction paying a payment order

Attributes

Attribute Type Required Description
status string Yes Transaction's status
created_at string Yes
normalized_txid string Yes Transaction's normalized id
outs [Out] Yes Transaction's outputs
txid string Yes Transaction's id
outs_sum integer Yes Paying amount of the transaction
blockchain_status string Yes Transaction's internal status

Out

Transaction's output

Attributes

Attribute Type Required Description
amount integer Yes Output's amount
n integer Yes Transaction output's index

PaymentOrderState

Data describing the current state of a payment order

Attributes

Attribute Type Required Description
status string Yes Payment order's status
paid PaidStatus Yes Payment order's paid amount
in_confirmation PaidStatus Yes Payment order's paid but unconfirmed amount
blockchain_status string Yes Payment order's internal status
unpaid PaidStatus Yes Payment order's unpaid amount

PaidStatus

Cryto and fiat paid amounts

Attributes

Attribute Type Required Description
fiat string Yes Fiat Amount
crypto integer Yes Cryto Amount

PaymentUpdateObject

Callback's trigger request body

Attributes

Attribute Type Required Description
callback string Yes Name of the callback to be sent

PaymentOrderDeletionResponse

Payment order deletion response

Attributes

Attribute Type Required Description
cancel_url string Yes The URL where the user is redirected upon payment order expiration/cancellation

PaymentOrderList

List of Business' payment orders

Attributes

Attribute Type Required Description
paymentorders [PaymentOrderRetrieval] Yes Business' payment orders

PaymentOrderCreation

Data required to create a new payment order

Attributes

Attribute Type Required Description
amount string Yes Payment order's fiat amount
cancel_url string No The URL where the user is redirected upon successful payment order expiration/cancellation
callback_url string No The URL contacted to send callbacks related to payment status changes
details string Yes Payment order's details
reference string No Business' reference of the payment order
required_confirmations integer No Required confirmations for transactions paying the payment order
continue_url string No The URL where the user is redirected upon successful payment

PaymentOrderCreationResponse

Response data for a payment order creation request

Attributes

Attribute Type Required Description
amount integer Yes Crypto amount of the payment order
expires_in integer Yes Expiration's time of the payment order
uuid string Yes UUID of the payment order
address string Yes Bitcoin address of the payment order
rate RateRetrieval Yes Crypto/Fiat rate of the payment order
redirect_url string Yes URL where to redirect the user to perform the payment
uri string Yes Bitcoin uri according to BIP 21 (https://github.com/bitcoin/bips/blob/master/bip-0021.mediawiki)
expiration_time string Yes Expiration's date of the payment order

CallbackPaymentOrder

Payment order retrieval data

Attributes

Attribute Type Required Description
cancel_url string Yes The URL where the user is redirected upon payment order expiration/cancellation
created_at string Yes Creation date of the payment order
uuid string Yes UUID of the payment order
address string Yes Bitcoin address of the payment order
currency CurrencyRetrieval Yes Fiat currency of the payment order
reference string Yes Business' reference for the payment order
rate RateRetrieval Yes Crypto/Fiat rate of the payment order
expires_in integer Yes Expiration time of the payment order
expiration_time string Yes Expiration date of the payment order
amount string Yes Fiat's amount of the payment order
chargeback_date string Yes Time at which either the payment order has been fully paid or is expired
resolved_at string Yes Time at which either the payment order has been fully paid or is expired
created_by PaymentOrderCreator Yes Data of the pos which created the payment order
callback_url string Yes The URL contacted to send callbacks related to payment status changes
required_confirmations integer Yes Required confirmations for transactions paying the payment order
continue_url string Yes The URL where the user is redirected upon successful payment
transactions [Transaction] Yes Transactions paying the payment order
dispute_start_date string Yes Time at which either the payment order has been fully paid or is expired
details string Yes Payment order's details
redirect_url string Yes URL where to redirect the user to perform the payment
uri string Yes Bitcoin uri
btc_amount integer Yes Bitcoin amount of the payment order
state PaymentOrderState Yes Current payment state of the payment order

Callbacks

Chainside will send callbacks if some event is triggered regarding one of your assets registered on the Business Panel. Our server will send a request to your webhooks that you need to parse and verify. You can do this using this SDK library in the following way:

HashMap<String, Object> config = new HashMap<>();
config.put("mode", "live");
config.put("clientId", "{webpos_client_id}");
config.put("secret", "{webpos_secret}");

ChainsideApiContext ctx = new ChainsideApiContext(config);
ChainsideCallbackHandler handler = new ChainsideCallbackHandler(ctx);

/* Retrieve http request and raw body in as an array of bytes
HashMap<String, String> headers = request.getHeaders();
byte[] rawBody = request.getRawBody();
*/

SdkObject parsedObject = handler.parse(headers, rawBody);

Callback structure

Parameter Type Required Description
object CallbackPaymentOrder Yes
object_type string Yes Type of the object sent in the callback
created_at string Yes Date in which the callback was sent
event string Yes Event which triggered the callback

Triggered events

Event Object Class
payment.completed CallbackPaymentOrder
payment.dispute.start CallbackPaymentOrder
payment.overpaid CallbackPaymentOrder
payment.cancelled CallbackPaymentOrder
payment.dispute.end CallbackPaymentOrder
payment.expired CallbackPaymentOrder
payment.chargeback CallbackPaymentOrder

Contributing

In order to maintain consistency between our backend and our SDKs, contributing through pull requests is highly discouraged. Consider posting an issue if you need to signal any problem with this library.

Security Issues

In case of a discovery of an actual or potential security issue please contact us at info@chainside.net