public ActionResult SendToPaymentProvider(
     PaymentProviderConfiguration configuration,
     GeneralisedPaymentTransfer transferObject,
     Action <PaymentProviderConfiguration, GeneralisedPaymentTransfer, string> saveProviderReference)
 {
     return(SendToPaymentProvider(configuration, transferObject, DateTime.Now));
 }
        public ActionResult SendToPaymentProvider(
            PaymentProviderConfiguration configuration,
            GeneralisedPaymentTransfer transferObject,
            Action <PaymentProviderConfiguration, GeneralisedPaymentTransfer, string> saveProviderReference)
        {
            var civicaXfer = new CivicaPaymentTransfer()
            {
                ProviderUrl          = Shared.Civica.Default.CivicaPostUrl,
                ReturnUrl            = transferObject.ReturnUrl,
                CallingApplicationId = Shared.Civica.Default.CivicaAppId,
                CallingApplicationTransactionReference = transferObject.TransactionId,
                GeneralLedgerCode = $"{transferObject.GeneralLedgerCode}-{transferObject.ProductId}",
                //PaymentSourceCode = transferObject.PaymentSourceCode,
                PaymentSourceCode = transferObject.IsMediated ? "02" : "01",
                PaymentTotal      = transferObject.Amount,
                PaymentLines      = new List <string>()
            };

            foreach (var item in transferObject.LineItems)
            {
                civicaXfer.PaymentLines.Add(FormatPaymentLine(item));
            }
            var resultView = PaymentFrameworkUtility.CreateView("~/Views/Payment/SendToCivica.cshtml", civicaXfer);

            var sendToPaymentLogMessage = PaymentFrameworkUtility.DescribeActionResultForLogging(resultView, true);

            this.Logger.CreateEntry(typeof(CivicaPaymentProvider), LogLevel.Info, sendToPaymentLogMessage);
            return(resultView);
        }
