Esempio n. 1
0
    private responseNMI ExecuteTransaction(string strUrl, stcTransactionDetailSet sT)
    {
        {
            var            iR          = new responseNMI();
            string         strResponse = "";
            HttpWebRequest hRequest    = HttpWebRequest.Create(strUrl) as HttpWebRequest;
            hRequest.Method      = "POST";
            hRequest.ContentType = "application/x-www-form-urlencoded";
            OpenAuthentication(sT, ref hRequest);

            using (HttpWebResponse hResponse = (HttpWebResponse)hRequest.GetResponse())
            {
                if (hResponse.StatusCode == HttpStatusCode.OK)
                {
                    var oReader = new StreamReader(hResponse.GetResponseStream());
                    strResponse = oReader.ReadToEnd();
                }
            }

            if (!string.IsNullOrEmpty(strResponse))
            {
                var    dict = HttpUtility.ParseQueryString(strResponse);
                string json = JsonConvert.SerializeObject(dict.Cast <string>().ToDictionary(k => k, v => dict[v]));
                iR = JsonConvert.DeserializeObject <responseNMI>(json);

                iR.response_message      = GetResponseText(iR.response);
                iR.avsresponse_message   = GetAVSResponse(iR.avsresponse);
                iR.cvvresponse_message   = GetAVSResponse(iR.cvvresponse);
                iR.response_code_message = GetResponseCodeMessage(iR.response_code);
            }

            return(iR);
        }
    }
Esempio n. 2
0
    private HttpWebRequest OpenAuthentication(stcTransactionDetailSet sT, ref HttpWebRequest hRequest)
    {
        string strEncoded = string.Format("{0}:", sT.merchant.processor.gateway.apiSecret);

        strEncoded = Convert.ToBase64String(Encoding.GetEncoding("ISO-8859-1").GetBytes(strEncoded));
        hRequest.Headers.Add("Authorization", string.Format("Basic {0}", strEncoded));
        return(hRequest);
    }
Esempio n. 3
0
    private responseNMI VoidTransaction(stcTransactionDetailSet sT)
    {
        var strUrl = new StringBuilder();

        strUrl.AppendFormat("{0}", sT.merchant.processor.gateway.getAPIUrl);
        strUrl.AppendFormat("?type={0}", "void");
        strUrl.AppendFormat("&security_key={0}", sT.merchant.processor.gateway.apiSecret);
        strUrl.AppendFormat("&transactionid={0}", sT.transaction.transactionId);
        strUrl.AppendFormat("&payment={0}", sT.customer.payment.paymentModeId);
        return(ExecuteTransaction(strUrl.ToString(), sT));
    }
Esempio n. 4
0
    private responseNMI CaptureTransaction(stcTransactionDetailSet sT)
    {
        var strUrl = new StringBuilder();

        strUrl.AppendFormat("{0}", sT.merchant.processor.gateway.getAPIUrl);
        strUrl.AppendFormat("?type={0}", "capture");
        strUrl.AppendFormat("&security_key={0}", sT.merchant.processor.gateway.apiSecret);
        strUrl.AppendFormat("&transactionid={0}", sT.transaction.transactionId);
        strUrl.AppendFormat("&amount={0}", sT.cart.cartAmount);
        return(ExecuteTransaction(strUrl.ToString(), sT));
    }
Esempio n. 5
0
    public stcTransactionDetailSet ProcessTransaction(stcTransactionDetailSet sT)
    {
        try
        {
            var iR = new responseNMI();

            switch (sT.transaction.paymentStatusId)
            {
            case enTransactionStatusList.Authorized:
            {
                iR = AuthCaptureTransaction(sT);
                break;
            }

            case enTransactionStatusList.AuthCaptured:
            {
                iR = AuthCaptureTransaction(sT);
                break;
            }

            case enTransactionStatusList.Captured:
            {
                iR = CaptureTransaction(sT);
                break;
            }

            case enTransactionStatusList.Voided:
            {
                iR = VoidTransaction(sT);
                break;
            }

            case enTransactionStatusList.Refunded:
            {
                iR = RefundTransaction(sT);
                break;
            }
            }
        }
        catch (Exception ex)
        {
            string message = ex.Message.ToString();
            // This is the ONLY Point where it is indicated that RESPONSE has ERROR

            sT.transaction.response.responseErrorCode = new stcErrorCodeSet()
            {
                errorCode = enErrorCodeList.Transaction_Process_General_Error
            };
        }

        return(sT);
    }
