Exemplo n.º 1
0
        public NvpCodec DirectPayment(OrderViewModel orderViewModel, ref NvpCodec decoder, ref string retMsg)
        {
            if (_env == "pilot")
            {
                _pendpointurl = "https://pilot-payflowpro.paypal.com";
            }

            var encoder = new NvpCodec();
            encoder["TENDER"] = "C";
            encoder["TRXTYPE"] = "S";
            encoder["ACCT"] = orderViewModel.CreditCardNumber;
            //encoder["CVV2"] = createOrderViewModel.Cvv2;
            encoder["EXPDATE"] = orderViewModel.ExpDate;
            encoder["ACCTTYPE"] = orderViewModel.PaymentOption;
            encoder["AMT"] = orderViewModel.Amt.ToString("c");
            encoder["CURRENCY"] = _currencyCode;
            encoder["FIRSTNAME"] = orderViewModel.FirstNameCreditCard;
            encoder["LASTNAME"] = orderViewModel.LastNameCreditCard;
            encoder["STREET"] = orderViewModel.CcAddress1;
            encoder["CITY"] = orderViewModel.CcCity;
            //encoder["STATE"] = createOrderViewModel.CcAddress2.ToUpper();
            encoder["ZIP"] = orderViewModel.CcPostalCode;
            encoder["COUNTRY"] = orderViewModel.CountryCode;

            // unique request ID
            Guid uid = Guid.NewGuid();
            encoder["INVNUM"] = uid.ToString();
            //encoder["ORDERDESC"] = createOrderViewModel.CourseName;
            encoder["VERBOSITY"] = "MEDIUM";
            encoder["Email"] = orderViewModel.Email;

            //encoder["COMMENT1"] = createOrderViewModel.TransactionDateTimeUtc.ToString("yyyy-MM-dd HH:mm:ss") + "-" + createOrderViewModel.CourseName;
            //encoder["COMMENT2"] = "elearning-" + createOrderViewModel.Organization;

            //Roger Code - Do I need to generate a token each time?
            //var token = Convert.ToBase64String(Guid.NewGuid().ToByteArray());
            //encoder["SECURETOKENID"] = token;
            //encoder["CREATESECURETOKEN"] = "Y";

            var pStrrequestforNvp = encoder.Encode();
            var pStresponsenvp = HttpCall(pStrrequestforNvp, uid.ToString());

            if (String.IsNullOrEmpty(pStresponsenvp))
                return null;

            decoder = new NvpCodec();
            decoder.Decode(pStresponsenvp);

            

            return decoder;

        }
Exemplo n.º 2
0
        public static OperationResult<bool> ProcessPaymentOrPromo(ref OrderViewModel viewModel)
        {
            var operationResult = new OperationResult<bool>();
            if (viewModel.Amt == 0)
            {
                viewModel.ConfirmationCode = "PROMO";
                viewModel.Ppref = "PROMO";
                viewModel.CorrelationId = "PROMO";
                viewModel.Tax1Amount = 0;
                operationResult.Result = true;
                operationResult.Message = "Promo Accepted";

            }
            else
            {
                //process Paypal Payment
                var amtBeforeTaxes = viewModel.Cart.CalculateOrderTotal();
                viewModel.Tax1Amount = amtBeforeTaxes*viewModel.Tax1Rate/100;

                var nvpapiCaller = new NvpApiCaller();

                viewModel.CurrencyCode = "CAD";
                viewModel.PaymentType = "Sale";

                viewModel.ExpDate = viewModel.ExpiryMonthCreditCard + viewModel.ExpiryYearCreditCard.Substring(2, 2);

                string retMsg = "";

                var decoder = new NvpCodec();

                //Submit Payment to PayPal
                nvpapiCaller.DirectPayment(viewModel, ref decoder, ref retMsg);

                var processorReturnCode = decoder["RESULT"].ToLower();
                if (processorReturnCode == "0")
                {
                    //Get confirmation code from PayPal
                    viewModel.ConfirmationCode = decoder["PNREF"];
                    viewModel.Ppref = decoder["PPREF"];
                    viewModel.CorrelationId = decoder["CORRELATIONID"];
                    retMsg = "ErrorCode=" + processorReturnCode + "&" + "Desc=" + decoder["RESPMSG"];
                    operationResult.Result = true;
                    operationResult.Message = "Payment Accepted by PayPal";

                }


            }
            return operationResult;
        }
Exemplo n.º 3
0
        /// <summary>
        /// Credentials added to the NVP string
        /// </summary>
        /// <returns></returns>
        private string BuildCredentialsNvpString()
        {
            var codec = new NvpCodec();

            if (!IsEmpty(_apiUser))
                codec["USER"] = _apiUser;

            if (!IsEmpty(_apiPassword))
                codec[Pwd] = _apiPassword;

            if (!IsEmpty(_apiVendor))
                codec[Vendor] = _apiVendor;

            if (!IsEmpty(ApiPartner))
                codec[Partner] = ApiPartner;

            return codec.Encode();
        }