Ejemplo n.º 1
0
        public static void CaptureCard()
        {
            var chargeService = new HpsCreditService(
                new HpsServicesConfig { SecretApiKey = "<your secret api key goes here>" });

            var creditCard = new HpsCreditCard                  // Valid Visa
            {
                Cvv = "123",
                ExpMonth = 12,
                ExpYear = 2025,
                Number = "4012002000060016"
            };

            var cardHolder = new HpsCardHolder
            {
                Email = "*****@*****.**",
                FirstName = "First",
                LastName = "Last",
                Phone = "555-555-5555",
                Address = new HpsAddress { Zip = "47130" }    // Zip is the only required address field.
            };

            var authResponse = chargeService.Authorize(10, "usd", creditCard, cardHolder);

            chargeService.Capture(authResponse.TransactionId);
        }
Ejemplo n.º 2
0
        public void RefundWithTrackData() {
            HpsTrackData trackData = new HpsTrackData {
                Value = "%B5473500000000014^MC TEST CARD^251210199998888777766665555444433332?;5473500000000014=25121019999888877776?",
                Method = HpsTrackDataMethod.Swipe
            };

            var creditService = new HpsCreditService(ServicesConfig);
            HpsRefund response = creditService.Refund(12.00M, "USD", trackData);
            Assert.IsNotNull(response);
            Assert.AreEqual("00", response.ResponseCode);
        }
Ejemplo n.º 3
0
        public void Discover_Swipe_ShouldVerify()
        {
            var service = new HpsCreditService(TestServicesConfig.ValidSecretKeyConfig());
            var verify = service.Verify(new HpsTrackData
            {
                Value = "%B6011000990156527^DIS TEST CARD^25121011000062111401?;6011000990156527=25121011000062111401?",
                Method = HpsTrackDataMethod.Swipe
            });

            Assert.IsNotNull(verify);
            StringAssert.Matches(verify.ResponseCode, new Regex("85"));
        }
Ejemplo n.º 4
0
        public void Visa_Swipe_ShouldVerify()
        {
            var service = new HpsCreditService(TestServicesConfig.ValidSecretKeyConfig());
            var verify = service.Verify(new HpsTrackData
            {
                Value = "%B4012002000060016^VI TEST CREDIT^251210118039000000000396?;4012002000060016=25121011803939600000?",
                Method = HpsTrackDataMethod.Swipe
            });

            Assert.IsNotNull(verify);
            StringAssert.Matches(verify.ResponseCode, new Regex("85"));
        }
Ejemplo n.º 5
0
        public void Mastercard_Swipe_ShouldVerify()
        {
            var service = new HpsCreditService(TestServicesConfig.ValidSecretKeyConfig());
            var verify = service.Verify(new HpsTrackData
            {
                Value = "%B5473500000000014^MC TEST CARD^251210199998888777766665555444433332?;5473500000000014=25121019999888877776?",
                Method = HpsTrackDataMethod.Swipe
            });

            Assert.IsNotNull(verify);
            StringAssert.Matches(verify.ResponseCode, new Regex("85"));
        }
Ejemplo n.º 6
0
        public void CvvWithLeadingZeros() {
            var card = new HpsCreditCard {
                Number = "4111111111111111",
                ExpMonth = 12,
                ExpYear = 2025,
                Cvv = "012"
            };

            var creditService = new HpsCreditService(ServicesConfig);
            var response = creditService.Charge(15.15m, "usd", card);
            Assert.IsNotNull(response);
            Assert.AreEqual("00", response.ResponseCode);
        }
Ejemplo n.º 7
0
        public void Mastercard_Swipe_ShouldAuthorizeAndCaptureWithTokenReq()
        {
            var service = new HpsCreditService(TestServicesConfig.ValidSecretKeyConfig());
            var auth = service.Authorize(15.09m, "usd", new HpsTrackData
            {
                Value = "%B5473500000000014^MC TEST CARD^251210199998888777766665555444433332?;5473500000000014=25121019999888877776?",
                Method = HpsTrackDataMethod.Swipe
            });

            Assert.IsNotNull(auth);
            StringAssert.Matches(auth.ResponseCode, new Regex("00"));

            var capture = service.Capture(auth.TransactionId, null);

            Assert.IsNotNull(capture);
            StringAssert.Matches(capture.ResponseCode, new Regex("00"));
        }
