Search in sources :

Example 1 with PayflowAPI

use of paypal.payflow.PayflowAPI in project ofbiz-framework by apache.

the class PayflowPro method getExpressCheckout.

public static Map<String, Object> getExpressCheckout(DispatchContext dctx, Map<String, Object> context) {
    LocalDispatcher dispatcher = dctx.getDispatcher();
    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";
    Map<String, String> data = new HashMap<String, String>();
    data.put("TRXTYPE", "O");
    data.put("TENDER", "P");
    data.put("ACTION", "G");
    String token = (String) cart.getAttribute("payPalCheckoutToken");
    if (UtilValidate.isNotEmpty(token)) {
        data.put("TOKEN", token);
    }
    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);
    if (!"0".equals(responseMap.get("RESULT"))) {
        Debug.logError("A problem occurred while requesting the checkout details from paypal: Result = " + responseMap.get("RESULT") + ", Message = " + responseMap.get("RESPMSG"), module);
        return ServiceUtil.returnError(UtilProperties.getMessage("AccountingErrorUiLabels", "AccountingPayPalCommunicationError", locale));
    }
    Map<String, Object> inMap = new HashMap<String, Object>();
    inMap.put("userLogin", cart.getUserLogin());
    inMap.put("partyId", cart.getOrderPartyId());
    inMap.put("contactMechId", cart.getShippingContactMechId());
    inMap.put("fromDate", UtilDateTime.nowTimestamp());
    inMap.put("payerId", responseMap.get("PAYERID"));
    inMap.put("expressCheckoutToken", token);
    inMap.put("payerStatus", responseMap.get("PAYERSTATUS"));
    inMap.put("avsAddr", responseMap.get("AVSADDR"));
    inMap.put("avsZip", responseMap.get("AVSZIP"));
    inMap.put("correlationId", responseMap.get("CORRELATIONID"));
    Map<String, Object> outMap = null;
    try {
        outMap = dispatcher.runSync("createPayPalPaymentMethod", inMap);
    } catch (GenericServiceException e) {
        Debug.logError(e, module);
        return ServiceUtil.returnError(e.getMessage());
    }
    String paymentMethodId = (String) outMap.get("paymentMethodId");
    cart.clearPayments();
    cart.addPaymentAmount(paymentMethodId, cart.getGrandTotal(), true);
    return ServiceUtil.returnSuccess();
}
Also used : Locale(java.util.Locale) GenericValue(org.apache.ofbiz.entity.GenericValue) LocalDispatcher(org.apache.ofbiz.service.LocalDispatcher) HashMap(java.util.HashMap) PayflowAPI(paypal.payflow.PayflowAPI) Date(java.util.Date) Delegator(org.apache.ofbiz.entity.Delegator) ShoppingCart(org.apache.ofbiz.order.shoppingcart.ShoppingCart) GenericServiceException(org.apache.ofbiz.service.GenericServiceException)

Example 2 with PayflowAPI

use of paypal.payflow.PayflowAPI in project ofbiz-framework by apache.

the class PayflowPro method ccRefund.

