GithubHelp home page GithubHelp logo

sdk-java's Introduction

LiqPay.com API SDK for Java

Build Status

LiqPay.com is payment system associated with PrivatBank.

API Documentation in Russian and in English

WARNING: This SDK is not thread safe. We would be very appreciated for your contribution.

Installation and usage

This library is published at BinTray and can be added as Maven dependency.

Use as Maven dependency

Add to your pom.xml repository and dependency:

<repositories>
    <repository>
        <id>bintray-stokito-maven</id>
        <name>stokito-maven</name>
        <url>https://api.bintray.com/maven/stokito/maven/liqpay-sdk</url>
    </repository>
</repositories>

<dependency>
    <groupId>com.liqpay</groupId>
    <artifactId>liqpay-sdk</artifactId>
    <version>0.6</version>
</dependency>

Then you can use it as described in API documentation:

// Creation of the HTML-form
Map params = new HashMap();
params.put("amount", "1.50");
params.put("currency", "USD");
params.put("description", "description text");
params.put("order_id", "order_id_1");	
params.put("sandbox", "1"); // enable the testing environment and card will NOT charged. If not set will be used property isCnbSandbox() 
LiqPay liqpay = new LiqPay(PUBLIC_KEY, PRIVATE_KEY);
String html = liqpay.cnb_form(params);		
System.out.println(html);

It is recommended to use some Inversion of Control (IoC) container, like Spring IoC or PicoContainer.

Use proxy

To use LiqPay with proxy you can initialize it like:

import java.net.InetSocketAddress;
import java.net.Proxy;

...

    Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("proxy.host.com", 8080);
    LiqPay liqpay = new LiqPay(PUBLIC_KEY, PRIVATE_KEY, proxy, "proxyLogin", "some proxy password");

Grails v2.x

In grails-app/conf/BuildConfig.groovy you should add repository and dependency:

grails.project.dependency.resolution = {
...
    repositories {
        grailsPlugins()
        ...
        mavenRepo 'http://dl.bintray.com/stokito/maven'
    }
    dependencies {
        ...
        compile 'com.liqpay:liqpay-sdk:0.6'
    }
...
}

Then you can add LiqPay bean in grails-app/conf/spring/resources.groovy:

import com.liqpay.LiqPay

// Place your Spring DSL code here
beans = {
    liqpay(LiqPay, '${com.liqpay.publicKey}', '${com.liqpay.privateKey}') {
        cnbSandbox = false // set true to enable the testing environment. Card is not charged
    }
}

It will create bean with name liqpay of class com.liqpay.LiqPay and pass to it's constructor public and private keys that defined in grails-app/conf/Config.groovy like this:

com.liqpay.publicKey = 'i31219995456'
com.liqpay.privateKey = '5czJZHmsjNJUiV0tqtBvPVaPJNZDyuoAIIYni68G'

Then you can use this liqpay bean with dependency injection in your services or controllers:

class UserController {
    LiqPayApi liqpay // this will inject liqpay bean defined in resources.groovy  

    def balanceReplenishment() {
        Map<String, String> params = [
                "amount"     : '30.5',
                "currency"   : 'UAH',
                "description": 'Balance replenishmenton on example.com',
                "order_id"   : "1",
                'result_url' : g.createLink(action: 'paymentResult', absolute: true).toString()]
        String button = liqpay.cnb_form(params);
        [button: button]
    }
}

And inside grails-app/views/user/balanceReplenishment.gsp you can output this button like this:

    <div>
        ${raw(button)}
    </div>

Changelog

All releases

v0.1 First Mavenized version.

Source

  • Just reformatted code.
  • Created some basic tests.
  • API wasn't changed and this release can't broke compilation.

v0.2 Improved tests

Source

  • Refactoring
  • More tests coverage
  • Parameter params of methods cnb_form() and api() now can by any Map, not only HashMap.
  • API wasn't changed and this release can't broke compilation.

v0.3 Some methods deprecated

Source

  • Introduced API interface LiqPayApi
  • Deprecated fields that should be constant host_checkout and liqpayApiUrl. They was replaced with private constants.
  • Deprecated constructor LiqPay(String publicKey, String privateKey, String liqpayApiUrl) because liqpayApiUrl is constant and can't be rewritten.
  • Deprecated method cnb_signature because signature is already calculated inside cnb_form(Map).
  • Deprecated shorthand method setProxy(String host, Integer port), you should use full setProxy(String host, Integer port, Proxy.Type) instead. In next release v0.5 it will be deprecated too, and you should construct Proxy instance yourself.
  • API wasn't changed and this release can't broke compilation.

v0.4 Last release that API compatible with old lib

Source JAR dependency

  • This release is recommended if you used original old lib since it shouldn't break compilation.
  • Params version and public_key are always set inside cnb_form() and api() methods.
  • Old version of cnb_form() accepted public_key parameter that can be differ from publicKeyinitialized in constructor.
  • Methods cnb_form() and api() doesn't add public_key and version to instance of params method. I.e. now you can pass unmodifable map and reuse it without side effects.
  • API wasn't changed and this release can't broke compilation.
  • Dependency was released in http://dl.bintray.com/stokito/maven repository and you can easily add it to your Maven project.

v0.5 Removed deprecated methods

Source JAR dependency

  • Removed deprecated method cnb_signature because signature is already calculated inside cnb_form(Map).
  • Method api() now returns general Map instead of concrete HashMap.
  • Removed deprecated fields liqpayApiUrl and host_checkout. They replaced with constants LiqPayApi.LIQPAY_API_URL and LiqPayApi.LIQPAY_API_CHECKOUT_URL.
  • Introduced two new properties proxyLogin and proxyPassword that should be used instead of deprecated method setProxyUser(login, password).
  • Introduced method setProxy(Proxy) that should be used instead of shorthand and deprecated setProxy(host, port, Proxy.Type).
  • API was changed in this release and can broke compilation.

v0.6 Enhanced usage

Source JAR dependency

  • Created constructor LiqPay(String publicKey, String privateKey, Proxy proxy, String proxyLogin, String proxyPassword) that initialize API with proxy
  • Defined new property isCnbSanbox() that can globally set sandbox param in cnb_form() instead of specifying it always in params

sdk-java's People

Contributors

rpuch avatar shurick-k avatar stokito avatar viplifes avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.