Examples

Custom Form with 3D Secure

Plants
& More

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

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

This example shows Custom Form with 3D Secure verification enabled.

Use these card details to test different scenarios

Scenario Card number
Enrolled for 3-D Secure 2
Not enrolled for 3-D Secure

Please check our guidelines for CSP here.



	@Controller
	@RequestMapping("/examples")
	public class ExamplesController {

		private static final String PRIVATE_KEY = "pr_test_tXHm9qV9qV9bjIRHcQr9PLPa";

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

		@RequestMapping(value = "/examples/custom-form-with-3d-secure/payment", method = POST)
		public String customFormSubmit(Model model,
			@RequestParam String tokenId, @RequestParam boolean requireEnrolledCard,
			@RequestParam boolean requireSuccessfulLiabilityShift) throws IOException {
			model.addAttribute("tokenId", tokenId);

			try (Shift4Gateway shift4Gateway = new Shift4Gateway(PRIVATE_KEY)) {
				ThreeDSecureRequest threeDSecureRequest = new ThreeDSecureRequest()
						.requireEnrolledCard(requireEnrolledCard)
						.requireSuccessfulLiabilityShiftForEnrolledCard(requireSuccessfulLiabilityShift);

				ChargeRequest request = new ChargeRequest()
						.amount(2499)
						.currency("USD")
						.threeDSecure(threeDSecureRequest)
						.card(new CardRequest(tokenId));

				Charge charge = securionPayGateway.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";
		}
	}