Create Linkpay Page
Learn how to create and use Linkpay Page resource with Java SDK
Overview
To integrate Linkpay
using Java, you must create a Linkpay
object and initialize it in Payment API using the Unzer
facade.
As a result you receive a unique ID of the page and a redirectURL
. Redirect customer URL to redirectUrl
value to proceed a payment:
Initialize a Linkpay Page
A Linkpay Page needs at least amount
, currency
and action
to be initialized.
Optional parameter for the API request can be added to a Linkpay
instance using the setter function of the given property as demonstrated in the example below.
For a complete list of request parameters, see the API reference.
package com.unzer.payment.integration.paymenttypes;
import com.unzer.payment.Linkpay;
import com.unzer.payment.Paypage;
import com.unzer.payment.Unzer;
import java.math.BigDecimal;
import java.net.URL;
import java.util.Currency;
import java.util.Map;
class Example {
void run() throws Exception {
Unzer unzer = new Unzer("s-priv-xxxxxxxxxx");
Linkpay page = new Linkpay();
// Set amount to be charged
page.setAmount(BigDecimal.valueOf(100.0));
// Choose between charge or authorize transaction type
page.setAction(Paypage.Action.AUTHORIZE); // or Paypage.Action.CHARGE
// Set optional parameters
page.setCurrency(Currency.getInstance("EUR"));
page.setReturnUrl(new URL("https://your.return.url"));
page.setLogoImage("https://your.logo.image.url");
page.setFullPageImage("https://your.logo.image.url");
page.setShopName("My Test Shop");
page.setShopDescription("We are selling goods.");
page.setTagline("We are selling goods.");
page.setOrderId("YourShopOrderId");
page.setTermsAndConditionUrl(new URL("https://your.tac.url"));
page.setPrivacyPolicyUrl(new URL("https://your.privacy.policy.url"));
page.setImprintUrl(new URL("https://your.imprint.url"));
page.setHelpUrl(new URL("https://your.help.url"));
page.setContactUrl(new URL("https://your.contact.url"));
page.setInvoiceId("YourShopInvoiceId");
page.setCard3ds("true");
// Add styling
page.setCss(Map.of(
"shopDescription", "color: purple",
"header", "background-color: red",
"helpUrl", "color: blue",
"contactUrl", "color: green"
));
// Send Linkpay Page to Unzer
page = unzer.linkpay(page);
// Provide redirect URL to customer.
String redirectUrl = page.getRedirectUrl();
// After customer submits the payment, they will be redirected to the returnUrl
// Store paymentId to be able to fetch the payment later
String paymentId = page.getPaymentId();
}
}
Fetch Linkpay resource
Payment Gateway allows to retrieve existing Linkpay resource by ID.
package com.unzer.payment.integration.paymenttypes;
import com.unzer.payment.Linkpay;
import com.unzer.payment.Unzer;
class Example {
void run() throws Exception {
Unzer unzer = new Unzer("s-priv-xxxxxxxxxx");
String pageId = "s-ppg-xxxxxxx";
Linkpay page = unzer.fetchLinkpay(pageId);
}
}
Exclude payment types
To exclude payment types from the Linkpay Page, pass a list of type names to Linkpay::setExcludeTypes
during initialization.
package com.unzer.payment.integration.paymenttypes;
import com.unzer.payment.Linkpay;
import com.unzer.payment.Unzer;
class Example {
void run() throws Exception {
Unzer unzer = new Unzer("s-priv-xxxxxxxxxx");
Linkpay page = new Linkpay();
// ...
// Exclude one
page.setExcludeTypes(new String[]{"paypal"});
// ...or several payment types
page.setExcludeTypes(new String[]{"paypal", "card"});
// ...
// Initialize
unzer.linkpay(page);
}
}
Additional Attributes
In Java SDK, you can set additional attributes by calling the general setter for adding additional attributes.
See Linkpay documentation to learn more about Additional Attributes
package com.unzer.payment.integration.paymenttypes;
import com.unzer.payment.Linkpay;
import com.unzer.payment.Unzer;
import java.util.Map;
class Example {
void run() throws Exception {
Unzer unzer = new Unzer("s-priv-xxxxxxxxxx");
// Create object
Linkpay page = new Linkpay();
//...
// Set attributes
// `setAdditionalAttributes` accepts only Map<String, String> as a parameter.
// Attribute name and value must be of String type.
page.setAdditionalAttributes(Map.of(
"effectiveInterestRate", "4.99",
"exemptionType", "lvp"
));
// ...
}
}