Hold funds on customer cards and capture them later
The PreAuthorization class allows you to hold funds on a customer’s card without immediately charging it. This is useful for scenarios like hotel reservations, car rentals, or any situation where you need to guarantee payment availability before providing services.
Hold funds on the customer’s card without charging
2
Capture
Charge the held amount when ready (e.g., after service delivery)
3
Refund or Void
Release the hold or refund if needed
Pre-authorization is not available for all accounts. This feature requires special approval from Flutterwave. Contact Flutterwave support to enable pre-authorization for your merchant account.
import com.github.theresasogunle.*;import org.json.JSONObject;public class PreAuthExample { public static void main(String[] args) throws Exception { // Configure special pre-auth keys RaveConstant.PUBLIC_KEY = "FLWPUBK-8cd258c49f38e05292e5472b2b15906e-X"; RaveConstant.SECRET_KEY = "FLWSECK-c51891678d48c39eff3701ff686bdb69-X"; RaveConstant.ENVIRONMENT = Environment.STAGING; PreAuthorization ch = new PreAuthorization(); ch.setCardno("5438898014560229") .setCharge_type("preauth") .setCvv("812") .setExpirymonth("08") .setExpiryyear("20") .setCurrency("NGN") .setCountry("NG") .setAmount("100") .setEmail("user@example.com") .setPhonenumber("08056552980") .setFirstname("John") .setLastname("Doe") .setIP("40.198.14") .setTxRef("MXX-ASC-4578") .setRedirect_url("https://rave-web.herokuapp.com/receivepayment") .setDevice_fingerprint("69e6b7f0b72037aa8428b70fbe03986c"); JSONObject response = ch.preAuthorizeCard(); System.out.println(response); // Extract flwRef from response for later use String flwRef = response.getJSONObject("data").getString("flwRef"); System.out.println("Pre-auth Reference: " + flwRef); }}
The charge_type parameter must be set to "preauth" for pre-authorization transactions. The system will hold the specified amount on the card without actually charging it.
When to use: Before capturing fundsEffect: Releases the hold on customer’s card without any chargeUse case: Customer cancels reservation before check-in
When to use: After capturing fundsEffect: Returns the captured amount to customer’s cardUse case: Customer returns item or service was not satisfactory