Paymentwall is the leading digital payments platform for globally monetizing digital goods and services. Paymentwall assists game publishers, dating sites, rewards sites, SaaS companies and many other verticals to monetize their digital content and services. Merchants can plugin Paymentwall's API to accept payments from over 100 different methods including credit cards, debit cards, bank transfers, SMS/Mobile payments, prepaid cards, eWallets, landline payments and others.
To sign up for a Paymentwall Merchant Account, click here.
This library allows developers to use Paymentwall APIs (Virtual Currency, Digital Goods featuring recurring billing, and Virtual Cart).
To use Paymentwall, all you need to do is to sign up for a Paymentwall Merchant Account so you can setup an Application designed for your site. To open your merchant account and set up an application, you can sign up here.
To install the library in your environment, you can download the ZIP archive, unzip it and place into your project.
Alternatively, you can run:
git clone git://github.com/paymentwall/paymentwall-java.git
Then use a code samples below.
<dependencies>
<dependency>
<groupId>com.paymentwall</groupId>
<artifactId>paymentwall-java</artifactId>
<version>2.0.2</version>
</dependency>
</dependencies>
import com.paymentwall.java.*;
Config.getInstance().setLocalApiType(Config.API_GOODS);
Config.getInstance().setPublicKey("YOUR_APPLICATION_KEY");
Config.getInstance().setPrivateKey("YOUR_SECRET_KEY");
The widget is a payment page hosted by Paymentwall that embeds the entire payment flow: selecting the payment method, completing the billing details, and providing customer support via the Help section. You can redirect the users to this page or embed it via iframe. Below is an example that renders an iframe with Paymentwall Widget.
WidgetBuilder widgetBuilder = new WidgetBuilder("user12345", "fp");
widgetBuilder.setProduct(
new ProductBuilder("product301") {{
setAmount(0.99);
setCurrencyCode("USD");
setName("100 coins");
setProductType(Product.TYPE_FIXED);
}}.build()
);
widgetBuilder.setExtraParams(
new LinkedHashMap<String, String>() {{
put("email", "user@hostname.com");
}}
);
Widget w = widgetBuilder.build();
return w.getHtmlCode();
The Pingback is a webhook notifying about a payment being made. Pingbacks are sent via HTTP/HTTPS to your servers. To process pingbacks use the following code:
Pingback pingback = new Pingback(request.getParameterMap(), request.getRemoteAddr());
if (pingback.validate(true)) {
String goods = pingback.getProductId();
String userId = pingback.getUserId();
if (pingback.isDeliverable()) {
// deliver Product to user with userId
} else if (pingback.isCancelable()) {
// withdraw Product from user with userId
}
return "OK";
} else
return pingback.getErrorSummary();
import com.paymentwall.java.*;
Config.getInstance().setLocalApiType(Config.API_VC);
Config.getInstance().setPublicKey("YOUR_APPLICATION_KEY");
Config.getInstance().setPrivateKey("YOUR_SECRET_KEY");
WidgetBuilder widgetBuilder = new WidgetBuilder("user12345","p1_1");
widgetBuilder.setExtraParams(
new LinkedHashMap<String, String>() {{
put("email", "user@hostname.com");
}}
);
Widget w = widgetBuilder.build();
return w.getHtmlCode();
Pingback pingback = new Pingback(request.getParameterMap(), request.getRemoteAddr());
if (pingback.validate(true)) {
Integer currency = pingback.getVirtualCurrencyAmount();
String userId = pingback.getUserId();
if (pingback.isDeliverable()) {
// deliver Product to user with userId
} else if (pingback.isCancelable()) {
// withdraw Product from user with userId
}
return "OK";
} else
return pingback.getErrorSummary();
import com.paymentwall.java.*;
Config.getInstance().setLocalApiType(Config.API_CART);
Config.getInstance().setPublicKey("YOUR_APPLICATION_KEY");
Config.getInstance().setPrivateKey("YOUR_SECRET_KEY");
You have to set up your products in merchant area for exact regions first in order to use widget call example code below.
WidgetBuilder widgetBuilder = new WidgetBuilder("user12345","p1_1");
widgetBuilder.setExtraParams(
new LinkedHashMap<String, String>() {{
put("email", "user@hostname.com");
}}
);
widgetBuilder.setProducts(new ArrayList<Product>(){{
add(
new ProductBuilder("product1") {{
setAmount(9.99);
setCurrencyCode("USD");
}}.build()
);
add(
new ProductBuilder("product2"){{
setAmount(1);
setCurrencyCode("USD");
}}.build()
);
}});
Widget w = widgetBuilder.build();
return w.getHtmlCode();
Pingback pingback = new Pingback(request.getParameterMap(), request.getRemoteAddr());
if (pingback.validate(true)) {
ArrayList<Product> goods = pingback.getProducts();
String userId = pingback.getUserId();
if (pingback.isDeliverable()) {
// deliver Product to user with userId
} else if (pingback.isCancelable()) {
// withdraw Product from user with userId
}
return "OK";
} else
return pingback.getErrorSummary();
Config.getInstance().setPublicKey("YOUR_APPLICATION_KEY");
Config.getInstance().setPrivateKey("YOUR_SECRET_KEY");
OneTimeToken token = new OneTimeToken();
token = (OneTimeToken) token.create(new LinkedHashMap<String, String>(){{
put("public_key", Config.getInstance().getPublicKey());
put("card[number]", "4242424242424242");
put("card[exp_month]", "11");
put("card[exp_year]", "19");
put("card[cvv]", "123");
}});
return token.getToken();
Charge charge = new Charge();
charge = (Charge)charge.create(new HashMap<String, String>(){{
put("token", token.getToken());
put("email", "email@example.com");
put("currency", "USD");
put("amount", "10.99");
// if you receive one-time token and make charge on same server, then use
// put("fingerprint", request.getParameter("fingerprint"));
// instead of next 2 lines
put("browser_domain", request.getHeader("VIA"));
put("browser_ip", request.getRemoteAddr());
put("description", "description");
}});
JSONObject response = charge.getPublicData();
if (charge.isSuccessful())
if (charge.isCaptured()) {
//deliver a product
} else if (charge.isUnderReview()) {
//decide on risk charge
}
return response.toString(); // need for JS communication
Charge charge = new Charge("CHARGE_ID");
charge = (Charge)charge.refund();
return charge.isRefunded();
Subscription subscription = new Subscription();
subscription = (Subscription) subscription.create( new HashMap<String, String>() {{
put("token" , token.getToken());
put("email", "email@example.com");
put("currency", "USD");
put("amount", "10.99");
// if you receive one-time token and make charge on same server, then use
// put("fingerprint", request.getParameter("fingerprint"));
// instead of next 2 lines
put("browser_domain", request.getHeader("VIA"));
put("browser_ip", request.getRemoteAddr());
put("description", "description");
put("plan", "goodsid");
put("period", "week");
put("period_duration", "2");
}});
return subscription.get("id");
Subscription subscription = new Subscription("SUBSCRIPTION_ID");
subscription = (Subscription)(subscription.cancel());
return subscription.isActive();
Signature.Widget widgetSignatureModel = new Signature.Widget();
return widgetSignatureModel.calculate(
new LinkedHashMap<String, ArrayList<String>>(), // widget params
2 // signature version
);
Signature.Pingback pingbackSignatureModel = new Signature.Pingback();
return pingbackSignatureModel.calculate(
new LinkedHashMap<String, ArrayList<String>>(), // widget params
1 // signature version
);