Frontend code
<form action="/examples/checkout-with-donation/payment" method="post">
<script src="https://securionpay.com/checkout.js"
class="securionpay-button"
data-key="pu_test_WVMFC9GFuvm54b0uorifKkCh"
data-checkout-request="YTdiZDQ4YjM2MmNkM2JhZWVjNjY2YzQ2NDQwZDE2ZjQyMzhhZDk1OWMzY2E2MDZhZTAzY2JlM2ZlYTA0MDc5NXx7ImN1c3RvbUNoYXJnZSI6eyJhbW91bnRPcHRpb25zIjpbMTAwLDIwMCw1MDAsMTAwMCwyMDAwXSwiY3VzdG9tQW1vdW50Ijp7Im1pbiI6MTAwLCJtYXgiOjEwMDAwfSwiY3VycmVuY3kiOiJFVVIifX0="
data-name="SecurionPay"
data-description="Checkout example"
data-checkout-button="Buy now"
data-class="btn btn-primary btn-lg">
</script>
</form>
Backend code
@Controller
@RequestMapping("/examples")
public class ExamplesController {
private static final String PRIVATE_KEY = "pr_test_tXHm9qV9qV9bjIRHcQr9PLPa";
@RequestMapping(value = "/examples/checkout-with-donation", method = GET)
public String checkout(Model model) throws IOException {
try (SecurionPayGateway securionPayGateway = new SecurionPayGateway(PRIVATE_KEY)) {
CheckoutRequest checkoutRequest = new CheckoutRequest()
.customCharge(new CustomCharge()
.currency("EUR")
.amountOptions(100, 200, 500, 1000, 2000)
.customAmount(100, 10000));
String signedCheckoutRequest = securionPayGateway.signCheckoutRequest(checkoutRequest);
model.addAttribute("signedCheckoutRequest", signedCheckoutRequest);
}
return "examples/checkout";
}
@RequestMapping(value = "/examples/checkout-with-donation/payment", method = POST)
public String checkoutSubmit(Model model, @RequestParam String securionpayChargeId) {
model.addAttribute("chargeId", securionpayChargeId);
return "examples/checkout";
}
}