Пример #3
0
        public ActionResult ProcessPayment(FormCollection form)
        {
            string requestId = _paymentProvider.GenerateUniqueIdentifier();

            this.Session["RequestId"] = requestId;


            var xfer = new GeneralisedPaymentTransfer()
            {
                Amount        = decimal.Parse(form["Amount"]), // -> "AMOUNT"
                ReturnUrl     = "http://localhost:59412" + Url.Action("ProviderCallback", "Capita"),
                TransactionId = requestId
            };

            PaymentProviderConfiguration providerConfig = new PaymentProviderConfiguration()
            {
                AccountIdentifer = this._capitaMerchantid,
                SharedSecret     = this._capitaSecretKey,
                SubAccountNumber = this._capitaScpid
            };

            xfer.Account           = this._capitaScpid;
            xfer.VariableReference = "164 Wandsworth Borough Council";
            xfer.Comment1          = "Activity : After school club";
            xfer.Comment2          = "PS56789/456";
            xfer.CustomerNumber    = "50939";
            xfer.GeneralLedgerCode = "WE333292049,WE330192071,WE333592049,WE333792049";
            xfer.IsMediated        = false;
            xfer.ProductId         = "56789";
            //xfer.VatCode = CapitaVatCode.StandardRate;
            //xfer.VatRate = 20;
            xfer.VatCode = CapitaVatCode.ZeroRate;
            xfer.VatRate = 0;
            //xfer.SaveCard = new SaveCard()
            //{
            //    PayerReference = "s12u34"
            //};
            xfer.LineItems = new System.Collections.Generic.List <CivicaLineItem>()
            {
                new CivicaLineItem()
                {
                    Amount    = decimal.Parse(form["Amount"]),
                    FundCode  = "16",
                    Narrative = "Play Service booking MULTI_153997_112816_138579",
                    Reference = "56789"
                }
            };

            var result = _paymentProvider.SendToPaymentProvider(providerConfig, xfer, SaveProviderReference);

            string rawHtml = PaymentFrameworkUtility.DescribeActionResultForLogging(result);

            System.Diagnostics.Trace.WriteLine(rawHtml);
            System.Diagnostics.Trace.WriteLine("Provider Reference: " + this.Session["ProviderReference"]);

            return(result);
        }
        public ActionResult SendToPaymentProvider(
            PaymentProviderConfiguration configuration,
            GeneralisedPaymentTransfer transferObject, DateTime nowLocalTime)
        {
            var realExXfer = new RealExPaymentTransfer()
            {
                MerchantId     = configuration.AccountIdentifer,
                OrderId        = transferObject.TransactionId,
                Amount         = (int)(transferObject.Amount * 100),
                ProviderUrl    = Shared.RealEx.Default.RealExPostUrl,
                ReturnUrl      = transferObject.ReturnUrl,
                Currency       = "GBP",
                Timestamp      = nowLocalTime.ToString("yyyyMMddHHmmss"),
                AutoSettleFlag = true
            };

            realExXfer.Account           = transferObject.Account;
            realExXfer.VariableReference = MessageContentUtility.TruncateAndStripDisallowed(transferObject.VariableReference, 50, RealexFields.RealexFieldVarRefDisallowRegex);
            realExXfer.CustomerNumber    = transferObject.CustomerNumber;
            realExXfer.ProductId         = MessageContentUtility.TruncateAndStripDisallowed(transferObject.ProductId, null, RealexFields.RealexFieldProductIdDisallowRegex);
            realExXfer.Comment1          = MessageContentUtility.TruncateAndStripDisallowed(transferObject.Comment1, 255, RealexFields.RealexFieldCommentDisallowRegex);
            realExXfer.Comment2          = MessageContentUtility.TruncateAndStripDisallowed(transferObject.Comment2, 255, RealexFields.RealexFieldCommentDisallowRegex);

            var fieldsForSignature = new List <string>();

            fieldsForSignature.Add(realExXfer.Timestamp);
            fieldsForSignature.Add(realExXfer.MerchantId);
            fieldsForSignature.Add(realExXfer.OrderId);
            fieldsForSignature.Add(realExXfer.Amount.ToString());
            fieldsForSignature.Add(realExXfer.Currency);

            if (transferObject.SaveCard != null)
            {
                realExXfer.HasSavedCard       = true;
                realExXfer.CardStorageEnabled = true;
                realExXfer.OfferSaveCard      = transferObject.SaveCard.OfferSaveCard;
                realExXfer.PaymentReference   = MessageContentUtility.TruncateAndStripDisallowed(transferObject.SaveCard.PaymentReference, 30, RealexFields.RealexFieldPaymentRefDisallowRegex);
                realExXfer.PayerReference     = MessageContentUtility.TruncateAndStripDisallowed(transferObject.SaveCard.PayerReference, 50, RealexFields.RealexFieldPayerRefDisallowRegex);
                realExXfer.PayerExists        = transferObject.SaveCard.PayerExists;
                fieldsForSignature.Add(realExXfer.PayerReference);
                fieldsForSignature.Add(realExXfer.PaymentReference);
            }

            realExXfer.Sha1Hash = CalculateRealexSignature(fieldsForSignature.ToArray(), configuration.SharedSecret);

            var resultView = PaymentFrameworkUtility.CreateView("~/Views/Payment/SendToRealEx.cshtml", realExXfer);

            var sendToPaymentLogMessage = PaymentFrameworkUtility.DescribeActionResultForLogging(resultView, true);

            this.Logger.CreateEntry(typeof(RealExPaymentProvider), LogLevel.Info, sendToPaymentLogMessage);
            return(resultView);
        }
        public ActionResult ProcessPayment(FormCollection form)
        {
            var xfer = new GeneralisedPaymentTransfer()
            {
                Amount            = decimal.Parse(form["Amount"]),               // -> "AMOUNT"
                ReturnUrl         = "http://localhost:59412" + Url.Action("ProviderCallback", "Default"),
                TransactionId     = _paymentProvider.GenerateUniqueIdentifier(), // -> "ORDER_ID"
                GeneralLedgerCode = "SOMECIVICACODE"
            };

            PaymentProviderConfiguration providerConfig = new PaymentProviderConfiguration()
            {
                AccountIdentifer = _realExMerchantid,
                SharedSecret     = _realExSecretKey
            };

            xfer.Account           = "";
            xfer.VariableReference = "";
            xfer.Comment1          = "";
            xfer.Comment2          = "";
            xfer.LineItems.Add(new CivicaLineItem()
            {
                Reference = "LINEREF",
                Amount    = 10.00m,
                Narrative = "Stuff paid for",
                FundCode  = "FUND"
            });

            var result = _paymentProvider.SendToPaymentProvider(providerConfig, xfer, null);

            string rawHtml = PaymentFrameworkUtility.DescribeActionResultForLogging(result);

            System.Diagnostics.Trace.WriteLine(rawHtml);

            return(result);
        }
        public ActionResult SendToPaymentProvider(
            PaymentProviderConfiguration configuration,
            GeneralisedPaymentTransfer transferObject,
            Action <PaymentProviderConfiguration, GeneralisedPaymentTransfer, string> saveProviderReference)
        {
            int siteId;

            int.TryParse(configuration.AccountIdentifer, out siteId);

            int scpId;

            int.TryParse(transferObject.Account, out scpId);

            int    hmacKeyId;
            string hmacSecretKey;

            CapitaApiHelpers.GetHmacIdAndSecretKey(configuration.SharedSecret, out hmacKeyId, out hmacSecretKey);

            string returnUrl = $"{transferObject.ReturnUrl}?{RoundTripTokenKey}={transferObject.TransactionId}";

            CapitaInvokeRequest request = new CapitaInvokeRequest()
            {
                SiteId              = siteId,
                ScpId               = scpId,
                HmacKeyId           = hmacKeyId,
                HmacKey             = hmacSecretKey,
                UniqueReference     = transferObject.TransactionId,
                PurchaseId          = transferObject.ProductId,
                BookingRef          = transferObject.Comment2,
                PurchaseDescription = transferObject.Comment1,
                PaymentTotal        = (int)(transferObject.Amount * 100),
                ReturnUrl           = returnUrl,
                IntegraCode         = transferObject.GeneralLedgerCode,
                IsMediated          = transferObject.IsMediated,
                FundCode            = Shared.Capita.Default.FundCode,
                VatCode             = transferObject.VatCode,
                VatRate             = transferObject.VatRate
            };

            if (transferObject.SaveCard != null)
            {
                request.SaveCard     = true;
                request.CardHolderId = MessageContentUtility.TruncateAndStripDisallowed(transferObject.SaveCard.PayerReference, 50, null);
            }

            //Call Capita web service to set up the payment
            CapitaInvokeResponse response = InvokeRequest(request);

            if (response != null && !response.Error)
            {
                //call this action method to save scpReference into PendingPayment table
                saveProviderReference(configuration, transferObject, response.ScpReference);
                RedirectResult resultView = new RedirectResult(response.RedirectUrl, true);
                var            sendToPaymentLogMessage = PaymentFrameworkUtility.DescribeActionResultForLogging(resultView, true);
                this.Logger.CreateEntry(typeof(CapitaPaymentProvider), LogLevel.Info, sendToPaymentLogMessage);
                return(resultView);
            }
            else
            {
                string errorMessage = "Capita Server returns null response.";
                if (response != null)
                {
                    errorMessage += " " + response.ErrorMessage;
                }

                this.Logger.CreateEntry(typeof(CapitaPaymentProvider), LogLevel.Error, errorMessage);
                return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError));
            }
        }
Пример #7
0
 public void SaveProviderReference(PaymentProviderConfiguration config,
                                   GeneralisedPaymentTransfer paymentTransfer, string providerReference)
 {
     this.Session["ProviderReference"] = providerReference;
 }