Ejemplo n.º 8
0
        public static void HandleErrors()
        {
            var chargeService = new HpsCreditService(
                new HpsServicesConfig {SecretApiKey = "<your secret api key goes here>"});

            var creditCard = new HpsCreditCard // Valid Visa
            {
                Cvv = "123",
                ExpMonth = 12,
                ExpYear = 2025,
                Number = "4012002000060016"
            };

            var cardHolder = new HpsCardHolder
            {
                Email = "*****@*****.**",
                FirstName = "First",
                LastName = "Last",
                Phone = "555-555-5555",
                Address = new HpsAddress {Zip = "47130"} // Zip is the only required address field.
            };

            try
            {
                chargeService.Charge(-5, "usd", creditCard, cardHolder);
            }
            catch (HpsInvalidRequestException e)
            {
                // handle error for amount less than zero dollars
                Console.WriteLine(e);
            }
            catch (HpsAuthenticationException e)
            {
                // handle errors related to your HpsServiceConfig
                Console.WriteLine(e);
            }
            catch (HpsCreditException e)
            {
                // handle card-related exceptions: card declined, processing error, etc
                Console.WriteLine(e);
            }
        }
        /// <summary>
        /// Refunds a payment
        /// </summary>
        /// <param name="refundPaymentRequest">Request</param>
        /// <returns>Result</returns>
        public RefundPaymentResult Refund(RefundPaymentRequest refundPaymentRequest)
        {
            var result = new RefundPaymentResult();

            var config = new HpsServicesConfig();
            config.SecretApiKey = _secureSubmitPaymentSettings.SecretApiKey;
            config.DeveloperId = "002914";
            config.VersionNumber = "1513";

            var creditService = new HpsCreditService(config);

            try
            {
                creditService.Refund(
                    refundPaymentRequest.AmountToRefund,
                    _currencyService.GetCurrencyById(_currencySettings.PrimaryStoreCurrencyId).CurrencyCode,
                    refundPaymentRequest.Order.CaptureTransactionId);

                var isOrderFullyRefunded = (refundPaymentRequest.AmountToRefund + refundPaymentRequest.Order.RefundedAmount == refundPaymentRequest.Order.OrderTotal);
                result.NewPaymentStatus = isOrderFullyRefunded ? PaymentStatus.Refunded : PaymentStatus.PartiallyRefunded;
            }
            catch (HpsException ex)
            {
                result.AddError(ex.Message);
            }

            return result;
        }
        /// <summary>
        /// Captures payment
        /// </summary>
        /// <param name="capturePaymentRequest">Capture payment request</param>
        /// <returns>Capture payment result</returns>
        public CapturePaymentResult Capture(CapturePaymentRequest capturePaymentRequest)
        {
            var result = new CapturePaymentResult();

            var config = new HpsServicesConfig();
            config.SecretApiKey = _secureSubmitPaymentSettings.SecretApiKey;
            config.DeveloperId = "002914";
            config.VersionNumber = "1513";

            var creditService = new HpsCreditService(config);

            try
            {
                var response = creditService.Capture(Convert.ToInt32(capturePaymentRequest.Order.AuthorizationTransactionId), capturePaymentRequest.Order.OrderTotal);

                result.NewPaymentStatus = PaymentStatus.Paid;
                result.CaptureTransactionId = response.TransactionId.ToString();
                result.CaptureTransactionResult = response.ResponseText;
            }
            catch (HpsException ex)
            {
                result.AddError(ex.Message);
            }

            return result;
        }
