use of paypal.payflow.PayflowAPI in project ofbiz-framework by apache.
the class PayflowPro method ccVoid.
public static Map<String, Object> ccVoid(DispatchContext dctx, Map<String, ? extends Object> context) {
Delegator delegator = dctx.getDelegator();
GenericValue paymentPref = (GenericValue) context.get("orderPaymentPreference");
GenericValue authTrans = (GenericValue) context.get("authTrans");
BigDecimal amount = (BigDecimal) context.get("releaseAmount");
String paymentGatewayConfigId = (String) context.get("paymentGatewayConfigId");
String configString = (String) context.get("paymentConfig");
Locale locale = (Locale) context.get("locale");
if (configString == null) {
configString = "payment.properties";
}
if (authTrans == null) {
authTrans = PaymentGatewayServices.getAuthTransaction(paymentPref);
}
if (authTrans == null) {
return ServiceUtil.returnError(UtilProperties.getMessage(resource, "AccountingPaymentTransactionAuthorizationNotFoundCannotRelease", locale));
}
boolean isPayPal = false;
// Are we doing a cc or a paypal payment?
if ("EXT_PAYPAL".equals(paymentPref.getString("paymentMethodTypeId"))) {
isPayPal = true;
}
// auth ref number
String refNum = authTrans.getString("referenceNum");
Map<String, String> data = UtilMisc.toMap("ORIGID", refNum);
// tx type (Void)
data.put("TRXTYPE", "V");
// get the orderID
String orderId = paymentPref.getString("orderId");
if (isPayPal) {
data.put("TENDER", "P");
data.put("NOTE", orderId);
} else {
// credit card tender
data.put("TENDER", "C");
data.put("COMMENT1", orderId);
// amount to void
data.put("AMT", amount.toString());
}
PayflowAPI pfp = init(delegator, paymentGatewayConfigId, configString, context);
// get the base params
StringBuilder params = makeBaseParams(delegator, paymentGatewayConfigId, configString);
// parse the context parameters
params.append("&").append(parseContext(data));
// transmit the request
if (Debug.verboseOn())
Debug.logVerbose("Sending to Verisign: " + params.toString(), module);
String resp;
if (!comparePaymentGatewayConfigValue(delegator, paymentGatewayConfigId, "enableTransmit", configString, "payment.verisign.enable_transmit", "false")) {
resp = pfp.submitTransaction(params.toString(), pfp.generateRequestId());
} else {
resp = "RESULT=0&AUTHCODE=T&PNREF=" + (new Date()).getTime() + "&RESPMSG=Testing";
}
if (Debug.verboseOn())
Debug.logVerbose("Response from Verisign: " + resp, module);
// check the response
Map<String, Object> result = ServiceUtil.returnSuccess();
parseVoidResponse(resp, result);
result.put("releaseAmount", amount);
return result;
}
use of paypal.payflow.PayflowAPI in project ofbiz-framework by apache.
the class PayflowPro method setExpressCheckout.
public static Map<String, Object> setExpressCheckout(DispatchContext dctx, Map<String, ? extends Object> context) {
Delegator delegator = dctx.getDelegator();
ShoppingCart cart = (ShoppingCart) context.get("cart");
Locale locale = cart.getLocale();
GenericValue payPalPaymentSetting = ProductStoreWorker.getProductStorePaymentSetting(delegator, cart.getProductStoreId(), "EXT_PAYPAL", null, true);
String paymentGatewayConfigId = payPalPaymentSetting.getString("paymentGatewayConfigId");
String configString = "payment.properties";
if (cart == null || cart.items().size() <= 0) {
return ServiceUtil.returnError(UtilProperties.getMessage("AccountingErrorUiLabels", "AccountingPayPalShoppingCartIsEmpty", locale));
}
Map<String, String> data = new HashMap<String, String>();
data.put("TRXTYPE", "O");
data.put("TENDER", "P");
data.put("ACTION", "S");
String token = (String) cart.getAttribute("payPalCheckoutToken");
if (UtilValidate.isNotEmpty(token)) {
data.put("TOKEN", token);
}
data.put("RETURNURL", getPaymentGatewayConfigValue(delegator, paymentGatewayConfigId, "returnUrl", configString, "payment.verisign.returnUrl"));
data.put("CANCELURL", getPaymentGatewayConfigValue(delegator, paymentGatewayConfigId, "cancelReturnUrl", configString, "payment.verisign.cancelReturnUrl"));
try {
addCartDetails(data, cart);
} catch (GenericEntityException e) {
Debug.logError(e, module);
return ServiceUtil.returnError(UtilProperties.getMessage(resource, "AccountingPayflowErrorRetreivingCartDetails", locale));
}
PayflowAPI pfp = init(delegator, paymentGatewayConfigId, null, context);
// get the base params
StringBuilder params = makeBaseParams(delegator, paymentGatewayConfigId, null);
// parse the context parameters
params.append("&").append(parseContext(data));
// transmit the request
if (Debug.verboseOn())
Debug.logVerbose("Sending to Verisign: " + params.toString(), module);
String resp;
if (!comparePaymentGatewayConfigValue(delegator, paymentGatewayConfigId, "enableTransmit", configString, "payment.verisign.enable_transmit", "false")) {
resp = pfp.submitTransaction(params.toString(), pfp.generateRequestId());
} else {
resp = "RESULT=0&TOKEN=" + (new Date()).getTime() + "&RESPMSG=Testing";
}
if (Debug.verboseOn())
Debug.logVerbose("Response from Verisign: " + resp, module);
Map<String, String> responseMap = parseResponse(resp);
String result = responseMap.get("RESULT");
if (!"0".equals(result)) {
String respMsg = responseMap.get("RESPMSG");
Debug.logError("A problem occurred while requesting an express checkout token from paypal: Result = " + result + ", Message = " + respMsg, module);
return ServiceUtil.returnError(UtilProperties.getMessage("AccountingErrorUiLabels", "AccountingPayPalCommunicationError", locale));
}
token = responseMap.get("TOKEN");
cart.setAttribute("payPalCheckoutToken", token);
return ServiceUtil.returnSuccess();
}
use of paypal.payflow.PayflowAPI in project ofbiz-framework by apache.
the class PayflowPro method doExpressCheckout.
public static Map<String, Object> doExpressCheckout(DispatchContext dctx, Map<String, Object> context) {
LocalDispatcher dispatcher = dctx.getDispatcher();
Delegator delegator = dctx.getDelegator();
GenericValue userLogin = (GenericValue) context.get("userLogin");
GenericValue paymentPref = (GenericValue) context.get("orderPaymentPreference");
OrderReadHelper orh = new OrderReadHelper(delegator, paymentPref.getString("orderId"));
GenericValue payPalPaymentSetting = ProductStoreWorker.getProductStorePaymentSetting(delegator, orh.getProductStoreId(), "EXT_PAYPAL", null, true);
String paymentGatewayConfigId = payPalPaymentSetting.getString("paymentGatewayConfigId");
String configString = "payment.properties";
GenericValue payPalPaymentMethod = null;
try {
payPalPaymentMethod = paymentPref.getRelatedOne("PaymentMethod", false);
payPalPaymentMethod = payPalPaymentMethod.getRelatedOne("PayPalPaymentMethod", false);
} catch (GenericEntityException e) {
Debug.logError(e, module);
return ServiceUtil.returnError(e.getMessage());
}
BigDecimal processAmount = paymentPref.getBigDecimal("maxAmount");
Map<String, String> data = new HashMap<String, String>();
data.put("TRXTYPE", "O");
data.put("TENDER", "P");
data.put("PAYERID", payPalPaymentMethod.getString("payerId"));
data.put("TOKEN", payPalPaymentMethod.getString("expressCheckoutToken"));
data.put("ACTION", "D");
// set the amount
data.put("AMT", processAmount.setScale(2).toPlainString());
PayflowAPI pfp = init(delegator, paymentGatewayConfigId, null, context);
// get the base params
StringBuilder params = makeBaseParams(delegator, paymentGatewayConfigId, null);
// parse the context parameters
params.append("&").append(parseContext(data));
// transmit the request
if (Debug.verboseOn())
Debug.logVerbose("Sending to Verisign: " + params.toString(), module);
String resp;
if (!comparePaymentGatewayConfigValue(delegator, paymentGatewayConfigId, "enableTransmit", configString, "payment.verisign.enable_transmit", "false")) {
resp = pfp.submitTransaction(params.toString(), pfp.generateRequestId());
} else {
resp = "RESULT=0&PAYERID=" + (new Date()).getTime() + "&RESPMSG=Testing";
}
Map<String, String> responseMap = parseResponse(resp);
Map<String, Object> inMap = new HashMap<String, Object>();
inMap.put("userLogin", userLogin);
inMap.put("paymentMethodId", payPalPaymentMethod.get("paymentMethodId"));
inMap.put("transactionId", responseMap.get("PNREF"));
Map<String, Object> outMap = null;
try {
outMap = dispatcher.runSync("updatePayPalPaymentMethod", inMap);
} catch (GenericServiceException e) {
Debug.logError(e, module);
return ServiceUtil.returnError(e.getMessage());
}
if (ServiceUtil.isError(outMap)) {
Debug.logError(ServiceUtil.getErrorMessage(outMap), module);
return outMap;
}
return ServiceUtil.returnSuccess();
}
use of paypal.payflow.PayflowAPI in project ofbiz-framework by apache.
the class PayflowPro method ccCapture.
public static Map<String, Object> ccCapture(DispatchContext dctx, Map<String, ? extends Object> context) {
Delegator delegator = dctx.getDelegator();
GenericValue paymentPref = (GenericValue) context.get("orderPaymentPreference");
GenericValue authTrans = (GenericValue) context.get("authTrans");
BigDecimal amount = (BigDecimal) context.get("captureAmount");
String paymentGatewayConfigId = (String) context.get("paymentGatewayConfigId");
String configString = (String) context.get("paymentConfig");
Locale locale = (Locale) context.get("locale");
if (configString == null) {
configString = "payment.properties";
}
boolean isPayPal = false;
// Are we doing a cc or a paypal payment?
if ("EXT_PAYPAL".equals(paymentPref.getString("paymentMethodTypeId"))) {
isPayPal = true;
}
if (authTrans == null) {
authTrans = PaymentGatewayServices.getAuthTransaction(paymentPref);
}
if (authTrans == null) {
return ServiceUtil.returnError(UtilProperties.getMessage(resource, "AccountingPaymentTransactionAuthorizationNotFoundCannotCapture", locale));
}
// auth ref number
String refNum = authTrans.getString("referenceNum");
Map<String, String> data = UtilMisc.toMap("ORIGID", refNum);
// tx type (Delayed Capture)
data.put("TRXTYPE", "D");
if (isPayPal) {
// paypal tender
data.put("TENDER", "P");
data.put("CAPTURECOMPLETE", "N");
} else {
// credit card tender
data.put("TENDER", "C");
// get the orderID
String orderId = paymentPref.getString("orderId");
data.put("COMMENT1", orderId);
}
// amount to capture
data.put("AMT", amount.toString());
PayflowAPI pfp = init(delegator, paymentGatewayConfigId, configString, context);
// get the base params
StringBuilder params = makeBaseParams(delegator, paymentGatewayConfigId, configString);
// parse the context parameters
params.append("&").append(parseContext(data));
// transmit the request
if (Debug.verboseOn())
Debug.logVerbose("Sending to Verisign: " + params.toString(), module);
String resp;
if (!comparePaymentGatewayConfigValue(delegator, paymentGatewayConfigId, "enableTransmit", configString, "payment.verisign.enable_transmit", "false")) {
resp = pfp.submitTransaction(params.toString(), pfp.generateRequestId());
} else {
resp = "RESULT=0&AUTHCODE=T&PNREF=" + (new Date()).getTime() + "&RESPMSG=Testing";
}
if (Debug.verboseOn())
Debug.logVerbose("Response from Verisign: " + resp, module);
// check the response
Map<String, Object> result = ServiceUtil.returnSuccess();
parseCaptureResponse(resp, result);
result.put("captureAmount", amount);
return result;
}
Aggregations