* @return Map with the result of the service, the output parameters
*/
public static Map<String, Object> updateCreditCard(DispatchContext ctx, Map<String, Object> context) {
Map<String, Object> result = FastMap.newInstance();
Delegator delegator = ctx.getDelegator();
Security security = ctx.getSecurity();
GenericValue userLogin = (GenericValue) context.get("userLogin");
Locale locale = (Locale) context.get("locale");
Timestamp now = UtilDateTime.nowTimestamp();
String partyId = ServiceUtil.getPartyIdCheckSecurity(userLogin, security, context, result, "PAY_INFO", "_UPDATE");
if (result.size() > 0) return result;
List<GenericValue> toBeStored = FastList.newInstance();
boolean isModified = false;
GenericValue paymentMethod = null;
GenericValue newPm = null;
GenericValue creditCard = null;
GenericValue newCc = null;
String paymentMethodId = (String) context.get("paymentMethodId");
try {
creditCard = delegator.findByPrimaryKey("CreditCard", UtilMisc.toMap("paymentMethodId", paymentMethodId));
paymentMethod = delegator.findByPrimaryKey("PaymentMethod", UtilMisc.toMap("paymentMethodId", paymentMethodId));
} catch (GenericEntityException e) {
Debug.logWarning(e.getMessage(), module);
return ServiceUtil.returnError(UtilProperties.getMessage(resource,
"AccountingCreditCardUpdateReadFailure", locale) + e.getMessage());
}
if (creditCard == null || paymentMethod == null) {
return ServiceUtil.returnError(UtilProperties.getMessage(resource,
"AccountingCreditCardUpdateWithPaymentMethodId", locale) + paymentMethodId);
}
if (!paymentMethod.getString("partyId").equals(partyId) && !security.hasEntityPermission("PAY_INFO", "_UPDATE", userLogin)) {
return ServiceUtil.returnError(UtilProperties.getMessage(resource,
"AccountingCreditCardUpdateWithoutPermission", UtilMisc.toMap("partyId", partyId,
"paymentMethodId", paymentMethodId), locale));
}