package com.bookshop.structural.adapter;
/**
* A third-party gateway the shop is contractually stuck with. Its API is incompatible
* with checkout in every way: amounts in pence as a long, customers as a formatted
* reference string, results as magic status codes. We cannot change this class.
*/
public class LegacyPaymentGateway {
public static final int STATUS_OK = 0;
public static final int STATUS_INSUFFICIENT_FUNDS = 12;
public static final int STATUS_INVALID_REFERENCE = 99;
/**
* @param customerReference must look like {@code "CUST/<id>"}
* @param amountInPence whole pence, e.g. 1999 for GBP 19.99
* @return one of the {@code STATUS_*} codes
*/
public int makePayment(String customerReference, long amountInPence) {
if (customerReference == null || !customerReference.startsWith("CUST/")) {
return STATUS_INVALID_REFERENCE;
}
if (amountInPence > 100_000) {
return STATUS_INSUFFICIENT_FUNDS;
}
return STATUS_OK;
}
}