Backend code
@Controller
public class ExamplesController {
private static final String PRIVATE_KEY = "pr_test_tXHm9qV9qV9bjIRHcQr9PLPa";
@RequestMapping(value = "/examples/custom-form", method = GET)
public String customForm(Model model) {
return "examples/custom-form";
}
@RequestMapping(value = "/examples/custom-form/payment", method = POST)
public String customFormSubmit(Model model, @RequestParam String tokenId) throws IOException {
model.addAttribute("tokenId", tokenId);
try (SecurionPayGateway securionPayGateway = new SecurionPayGateway(PRIVATE_KEY)) {
ChargeRequest request = new ChargeRequest()
.amount(2499)
.currency("EUR")
.card(new CardRequest(tokenId));
Charge charge = securionPayGateway.createCharge(request);
model.addAttribute("chargeId", charge.getId());
} catch (SecurionPayException e) {
model.addAttribute("errorType", e.getType());
model.addAttribute("errorCode", e.getCode());
model.addAttribute("errorMessage", e.getMessage());
model.addAttribute("chargeId", e.getChargeId());
}
return "examples/custom-form";
}
}