public void charge_visa_EMV_Prev_Chip_Card_Read_Success()
        {
            var cardHolder = new HpsCardHolder {Address = new HpsAddress {Address = "6860 Dallas Pkwy", Zip = "75024"}};
            var directMarketData = new HpsDirectMarketData {InvoiceNumber = "123456"};
            var trackData = new HpsTrackData { Value = ";4761739001010036=15122011184404889?" };

            var typeBuilder = _creditService.Charge(17.01m);

            var emvData = new HpsEmvDataType
            {
                ChipCondition = emvChipConditionType.CHIP_FAILED_PREV_SUCCESS,
                ChipConditionSpecified = false,
                TagData = "9F4005F000F0A0019F02060000000025009F03060000000000009F2608D90A06501B48564E82027C005F3401019F360200029F0702FF009F0802008C9F0902008C9F34030403029F2701809F0D05F0400088009F0E0508000000009F0F05F0400098005F280208409F390105FFC605DC4000A800FFC7050010000000FFC805DC4004F8009F3303E0B8C89F1A0208409F350122950500000080005F2A0208409A031409109B02E8009F21030811539C01009F37045EED3A8E4F07A00000000310109F0607A00000000310108407A00000000310109F100706010A03A400029F410400000001"
            };

            var builder = typeBuilder.WithTrackData(trackData);

            var chargeResponse = builder
                .WithCardHolder(cardHolder)
                .WithDirectMarketData(directMarketData)
                .WithEMVData(emvData)
                .WithAllowDuplicates(true)
                .Execute();

            Assert.IsNotNull(chargeResponse);
            Assert.AreEqual("00", chargeResponse.ResponseCode);
        }
        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_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_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_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_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);
        }
        public HpsCharge Charge(decimal amount, string currency, HpsTrackData trackData, HpsEncryptionData encryptionData = null,
            decimal gratuity = 0, bool allowPartialAuthorization = false, bool requestMultiUseToken = false,
            HpsDirectMarketData directMarketData = null, string emvData = "", bool allowDuplicates = false)
        {
            HpsInputValidation.CheckAmount(amount);
            HpsInputValidation.CheckCurrency(currency);

            /* Build the transaction request. */
            var transaction = new PosRequestVer10Transaction
            {
                Item = new PosCreditSaleReqType
                {
                    Block1 = new CreditSaleReqBlock1Type
                    {
                        Amt = amount,
                        GratuityAmtInfo = gratuity,
                        GratuityAmtInfoSpecified = gratuity != 0,
                        AllowPartialAuth = allowPartialAuthorization ? booleanType.Y : booleanType.N,
                        AllowPartialAuthSpecified = true,
                        AllowDup = allowDuplicates ? booleanType.Y : booleanType.N,
                        AllowDupSpecified = true,
                        CardData = new CardDataType
                        {
                            TokenRequest = requestMultiUseToken ? booleanType.Y : booleanType.N,
                            Item = HydrateCardTrackData(trackData),
                            EncryptionData = HydrateEncryptionData(encryptionData)
                        },
                        DirectMktData = HydrateDirectMktData(directMarketData),
                        EMVData = HydrateEmvData(emvData)
                    }
                },
                ItemElementName = ItemChoiceType1.CreditSale
            };

            return SubmitCharge(transaction, amount, currency);
        }
        /// <summary>
        /// The <b>credit sale</b> transaction authorizes a sale purchased with a credit card. The
        /// authorization in place in the current open batch (should auto-close for e-commerce
        /// transactions). If a batch is not open, this transaction will create an open batch.
        /// </summary>
        /// <param name="amount">The amount (in dollars).</param>
        /// <param name="currency">The currency (3-letter ISO code for currency).</param>
        /// <param name="token">The secure token</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>
        /// <param name="directMarketData">The direct market data.</param>
        /// <returns>The <see cref="HpsCharge"/>.</returns>
        public HpsCharge Charge(decimal amount, string currency, string token, HpsCardHolder cardHolder = null,
            bool requestMultiUseToken = false, string descriptor = null, bool allowPartialAuth = false,
            HpsTransactionDetails details = null, decimal gratuity = 0, HpsDirectMarketData directMarketData = null)
        {
            HpsInputValidation.CheckAmount(amount);
            HpsInputValidation.CheckCurrency(currency);

            /* Build the transaction request. */
            var transaction = new PosRequestVer10Transaction
            {
                Item = new PosCreditSaleReqType
                {
                    Block1 = new CreditSaleReqBlock1Type
                    {
                        AllowDup = booleanType.Y,
                        AllowDupSpecified = true,
                        AllowPartialAuth = allowPartialAuth ? booleanType.Y : booleanType.N,
                        AllowPartialAuthSpecified = true,
                        Amt = amount,
                        GratuityAmtInfo = gratuity,
                        GratuityAmtInfoSpecified = gratuity != 0,
                        CardHolderData = cardHolder == null ? null : HydrateCardHolderData(cardHolder),
                        CardData = new CardDataType
                        {
                            TokenRequest = requestMultiUseToken ? booleanType.Y : booleanType.N,
                            Item = new CardDataTypeTokenData
                            {
                                TokenValue = token
                            }
                        },
                        AdditionalTxnFields = HydrateAdditionalTxnFields(details),
                        TxnDescriptor = descriptor,
                        DirectMktData = HydrateDirectMktData(directMarketData)
                    }
                },
                ItemElementName = ItemChoiceType1.CreditSale
            };

            return SubmitCharge(transaction, amount, currency, (details == null) ? null : details.ClientTransactionId);
        }
        /// <summary>
        /// A <b>Capture</b> transaction adds a previous authorization transaction to the current open
        /// batch. If a batch is not open, this transaction will create one. 
        /// </summary>
        /// <param name="transactionId">The authorization transaction ID.</param>
        /// <param name="amount">An amount to charge (optional). Used if different from original authorization.</param>
        /// <param name="gratuity">The gratuity amount (optional).</param>
        /// <param name="clientTransactionId">The optional client transaction ID.</param>
        /// <param name="directMarketData">The direct market data.</param>
        /// <returns>The details of the charge captured.</returns>
        public HpsReportTransactionDetails Capture(int transactionId, decimal? amount = null, decimal? gratuity = null,
            long? clientTransactionId = null, HpsDirectMarketData directMarketData = null)
        {
            /* Build the transaction request. */
            var transaction = new PosRequestVer10Transaction
            {
                Item = new PosCreditAddToBatchReqType
                {
                    GatewayTxnId = transactionId
                },
                ItemElementName = ItemChoiceType1.CreditAddToBatch
            };

            var request = (PosCreditAddToBatchReqType)transaction.Item;
            request.AmtSpecified = amount.HasValue;
            if (amount.HasValue)
            {
                request.Amt = amount.Value;
            }

            request.GratuityAmtInfoSpecified = gratuity.HasValue;
            if (gratuity.HasValue)
            {
                request.GratuityAmtInfo = gratuity.Value;
            }

            request.DirectMktData = HydrateDirectMktData(directMarketData);

            /* Submit the transaction. */
            var rsp = DoTransaction(transaction, clientTransactionId).Ver10;
            HpsGatewayResponseValidation.CheckResponse(rsp, ItemChoiceType2.CreditAddToBatch);

            return Get(transactionId);
        }
        public void ecomm_018_partial_approval_visa() {
            var cardHolder = new HpsCardHolder { Address = new HpsAddress { Address = "6860", Zip = "75024" } };
            var directMarketData = new HpsDirectMarketData { InvoiceNumber = "123456" };

            var card = new HpsCreditCard {
                Number = "4012002000060016",
                ExpMonth = 12,
                ExpYear = 2025,
                Cvv = "123"
            };

            var response = _creditService.Charge(130m)
                .WithCard(card)
                .WithCardHolder(cardHolder)
                .WithDirectMarketData(directMarketData)
                .WithAllowPartialAuth(true)
                .Execute();

            Assert.IsNotNull(response);
            Assert.AreEqual("10", response.ResponseCode);

            Assert.IsNotNull(response);
            Assert.AreEqual(110.00m, response.AuthorizedAmount);
        }
        public void ecomm_012_charge_discover() {
            var cardHolder = new HpsCardHolder { Address = new HpsAddress { Address = "6860", Zip = "750241234" } };
            var directMarketData = new HpsDirectMarketData { InvoiceNumber = "123456" };

            var typeBuilder = _creditService.Charge(17.03m);

            var card = new HpsCreditCard {
                Number = "6011000990156527",
                ExpMonth = 12,
                ExpYear = 2025,
                Cvv = "123"
            };

            // ReSharper disable once ConditionIsAlwaysTrueOrFalse
            // ReSharper disable once UnreachableCode
            // ReSharper disable once CSharpWarnings::CS0162
            var builder = UseTokens ? typeBuilder.WithToken(discoverToken) :
                typeBuilder.WithCard(card);

            var chargeResponse = builder
                .WithCardHolder(cardHolder)
                .WithDirectMarketData(directMarketData)
                .Execute();

            Assert.IsNotNull(chargeResponse);
            Assert.AreEqual("00", chargeResponse.ResponseCode);
        }
        public void ecomm_010_charge_visa() {
            var cardHolder = new HpsCardHolder { Address = new HpsAddress { Address = "6860 Dallas Pkwy", Zip = "75024" } };
            var directMarketData = new HpsDirectMarketData { InvoiceNumber = "123456" };

            var typeBuilder = _creditService.Charge(17.01m);

            var card = new HpsCreditCard {
                Number = "4012002000060016",
                ExpMonth = 12,
                ExpYear = 2025,
                Cvv = "123"
            };

            // ReSharper disable once ConditionIsAlwaysTrueOrFalse
            // ReSharper disable once UnreachableCode
            // ReSharper disable once CSharpWarnings::CS0162
            var builder = UseTokens ? typeBuilder.WithToken(visaToken) :
                typeBuilder.WithCard(card);

            var chargeResponse = builder
                .WithCardHolder(cardHolder)
                .WithDirectMarketData(directMarketData)
                .Execute();

            Assert.IsNotNull(chargeResponse);
            Assert.AreEqual("00", chargeResponse.ResponseCode);
            test10TransactionId = chargeResponse.TransactionId;
        }
        public void charge_visa_EMV_Issuer_Response_is_Present()
        {
            var cardHolder = new HpsCardHolder { Address = new HpsAddress() { Address = "6860 Dallas Pkwy", Zip = "75024" } };
            var directMarketData = new HpsDirectMarketData { InvoiceNumber = "123456" };
            var trackData = new HpsTrackData { Value = ";4761739001010036=15122011184404889?" };

            var emvData = new HpsEmvDataType
            {
                TagData = "9F4005F000F0A0019F02060000000025009F03060000000000009F2608D90A06501B48564E82027C005F3401019F360200029F0702FF009F0802008C9F0902008C9F34030403029F2701809F0D05F0400088009F0E0508000000009F0F05F0400098005F280208409F390105FFC605DC4000A800FFC7050010000000FFC805DC4004F8009F3303E0B8C89F1A0208409F350122950500000080005F2A0208409A031409109B02E8009F21030811539C01009F37045EED3A8E4F07A00000000310109F0607A00000000310108407A00000000310109F100706010A03A400029F410400000001"
            };

            var typeBuilder = _creditService.Charge(17.01m);
            var builder = typeBuilder.WithTrackData(trackData);

            var chargeResponse = builder
                .WithCardHolder(cardHolder)
                .WithDirectMarketData(directMarketData)
                .WithEMVData(emvData)
                .Execute();

            Assert.IsNotNull(chargeResponse);
            Assert.IsNotNull(chargeResponse.EMVIssuerResp);
        }