Create Payment Page
Learn how to create and use Payment Page resource with Java SDK
Overview
To be able to use the Payment Page integrationwith the Java SDK, you must create a Paypage
instance and initialize it using the Unzer
object.As a result you get an ID and a redirectURL
which can be used to show the Payment Page:
- use the Payment Page ID to render the embedded Payment Page as described in Embedded Payment Page guide.
- or redirect your customer to the
redirectURL
to use hosted Payment Page as shown in the Hosted Payment Page guide.
Initialize a Payment Page
A Payment Page needs at least amount
, currency
, returnUrl
and action
to be initialized. Optional parameter for the API request can be added to your paypage
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.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");
Paypage page = new Paypage();
// 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 Payment Page to Unzer
page = unzer.paypage(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 a Payment Page
You can find an already created payment page by searching for its ID.
package com.unzer.payment.integration.paymenttypes;
import com.unzer.payment.Paypage;
import com.unzer.payment.Unzer;
class Example {
void run() throws Exception {
Unzer unzer = new Unzer("s-priv-xxxxxxxxxx");
String paypageId = "s-ppg-xxxxxxx";
Paypage page = unzer.fetchPaypage(paypageId);
}
}
Exclude payment types
To exclude payment types from the Payment Page, pass a list of type names to paypage.setExcludeTypes
during initialization.
package com.unzer.payment.integration.paymenttypes;
import com.unzer.payment.Paypage;
import com.unzer.payment.Unzer;
class Example {
void run() throws Exception {
Unzer unzer = new Unzer("s-priv-xxxxxxxxxx");
Paypage page = new Paypage();
// ...
// Exclude one
page.setExcludeTypes(new String[]{"paypal"});
// ...or several payment types
page.setExcludeTypes(new String[]{"paypal", "card"});
// ...
// Initialize
unzer.paypage(page);
}
}
Additional Attributes
In Java SDK, you can set additional attributes by calling the general setter for adding additional attributes.
See Paypage documentationto learn more about Additional Attributes
package com.unzer.payment.integration.paymenttypes;
import com.unzer.payment.Paypage;
import com.unzer.payment.Unzer;
import java.util.Map;
class Example {
void run() throws Exception {
Unzer unzer = new Unzer("s-priv-xxxxxxxxxx");
// Create object
Paypage page = new Paypage();
//...
// 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"
));
// ...
}
}