Ejemplo n.º 11
0
        public void Visa_Swipe_ShouldPartiallyApproveAndCapture()
        {
            var service = new HpsCreditService(TestServicesConfig.ValidSecretKeyConfig());
            var auth = service.Authorize(110, "usd", new HpsTrackData
            {
                Value = "%B4012002000060016^VI TEST CREDIT^251210118039000000000396?;4012002000060016=25121011803939600000?",
                Method = HpsTrackDataMethod.Swipe
            });

            Assert.IsNotNull(auth);
            StringAssert.Matches(auth.ResponseCode, new Regex("00"));

            var capture = service.Capture(auth.TransactionId, 130);

            Assert.IsNotNull(capture);
            StringAssert.Matches(capture.ResponseCode, new Regex("00"));
        }
Ejemplo n.º 12
0
        public void GetTransactionHasTxnStatus()
        {
            // Make transaction
            var card = new HpsCreditCard
            {
                Number = "4111111111111111",
                ExpMonth = 12,
                ExpYear = 2025,
                Cvv = "012"
            };

            var creditService = new HpsCreditService(ServicesConfig);
            var response = creditService.Charge(15.15m, "usd", card);
            Assert.IsNotNull(response);
            Assert.AreEqual("00", response.ResponseCode);

            // Get details
            var details = creditService.Get(response.TransactionId);
            Assert.IsNotNull(details);
            Assert.IsNotNull(details.TransactionStatus);
            Assert.AreNotEqual("", details.TransactionStatus);
        }
Ejemplo n.º 13
0
        public void CreditVerifyWithTokenExpiry() {
            var card = new HpsCreditCard {
                Number = "4111111111111111",
                ExpMonth = 12,
                ExpYear = 2014,
                Cvv = "123"
            };

            var tokenService = new HpsTokenService("pkapi_cert_m0e9bI2WbBHk0ALyQL");
            var token_reponse = tokenService.GetToken(card);

            var creditService = new HpsCreditService(new HpsServicesConfig {
                SecretApiKey = "skapi_cert_MTeSAQAfG1UA9qQDrzl-kz4toXvARyieptFwSKP24w"
            });
            var response = creditService.Verify(token_reponse.token_value, null, false, null, 12, 2025);
            Assert.IsNotNull(response);
            Assert.AreEqual("85", response.ResponseCode);
        }
        public void Integration_WhenTokenIsAcquired_ShouldBeAbleToCharge()
        {
            var token = _tokenService.GetToken(TestCreditCard.ValidVisa);
            var chargeService = new HpsCreditService(TestServicesConfig.ValidSecretKeyConfig());
            var charge = chargeService.Charge(
                1, 
                "usd", 
                token.token_value, 
                TestCardHolder.ValidCardHolder);

            Assert.IsNotNull(charge.AuthorizationCode);
        }
Ejemplo n.º 15
0
        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>");
            }            
        }
Ejemplo n.º 16
0
        public void Mastercard_ManualNotPresent_ShouldAuthorizeAndCapture()
        {
            var service = new HpsCreditService(TestServicesConfig.ValidSecretKeyConfig());
            var auth = service.Authorize(17.09m, "usd", TestCreditCard.ValidMasterCard, TestCardHolder.CertCardHolderStreetNumberZipOnly);
            Assert.AreEqual("00", auth.ResponseCode);

            var capture = service.Capture(auth.TransactionId, null);

            Assert.IsNotNull(capture);
            StringAssert.Matches(capture.ResponseCode, new Regex("00"));
        }
Ejemplo n.º 17
0
        public void Discover_Swipe_ShouldPartiallyApproveAndCapture()
        {
            var service = new HpsCreditService(TestServicesConfig.ValidSecretKeyConfig());
            var auth = service.Authorize(40, "usd", new HpsTrackData
            {
                Value = "%B6011000990156527^DIS TEST CARD^25121011000062111401?;6011000990156527=25121011000062111401?",
                Method = HpsTrackDataMethod.Swipe
            });

            Assert.IsNotNull(auth);
            StringAssert.Matches(auth.ResponseCode, new Regex("00"));

            var capture = service.Capture(auth.TransactionId, 40);

            Assert.IsNotNull(capture);
            StringAssert.Matches(capture.ResponseCode, new Regex("00"));
        }
