For any question, we are one click away

Contact us

Server Side SDK general module

Overview

Server Side SDK is API wrapper implemented on Java. If you need SDK on another language, please contact us.

Download SDK files

Installation

Manually deploy artifacts to your dependency management system.
Examples for local maven repository:

  1. sdk.pom

    mvn install:install-file -Dfile="sdk.pom" -DpomFile="sdk.pom"
  2. core.jar using core.pom

    mvn install:install-file -Dfile="core.jar" -DpomFile="core.pom"
  3. api-client.jar using api-client.pom

    mvn install:install-file -Dfile="api-client.jar" -DpomFile="api-client.pom"

Requirements

Gradle users

Add this dependency to your project's build file:

implementation "net.payrdr.integrations:api-client:1.0.0"

Maven users

Add this dependency to your project's POM:

<dependency>
    <groupId>net.payrdr.integrations</groupId>
    <artifactId>api-client</artifactId>
    <version>1.0-SNAPSHOT</version>
</dependency>

Usage

Basic usage with minimal configuration:

import net.payrdr.integrations.sdk.apiclient.regiserOrder.RegisterOrderResponse;
import net.payrdr.integrations.sdk.apiclient.regiserOrder.RegisterOrderRequest;
import net.payrdr.integrations.sdk.apiclient.ApiClient;

public class ApiExample {

   public static void main(String[] args) {
       ApiClient client = new ApiClient.Builder()
              .username(username)
              .password(password)
              .baseUrl(baseUrl)
              .build();

      RegisterOrderRequest request = RegisterOrderRequest.builder()
              .setAmount(10000)
              .setReturnUrl("https://mybestmerchantreturnurl.com")
              .build();

      RegisterOrderResponse response = client.registerOrder(request);
   }
}

Configuration

Base URL

Static URL prefix for every API method.
Example: https://uat.dskbank.bg/payment/rest/register.do . Here:

Request authentication customization

Configured authenticator would be used by default in API client.

Prebuilt authentication options:

If built-in authentication methods are not enough, feel free to extend net.payrdr.integrations.sdk.apiclient.ApiRequestAuthenticator and provide it to the builder via authenticator(ApiRequestAuthenticator) method.

Enabling request signature

To have a possibility to sign requests, first contact technical support service to enable signatures for you. Then upload a certificate using Merchant Portal.

You need to provide a key pair to ApiClient to generate a hash and a signature using your secret key in the process of sending a request.

Private RSA key can be configured in two ways:

Signature algorithm

Default request signature algorithm is SHA256WithRSA. Default net.payrdr.integrations.sdk.core.security.SHA256WithRSASigner would be initialized using provided java.security.PrivateKey.

During request execution, the request body would be transformed to hash (X-Hash) and the signature value (X-Signature) and passed in the request headers.

X-Hash: GDrobAlCcpdOOlVuqra7Oogl/4s3vToGOXGpf3t/wJ0= 
    X-Signature: TJrm6jYAf2ssp/iYoDb3B+nuPqQ572oe/3a2RQ4oG2BFbmeRcoiITvR6tybNsbRHvRRlJys/2xFBW9ilee9GCN9WwYJ9h/MDyUEktj6NLZOztBAWi+7S8LDaiEWd+MUdTqe0hdiqo/lY2uIlEMTtkqTB7LsbEhrJ6NhJdpSxrstAnpyGIrGfldt0Vz+gz+YQ5XXrwhD6HyGShqV+tXzxcMdezWJJJ8vH5C0s  4jij2PuoauUSHkTrSc4vIJl/TPMliLJNsC5KCXka4/1hSr0exawFBekRldFnv5YvFakWJUN3kEc8  w3uauzTDh+CG0/Vxs/3gNun7e9ik9kCpwdiSMw==

No additional configuration is needed to use default SHA256WithRSASigner.

Custom algorithm can be implemented using net.payrdr.integrations.sdk.core.security.RequestSigner interface.
Pass your implementation to ApiClient.Builder.requestSigner(RequestSigner) method:

