// payment processing wrappers (process/release/refund)
public static Map<String, Object> giftCardProcessor(DispatchContext dctx, Map<String, Object> context) {
LocalDispatcher dispatcher = dctx.getDispatcher();
GenericValue userLogin = (GenericValue) context.get("userLogin");
Locale locale = (Locale) context.get("locale");
GenericValue giftCard = (GenericValue) context.get("giftCard");
GenericValue party = (GenericValue) context.get("billToParty");
String paymentConfig = (String) context.get("paymentConfig");
String currency = (String) context.get("currency");
String orderId = (String) context.get("orderId");
BigDecimal amount = (BigDecimal) context.get("processAmount");
// make sure we have a currency
if (currency == null) {
currency = UtilProperties.getPropertyValue("general.properties", "currency.uom.id.default", "USD");
}
Map<String, Object> redeemCtx = FastMap.newInstance();
redeemCtx.put("userLogin", userLogin);
redeemCtx.put("paymentConfig", paymentConfig);
redeemCtx.put("cardNumber", giftCard.get("cardNumber"));
redeemCtx.put("pin", giftCard.get("pinNumber"));
redeemCtx.put("currency", currency);
redeemCtx.put("orderId", orderId);
redeemCtx.put("partyId", party.get("partyId"));
redeemCtx.put("amount", amount);
// invoke the redeem service
Map<String, Object> redeemResult = null;
try {
redeemResult = dispatcher.runSync("redeemGiftCard", redeemCtx);
} catch (GenericServiceException e) {
Debug.logError(e, "Problem calling the redeem service", module);
return ServiceUtil.returnError(UtilProperties.getMessage(resource,
"AccountingValueLinkUnableToRedeemGiftCardFailure", locale));
}
Map<String, Object> result = ServiceUtil.returnSuccess();
if (redeemResult != null) {
Boolean processResult = (Boolean) redeemResult.get("processResult");
// confirm the amount redeemed; since VL does not error in insufficient funds
if (processResult.booleanValue()) {
BigDecimal previous = (BigDecimal) redeemResult.get("previousAmount");
if (previous == null) previous = BigDecimal.ZERO;
BigDecimal current = (BigDecimal) redeemResult.get("amount");
if (current == null) current = BigDecimal.ZERO;
BigDecimal redeemed = previous.subtract(current);
Debug.logInfo("Redeemed (" + amount + "): " + redeemed + " / " + previous + " : " + current, module);
if (redeemed.compareTo(amount) < 0) {
// we didn't redeem enough void the transaction and return false
Map<String, Object> voidResult = null;
try {
voidResult = dispatcher.runSync("voidRedeemGiftCard", redeemCtx);
} catch (GenericServiceException e) {
Debug.logError(e, module);
}
if (ServiceUtil.isError(voidResult)) {
return voidResult;