Ejemplo n.º 18
0
        public void Mastercard_Swipe_ShouldCharge()
        {
            var service = new HpsCreditService(TestServicesConfig.ValidSecretKeyConfig());
            var charge = service.Charge(15.02m, "usd", new HpsTrackData
            {
                Value = "%B5473500000000014^MC TEST CARD^251210199998888777766665555444433332?;5473500000000014=25121019999888877776?",
                Method = HpsTrackDataMethod.Swipe
            }, null, 0M, false, false, null, "", true);

            Assert.IsNotNull(charge);
            StringAssert.Matches(charge.ResponseCode, new Regex("00"));
        }
Ejemplo n.º 19
0
        public void Mastercard_Manual_ShouldPartiallyApproveAndCapture()
        {
            var service = new HpsCreditService(TestServicesConfig.ValidSecretKeyConfig());
            var auth = service.Authorize(65, "usd", TestCreditCard.ValidMasterCard, TestCardHolder.CertCardHolderShortZip);
            Assert.AreEqual("00", auth.ResponseCode);

            var capture = service.Capture(auth.TransactionId, 145);

            Assert.IsNotNull(capture);
            StringAssert.Matches(capture.ResponseCode, new Regex("00"));
        }
Ejemplo n.º 20
0
        public void Amex_Swipe_ShouldCharge()
        {
            var service = new HpsCreditService(TestServicesConfig.ValidSecretKeyConfig());
            var charge = service.Charge(15.04m, "usd", new HpsTrackData
            {
                Value = "%B3727 006992 51018^AMEX TEST CARD^2512990502700?;372700699251018=2512990502700?",
                Method = HpsTrackDataMethod.Swipe
            });

            Assert.IsNotNull(charge);
            StringAssert.Matches(charge.ResponseCode, new Regex("00"));
        }
Ejemplo n.º 21
0
        public void DiscoverJcb_Swipe_ShouldCharge()
        {
            var service = new HpsCreditService(TestServicesConfig.ValidSecretKeyConfig());
            var charge = service.Charge(15.04m, "usd", new HpsTrackData
            {
                Value = "%B6011000990156527^DIS TEST CARD^25121011000062111401?;6011000990156527=25121011000062111401?",
                Method = HpsTrackDataMethod.Swipe
            });

            Assert.IsNotNull(charge);
            StringAssert.Matches(charge.ResponseCode, new Regex("00"));
        }
Ejemplo n.º 22
0
        public void Visa_Swipe_ShouldChargeVoid()
        {
            var service = new HpsCreditService(TestServicesConfig.ValidSecretKeyConfig());
            var charge = service.Charge(15.06m, "usd", new HpsTrackData
            {
                Value = "%B4012002000060016^VI TEST CREDIT^251210118039000000000396?;4012002000060016=25121011803939600000?",
                Method = HpsTrackDataMethod.Swipe
            });

            Assert.IsNotNull(charge);
            StringAssert.Matches(charge.ResponseCode, new Regex("00"));
        }
Ejemplo n.º 23
0
 public void Amex_Manual_ShouldVerify()
 {
     var creditSvc = new HpsCreditService(TestServicesConfig.ValidSecretKeyConfig());
     var response = creditSvc.Verify(TestCreditCard.ValidAmex, TestCardHolder.CertCardHolderShortZip, true);
     Assert.AreEqual("00", response.ResponseCode);
 }
