Example #1
0
        internal new HpsAuthorization FromResponse(PosResponseVer10 response)
        {
            base.FromResponse(response);

            if (response.Transaction == null)
            {
                return(this);
            }

            var authResponse = (AuthRspStatusType)response.Transaction.Item;

            this.AuthorizationCode = authResponse.AuthCode;
            this.AvsResultCode     = authResponse.AVSRsltCode;
            this.AvsResultText     = authResponse.AVSRsltText;
            this.CvvResultCode     = authResponse.CVVRsltCode;
            this.CvvResultText     = authResponse.CVVRsltText;
            this.AuthorizedAmount  = authResponse.AuthAmt;
            this.CardType          = authResponse.CardType;
            this.Descriptor        = authResponse.TxnDescriptor;
            this.CpcIndicator      = authResponse.CPCInd;

            if (response.Header.TokenData != null)
            {
                HpsTokenData token = new HpsTokenData {
                    TokenRspCode = response.Header.TokenData.TokenRspCode,
                    TokenRspMsg  = response.Header.TokenData.TokenRspMsg,
                    TokenValue   = response.Header.TokenData.TokenValue
                };

                this.TokenData = token;
            }

            return(this);
        }
        internal new HpsAuthorization FromResponse(PosResponseVer10 response) {
            base.FromResponse(response);

            if (response.Transaction == null)
                return this;

            var authResponse = (AuthRspStatusType)response.Transaction.Item;

            this.AuthorizationCode = authResponse.AuthCode;
            this.AvsResultCode = authResponse.AVSRsltCode;
            this.AvsResultText = authResponse.AVSRsltText;
            this.CvvResultCode = authResponse.CVVRsltCode;
            this.CvvResultText = authResponse.CVVRsltText;
            this.AuthorizedAmount = authResponse.AuthAmt;
            this.CardType = authResponse.CardType;
            this.Descriptor = authResponse.TxnDescriptor;
            this.CpcIndicator = authResponse.CPCInd;

            if (response.Header.TokenData != null) {
                HpsTokenData token = new HpsTokenData {
                    TokenRspCode = response.Header.TokenData.TokenRspCode,
                    TokenRspMsg = response.Header.TokenData.TokenRspMsg,
                    TokenValue = response.Header.TokenData.TokenValue
                };

                this.TokenData = token;
            }

            return this;
        }
