public static HpsToken TokenizeCard(HpsCreditCard card) { if (Tokens.ContainsKey(card.Number)) { return Tokens[card.Number]; } var token = _tokenService.GetToken(card); Tokens.Add(card.Number, token); return token; }
public void Validation_TooLongCardNumber_ShouldReturnError() { var card = new HpsCreditCard { Number = "11111111111111111111111111111111111" }; var response = _tokenService.GetToken(card); var error = response.error; Assert.IsNotNull(error); Assert.AreEqual("2", error.code); Assert.AreEqual("card.number", error.param); Assert.AreEqual("Card number is invalid.", error.message); }
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); }
public void moto_002_verify_master_card() { var card = new HpsCreditCard { Number = "5473500000000014", ExpMonth = 12, ExpYear = 2025 }; var response = _creditService.Verify() .WithCard(card) .WithRequestMultiUseToken(UseTokens) .Execute(); Assert.IsNotNull(response); Assert.AreEqual("85", response.ResponseCode); }
public void ecomm_002_verify_master_card() { var card = new HpsCreditCard { Number = "5473500000000014", ExpMonth = 12, ExpYear = 2025 }; // ReSharper disable once RedundantArgumentDefaultValue var response = _creditService.Verify() .WithCard(card) .WithRequestMultiUseToken(UseTokens) .Execute(); Assert.IsNotNull(response); Assert.AreEqual("85", response.ResponseCode); }
public void AddPaymentMethodWithToken() { // Create Customer var customer = new HpsPayPlanCustomer { CustomerIdentifier = GetIdentifier("Person"), FirstName = "John", LastName = "Doe", CustomerStatus = HpsPayPlanCustomerStatus.Active, PrimaryEmail = "*****@*****.**", AddressLine1 = "123 Main St", City = "Dallas", StateProvince = "TX", ZipPostalCode = "98765", Country = "USA", PhoneDay = "5551112222" }; HpsPayPlanService payPlanService = new HpsPayPlanService(TestServicesConfig.ValidTokenServiceConfig()); var response = payPlanService.AddCustomer(customer); var customerKey = response.CustomerKey; // Create Card & Token var card = new HpsCreditCard { Number = "4111111111111111", ExpMonth = 12, ExpYear = 2020, Cvv = "123" }; var tokenService = new HpsTokenService("pkapi_cert_jKc1FtuyAydZhZfbB3"); var tokenResponse = tokenService.GetToken(card); // Create & Add Payment via Token var newPaymentMethod = new HpsPayPlanPaymentMethod { CustomerKey = customerKey, NameOnAccount = "Bill Johnson", PaymentToken = tokenResponse.token_value, PaymentMethodType = HpsPayPlanPaymentMethodType.CreditCard, Country = "USA" }; var result = payPlanService.AddPaymentMethod(newPaymentMethod); Assert.IsNotNull(result); Assert.IsNotNull(result.PaymentMethodKey); }
/// <summary> /// A <b>credit authorization</b> transaction authorizes a credit card transaction. The authorization is NOT placed /// in the batch. The <b>credit authorization</b> transaction can be committed by using the capture method. /// </summary> /// <param name="amount">Amount to verify.</param> /// <param name="currency">Currency to use (e.g. "USD").</param> /// <param name="card">The credit card information.</param> /// <param name="cardHolder">The card holder information (used for AVS).</param> /// <param name="requestMultiUseToken">Request a multi-use token</param> /// <param name="descriptor">Transaction description that is concatenated to a configurable /// merchant DBA name. The resulting string is sent to the card issuer for the Merchant Name.</param> /// <param name="allowPartialAuth">Indicated whether partial authorization is supported.</param> /// <param name="details">The transaction details.</param> /// <param name="gratuity">The gratuity amount.</param> /// <returns>The <see cref="HpsAuthorization"/>.</returns> public HpsAuthorization Authorize(decimal amount, string currency, HpsCreditCard card, HpsCardHolder cardHolder = null, bool requestMultiUseToken = false, string descriptor = null, bool allowPartialAuth = false, HpsTransactionDetails details = null, decimal gratuity = 0) { HpsInputValidation.CheckAmount(amount); HpsInputValidation.CheckCurrency(currency); /* Build the transaction request. */ var transaction = new PosRequestVer10Transaction { Item = new PosCreditAuthReqType { Block1 = new CreditAuthReqBlock1Type { AllowDup = booleanType.Y, AllowDupSpecified = true, AllowPartialAuth = allowPartialAuth ? booleanType.Y : booleanType.N, AllowPartialAuthSpecified = true, CardHolderData = cardHolder == null ? null : HydrateCardHolderData(cardHolder), CardData = new CardDataType { TokenRequest = requestMultiUseToken ? booleanType.Y : booleanType.N, Item = HydrateCardManualEntry(card) }, Amt = amount, GratuityAmtInfo = gratuity, GratuityAmtInfoSpecified = gratuity != 0, AdditionalTxnFields = HydrateAdditionalTxnFields(details), TxnDescriptor = descriptor } }, ItemElementName = ItemChoiceType1.CreditAuth }; return SubmitAuthorize(transaction, amount, currency, (details == null) ? null : details.ClientTransactionId); }
public void moto_019_partial_approval_discover() { var cardHolder = new HpsCardHolder { Address = new HpsAddress { Address = "6860", Zip = "75024" } }; var directMarketData = new HpsDirectMarketData { InvoiceNumber = "123456" }; var card = new HpsCreditCard { Number = "6011000990156527", ExpMonth = 12, ExpYear = 2025, Cvv = "123" }; var response = _creditService.Charge(145m) .WithCard(card) .WithCardHolder(cardHolder) .WithDirectMarketData(directMarketData) .WithAllowPartialAuth(true) .Execute(); Assert.IsNotNull(response); Assert.AreEqual("10", response.ResponseCode); Assert.IsNotNull(response); Assert.AreEqual(65.00m, response.AuthorizedAmount); }
public void moto_017_authorization_discover() { var cardHolder = new HpsCardHolder { Address = new HpsAddress { Address = "6860", Zip = "75024" } }; var directMarketData = new HpsDirectMarketData { InvoiceNumber = "123456" }; var card = new HpsCreditCard { Number = "6011000990156527", ExpMonth = 12, ExpYear = 2025, Cvv = "123" }; var authResponse = _creditService.Authorize(17.07m) .WithCard(card) .WithCardHolder(cardHolder) .WithDirectMarketData(directMarketData) .Execute(); Assert.IsNotNull(authResponse); Assert.AreEqual("00", authResponse.ResponseCode); }
public void moto_016_authorization_master_card() { var cardHolder = new HpsCardHolder { Address = new HpsAddress { Address = "6860 Dallas Pkwy", Zip = "750241234" } }; var directMarketData = new HpsDirectMarketData { InvoiceNumber = "123456" }; var card = new HpsCreditCard { Number = "5473500000000014", ExpMonth = 12, ExpYear = 2025, Cvv = "123" }; var authResponse = _creditService.Authorize(17.07m) .WithCard(card) .WithCardHolder(cardHolder) .WithDirectMarketData(directMarketData) .Execute(); Assert.IsNotNull(authResponse); Assert.AreEqual("00", authResponse.ResponseCode); // test 016b Capture/AddToBatch var captureResponse = _creditService.Capture(authResponse.TransactionId).Execute(); Assert.IsNotNull(captureResponse); Assert.AreEqual("00", captureResponse.ResponseCode); }
public void moto_014_charge_jcb() { var cardHolder = new HpsCardHolder { Address = new HpsAddress { Address = "6860 Dallas Pkwy", Zip = "750241234" } }; var directMarketData = new HpsDirectMarketData { InvoiceNumber = "123456" }; var card = new HpsCreditCard { Number = "3566007770007321", ExpMonth = 12, ExpYear = 2025, Cvv = "123" }; var chargeResponse = _creditService.Charge(17.05m) .WithCard(card) .WithCardHolder(cardHolder) .WithDirectMarketData(directMarketData) .Execute(); Assert.IsNotNull(chargeResponse); Assert.AreEqual("00", chargeResponse.ResponseCode); }
public void moto_023_level_ii_response_r() { var cardHolder = new HpsCardHolder { Address = new HpsAddress { Address = "6860", Zip = "75024" } }; var card = new HpsCreditCard { Number = "4012002000060016", ExpMonth = 12, ExpYear = 2025, Cvv = "123" }; var chargeResponse = _creditService.Charge(123.45m) .WithCard(card) .WithCardHolder(cardHolder) .WithCpcReq(true) .Execute(); Assert.IsNotNull(chargeResponse); Assert.AreEqual("00", chargeResponse.ResponseCode); Assert.AreEqual("R", chargeResponse.CpcIndicator); var cpcData = new HpsCpcData { TaxType = taxTypeType.TAXEXEMPT }; var cpcResponse = _creditService.CpcEdit(chargeResponse.TransactionId) .WithCpcData(cpcData) .Execute(); Assert.IsNotNull(cpcResponse); Assert.AreEqual("00", cpcResponse.ResponseCode); }
public void moto_027_level_ii_response_s() { var cardHolder = new HpsCardHolder { Address = new HpsAddress { Address = "6860", Zip = "75024" } }; var card = new HpsCreditCard { Number = "5473500000000014", ExpMonth = 12, ExpYear = 2025, Cvv = "123" }; var chargeResponse = _creditService.Charge(111.08m) .WithCard(card) .WithCardHolder(cardHolder) .WithCpcReq(true) .Execute(); Assert.IsNotNull(chargeResponse); Assert.AreEqual("00", chargeResponse.ResponseCode); Assert.AreEqual("S", chargeResponse.CpcIndicator); var cpcData = new HpsCpcData { CardHolderPoNumber = "9876543210", TaxAmount = 1.00m, TaxType = taxTypeType.SALESTAX }; var cpcResponse = _creditService.CpcEdit(chargeResponse.TransactionId) .WithCpcData(cpcData) .Execute(); Assert.IsNotNull(cpcResponse); Assert.AreEqual("00", cpcResponse.ResponseCode); }
public void moto_006_charge_visa_token() { var cardHolder = new HpsCardHolder { Address = new HpsAddress { Address = "6860 Dallas Pkwy", Zip = "75024" } }; var card = new HpsCreditCard { Number = "4012002000060016", ExpMonth = 12, ExpYear = 2025 }; var response = _creditService.Charge(13.01m) .WithCard(card) .WithCardHolder(cardHolder) .WithRequestMultiUseToken(true) .Execute(); Assert.IsNotNull(response); Assert.AreEqual("00", response.ResponseCode); visaToken = response.TokenData.TokenValue; }
public void moto_005_balance_inquiry_visa() { var card = new HpsCreditCard { Number = "4012002000060016", ExpMonth = 12, ExpYear = 2025 }; var response = _creditService.PrePaidBalanceInquiry() .WithCard(card) .Execute(); Assert.IsNotNull(response); Assert.AreEqual("00", response.ResponseCode); }
public void moto_004_verify_amex() { var cardHolder = new HpsCardHolder { Address = new HpsAddress { Zip = "75024" } }; var card = new HpsCreditCard { Number = "372700699251018", ExpMonth = 12, ExpYear = 2025 }; var response = _creditService.Verify() .WithCard(card) .WithCardHolder(cardHolder) .WithRequestMultiUseToken(UseTokens) .Execute(); Assert.IsNotNull(response); Assert.AreEqual("00", response.ResponseCode); }
public void moto_040_charge_gsb() { var cardHolder = new HpsCardHolder { Address = new HpsAddress { Address = "6860", Zip = "75024" } }; var card = new HpsCreditCard { Number = "6277220572999800", ExpYear = 2049, ExpMonth = 12 }; var chargeResponse = _creditService.Charge(2.10m) .WithCard(card) .WithCardHolder(cardHolder) .WithDirectMarketData(new HpsDirectMarketData { InvoiceNumber = "123456" }) .Execute(); Assert.IsNotNull(chargeResponse); Assert.AreEqual("00", chargeResponse.ResponseCode); }
public void moto_037_balance_inquiry_gsb() { var cardHolder = new HpsCardHolder { Address = new HpsAddress { Address = "6860", Zip = "75024" } }; var card = new HpsCreditCard { Number = "6277220572999800", ExpYear = 2049, ExpMonth = 12 }; var response = _creditService.PrePaidBalanceInquiry() .WithCard(card) .WithCardHolder(cardHolder) .Execute(); Assert.IsNotNull(response); Assert.AreEqual("00", response.ResponseCode); }
/// <summary> /// A <b>credit account verify</b> transaction is used to verify that the account is in good standing /// with the issuer. This is a zero dollar transaction with no associated authorization. Since VISA and /// other issuers have started assessing penalties for one dollar authorizations, this provides a way for /// merchants to accomplish the same task while avoiding these penalties. /// </summary> /// <param name="card">The credit card information.</param> /// <param name="cardHolder">The card holder information (used for AVS).</param> /// <param name="requestMultiUseToken">Request a multi-use token.</param> /// <param name="clientTransactionId">Optional client transaction ID.</param> /// <returns>The <see cref="HpsCharge"/>.</returns> public HpsAccountVerify Verify(HpsCreditCard card, HpsCardHolder cardHolder = null, bool requestMultiUseToken = false, long? clientTransactionId = null) { /* Build the transaction request. */ var transaction = new PosRequestVer10Transaction { Item = new PosCreditAccountVerifyReqType { Block1 = new CreditAccountVerifyBlock1Type { CardHolderData = cardHolder == null ? null : HydrateCardHolderData(cardHolder), CardData = new CardDataType { TokenRequest = requestMultiUseToken ? booleanType.Y : booleanType.N, Item = HydrateCardManualEntry(card) } } }, ItemElementName = ItemChoiceType1.CreditAccountVerify }; return SubmitVerify(transaction, clientTransactionId); }
public void moto_020_partial_approval_master_card() { var cardHolder = new HpsCardHolder { Address = new HpsAddress { Address = "6860", Zip = "75024" } }; var directMarketData = new HpsDirectMarketData { InvoiceNumber = "123456" }; var card = new HpsCreditCard { Number = "5473500000000014", ExpMonth = 12, ExpYear = 2025, Cvv = "123" }; var chargeResponse = _creditService.Charge(155m) .WithCard(card) .WithCardHolder(cardHolder) .WithDirectMarketData(directMarketData) .WithAllowPartialAuth(true) .Execute(); Assert.IsNotNull(chargeResponse); Assert.AreEqual("10", chargeResponse.ResponseCode); Assert.IsNotNull(chargeResponse); Assert.AreEqual(100.00m, chargeResponse.AuthorizedAmount); test20TransactionId = chargeResponse.TransactionId; }
public void moto_022_level_ii_response_b() { var cardHolder = new HpsCardHolder { Address = new HpsAddress { Address = "6860", Zip = "750241234" } }; var card = new HpsCreditCard { Number = "4012002000060016", ExpMonth = 12, ExpYear = 2025, Cvv = "123" }; var chargeResponse = _creditService.Charge(112.34m) .WithCard(card) .WithCardHolder(cardHolder) .WithAllowDuplicates(true) .WithCpcReq(true) .Execute(); Assert.IsNotNull(chargeResponse); Assert.AreEqual("00", chargeResponse.ResponseCode); Assert.AreEqual("B", chargeResponse.CpcIndicator); var cpcData = new HpsCpcData { TaxType = taxTypeType.SALESTAX, TaxAmount = 1.00m }; var cpcResponse = _creditService.CpcEdit(chargeResponse.TransactionId) .WithCpcData(cpcData) .Execute(); Assert.IsNotNull(cpcResponse); Assert.AreEqual("00", cpcResponse.ResponseCode); }
public void moto_032_level_ii_no_response() { var cardHolder = new HpsCardHolder { Address = new HpsAddress { Address = "6860", Zip = "75024" } }; var card = new HpsCreditCard { Number = "372700699251018", ExpMonth = 12, ExpYear = 2025, Cvv = "1234" }; var chargeResponse = _creditService.Charge(111.13m) .WithCard(card) .WithCardHolder(cardHolder) .WithCpcReq(true) .Execute(); Assert.IsNotNull(chargeResponse); Assert.AreEqual("00", chargeResponse.ResponseCode); Assert.AreEqual("0", chargeResponse.CpcIndicator); var cpcData = new HpsCpcData { CardHolderPoNumber = "9876543210", TaxType = taxTypeType.TAXEXEMPT }; var cpcResponse = _creditService.CpcEdit(chargeResponse.TransactionId) .WithCpcData(cpcData) .Execute(); Assert.IsNotNull(cpcResponse); Assert.AreEqual("00", cpcResponse.ResponseCode); }
public void moto_007_charge_master_card_token() { var cardHolder = new HpsCardHolder { Address = new HpsAddress { Address = "6860", Zip = "75024" } }; var card = new HpsCreditCard { Number = "5473500000000014", ExpMonth = 12, ExpYear = 2025, Cvv = "123" }; var response = _creditService.Charge(13.02m) .WithCard(card) .WithCardHolder(cardHolder) .WithRequestMultiUseToken(true) .Execute(); Assert.IsNotNull(response); Assert.AreEqual("00", response.ResponseCode); masterCardToken = response.TokenData.TokenValue; }
public void moto_034_offline_credit_return() { var directMarketData = new HpsDirectMarketData { InvoiceNumber = "123456" }; var card = new HpsCreditCard { Number = "5473500000000014", ExpMonth = 12, ExpYear = 2025, Cvv = "123" }; var response = _creditService.Refund(15.15m) .WithCard(card) .WithDirectMarketData(directMarketData) .Execute(); Assert.IsNotNull(response); Assert.AreEqual("00", response.ResponseCode); }
public void moto_003_verify_discover() { var card = new HpsCreditCard { Number = "6011000990156527", ExpMonth = 12, ExpYear = 2025 }; var response = _creditService.Verify() .WithCard(card) .WithCardHolder(new HpsCardHolder { Address = new HpsAddress { Zip = "75024" } }) .WithRequestMultiUseToken(UseTokens) .Execute(); Assert.IsNotNull(response); Assert.AreEqual("00", response.ResponseCode); }
public void moto_008_charge_discover_token() { var cardHolder = new HpsCardHolder { Address = new HpsAddress { Address = "6860", Zip = "750241234" } }; var card = new HpsCreditCard { Number = "6011000990156527", ExpMonth = 12, ExpYear = 2025, Cvv = "123" }; var response = _creditService.Charge(13.03m) .WithCard(card) .WithCardHolder(cardHolder) .WithRequestMultiUseToken(true) .Execute(); Assert.IsNotNull(response); Assert.AreEqual("00", response.ResponseCode); discoverToken = response.TokenData.TokenValue; }
public void moto_033_offline_authorization() { var directMarketData = new HpsDirectMarketData { InvoiceNumber = "123456" }; var card = new HpsCreditCard { Number = "4012002000060016", ExpMonth = 12, ExpYear = 2025, Cvv = "123" }; var response = _creditService.OfflineAuth(17.10m) .WithCard(card) .WithOfflineAuthCode("654321") .WithDirectMarketData(directMarketData) .Execute(); Assert.IsNotNull(response); Assert.AreEqual("00", response.ResponseCode); }
public void moto_009_charge_amex_token() { var cardHolder = new HpsCardHolder { Address = new HpsAddress { Address = "6860 Dallas Pkwy", Zip = "75024" } }; var card = new HpsCreditCard { Number = "372700699251018", ExpMonth = 12, ExpYear = 2025, Cvv = "1234" }; var response = _creditService.Charge(13.04m) .WithCard(card) .WithCardHolder(cardHolder) .WithRequestMultiUseToken(true) .Execute(); Assert.IsNotNull(response); Assert.AreEqual("00", response.ResponseCode); amexToken = response.TokenData.TokenValue; }
/// <summary> /// Get a token for a given credit card. /// </summary> /// <param name="cardData">An instance representing a credit card.</param> /// <returns>A token with expiration information.</returns> public HpsToken GetToken(HpsCreditCard cardData) { return RequestToken(new HpsCardToken(cardData)); }
public void moto_013_charge_amex() { var cardHolder = new HpsCardHolder { Address = new HpsAddress { Address = "6860 Dallas Pkwy", Zip = "75024" } }; var directMarketData = new HpsDirectMarketData { InvoiceNumber = "123456" }; var typeBuilder = _creditService.Charge(17.04m); var card = new HpsCreditCard { Number = "372700699251018", ExpMonth = 12, ExpYear = 2025, Cvv = "1234" }; // ReSharper disable once ConditionIsAlwaysTrueOrFalse // ReSharper disable once UnreachableCode // ReSharper disable once CSharpWarnings::CS0162 var builder = UseTokens ? typeBuilder.WithToken(amexToken) : typeBuilder.WithCard(card); var chargeResponse = builder .WithCardHolder(cardHolder) .WithDirectMarketData(directMarketData) .Execute(); Assert.IsNotNull(chargeResponse); Assert.AreEqual("00", chargeResponse.ResponseCode); }