Plants
& More

Single Line

Single Line enables you to seamlessly integrate card payment directly on your website with a single visual element.

In the following example, you can see how simple it is to embed card payments with a card component.

Use these card details to test different scenarios

Success
4242 4242 4242 4242
Copied
Insufficient funds
4024 0071 1846 8684
Copied


    @Controller
    public class ExamplesController {

        private static final String PRIVATE_KEY = "pr_test_tXHm9qV9qV9bjIRHcQr9PLPa";

        @RequestMapping(value = "/examples/single-line", method = GET)
        public String singleLine(Model model) {
            return "examples/single-line";
        }

        @RequestMapping(value = "/examples/single-line/payment", method = POST)
        public String singleLineSubmit(Model model, @RequestParam String tokenId) throws IOException {
            model.addAttribute("tokenId", tokenId);

            try (Shift4Gateway shift4Gateway = new Shift4Gateway(PRIVATE_KEY)) {
                ChargeRequest request = new ChargeRequest()
                    .amount(2499)
                    .currency("USD")
                    .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/single-line";
        }
    }