liqpay.ua is payment system associated with PrivatBank.
API Documentation in Ukrainian and in English
WARNING: This SDK is not thread safe. We would be very appreciated for your contribution.
This library is published at GitHub and can be added as Maven dependency.
Add to your pom.xml repository and dependency:
<repositories>
<repository>
<id>repository</id>
<url>https://github.com/liqpay/sdk-java/raw/repository</url>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</snapshots>
</repository>
</repositories>
<dependency>
<groupId>com.liqpay</groupId>
<artifactId>liqpay-sdk</artifactId>
<version>0.8-SNAPSHOT</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.
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");In grails-app/conf/BuildConfig.groovy you should add repository and dependency:
grails.project.dependency.resolution = {
...
repositories {
grailsPlugins()
...
mavenRepo 'https://github.com/liqpay/sdk-java/raw/repository'
}
dependencies {
...
compile 'com.liqpay:liqpay-sdk:0.8-SNAPSHOT'
}
...
}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>- Just reformatted code.
- Created some basic tests.
- API wasn't changed and this release can't broke compilation.
- Refactoring
- More tests coverage
- Parameter
paramsof methodscnb_form()andapi()now can by anyMap, not onlyHashMap. - API wasn't changed and this release can't broke compilation.
- Introduced API interface
LiqPayApi - Deprecated fields that should be constant
host_checkoutandliqpayApiUrl. They was replaced with private constants. - Deprecated constructor
LiqPay(String publicKey, String privateKey, String liqpayApiUrl)becauseliqpayApiUrlis constant and can't be rewritten. - Deprecated method
cnb_signaturebecause signature is already calculated insidecnb_form(Map). - Deprecated shorthand method
setProxy(String host, Integer port), you should use fullsetProxy(String host, Integer port, Proxy.Type)instead. In next release v0.5 it will be deprecated too, and you should constructProxyinstance yourself. - API wasn't changed and this release can't broke compilation.
- This release is recommended if you used original old lib since it shouldn't break compilation.
- Params
versionandpublic_keyare always set insidecnb_form()andapi()methods. - Old version of
cnb_form()acceptedpublic_keyparameter that can be differ frompublicKeyinitialized in constructor. - Methods
cnb_form()andapi()doesn't addpublic_keyandversionto instance ofparamsmethod. 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.
- Removed deprecated method
cnb_signaturebecause signature is already calculated insidecnb_form(Map). - Method
api()now returns generalMapinstead of concreteHashMap. - Removed deprecated fields
liqpayApiUrlandhost_checkout. They replaced with constantsLiqPayApi.LIQPAY_API_URLandLiqPayApi.LIQPAY_API_CHECKOUT_URL. - Introduced two new properties
proxyLoginandproxyPasswordthat should be used instead of deprecated methodsetProxyUser(login, password). - Introduced method
setProxy(Proxy)that should be used instead of shorthand and deprecatedsetProxy(host, port, Proxy.Type). - API was changed in this release and can broke compilation.
- 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 setsandboxparam incnb_form()instead of specifying it always inparams
- Changed url form liqpay.com to liqpay.ua
- Changed cnb_form method. New form.
