& More

Custom Form with additional fields

Custom Form enables you to integrate card payments directly on your website.

You have complete control over the look and feel of your payment flow when using Custom Form, but if you need a faster and easier integration, you can always use Checkout.

The following example shows Custom Form with all the additional fields supported.

Use these card details to test different scenarios

4242 4242 4242 4242
Insufficient funds
4024 0071 1846 8684

	public class ExamplesController {

		private static final String PRIVATE_KEY = "pr_test_tXHm9qV9qV9bjIRHcQr9PLPa";

		@RequestMapping(value = "/examples/custom-form-with-additional-fields", method = GET)
		public String customForm(Model model) {
			return "examples/custom-form";

		@RequestMapping(value = "/examples/custom-form-with-additional-fields/payment", method = POST)
		public String customFormSubmit(Model model, @RequestParam String tokenId) throws IOException {
			model.addAttribute("tokenId", tokenId);

			try (Shift4Gateway shift4Gateway = new Shift4Gateway(PRIVATE_KEY)) {
				ChargeRequest request = new ChargeRequest()
						.card(new CardRequest(tokenId));

				Charge charge = shift4Gateway.createCharge(request);

				model.addAttribute("chargeId", charge.getId());

			} catch (Shift4Exception 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";