public static Map<String, Object> ccRefund(DispatchContext dctx, Map<String, ? extends Object> context) {
    Delegator delegator = dctx.getDelegator();
    GenericValue paymentPref = (GenericValue) context.get("orderPaymentPreference");
    BigDecimal amount = (BigDecimal) context.get("refundAmount");
    String paymentGatewayConfigId = (String) context.get("paymentGatewayConfigId");
    String configString = (String) context.get("paymentConfig");
    Locale locale = (Locale) context.get("locale");
    if (configString == null) {
        configString = "payment.properties";
    }
    GenericValue captureTrans = PaymentGatewayServices.getCaptureTransaction(paymentPref);
    if (captureTrans == null) {
        return ServiceUtil.returnError(UtilProperties.getMessage(resource, "AccountingPaymentTransactionAuthorizationNotFoundCannotRefund", 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 = captureTrans.getString("referenceNum");
    Map<String, String> data = UtilMisc.toMap("ORIGID", refNum);
    // tx type (Credit)
    data.put("TRXTYPE", "C");
    // get the orderID
    String orderId = paymentPref.getString("orderId");
    if (isPayPal) {
        data.put("TENDER", "P");
        data.put("MEMO", orderId);
        // PayPal won't allow us to refund more than the capture amount
        BigDecimal captureAmount = captureTrans.getBigDecimal("amount");
        amount = amount.min(captureAmount);
    } else {
        // credit card tender
        data.put("TENDER", "C");
        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();
    parseRefundResponse(resp, result);
    result.put("refundAmount", amount);
    return result;
}
Also used : Locale(java.util.Locale) GenericValue(org.apache.ofbiz.entity.GenericValue) Delegator(org.apache.ofbiz.entity.Delegator) PayflowAPI(paypal.payflow.PayflowAPI) BigDecimal(java.math.BigDecimal) Date(java.util.Date)

Example 3 with PayflowAPI

use of paypal.payflow.PayflowAPI in project ofbiz-framework by apache.

the class PayflowPro method init.

private static PayflowAPI init(Delegator delegator, String paymentGatewayConfigId, String resource, Map<String, ? extends Object> context) {
    // No more used
    // String certsPath = FlexibleStringExpander.expandString(getPaymentGatewayConfigValue(delegator, paymentGatewayConfigId, "certsPath", resource, "payment.verisign.certsPath", "pfcerts"), context);
    String hostAddress = getPaymentGatewayConfigValue(delegator, paymentGatewayConfigId, "hostAddress", resource, "payment.verisign.hostAddress", "pilot-payflowpro.paypal.com");
    Integer hostPort = Integer.decode(getPaymentGatewayConfigValue(delegator, paymentGatewayConfigId, "hostPort", resource, "payment.verisign.hostPort", "443"));
    Integer timeout = Integer.decode(getPaymentGatewayConfigValue(delegator, paymentGatewayConfigId, "timeout", resource, "payment.verisign.timeout", "80"));
    String proxyAddress = getPaymentGatewayConfigValue(delegator, paymentGatewayConfigId, "proxyAddress", resource, "payment.verisign.proxyAddress", "");
    Integer proxyPort = Integer.decode(getPaymentGatewayConfigValue(delegator, paymentGatewayConfigId, "proxyPort", resource, "payment.verisign.proxyPort", "80"));
    String proxyLogon = getPaymentGatewayConfigValue(delegator, paymentGatewayConfigId, "proxyLogon", resource, "payment.verisign.proxyLogon", "");
    String proxyPassword = getPaymentGatewayConfigValue(delegator, paymentGatewayConfigId, "proxyPassword", resource, "payment.verisign.proxyPassword", "");
    String logFileName = FlexibleStringExpander.expandString(getPaymentGatewayConfigValue(delegator, paymentGatewayConfigId, "logFileName", resource, "payment.verisign.logFileName", ""), context);
    Integer loggingLevel = Integer.decode(getPaymentGatewayConfigValue(delegator, paymentGatewayConfigId, "loggingLevel", resource, "payment.verisign.loggingLevel", "6"));
    Integer maxLogFileSize = Integer.decode(getPaymentGatewayConfigValue(delegator, paymentGatewayConfigId, "maxLogFileSize", resource, "payment.verisign.maxLogFileSize", "1000000"));
    boolean stackTraceOn = "Y".equalsIgnoreCase(getPaymentGatewayConfigValue(delegator, paymentGatewayConfigId, "stackTraceOn", resource, "payment.verisign.stackTraceOn", "N"));
    PayflowAPI pfp = new PayflowAPI(hostAddress, hostPort.intValue(), timeout.intValue(), proxyAddress, proxyPort.intValue(), proxyLogon, proxyPassword);
    SDKProperties.setLogFileName(logFileName);
    SDKProperties.setLoggingLevel(loggingLevel);
    SDKProperties.setMaxLogFileSize(maxLogFileSize);
    SDKProperties.setStackTraceOn(stackTraceOn);
    return pfp;
}
Also used : PayflowAPI(paypal.payflow.PayflowAPI)

Example 4 with PayflowAPI

use of paypal.payflow.PayflowAPI in project adempiere by adempiere.

the class PP_PayFlowPro4 method process.

//  processCC
/**
	 *  Process Transaction
	 *  @param parameter Command String
	 *  @return true if processed successfully
	 */
public boolean process(String parameter) {
    long start = System.currentTimeMillis();
    StringBuffer param = new StringBuffer(parameter);
    //  Usr/Pwd
    param.append("&PARTNER=").append(p_mpp.getPartnerID()).append("&VENDOR=").append(p_mpp.getVendorID()).append("&USER=").append(p_mpp.getUserID()).append("&PWD=").append(p_mpp.getPassword());
    // PCI DSS don't log private data
    // log.fine("-> " + param.toString());
    SDKProperties.setHostAddress(p_mpp.getHostAddress());
    SDKProperties.setHostPort(p_mpp.getHostPort());
    SDKProperties.setTimeOut(getTimeout());
    SDKProperties.setProxyAddress(p_mpp.getProxyAddress());
    SDKProperties.setProxyPort(p_mpp.getProxyPort());
    SDKProperties.setProxyLogin(p_mpp.getProxyLogon());
    SDKProperties.setProxyPassword(p_mpp.getProxyPassword());
    //Logging is by default off. To turn logging on uncomment the following lines:
    //SDKProperties.setLogFileName("payflow_java.log");
    //SDKProperties.setLoggingLevel(PayflowConstants.SEVERITY_DEBUG);
    //SDKProperties.setMaxLogFileSize(1000000);
    //SDKProperties.setStackTraceOn(true);
    //		 Create an instance of PayflowAPI.
    m_pp = new PayflowAPI();
    // RequestId is a unique string that is required for each & every transaction.
    // The merchant can use her/his own algorithm to generate this unique request id or
    // use the SDK provided API to generate this as shown below (PayflowAPI.generateRequestId).
    String requestId = m_pp.generateRequestId();
    String response = m_pp.submitTransaction(param.toString(), requestId);
    // Create a new Client Information data object.
    ClientInfo clInfo = new ClientInfo();
    // Set the ClientInfo object of the PayflowAPI.
    m_pp.setClientInfo(clInfo);
    // Following lines of code are optional.
    // Begin optional code for displaying SDK errors ...
    // It is used to read any errors that might have occured in the SDK.
    // Get the transaction errors.
    String transErrors = m_pp.getTransactionContext().toString();
    if (transErrors != null && transErrors.length() > 0) {
        log.log(Level.SEVERE, "Transaction Errors from SDK = \n" + transErrors);
    }
    p_mp.setR_Result("");
    //	complete info
    p_mp.setR_Info(response);
    //  RESULT=1&PNREF=PN0001480030&RESPMSG=Invalid User Authentication
    //  RESULT=0&PNREF=P60501480167&RESPMSG=Approved&AUTHCODE=010101&AVSADDR=X&AVSZIP=X
    //	RESULT=-31&RESPMSG=The certificate chain did not validate, no local certificate found, javax.net.ssl.SSLException: Cert Path = C:\Adempiere\lib, Working Directory = C:\Adempiere\adempiere-all2\client\temp
    StringTokenizer st = new StringTokenizer(response, "&", false);
    while (st.hasMoreTokens()) {
        String token = st.nextToken();
        int pos = token.indexOf('=');
        String name = token.substring(0, pos);
        String value = token.substring(pos + 1);
        //
        if (name.equals("RESULT")) {
            p_mp.setR_Result(value);
            m_ok = RESULT_OK.equals(value);
        } else if (name.equals("PNREF"))
            p_mp.setR_PnRef(value);
        else if (name.equals("RESPMSG"))
            p_mp.setR_RespMsg(value);
        else if (name.equals("AUTHCODE"))
            p_mp.setR_AuthCode(value);
        else if (name.equals("AVSADDR"))
            p_mp.setR_AvsAddr(value);
        else if (name.equals("AVSZIP"))
            p_mp.setR_AvsZip(value);
        else if (//	N=YSA, Y=International
        name.equals("IAVS"))
            ;
        else if (//	Y/N X=not supported
        name.equals("CVV2MATCH"))
            ;
        else
            log.log(Level.SEVERE, "Response unknown = " + token);
    }
    //  Problems with rc (e.g. 0 with Result=24)
    return m_ok;
}
Also used : ClientInfo(paypal.payflow.ClientInfo) PayflowAPI(paypal.payflow.PayflowAPI)

Example 5 with PayflowAPI

use of paypal.payflow.PayflowAPI in project ofbiz-framework by apache.

the class PayflowPro method ccProcessor.

/**
 * Authorize credit card payment service. Service wrapper around PayFlow Pro API.
 * @param dctx Service Engine DispatchContext.
 * @param context Map context of parameters.
 * @return Response map, including RESPMSG, and RESULT keys.
 */
public static Map<String, Object> ccProcessor(DispatchContext dctx, Map<String, ? extends Object> context) {
    Delegator delegator = dctx.getDelegator();
    GenericValue paymentPref = (GenericValue) context.get("orderPaymentPreference");
    GenericValue authTrans = (GenericValue) context.get("authTrans");
    String orderId = (String) context.get("orderId");
    String cvv2 = (String) context.get("cardSecurityCode");
    BigDecimal processAmount = (BigDecimal) context.get("processAmount");
    GenericValue party = (GenericValue) context.get("billToParty");
    GenericValue cc = (GenericValue) context.get("creditCard");
    GenericValue payPalPaymentMethod = (GenericValue) context.get("payPalPaymentMethod");
    GenericValue ps = (GenericValue) context.get("billingAddress");
    String paymentGatewayConfigId = (String) context.get("paymentGatewayConfigId");
    String configString = (String) context.get("paymentConfig");
    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;
    }
    Map<String, String> data = new HashMap<String, String>();
    boolean isReAuth = false;
    if (isPayPal) {
        data.put("TRXTYPE", "A");
        data.put("TENDER", "P");
        data.put("ORIGID", payPalPaymentMethod.getString("transactionId"));
    } else {
        if (authTrans == null) {
            authTrans = PaymentGatewayServices.getAuthTransaction(paymentPref);
        }
        // set the orderId as comment1 so we can query in PF Manager
        data.put("COMMENT1", orderId);
        data.put("PONUM", orderId);
        data.put("CUSTCODE", party.getString("partyId"));
        // transaction type
        if (comparePaymentGatewayConfigValue(delegator, paymentGatewayConfigId, "preAuth", configString, "payment.verisign.preAuth", "Y")) {
            data.put("TRXTYPE", "A");
            // only support re-auth for auth types; sale types don't do it
            if (authTrans != null) {
                String refNum = authTrans.getString("referenceNum");
                data.put("ORIGID", refNum);
                isReAuth = true;
            }
        } else {
            data.put("TRXTYPE", "S");
        }
        // credit card tender
        data.put("TENDER", "C");
        // card security code
        if (UtilValidate.isNotEmpty(cvv2)) {
            data.put("CVV2", cvv2);
        }
        // get the payment information
        data.put("ACCT", cc.getString("cardNumber"));
        // name on card
        String name = cc.getString("firstNameOnCard") + " " + cc.getString("lastNameOnCard");
        data.put("FIRSTNAME", cc.getString("firstNameOnCard"));
        data.put("LASTNAME", cc.getString("lastNameOnCard"));
        data.put("COMMENT2", name);
        if (cc.get("expireDate") != null) {
            String exp = cc.getString("expireDate");
            String expDate = exp.substring(0, 2);
            expDate = expDate + exp.substring(exp.length() - 2);
            data.put("EXPDATE", expDate);
        }
        // gather the address info
        if (ps != null) {
            String street = ps.getString("address1") + ((UtilValidate.isNotEmpty(ps.getString("address2"))) ? " " + ps.getString("address2") : "");
            data.put("STREET" + "[" + street.length() + "]", street);
            data.put("ZIP", ps.getString("postalCode"));
        }
    }
    // set the amount
    data.put("AMT", processAmount.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);
    }
    if (isPayPal) {
        // Attach the avs info returned in doExpressCheckout and stored in PayPalPaymentMethod
        resp += "&AVSADDR=" + payPalPaymentMethod.getString("avsAddr") + "&AVSZIP=" + payPalPaymentMethod.getString("avsZip");
    }
    // check the response
    Map<String, Object> result = ServiceUtil.returnSuccess();
    parseAuthResponse(delegator, paymentGatewayConfigId, resp, result, configString, isReAuth, isPayPal);
    result.put("processAmount", processAmount);
    return result;
}
Also used : GenericValue(org.apache.ofbiz.entity.GenericValue) Delegator(org.apache.ofbiz.entity.Delegator) HashMap(java.util.HashMap) PayflowAPI(paypal.payflow.PayflowAPI) BigDecimal(java.math.BigDecimal) Date(java.util.Date)

Aggregations

PayflowAPI (paypal.payflow.PayflowAPI)9 Date (java.util.Date)7 Delegator (org.apache.ofbiz.entity.Delegator)7 GenericValue (org.apache.ofbiz.entity.GenericValue)7 BigDecimal (java.math.BigDecimal)5 Locale (java.util.Locale)5 HashMap (java.util.HashMap)4 GenericEntityException (org.apache.ofbiz.entity.GenericEntityException)2 ShoppingCart (org.apache.ofbiz.order.shoppingcart.ShoppingCart)2 GenericServiceException (org.apache.ofbiz.service.GenericServiceException)2 LocalDispatcher (org.apache.ofbiz.service.LocalDispatcher)2 OrderReadHelper (org.apache.ofbiz.order.order.OrderReadHelper)1 ClientInfo (paypal.payflow.ClientInfo)1