예제 #1
0
        public static void AuthorizeCard()
        {
            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.
            };

            chargeService.Authorize(10, "usd", creditCard, cardHolder);
        }
        /// <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;
        }
예제 #3
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"));
        }
예제 #4
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"));
        }
예제 #5
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"));
        }
예제 #6
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"));
        }
예제 #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"));
        }
예제 #8
0
        public void CreditAuthWithTokenExpiry() {
            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.Authorize(10m, "usd", token_reponse.token_value, null, false, null, false, null, 0, 12, 2025);
            Assert.IsNotNull(response);
            Assert.AreEqual("00", response.ResponseCode);
        }