Esempio n. 6
0
    private responseNMI AuthCaptureTransaction(stcTransactionDetailSet sT)
    {
        var strUrl = new StringBuilder();

        strUrl.AppendFormat("{0}", sT.merchant.processor.gateway.getAPIUrl);
        strUrl.AppendFormat("?security_key={0}", sT.merchant.processor.gateway.apiSecret);
        strUrl.AppendFormat("&payment={0}", sT.customer.payment.paymentModeId);
        strUrl.AppendFormat("&type={0}", "auth");
        strUrl.AppendFormat("&amount={0}", sT.cart.cartAmount);
        strUrl.AppendFormat("&ccnumber={0}", sT.customer.payment.card.cardNumber);
        strUrl.AppendFormat("&ccexp={0}", sT.customer.payment.card.cardExpiration);
        strUrl.AppendFormat("&cvv={0}", sT.customer.payment.card.cardCVV);
        if (!string.IsNullOrEmpty(sT.customer.payment.eCheck.bankAccountName))
        {
            strUrl.AppendFormat("&checkname={0}", sT.customer.payment.eCheck.bankAccountName);
        }
        if (!string.IsNullOrEmpty(sT.customer.payment.eCheck.bankABA))
        {
            strUrl.AppendFormat("&checkaba={0}", sT.customer.payment.eCheck.bankABA);
        }
        if (!string.IsNullOrEmpty(sT.customer.payment.eCheck.bankAccountNumber))
        {
            strUrl.AppendFormat("&checkaccount={0}", sT.customer.payment.eCheck.bankAccountNumber);
        }
        if (!string.IsNullOrEmpty(sT.customer.payment.eCheck.bankECheckType))
        {
            strUrl.AppendFormat("&account_holder_type={0}", sT.customer.payment.eCheck.bankECheckType);
        }
        if (!string.IsNullOrEmpty(sT.customer.payment.eCheck.bankAccountType))
        {
            strUrl.AppendFormat("&account_type={0}", sT.customer.payment.eCheck.bankAccountType);
        }
        if (!string.IsNullOrEmpty(sT.cart.currency.currency))
        {
            strUrl.AppendFormat("&currency={0}", sT.cart.currency.currency);
        }
        if (!string.IsNullOrEmpty(sT.customer.ipAddress))
        {
            strUrl.AppendFormat("&ipaddress={0}", sT.customer.ipAddress);
        }
        if (!string.IsNullOrEmpty(sT.customer.billing.firstName))
        {
            strUrl.AppendFormat("&first_name={0}", sT.customer.billing.firstName);
        }
        if (!string.IsNullOrEmpty(sT.customer.billing.lastName))
        {
            strUrl.AppendFormat("&last_name={0}", sT.customer.billing.lastName);
        }
        if (!string.IsNullOrEmpty(sT.customer.billing.companyName))
        {
            strUrl.AppendFormat("&company={0}", sT.customer.billing.companyName);
        }
        if (!string.IsNullOrEmpty(sT.customer.billing.address))
        {
            strUrl.AppendFormat("&address1={0}", sT.customer.billing.address);
        }
        if (!string.IsNullOrEmpty(sT.customer.billing.city))
        {
            strUrl.AppendFormat("&city={0}", sT.customer.billing.city);
        }
        if (!string.IsNullOrEmpty(sT.customer.billing.state))
        {
            strUrl.AppendFormat("&state={0}", sT.customer.billing.state);
        }
        if (!string.IsNullOrEmpty(sT.customer.billing.zipcode))
        {
            strUrl.AppendFormat("&zip={0}", sT.customer.billing.zipcode);
        }
        if (!string.IsNullOrEmpty(sT.customer.billing.country.country))
        {
            strUrl.AppendFormat("&country={0}", sT.customer.billing.country.country);
        }
        if (!string.IsNullOrEmpty(sT.customer.billing.phone))
        {
            strUrl.AppendFormat("&phone={0}", sT.customer.billing.phone);
        }
        if (!string.IsNullOrEmpty(sT.customer.billing.fax))
        {
            strUrl.AppendFormat("&fax={0}", sT.customer.billing.fax);
        }
        if (!string.IsNullOrEmpty(sT.customer.billing.email))
        {
            strUrl.AppendFormat("&email={0}", sT.customer.billing.email);
        }
        if (!string.IsNullOrEmpty(sT.customer.shipping.firstName))
        {
            strUrl.AppendFormat("&shipping_firstname={0}", sT.customer.shipping.firstName);
        }
        if (!string.IsNullOrEmpty(sT.customer.shipping.lastName))
        {
            strUrl.AppendFormat("&shipping_lastname={0}", sT.customer.shipping.lastName);
        }
        if (!string.IsNullOrEmpty(sT.customer.shipping.companyName))
        {
            strUrl.AppendFormat("&shipping_company={0}", sT.customer.shipping.companyName);
        }
        if (!string.IsNullOrEmpty(sT.customer.shipping.address))
        {
            strUrl.AppendFormat("&shipping_address1={0}", sT.customer.shipping.address);
        }
        if (!string.IsNullOrEmpty(sT.customer.shipping.city))
        {
            strUrl.AppendFormat("&shipping_city={0}", sT.customer.shipping.city);
        }
        if (!string.IsNullOrEmpty(sT.customer.shipping.state))
        {
            strUrl.AppendFormat("&shipping_state={0}", sT.customer.shipping.state);
        }
        if (!string.IsNullOrEmpty(sT.customer.shipping.zipcode))
        {
            strUrl.AppendFormat("&shipping_zip={0}", sT.customer.shipping.zipcode);
        }
        if (!string.IsNullOrEmpty(sT.customer.shipping.country.country))
        {
            strUrl.AppendFormat("&shipping_country={0}", sT.customer.shipping.country.country);
        }
        if (!string.IsNullOrEmpty(sT.customer.shipping.email))
        {
            strUrl.AppendFormat("&shipping_email={0}", sT.customer.shipping.email);
        }
        return(ExecuteTransaction(strUrl.ToString(), sT));
    }