Example #1
0
        // Get all Meta data about Instruments and connect data to Instrument Object.
        static void InstrumentsWithMetadata()
        {
            ApiClient api = new ApiClient(_apiKey);

            // get all Meta data
            CountriesRespV1 cr = api.GetCountries();
            BranchesRespV1  br = api.GetBranches();
            SectorsRespV1   sr = api.GetSectors();
            MarketsRespV1   mr = api.GetMarkets();

            // Get all Instruments
            InstrumentRespV1 inst = api.GetInstruments();

            // Connect Meta data to Instruments
            foreach (InstrumentV1 c in inst.Instruments)
            {
                CountryV1 country = cr.Countries.FirstOrDefault(o => o.Id == c.CountryId);
                c.CountryModel = country;

                MarketV1 Market = mr.Markets.FirstOrDefault(o => o.Id == c.MarketId);
                c.MarketModel = Market;


                BranchV1 Branch = br.Branches.FirstOrDefault(o => o.Id == c.BranchId);
                c.BranchModel = Branch;

                SectorV1 Sector = sr.Sectors.FirstOrDefault(o => o.Id == c.SectorId);
                c.SectorModel = Sector;
            }

            // Print Data to see all is ok
            foreach (InstrumentV1 c in inst.Instruments)
            {
                if (c.Instrument == Instrument.Index) // Index don't have any Branch or Sector
                {
                    Console.WriteLine(c.Name + " : " + c.CountryModel.Name + " : " + c.MarketModel.Name);
                }
                else
                {
                    Console.WriteLine(c.Name + " : " + c.CountryModel.Name + " : " + c.MarketModel.Name + " : " + c.BranchModel.Name + " : " + c.SectorModel.Name);
                }
            }
        }
        public bool PayYourBill(string strCardNumber, string strCCNumber, int strCardExpiryMonth, int strCardExpiryYear
             , string strAmount, CardTypeV1 CardType, string strFirstName, string strLastname,
             string strStreet, string strCity, StateV1 State, CountryV1 Country, string ZipCode,
             string strPhone, string strEmail, string strCustomerIp, out string confirmationId)
        {
            try
            {
            CCAuthRequestV1 ccAuthRequest = new CCAuthRequestV1();
            MerchantAccountV1 merchantAccount = new MerchantAccountV1();
            merchantAccount.accountNum = ConfigurationSettings.AppSettings["AccountNumber"].ToString();
            merchantAccount.storeID = ConfigurationSettings.AppSettings["StoteId"].ToString();
            merchantAccount.storePwd = ConfigurationSettings.AppSettings["StotePwd"].ToString();
            ccAuthRequest.merchantAccount = merchantAccount;
            ccAuthRequest.merchantRefNum = ConfigurationSettings.AppSettings["ReferancePrefix"].ToString() + "1122345";

            ccAuthRequest.amount = strAmount + ".00";
            CardV1 card = new CardV1();
            card.cardNum = strCardNumber;
            CardExpiryV1 cardExpiry = new CardExpiryV1();
            cardExpiry.month = strCardExpiryMonth;
            cardExpiry.year = strCardExpiryYear;
            card.cardExpiry = cardExpiry;
            card.cardType = CardType;
            card.cardTypeSpecified = true;
            card.cvdIndicator = 1;
            card.cvdIndicatorSpecified = true;
            card.cvd = strCCNumber;
            ccAuthRequest.card = card;
            BillingDetailsV1 billingDetails = new BillingDetailsV1();
            billingDetails.cardPayMethod = CardPayMethodV1.WEB; //WEB = Card Number Provided
            billingDetails.cardPayMethodSpecified = true;
            billingDetails.firstName = strFirstName;
            billingDetails.lastName = strLastname;
            billingDetails.street = strStreet;
            billingDetails.city = strCity;
            //billingDetails.Item = (object)State; // California
            //billingDetails.country = Country; // United States
            billingDetails.countrySpecified = false;
            billingDetails.zip = ZipCode;
            billingDetails.phone = strPhone;
            billingDetails.email = strEmail;
            ccAuthRequest.billingDetails = billingDetails;
            ccAuthRequest.previousCustomer = true;
            ccAuthRequest.previousCustomerSpecified = true;
            ccAuthRequest.customerIP = strCustomerIp;
            ccAuthRequest.productType = ProductTypeV1.M;
            //M = Both Digital and Physical(e.g., software downloaded followed by media
            //shipment)
            ccAuthRequest.productTypeSpecified = true;
            //Request a 3D Secure Lookup
            CardRiskServiceV1[] riskServices = { CardRiskServiceV1.TDS };
            ccAuthRequest.cardRiskService = riskServices;
            // Perform the Web Services call for the purchase
            CreditCardServiceV1 ccService = new CreditCardServiceV1();
            CCTxnResponseV1 ccTxnResponse = ccService.ccPurchase(ccAuthRequest);
            // Print out the result
            String responseTxt = ccTxnResponse.code + " - " + ccTxnResponse.decision + " - "
            + ccTxnResponse.description + Environment.NewLine;
            // Print out the PAReq and ACSUrl
            if ((ccTxnResponse.tdsResponse != null) &&
            (ccTxnResponse.tdsResponse.paymentRequest != null) &&
            (ccTxnResponse.tdsResponse.acsURL != null))
            {
                responseTxt += "PaReq: " + ccTxnResponse.tdsResponse.paymentRequest +
                Environment.NewLine +
                "ACSUrl: " + ccTxnResponse.tdsResponse.acsURL +
                Environment.NewLine;
            }
            responseTxt += "Details:" + Environment.NewLine;
            if (ccTxnResponse.detail != null)
            {
                for (int i = 0; i < ccTxnResponse.detail.Length; i++)
                {
                    responseTxt += " - " + ccTxnResponse.detail[i].tag + " - " +
                    ccTxnResponse.detail[i].value + Environment.NewLine;
                }
            }
            responseTxt = responseTxt.Replace("\n", Environment.NewLine);
            System.Console.WriteLine(responseTxt);
            if (DecisionV1.ACCEPTED.Equals(ccTxnResponse.decision))
            {
                confirmationId = ccTxnResponse.confirmationNumber;
                return true;
                //  return "Transaction Successful.";
            }
            else
            {
                confirmationId = string.Empty;
                return false;
                //  return ("Transaction Failed with decision: " + ccTxnResponse.decision);
            }
            }
            catch
            {
            confirmationId = string.Empty;
            return false;
            }
        }
    // UD: for saving Default Theme in DefaultTheme
    // New added to Call BeanStream server
    protected string PayYourBill(string strCardNumber, string strCCNumber, int strCardExpiryMonth, int strCardExpiryYear
             , double strAmount, CardTypeV1 CardType, string strFirstName, string strLastname,
             string strStreet, string strCity, StateV1 State, CountryV1 Country, string ZipCode,
             string strPhone, string strEmail, string strCustomerIp, out string confirmationId, out string errorMesg, out bool bIsSuccess)
    {
        try
        {
            #region BeanStream code
            errorMesg = "";
            confirmationId = "";
            bIsSuccess = false;
            var trnOrderNumber = Guid.NewGuid().ToString().Substring(0, 10);
            var errorPage = "http://localhost:4941/DevelopmentWebsite/Create.aspx";  //ConfigurationManager.AppSettings["APP_BASE_DOMAIN"] + "tributes/TributeCreation.aspx";
            var approvedPage = "http://localhost:4941/DevelopmentWebsite/Create.aspx";//ConfigurationManager.AppSettings["APP_BASE_DOMAIN"] + "tributes/TributeCreation.aspx";
            var declinedPage = "http://localhost:4941/DevelopmentWebsite/Create.aspx";//ConfigurationManager.AppSettings["APP_BASE_DOMAIN"] + "tributes/TributeCreation.aspx";
            var username = ConfigurationManager.AppSettings["BeanUserName"];
            var password = ConfigurationManager.AppSettings["BeanUserPwd"];
            var month = strCardExpiryMonth.ToString().Length > 0 && strCardExpiryMonth.ToString().Length == 1 ? "0" + strCardExpiryMonth.ToString() : strCardExpiryMonth.ToString();
            var year = strCardExpiryYear.ToString().Length > 0 && strCardExpiryYear.ToString().Length == 4 ? strCardExpiryYear.ToString().Substring(2, 2) : strCardExpiryYear.ToString();

            var redirectedURL = ConfigurationManager.AppSettings["BeanStreamUrl"]
                + "?merchant_id=" + ConfigurationManager.AppSettings["MerchantId"]
                + "&requestType=" + ConfigurationManager.AppSettings["requestType"]
                + "&trnType=" + ConfigurationManager.AppSettings["trnType"]
                + "&trnOrderNumber=" + trnOrderNumber
                + "&trnAmount=" + strAmount
                + "&trnCardOwner=" + strFirstName + " " + strLastname
                + "&trnCardNumber=" + strCardNumber
                + "&trnExpMonth=" + month
                + "&trnExpYear=" + year
                + "&ordName=" + strFirstName + " " + strLastname
                + "&ordAddress1=" + strStreet
                + "&ordCity=" + strCity
                + "&ordProvince=" + State
                + "&ordCountry=" + Country
                + "&ordPostalCode=" + ZipCode
                + "&ordPhoneNumber=" + strPhone
                + "&ordEmailAddress=" + strEmail
                + "&errorPage=" + errorPage
                + "&approvedPage=" + approvedPage
                + "&declinedPage=" + declinedPage
                + "&trnCardCvd=" + strCCNumber
                + "&username="******"&password="******"trnApproved=1"))
                bIsSuccess = true;
            else if (!string.IsNullOrEmpty(sResponceText) && sResponceText.Contains("trnApproved=0"))
                bIsSuccess = false;

            var sResponseArr = sResponceText.Split('&');
            if (sResponseArr.Length >= 2)
                confirmationId = sResponseArr[1].Split('=')[1];
            else confirmationId = "0";

            return sResponceText;
            #endregion
        }
        catch (Exception ex)
        {
            throw new ApplicationException("PAYMENT");
        }
    }
        public bool PayYourBill(string strCardNumber, string strCCNumber, int strCardExpiryMonth, int strCardExpiryYear
             , double strAmount, CardTypeV1 CardType, string strFirstName, string strLastname,
             string strStreet, string strCity, StateV1 State, CountryV1 Country, string ZipCode,
             string strPhone, string strEmail, string strCustomerIp,  string confirmationId,  string errorMesg)
        {
            try
            {
                #region Optimal payment code
                //CCAuthRequestV1 ccAuthRequest = new CCAuthRequestV1();
                //MerchantAccountV1 merchantAccount = new MerchantAccountV1();
                //merchantAccount.accountNum = WebConfig.AccountNumber;
                //merchantAccount.storeID = WebConfig.StoteId;
                //merchantAccount.storePwd = WebConfig.StotePwd;
                //ccAuthRequest.merchantAccount = merchantAccount;
                //ccAuthRequest.merchantRefNum = WebConfig.ReferancePrefix + DateTime.Now.ToString();

                //ccAuthRequest.amount = strAmount.ToString();
                //CardV1 card = new CardV1();
                //card.cardNum = strCardNumber;
                //CardExpiryV1 cardExpiry = new CardExpiryV1();
                //cardExpiry.month = strCardExpiryMonth;
                //cardExpiry.year = strCardExpiryYear;
                //card.cardExpiry = cardExpiry;
                //card.cardType = CardType;
                //card.cardTypeSpecified = true;
                //card.cvdIndicator = 1;
                //card.cvdIndicatorSpecified = true;
                //card.cvd = strCCNumber;
                //ccAuthRequest.card = card;
                //BillingDetailsV1 billingDetails = new BillingDetailsV1();
                //billingDetails.cardPayMethod = CardPayMethodV1.WEB; //WEB = Card Number Provided
                //billingDetails.cardPayMethodSpecified = true;
                //billingDetails.firstName = strFirstName;
                //billingDetails.lastName = strLastname;
                //billingDetails.street = strStreet;
                //billingDetails.city = strCity;
                ////billingDetails.Item = (object)State; // California
                ////billingDetails.country = Country; // United States
                //billingDetails.countrySpecified = false;
                //billingDetails.zip = ZipCode;
                //billingDetails.phone = strPhone;
                //billingDetails.email = strEmail;
                //ccAuthRequest.billingDetails = billingDetails;
                //ccAuthRequest.previousCustomer = true;
                //ccAuthRequest.previousCustomerSpecified = true;
                //ccAuthRequest.customerIP = strCustomerIp;
                //ccAuthRequest.productType = ProductTypeV1.M;
                ////M = Both Digital and Physical(e.g., software downloaded followed by media
                ////shipment)
                //ccAuthRequest.productTypeSpecified = true;
                ////Request a 3D Secure Lookup
                //CardRiskServiceV1[] riskServices = { CardRiskServiceV1.TDS };
                //ccAuthRequest.cardRiskService = riskServices;
                //// Perform the Web Services call for the purchase
                //CreditCardServiceV1 ccService = new CreditCardServiceV1();
                //CCTxnResponseV1 ccTxnResponse = ccService.ccPurchase(ccAuthRequest);
                //// Print out the result
                //String responseTxt = ccTxnResponse.code + " - " + ccTxnResponse.decision + " - "
                //+ ccTxnResponse.description + Environment.NewLine;
                //// Print out the PAReq and ACSUrl
                //if ((ccTxnResponse.tdsResponse != null) &&
                //(ccTxnResponse.tdsResponse.paymentRequest != null) &&
                //(ccTxnResponse.tdsResponse.acsURL != null))
                //{
                //    responseTxt += "PaReq: " + ccTxnResponse.tdsResponse.paymentRequest +
                //    Environment.NewLine +
                //    "ACSUrl: " + ccTxnResponse.tdsResponse.acsURL +
                //    Environment.NewLine;
                //}
                //responseTxt += "Details:" + Environment.NewLine;
                //if (ccTxnResponse.detail != null)
                //{
                //    for (int i = 0; i < ccTxnResponse.detail.Length; i++)
                //    {
                //        responseTxt += " - " + ccTxnResponse.detail[i].tag + " - " +
                //        ccTxnResponse.detail[i].value + Environment.NewLine;
                //    }
                //}
                //responseTxt = responseTxt.Replace("\n", Environment.NewLine);
                //System.Console.WriteLine(responseTxt);
                //if (DecisionV1.ACCEPTED.Equals(ccTxnResponse.decision))
                //{
                //    confirmationId = ccTxnResponse.confirmationNumber;
                //    errorMesg = ccTxnResponse.description;
                //    return true;
                //    //  return "Transaction Successful.";
                //}
                //else
                //{
                //    confirmationId = string.Empty;
                //    errorMesg = ccTxnResponse.description;
                //    return false;
                //    //  return ("Transaction Failed with decision: " + ccTxnResponse.decision);
                //}

                #endregion

                #region BeanStream code
                errorMesg = "";
                confirmationId = "";
                var trnOrderNumber = Guid.NewGuid().ToString().Substring(0, 10);
                var errorPage = "http://localhost:4941/DevelopmentWebsite/Create.aspx";  //ConfigurationManager.AppSettings["APP_BASE_DOMAIN"] + "tributes/TributeCreation.aspx";
                var approvedPage = "http://localhost:4941/DevelopmentWebsite/Create.aspx?AccountType=3";//ConfigurationManager.AppSettings["APP_BASE_DOMAIN"] + "tributes/TributeCreation.aspx";
                var declinedPage = "http://localhost:4941/DevelopmentWebsite/Create.aspx?AccountType=3";//ConfigurationManager.AppSettings["APP_BASE_DOMAIN"] + "tributes/TributeCreation.aspx";
                var username = ConfigurationManager.AppSettings["BeanUserName"];
                var password = ConfigurationManager.AppSettings["BeanUserPwd"];
                var month = strCardExpiryMonth.ToString().Length > 0 && strCardExpiryMonth.ToString().Length == 1 ? "0" + strCardExpiryMonth.ToString() : strCardExpiryMonth.ToString();
                var year = strCardExpiryYear.ToString().Length > 0 && strCardExpiryYear.ToString().Length == 4 ? strCardExpiryYear.ToString().Substring(2, 2) : strCardExpiryYear.ToString();

                var redirectedURL = ConfigurationManager.AppSettings["BeanStreamUrl"]
                    + "?merchant_id=" + ConfigurationManager.AppSettings["MerchantId"]
                    //+ "&requestType=" + ConfigurationManager.AppSettings["requestType"]
                    + "&trnType=" + ConfigurationManager.AppSettings["trnType"]
                    + "&trnOrderNumber=" + trnOrderNumber
                    + "&trnAmount=" + strAmount
                    + "&trnCardOwner=" + strFirstName + " " + strLastname
                    + "&trnCardNumber=" + strCardNumber
                    + "&trnExpMonth=" + month
                    + "&trnExpYear=" + year
                    + "&ordName=" + strFirstName + " " + strLastname
                    + "&ordAddress1=" + strStreet
                    + "&ordCity=" + strCity
                    + "&ordProvince=" + State
                    + "&ordCountry=" + Country
                    + "&ordPostalCode=" + ZipCode
                    + "&ordPhoneNumber=" + strPhone
                    + "&ordEmailAddress=" + strEmail
                    + "&errorPage=" + errorPage
                    + "&approvedPage=" + approvedPage
                    + "&declinedPage=" + declinedPage
                    + "&trnCardCvd=" + strCCNumber
                    + "&username="******"&password="******"PAYMENT");
                //confirmationId = string.Empty;
                errorMesg = "Transaction Failed. Please try again later.";
                return false;

            }
        }