Example #3
0
        internal new HpsReportTransactionDetails FromResponse(PosResponseVer10 response)
        {
            var reportResponse = (PosReportTxnDetailRspType)response.Transaction.Item;

            base.FromResponse(response);

            OriginalTransactionId = reportResponse.OriginalGatewayTxnId;
            TransactionType       = ServiceNameToTransactionType(reportResponse.ServiceName);

            var data = reportResponse.Data;

            SettlementAmount   = data.SettlementAmt;
            MaskedCardNumber   = data.MaskedCardNbr;
            TransactionUtcDate = reportResponse.ReqUtcDT;
            AuthorizedAmount   = data.AuthAmt;
            AvsResultCode      = data.AVSRsltCode;
            AvsResultText      = data.AVSRsltText;
            CardType           = data.CardType;
            Descriptor         = data.TxnDescriptor;
            CpcIndicator       = data.CPCInd;
            CvvResultCode      = data.CVVRsltCode;
            CvvResultText      = data.CVVRsltText;
            ReferenceNumber    = data.RefNbr;
            ResponseCode       = data.RspCode;
            ResponseText       = data.RspText;
            if (data.TokenizationMsg != null)
            {
                TokenData = new HpsTokenData {
                    TokenRspMsg = data.TokenizationMsg
                }
            }
            ;
            if (data.AdditionalTxnFields != null)
            {
                Memo          = data.AdditionalTxnFields.Description;
                InvoiceNumber = data.AdditionalTxnFields.InvoiceNbr;
                CustomerId    = data.AdditionalTxnFields.CustomerID;
            }

            if (data.RspCode != "0")
            {
                if (Exceptions == null)
                {
                    Exceptions = new HpsChargeExceptions();
                }
                Exceptions.IssuerException = HpsIssuerResponseValidation.GetException(
                    response.Header.GatewayTxnId,
                    data.RspCode,
                    data.RspText
                    );
            }

            return(this);
        }
    }
        internal new HpsReportTransactionDetails FromResponse(PosResponseVer10 response) {
            var reportResponse = (PosReportTxnDetailRspType)response.Transaction.Item;

            base.FromResponse(response);

            OriginalTransactionId = reportResponse.OriginalGatewayTxnId;
            TransactionType = ServiceNameToTransactionType(reportResponse.ServiceName);

            var data = reportResponse.Data;
            SettlementAmount = data.SettlementAmt;
            MaskedCardNumber = data.MaskedCardNbr;
            TransactionUtcDate = reportResponse.ReqUtcDT;
            AuthorizedAmount = data.AuthAmt;
            AvsResultCode = data.AVSRsltCode;
            AvsResultText = data.AVSRsltText;
            CardType = data.CardType;
            Descriptor = data.TxnDescriptor;
            CpcIndicator = data.CPCInd;
            CvvResultCode = data.CVVRsltCode;
            CvvResultText = data.CVVRsltText;
            ReferenceNumber = data.RefNbr;
            ResponseCode = data.RspCode;
            ResponseText = data.RspText;
            TransactionStatus = data.TxnStatus;
            if (data.TokenizationMsg != null)
                TokenData = new HpsTokenData {
                    TokenRspMsg = data.TokenizationMsg
                };
            if (data.AdditionalTxnFields != null) {
                Memo = data.AdditionalTxnFields.Description;
                InvoiceNumber = data.AdditionalTxnFields.InvoiceNbr;
                CustomerId = data.AdditionalTxnFields.CustomerID;
            }

            if (data.RspCode != "0") {
                if (Exceptions == null)
                    Exceptions = new HpsChargeExceptions();
                Exceptions.IssuerException = HpsIssuerResponseValidation.GetException(
                    response.Header.GatewayTxnId,
                    data.RspCode,
                    data.RspText
                );
            }

            return this;
        }
        private void ProcessPayment()
        {
            var details = GetOrderDetails();

            var config = new HpsServicesConfig
            {
                // The following variables will be provided to you during certification
                SecretApiKey = "skapi_cert_MYl2AQAowiQAbLp5JesGKh7QFkcizOP2jcX9BrEMqQ",                
                VersionNumber = "0000",
                DeveloperId = "000000"
            };

            var chargeService = new HpsCreditService(config);

            var numbers = new Regex("^[0-9]+$");

            var address = new HpsAddress
            {
                Address = details.Address,
                City = details.City,
                State = details.State,
                Country = "United States",
                Zip = numbers.Match(details.Zip ?? string.Empty).ToString()
            };

            var validCardHolder = new HpsCardHolder
            {
                FirstName = details.FirstName,
                LastName = details.LastName,
                Address = address,
                Phone = numbers.Match(details.PhoneNumber ?? string.Empty).ToString()
            };

            var suToken = new HpsTokenData
            {
                TokenValue = details.Token_value
            };

            try
            {
                var authResponse = chargeService.Charge(15.15m, "usd", suToken.TokenValue, validCardHolder);

                SendEmail();

                Response.Write("<h1>Success!</h1><p>Thank you, " + 
                               details.FirstName + 
                               ", for your order of $15.15.</p>" +
                               "Transaction Id: " + authResponse.TransactionId);                
            }
            catch (HpsInvalidRequestException e)
            {
                // handle error for amount less than zero dollars
                Response.Write("<h3>Error</h3>" +  "<strong>amount less than zero dollars: " + e.Message + "</strong>");
            }
            catch (HpsAuthenticationException e)
            {
                // handle errors related to your HpsServiceConfig
                Response.Write("<h3>Error</h3>" + "<strong>Bad Config: " + e.Message + "</strong>");
            }
            catch (HpsCreditException e)
            {
                // handle card-related exceptions: card declined, processing error, etc
                Response.Write("<h3>Error</h3>" + "<strong>card declined, processing error, etc: " + e.Message + "</strong>");
            }
            catch (HpsGatewayException e)
            {
                // handle gateway-related exceptions: invalid cc number, gateway-timeout, etc
                Response.Write("<h3>Error</h3>" + "<strong>invalid cc number, gateway-timeout, etc: " + e.Message + "</strong>");
            }            
        }
        public ActionResult ProcessPayment(OrderDetails details)
        {
            var config = new HpsServicesConfig
            {
                SecretApiKey = "skapi_cert_MYl2AQAowiQAbLp5JesGKh7QFkcizOP2jcX9BrEMqQ",
                // The following variables will be provided to you during certification
                VersionNumber = "0000",
                DeveloperId = "000000"
            };

            var chargeService = new HpsCreditService(config);

            var numbers = new Regex("^[0-9]+$");

            var address = new HpsAddress
            {
                Address = details.Address,
                City = details.City,
                State = details.State,
                Country = "United States",
                Zip = numbers.Match(details.Zip ?? string.Empty).ToString()
            };

            var validCardHolder = new HpsCardHolder
            {
                FirstName = details.FirstName,
                LastName = details.LastName,
                Address = address,
                Phone = numbers.Match(details.PhoneNumber ?? string.Empty).ToString()
            };

            var suToken = new HpsTokenData
            {
                TokenValue = details.Token_value
            };

            try
            {
                var authResponse = chargeService.Charge(15.15m, "usd", suToken.TokenValue, validCardHolder);                

                SendEmail();

                return View("Success", new SuccessModel {
                    FirstName = details.FirstName,
                    TransactionId = authResponse.TransactionId
                });
            }
            catch (HpsInvalidRequestException e)
            {
                // handle error for amount less than zero dollars
                return View("Error", model: "amount less than zero dollars: " + e.Message);
            }
            catch (HpsAuthenticationException e)
            {
                // handle errors related to your HpsServiceConfig
                return View("Error", model: "Bad Config: " + e.Message);
            }
            catch (HpsCreditException e)
            {
                // handle card-related exceptions: card declined, processing error, etc
                return View("Error", model: "card declined, processing error, etc: " + e.Message);
            }
            catch (HpsGatewayException e)
            {
                // handle gateway-related exceptions: invalid cc number, gateway-timeout, etc
                return View("Error", model: "invalid cc number, gateway-timeout, etc: " + e.Message);
            }            
        }