Ejemplo n.º 24
0
 public void MasterCard_PresentManual_ShouldCharge()
 {
     var service = new HpsCreditService(TestServicesConfig.ValidSecretKeyConfig());
     var response = service.Charge(16.02m, "usd", TestCreditCard.ValidMasterCard,
         TestCardHolder.CertCardHolderShortZipNoStreet, false, TestDescriptor);
     Assert.IsNotNull(response);
     StringAssert.Matches(response.ResponseCode, new Regex("^00$"));
 }
        /// <summary>
        /// Process a payment
        /// </summary>
        /// <param name="processPaymentRequest">Payment info required for an order processing</param>
        /// <returns>Process payment result</returns>
        public ProcessPaymentResult ProcessPayment(ProcessPaymentRequest processPaymentRequest)
        {
            var result = new ProcessPaymentResult();
            var token = (string)processPaymentRequest.CustomValues["token_value"];

            var config = new HpsServicesConfig();
            config.SecretApiKey = _secureSubmitPaymentSettings.SecretApiKey;
            config.DeveloperId = "002914";
            config.VersionNumber = "1513";

            var creditService = new HpsCreditService(config);
            var customer = _customerService.GetCustomerById(processPaymentRequest.CustomerId);

            var cardHolder = new HpsCardHolder();
            cardHolder.Address = new HpsAddress();
            cardHolder.Address.Address = customer.BillingAddress.Address1;
            cardHolder.Address.City = customer.BillingAddress.City;
            cardHolder.Address.State = customer.BillingAddress.StateProvince.Abbreviation;
            cardHolder.Address.Zip = customer.BillingAddress.ZipPostalCode.Replace("-", "");
            cardHolder.Address.Country = customer.BillingAddress.Country.ThreeLetterIsoCode;

            HpsAuthorization response = null;

            try
            {
                if (_secureSubmitPaymentSettings.TransactMode == TransactMode.Authorize)
                {
                    // auth
                    response = creditService.Authorize(
                        processPaymentRequest.OrderTotal,
                        _currencyService.GetCurrencyById(_currencySettings.PrimaryStoreCurrencyId).CurrencyCode,
                        token,
                        cardHolder,
                        false);

                    result.NewPaymentStatus = PaymentStatus.Authorized;
                    result.AuthorizationTransactionCode = response.AuthorizationCode;
                    result.AuthorizationTransactionId = response.TransactionId.ToString();
                }
                else
                {
                    //capture
                    response = creditService.Charge(
                        processPaymentRequest.OrderTotal,
                        _currencyService.GetCurrencyById(_currencySettings.PrimaryStoreCurrencyId).CurrencyCode,
                        token,
                        cardHolder,
                        false);

                    result.NewPaymentStatus = PaymentStatus.Paid;
                    result.CaptureTransactionId = response.TransactionId.ToString();
                    result.CaptureTransactionResult = response.ResponseText;
                }
            }
            catch (HpsException ex)
            {
                result.AddError(ex.Message);
            }

            return result;
        }
Ejemplo n.º 26
0
 public void Jcb_NotPresentManual_ShouldCharge()
 {
     var service = new HpsCreditService(TestServicesConfig.ValidSecretKeyConfig());
     var response = service.Charge(17.05m, "usd", TestCreditCard.ValidJcb,
         TestCardHolder.CertCardHolderLongZip, false, TestDescriptor);
     Assert.IsNotNull(response);
     StringAssert.Matches(response.ResponseCode, new Regex("^00$"));
 }
        /// <summary>
        /// Voids a payment
        /// </summary>
        /// <param name="voidPaymentRequest">Request</param>
        /// <returns>Result</returns>
        public VoidPaymentResult Void(VoidPaymentRequest voidPaymentRequest)
        {
            var result = new VoidPaymentResult();

            var config = new HpsServicesConfig();
            config.SecretApiKey = _secureSubmitPaymentSettings.SecretApiKey;
            config.DeveloperId = "002914";
            config.VersionNumber = "1513";

            var creditService = new HpsCreditService(config);

            try
            {
                if (string.IsNullOrEmpty(voidPaymentRequest.Order.CaptureTransactionId))
                {
                    creditService.Void(Convert.ToInt32(voidPaymentRequest.Order.AuthorizationTransactionId));
                }
                else
                {
                    creditService.Void(Convert.ToInt32(voidPaymentRequest.Order.CaptureTransactionId));
                }

                result.NewPaymentStatus = PaymentStatus.Voided;
            }
            catch (HpsException ex)
            {
                result.AddError(ex.Message);
            }

            return result;
        }
Ejemplo n.º 28
0
        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);
            }            
        }