import net.payrdr.integrations.sdk.apiclient.ApiClient;

    public class ApiExample {

        public static void main(String[] args) {
            ApiClient client = new ApiClient.Builder()
                    .username(username)
                    .password(password)
                    .baseUrl(baseUrl)
                    .requestSigner(new RequestSigner() {
                        @Override
                        public void init(PrivateKey privateKey) {
                            //do some magic with provided private key
                        }

                        @Override
                        public void sign(HttpRequest request) {
                            // Here we can customize request signature. Key would be loaded by KeyProvider
                        }
                    })
                    .build();
        }
    }

HTTP client customization

By default, built-in HttpClient wraps HttpsUrlConnection.

Customization handles:
Custom HTTP client implementation

HTTP client can be replaced with your own implementation using net.payrdr.integrations.sdk.core.http.(HttpClient,HttpRequest,HttpResponse) interfaces:

import net.payrdr.integrations.sdk.apiclient.ApiClient;
    import net.payrdr.integrations.sdk.core.http.HttpClient;
    import net.payrdr.integrations.sdk.core.http.HttpRequest;
    import net.payrdr.integrations.sdk.core.http.HttpResponse;

    public class ApiExample {

       public static void main(String[] args) {
            ApiClient client = new ApiClient.Builder()
                .username(username)
                .password(password)
                .baseUrl(baseUrl)
                .httpClient(new HttpClient() {
                        @Override
                        public HttpResponse execute(HttpRequest request) {
                            // do some magic and transform HttpRequest into HttpResponse
                            return null;
                        }

                        @Override
                        public HttpRequest requestInstance() {
                            // return some implementation of HttpRequest.
                            return null;
                        }
                })
                .build();
       }
    }

Serialization/deserialization customization

Content-types supported by default for request serialization:

Cotent-types supported by default for response deserialization:

Customization

Custom serializer can be implemented using net.payrdr.integrations.sdk.apiclient.serialization.RequestSerializer and net.payrdr.integrations.sdk.apiclient.serialization.ResponseDeserializer interfaces.

Implementations can be registered via ApiClient.Builder.registerSerializer(RequestSerializer) and ApiClient.Builder.registerDeserializer(ResponseDeserializer) methods.

import net.payrdr.integrations.sdk.apiclient.ApiClient;

    public class ApiExample {

        public static void main(String[] args) {
            ApiClient client = new ApiClient.Builder()
                    .username(username)
                    .password(password)
                    .baseUrl(baseUrl)
                    .registerSerializer(new RequestSerializer() {

                        @Override
                        public ContentType getContentType() {
                            //register new ContentType in cache
                            return ContentType.of("custom/content-type");
                        }

                        @Override
                        public String serialize(ApiRequest request) {
                            return "MY_CUSTOM_SERIALIZATION";
                        }
                    })
                    .registerDeserializer(new ResponseDeserializer() {

                        @Override
                        public ContentType getContentType() {
                            //use registered ContentType from cache
                            return ContentType.of("custom/content-type");
                        }

                        @Override
                        public <T extends ApiResponse> T deserialize(String responseBody, Class<T> responseType) {
                            //DO THE DESERIALIZATION MAGIC IN HERE
                            return (T) new ApiResponse() {};
                        }
                    })
                    .build();
        }
    }

Also you can customize Gson library configurations using ApiClient.Builder.gson(Gson) method:

import net.payrdr.integrations.sdk.apiclient.ApiClient;

    public class ApiExample {

        public static void main(String[] args) {
            ApiClient client = new ApiClient.Builder()
                    .username(username)
                    .password(password)
                    .baseUrl(baseUrl)
                    .gson(new GsonBuilder()
                        .setFieldNamingPolicy(FieldNamingPolicy.IDENTITY)
                        .setDateFormat("yyyy-MM-dd'T'HH:mm:ss")
                        .create())
                    .build();
        }
    }

Exceptions

All exceptions are RuntimeException and can be of the following types:

Building new API methods

Can be done by simple extending of net.payrdr.integrations.sdk.apiclient(ApiRequest,ApiResponse) classes.

Abstract methods of ApiRequest:

Default methods of ApiRequest:

Categories:
eCommerce SDK
Categories
Search results