This example demonstrates a payment form using the Blik payment method where the customer authorizes the payment using their mobile banking app.
In test mode, including this example, you can use predefined codes to get different final outcome of the charge.
The following payment codes result in a successful charge, each with a different delay before final result is resolved.
The full transaction involves a few straightforward steps:
pending status and flow.nextAction equals mobile_app_confirmation.
    successful or failed depending on the payment outcome.
    Every Charge includes a clientObjectId, which can be used with shift4.js. It allows retrieving all necessary payment information in the browser without exposing sensitive data.
  
    By using shift4.js, handling the Blik with code flow becomes easier. It can manage redirects and automatically track the final payment status for you.
  
    To use this functionality, pass the clientObjectId from your server to the browser and invoke the handleChargeNextAction method with it.
    This will trigger request to Blik and wait for the result before resolving.
  
    You’ll need to access clientObjectId in two situations:
  
    Once the payment is completed, handleChargeNextAction will resolve with a minimal Charge object, exposing only the required result information, ensuring user privacy and security.
  
                @AjaxController
@RequestMapping("/ajax/examples/charge-with-blik-with-code")
@RequiredArgsConstructor
class ExamplesAjaxChargeWithBlikController {
    @PostMapping("/payment")
    Map ajaxPaymentMethod(@RequestBody PaymentMethodExampleRequest exampleRequest,
                                          HttpServletRequest request
    ) throws IOException {
        try (Shift4Gateway shift4Gateway = createShift4GatewayForPaymentMethods()) {
            // create payment method
            var paymentMethodRequest = new PaymentMethodRequest()
                    .set("type", "blik")
                    .set("fraudCheckData", new FraudCheckDataRequest()
                            .setUserAgent(RequestUtils.getUserAgent(request))
                            .setIpAddress(RequestUtils.getIp(request))
                    )
                    .billing(new BillingRequest()
                            .address(new AddressRequest().country("PL"))
                    )
                    .set("blik", new PaymentMethodDetailsRequest.Blik().setCode(exampleRequest.code));
            var paymentMethod = shift4Gateway.createPaymentMethod(paymentMethodRequest);
            // create charge using payment method
            var chargeRequest = new ChargeRequest(100, "PLN")
                    .paymentMethod(new PaymentMethodRequest(paymentMethod.getId()));
            var charge = shift4Gateway.createCharge(chargeRequest);
            // pass clientObjectId of charge to frontend
            return singletonMap("clientObjectId", charge.getClientObjectId());
        } catch (Shift4Exception e) {
            throw new BadRequestException(e.getMessage());
        }
    }
    static class PaymentMethodExampleRequest {
        String code;
    }
}