public override HpsAuthorization Execute()
        {
            base.Execute();

            HpsInputValidation.CheckAmount(amount.Value);
            var block1 = new CreditAdditionalAuthReqBlock1Type {
                Amt                   = amount.Value,
                AllowDup              = allowDuplicates ? booleanType.Y : booleanType.N,
                GatewayTxnId          = transactionId,
                GatewayTxnIdSpecified = true
            };

            if (details != null)
            {
                block1.AdditionalTxnFields = service.HydrateAdditionalTxnFields(details);
            }
            if (txnDescriptor != null)
            {
                block1.TxnDescriptor = txnDescriptor;
            }

            var transaction = new PosRequestVer10Transaction {
                Item = new PosCreditAdditionalAuthReqType {
                    Block1 = block1
                },
                ItemElementName = ItemChoiceType1.CreditAdditionalAuth
            };

            long?clientTransactionId = service.GetClientTransactionId(details);
            var  response            = service.SubmitTransaction(transaction, clientTransactionId);

            return(new HpsAuthorization().FromResponse(response));
        }
        /// <summary>
        /// An <b>AddValue</b> transaction is used to add an amount to the value of an active gift card.
        /// </summary>
        /// <param name="amount">The amount (in dollars).</param>
        /// <param name="currency">Transaction currency.</param>
        /// <param name="giftCard">The gift card information.</param>
        /// <returns>The <see cref="HpsGiftCardAddValue"/>.</returns>
        public HpsGiftCardResponse AddValue(decimal amount, string currency, HpsGiftCard giftCard)
        {
            HpsInputValidation.CheckAmount(amount);
            HpsInputValidation.CheckCurrency(currency);

            /* Build the transaction request. */
            var transaction = new PosRequestVer10Transaction
            {
                Item = new PosGiftCardAddValueReqType
                {
                    Block1 = new GiftCardAddValueReqBlock1Type
                    {
                        Amt      = amount,
                        CardData = new GiftCardDataType
                        {
                            Item            = giftCard.Value,
                            ItemElementName = giftCard.ValueType,
                            EncryptionData  = (giftCard.EncryptionData == null) ? null : new EncryptionDataType
                            {
                                EncryptedTrackNumber = giftCard.EncryptionData.EncryptedTrackNumber,
                                KSN     = giftCard.EncryptionData.Ksn,
                                KTB     = giftCard.EncryptionData.Ktb,
                                Version = giftCard.EncryptionData.Version
                            }
                        }
                    }
                },
                ItemElementName = ItemChoiceType1.GiftCardAddValue
            };

            /* Submit the transaction. */
            return(SubmitAddValue(transaction));
        }
Example #3
0
        public override HpsGiftCardResponse Execute()
        {
            base.Execute();

            HpsInputValidation.CheckAmount(amount.Value);

            var block1 = new GiftCardRewardReqBlock1Type {
                Amt      = amount.Value,
                CardData = service.HydrateGiftCardData(card),
                Currency = currency
            };

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

            block1.TaxAmtInfoSpecified = tax.HasValue;
            if (tax != null)
            {
                block1.TaxAmtInfo = tax.Value;
            }

            var transaction = new PosRequestVer10Transaction {
                Item = new PosGiftCardRewardReqType {
                    Block1 = block1
                },
                ItemElementName = ItemChoiceType1.GiftCardReward
            };

            var response = service.SubmitTransaction(transaction);

            return(new HpsGiftCardResponse().FromResponse(response));
        }
Example #4
0
        public override HpsDebitAuthorization Execute()
        {
            base.Execute();

            HpsInputValidation.CheckAmount(amount.Value);

            var block1 = new DebitSaleReqBlock1Type {
                Amt                       = amount.Value,
                AllowDup                  = allowDuplicates ? booleanType.Y : booleanType.N,
                AllowDupSpecified         = true,
                AllowPartialAuth          = allowPartialAuth ? booleanType.Y : booleanType.N,
                AllowPartialAuthSpecified = true
            };

            if (trackData != null)
            {
                block1.TrackData = trackData.Value;
                if (trackData.EncryptionData != null)
                {
                    block1.EncryptionData = service.HydrateEncryptionData(trackData.EncryptionData);
                }
            }
            if (token != null)
            {
                block1.TokenValue = token;
            }

            if (pinBlock != null)
            {
                block1.PinBlock = pinBlock;
            }

            if (cardHolder != null)
            {
                block1.CardHolderData = service.HydrateCardHolderData(cardHolder);
            }

            block1.CashbackAmtInfoSpecified = cashBack.HasValue;
            if (block1.CashbackAmtInfoSpecified)
            {
                block1.CashbackAmtInfo = cashBack.Value;
            }

            if (details != null)
            {
                block1.AdditionalTxnFields = service.HydrateAdditionalTxnFields(details);
            }

            var transaction = new PosRequestVer10Transaction {
                Item = new PosDebitSaleReqType {
                    Block1 = block1
                },
                ItemElementName = ItemChoiceType1.DebitSale
            };

            var clientTxnId = service.GetClientTransactionId(details);

            return(service.SubmitTransaction(transaction, clientTxnId));
        }
Example #5
0
        public HpsCheckResponse BuildTransaction(checkActionType action, HpsCheck check, decimal?amount, long?clientTransactionId = null, bool checkVerify = false, bool achVerify = false)
        {
            if (amount.HasValue)
            {
                HpsInputValidation.CheckAmount(amount.Value);
            }

            if (check.SecCode == "CCD" && (check.CheckHolder == null || check.CheckHolder.CheckName == null))
            {
                throw new HpsInvalidRequestException(HpsExceptionCodes.MissingCheckName, "For SEC Code CCD the check name is required.", "CheckName");
            }

            var block1 = new CheckSaleReqBlock1Type {
                CheckAction            = action,
                SECCode                = check.SecCode,
                AccountInfo            = HydrateCheckData(check),
                AmtSpecified           = amount.HasValue,
                CheckTypeSpecified     = check.CheckType.HasValue,
                DataEntryModeSpecified = check.DataEntryMode.HasValue,
                VerifyInfo             = new VerifyInfoType {
                    ACHVerify            = achVerify ? booleanType.Y : booleanType.N,
                    ACHVerifySpecified   = true,
                    CheckVerify          = checkVerify ? booleanType.Y : booleanType.N,
                    CheckVerifySpecified = true
                }
            };

            if (block1.AmtSpecified)
            {
                block1.Amt = amount.Value;
            }

            if (block1.CheckTypeSpecified)
            {
                block1.CheckType = check.CheckType.Value;
            }
            if (block1.DataEntryModeSpecified)
            {
                block1.DataEntryMode = check.DataEntryMode.Value;
            }
            if (check.CheckHolder != null)
            {
                block1.ConsumerInfo = HydrateConsumerInfo(check.CheckHolder);
            }

            var transaction = new PosRequestVer10Transaction {
                Item = new PosCheckSaleReqType {
                    Block1 = block1
                },
                ItemElementName = ItemChoiceType1.CheckSale
            };

            return(SubmitTransaction(transaction, clientTransactionId));
        }
Example #6
0
        /// <summary>
        /// A Debit Reversal transaction reverses a Debit Charge or Debit Return transaction.
        /// </summary>
        /// <param name="transactionId">The gateway transaciton ID of the charge to be reversed.</param>
        /// <param name="trackData">The data read from the card by the card reader.</param>
        /// <param name="amount">Authorization amount.</param>
        /// <param name="authorizedAmount">Settlement amount or New Authorization amount after reversal occures.</param>
        /// <param name="encryptionData">E3 encryption data group.</param>
        /// <param name="details">Group containing additional transaction fields to be included in detail reporting.</param>
        /// <param name="clientTransactionId">The client transaction ID.</param>
        /// <returns>The reversal result.</returns>
        public HpsTransaction Reverse(int transactionId, decimal amount, string trackData, decimal?authorizedAmount = null,
                                      HpsEncryptionData encryptionData = null, HpsTransactionDetails details = null, long?clientTransactionId = null)
        {
            HpsInputValidation.CheckAmount(amount);

            /* Build the transaction request. */
            var transaction = new PosRequestVer10Transaction
            {
                Item = new PosDebitReversalReqType
                {
                    Block1 = new DebitReversalReqBlock1Type
                    {
                        GatewayTxnId          = transactionId,
                        GatewayTxnIdSpecified = true,
                        TrackData             = trackData,
                        Amt                 = amount,
                        EncryptionData      = HydrateEncryptionData(encryptionData),
                        AdditionalTxnFields = HydrateAdditionalTxnFields(details)
                    }
                },
                ItemElementName = ItemChoiceType1.DebitReversal
            };

            if (authorizedAmount.HasValue)
            {
                var block = ((PosDebitReversalReqType)transaction.Item).Block1;
                block.AuthAmt          = authorizedAmount.Value;
                block.AuthAmtSpecified = true;
            }

            var rsp = DoTransaction(transaction, clientTransactionId).Ver10;

            HpsGatewayResponseValidation.CheckResponse(rsp, ItemChoiceType2.DebitReversal);

            long?clientTxnId = null;

            if (rsp.Header.ClientTxnId != default(long))
            {
                clientTxnId = rsp.Header.ClientTxnId;
            }

            return(new HpsTransaction
            {
                Header = HydrateTransactionHeader(rsp.Header),
                TransactionId = rsp.Header.GatewayTxnId,
                ClientTransactionId = clientTxnId,
                ResponseCode = "00",
                ResponseText = string.Empty
            });
        }
        public override HpsDebitAuthorization Execute()
        {
            base.Execute();

            HpsInputValidation.CheckAmount(amount.Value);

            var block1 = new DebitReversalReqBlock1Type {
                Amt = amount.Value
            };

            block1.AuthAmtSpecified = authorizedAmount.HasValue;
            if (block1.AuthAmtSpecified)
            {
                block1.AuthAmt = authorizedAmount.Value;
            }

            if (trackData != null)
            {
                block1.TrackData = trackData.Value;
                if (trackData.EncryptionData != null)
                {
                    block1.EncryptionData = service.HydrateEncryptionData(trackData.EncryptionData);
                }
            }
            if (transactionId != null)
            {
                block1.GatewayTxnId          = transactionId.Value;
                block1.GatewayTxnIdSpecified = true;
            }

            if (details != null)
            {
                block1.AdditionalTxnFields = service.HydrateAdditionalTxnFields(details);
            }

            var transaction = new PosRequestVer10Transaction {
                Item = new PosDebitReversalReqType {
                    Block1 = block1
                },
                ItemElementName = ItemChoiceType1.DebitReversal
            };

            var clientTxnId = service.GetClientTransactionId(details);

            return(service.SubmitTransaction(transaction, clientTxnId));
        }
Example #8
0
        /// <summary>
        /// A Debit Charge transaction performs a sale purchased with a Debit Card. The Debit Charge is placed
        /// in the current open batch. If a batch is not open, this transaction creates an open batch.
        /// </summary>
        /// <param name="amount">Authorization amount.</param>
        /// <param name="currency">Currency type ("usd").</param>
        /// <param name="trackData">Track data read from the card by the card reader.</param>
        /// <param name="pinBlock">PIN block.</param>
        /// <param name="cashBackAmount">Contains the portion of the amount that is cash back.</param>
        /// <param name="allowDuplicates">Indicates whether to allow duplicate transactions.</param>
        /// <param name="allowPartialAuth">Indicate whether to allow partial authorization.</param>
        /// <param name="cardHolder">Card holder information.</param>
        /// <param name="encryptionData">E3 encryption data group.</param>
        /// <param name="details">Group containing additional transaction fields to be inclided in detail reporting.</param>
        /// <param name="clientTransactionId">The client transaction ID.</param>
        /// <returns>The Debit Charge result.</returns>
        public HpsAuthorization Charge(decimal amount, string currency, string trackData, string pinBlock,
                                       HpsEncryptionData encryptionData = null, bool allowDuplicates      = false, decimal?cashBackAmount       = null,
                                       bool allowPartialAuth            = false, HpsCardHolder cardHolder = null, HpsTransactionDetails details = null,
                                       long?clientTransactionId         = null)
        {
            HpsInputValidation.CheckAmount(amount);
            HpsInputValidation.CheckCurrency(currency);

            var transaction = new PosRequestVer10Transaction
            {
                Item = new PosDebitSaleReqType
                {
                    Block1 = new DebitSaleReqBlock1Type
                    {
                        TrackData         = trackData,
                        AllowDup          = allowDuplicates ? booleanType.Y : booleanType.N,
                        AllowDupSpecified = true,
                        CardHolderData    = cardHolder == null ? null : HydrateCardHolderData(cardHolder),
                        Amt                       = amount,
                        CashbackAmtInfo           = cashBackAmount.HasValue ? cashBackAmount.Value : 0,
                        CashbackAmtInfoSpecified  = cashBackAmount.HasValue,
                        AllowPartialAuth          = allowPartialAuth ? booleanType.Y : booleanType.N,
                        AllowPartialAuthSpecified = true,
                        PinBlock                  = pinBlock,
                        EncryptionData            = HydrateEncryptionData(encryptionData),
                        AdditionalTxnFields       = HydrateAdditionalTxnFields(details)
                    }
                },
                ItemElementName = ItemChoiceType1.DebitSale
            };

            var rsp = DoTransaction(transaction, clientTransactionId).Ver10;

            HpsGatewayResponseValidation.CheckResponse(rsp, ItemChoiceType2.DebitSale);

            var chargeResponse = (AuthRspStatusType)rsp.Transaction.Item;

            HpsIssuerResponseValidation.CheckResponse(rsp.Header.GatewayTxnId, chargeResponse.RspCode, chargeResponse.RspText);

            return(HydrateAuthorization <HpsAuthorization>(rsp));
        }
        public override HpsGiftCardResponse Execute()
        {
            base.Execute();

            HpsInputValidation.CheckAmount(amount.Value);
            HpsInputValidation.CheckCurrency(currency);

            var transaction = new PosRequestVer10Transaction {
                Item = new PosGiftCardActivateReqType {
                    Block1 = new GiftCardActivateReqBlock1Type {
                        Amt      = amount.Value,
                        CardData = service.HydrateGiftCardData(card)
                    }
                },
                ItemElementName = ItemChoiceType1.GiftCardActivate
            };

            var response = service.SubmitTransaction(transaction);

            return(new HpsGiftCardResponse().FromResponse(response));
        }
        /// <summary>
        /// A <b>Reverse</b> transaction is used to cancel a previously approved Sale, Activate, or AddValue
        /// from the current open batch. If successful, the gift card balance is restored to the amount prior
        /// to the transaction being reversed.
        /// </summary>
        /// <param name="giftCard">The gift card information.</param>
        /// <param name="amount">Amount of the transaction to be reversed.</param>
        /// <param name="currency">Identifies the currency of a financial transaction ("usd" or "points")</param>
        /// <returns>The <see cref="HpsGiftCardReward"/>.</returns>
        public HpsGiftCardResponse Reverse(HpsGiftCard giftCard, decimal amount, string currency = "usd")
        {
            HpsInputValidation.CheckAmount(amount);
            HpsInputValidation.CheckCurrency(currency);

            /* Build the transaction request. */
            var transaction = new PosRequestVer10Transaction
            {
                Item = new PosGiftCardReversalReqType
                {
                    Block1 = new GiftCardReversalReqBlock1Type
                    {
                        Amt      = amount,
                        CardData = HydrateGiftCardData(giftCard)
                    }
                },
                ItemElementName = ItemChoiceType1.GiftCardReversal
            };

            /* Submit the transaction. */
            return(SubmitReversal(transaction));
        }
        /// <summary>
        /// A <b>Reverse</b> transaction is used to cancel a previously approved Sale, Activate, or AddValue
        /// from the current open batch. If successful, the gift card balance is restored to the amount prior
        /// to the transaction being reversed.
        /// </summary>
        /// <param name="transactionId">Transaction identifier assigned by Portico Gateway of the transaction to be reversed.</param>
        /// <param name="amount">Amount of the transaction to be reversed.</param>
        /// <param name="currency">Identifies the currency of a financial transaction ("usd" or "points")</param>
        /// <returns>The <see cref="HpsGiftCardReward"/>.</returns>
        public HpsGiftCardResponse Reverse(long transactionId, decimal amount, string currency = "usd")
        {
            HpsInputValidation.CheckAmount(amount);

            /* Build the transaction request. */
            var transaction = new PosRequestVer10Transaction
            {
                Item = new PosGiftCardReversalReqType
                {
                    Block1 = new GiftCardReversalReqBlock1Type
                    {
                        Amt                   = amount,
                        GatewayTxnId          = transactionId,
                        GatewayTxnIdSpecified = true
                    }
                },
                ItemElementName = ItemChoiceType1.GiftCardReversal
            };

            /* Submit the transaction. */
            return(SubmitReversal(transaction));
        }
        public override HpsGiftCardResponse Execute()
        {
            base.Execute();

            HpsInputValidation.CheckAmount(amount.Value);

            var block1 = new GiftCardReversalReqBlock1Type {
                Amt = amount.Value
            };

            if (card != null)
            {
                block1.CardData = service.HydrateGiftCardData(card);
            }
            else if (transactionId != null)
            {
                block1.GatewayTxnId          = transactionId.Value;
                block1.GatewayTxnIdSpecified = true;
            }
            else if (clientTransactionId != null)
            {
                block1.ClientTxnId          = clientTransactionId.Value;
                block1.ClientTxnIdSpecified = true;
            }

            var transaction = new PosRequestVer10Transaction {
                Item = new PosGiftCardReversalReqType {
                    Block1 = block1
                },
                ItemElementName = ItemChoiceType1.GiftCardReversal
            };

            var response = service.SubmitTransaction(transaction);

            return(new HpsGiftCardResponse().FromResponse(response));
        }
Example #13
0
        /// <summary>
        /// A Debit Return transaction returns funds to the cardholder. The transaction is generally used as a
        /// counterpart to a Debit Charge transaction that needs to be reversed. The Debit Return transaction is
        /// placed in the current open batch. If a batch is not open, this transaction create an open batch.
        /// </summary>
        /// <param name="transactionId">The gateway transaciton ID of the charge to be returned.</param>
        /// <param name="trackData">Track data read from the card by the card reader.</param>
        /// <param name="amount">Authorization amount.</param>
        /// <param name="pinBlock">PIN block.</param>
        /// <param name="allowDuplicates">Indicates whether to allow duplicate transacitons.</param>
        /// <param name="cardHolder">Card holder information.</param>
        /// <param name="encryptionData">E3 encryption data group.</param>
        /// <param name="details">Group containing additional transaction fields to be included in detail reporting.</param>
        /// <param name="clientTransactionId">Client transaction ID.</param>
        /// <returns>The Return (Authorization) results.</returns>
        public HpsAuthorization Return(int transactionId, decimal amount, string trackData, string pinBlock,
                                       bool allowDuplicates          = false, HpsCardHolder cardHolder = null, HpsEncryptionData encryptionData = null,
                                       HpsTransactionDetails details = null, long?clientTransactionId  = null)
        {
            HpsInputValidation.CheckAmount(amount);

            /* Build the transaction request. */
            var transaction = new PosRequestVer10Transaction
            {
                Item = new PosDebitReturnReqType
                {
                    Block1 = new DebitReturnReqBlock1Type
                    {
                        TrackData         = trackData,
                        AllowDup          = allowDuplicates ? booleanType.Y : booleanType.N,
                        AllowDupSpecified = true,
                        CardHolderData    = cardHolder == null ? null : HydrateCardHolderData(cardHolder),
                        Amt                 = amount,
                        PinBlock            = pinBlock,
                        EncryptionData      = HydrateEncryptionData(encryptionData),
                        AdditionalTxnFields = HydrateAdditionalTxnFields(details)
                    }
                },
                ItemElementName = ItemChoiceType1.DebitReturn
            };

            var rsp = DoTransaction(transaction, clientTransactionId).Ver10;

            HpsGatewayResponseValidation.CheckResponse(rsp, ItemChoiceType2.DebitReturn);

            var returnRsp = (AuthRspStatusType)rsp.Transaction.Item;

            HpsIssuerResponseValidation.CheckResponse(rsp.Header.GatewayTxnId, returnRsp.RspCode, returnRsp.RspText);

            return(HydrateAuthorization <HpsAuthorization>(rsp));
        }
Example #14
0
        public override HpsCharge Execute()
        {
            base.Execute();

            var block1 = new CreditSaleReqBlock1Type {
                AllowDup                  = allowDuplicates ? booleanType.Y : booleanType.N,
                AllowDupSpecified         = true,
                AllowPartialAuth          = allowPartialAuth ? booleanType.Y : booleanType.N,
                AllowPartialAuthSpecified = true,
                Amt = amount.Value
            };

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

            block1.ConvenienceAmtInfoSpecified = convenienceAmt.HasValue;
            if (block1.ConvenienceAmtInfoSpecified)
            {
                block1.ConvenienceAmtInfo = convenienceAmt.Value;
                HpsInputValidation.CheckAmount(block1.ConvenienceAmtInfo);
            }
            block1.ShippingAmtInfoSpecified = shippingAmt.HasValue;
            if (block1.ShippingAmtInfoSpecified)
            {
                block1.ShippingAmtInfo = shippingAmt.Value;
                HpsInputValidation.CheckAmount(block1.ShippingAmtInfo);
            }

            if (cardHolder != null)
            {
                block1.CardHolderData = service.HydrateCardHolderData(cardHolder);
            }

            var cardData = new CardDataType();

            if (card != null)
            {
                cardData.Item = service.HydrateCardManualEntry(card, cardPresent, readerPresent);
                if (card.EncryptionData != null)
                {
                    cardData.EncryptionData = service.HydrateEncryptionData(card.EncryptionData);
                }
            }
            if (token != null)
            {
                cardData.Item = service.HydrateTokenData(token, cardPresent, readerPresent);
            }
            if (trackData != null)
            {
                cardData.Item = service.HydrateCardTrackData(trackData);
                if (trackData.EncryptionData != null)
                {
                    cardData.EncryptionData = service.HydrateEncryptionData(trackData.EncryptionData);
                }
            }
            cardData.TokenRequest = requestMultiUseToken ? booleanType.Y : booleanType.N;

            if (cpcReq)
            {
                block1.CPCReq          = booleanType.Y;
                block1.CPCReqSpecified = true;
            }

            if (details != null)
            {
                block1.AdditionalTxnFields = service.HydrateAdditionalTxnFields(details);
            }
            if (txnDescriptor != null)
            {
                block1.TxnDescriptor = txnDescriptor;
            }
            if (autoSubstantiation != null)
            {
                block1.AutoSubstantiation = service.HydrateAutoSubstantiation(autoSubstantiation);
            }
            if (originalTxnReferenceData != null)
            {
                block1.OrigTxnRefData = new origTxnRefDataType {
                    AuthCode        = originalTxnReferenceData.AuthorizationCode,
                    CardNbrLastFour = originalTxnReferenceData.CardNumberLast4
                }
            }
            ;
            if (directMarketData != null)
            {
                block1.DirectMktData = service.HydrateDirectMktData(directMarketData);
            }
            block1.CardData = cardData;

            if (tagData != null)
            {
                block1.TagData = service.HydrateTagData(tagData);
            }

            if (secureEcommerce != null)
            {
                block1.SecureECommerce = service.HydrateSecureEcommerce(secureEcommerce);
            }

            var transaction = new PosRequestVer10Transaction {
                Item = new PosCreditSaleReqType {
                    Block1 = block1
                },
                ItemElementName = ItemChoiceType1.CreditSale
            };

            var clientTransactionId = service.GetClientTransactionId(details);
            var response            = service.SubmitTransaction(transaction, clientTransactionId);
            var charge = new HpsCharge().FromResponse(response);

            if (rewards != null && charge.ResponseCode == "00")
            {
                var giftClient = new HpsFluentGiftCardService(service.ServicesConfig);
                try {
                    charge.RewardsResponse = giftClient.Reward(amount).WithCard(rewards).Execute();
                }
                catch (HpsException) { /* NOM NOM */ }
            }

            return(charge);
        }
Example #15
0
        /// <summary>
        /// A <b>Sale</b> transaction is used to process transactions using bank account information as the payment method.
        /// The transaction service can be used to perform a Sale or Return transaction by indicating the Check Action.
        /// <br></br><br></br>
        /// <b>NOTE:</b> The Portico Gateway supports both GETI and HPS Colonnade for processing check transactions. While
        /// the available services are the same regardless of the check processor, the services may have different behaviors.
        /// For example, GETI-processed Check Sale transactions support the ability to override a Check Sale transaction
        /// already presented as well as the ability to verify a check.
        /// </summary>
        /// <param name="action">Type of Check Action (Sale, Return, Override).</param>
        /// <param name="check">The Check information.</param>
        /// <param name="amount">The amount of the sale.</param>
        /// <returns>The <see cref="HpsCheckResponse"/>.</returns>
        public HpsCheckResponse Sale(checkActionType action, HpsCheck check, decimal amount)
        {
            HpsInputValidation.CheckAmount(amount);

            /* Build the transaction request. */
            var transaction = new PosRequestVer10Transaction
            {
                Item = new PosCheckSaleReqType
                {
                    Block1 = new CheckSaleReqBlock1Type
                    {
                        Amt         = amount,
                        AccountInfo = new AccountInfoType
                        {
                            AccountNumber = check.AccountNumber,
                            CheckNumber   = check.CheckNumber,
                            MICRData      = check.MicrNumber,
                            RoutingNumber = check.RoutingNumber
                        },
                        AmtSpecified = true,
                        CheckAction  = action,
                        SECCode      = check.SecCode,
                        VerifyInfo   = new VerifyInfoType
                        {
                            CheckVerify          = check.CheckVerify ? booleanType.Y : booleanType.N,
                            CheckVerifySpecified = true,
                            ACHVerify            = check.AchVerify ? booleanType.Y : booleanType.N,
                            ACHVerifySpecified   = true
                        }
                    }
                },
                ItemElementName = ItemChoiceType1.CheckSale
            };

            var block1 = ((PosCheckSaleReqType)transaction.Item).Block1;

            if (check.AccountType.HasValue)
            {
                block1.AccountInfo.AccountType          = check.AccountType.Value;
                block1.AccountInfo.AccountTypeSpecified = true;
            }
            else
            {
                block1.AccountInfo.AccountTypeSpecified = false;
            }

            if (check.CheckType.HasValue)
            {
                block1.CheckType          = check.CheckType.Value;
                block1.CheckTypeSpecified = true;
            }
            else
            {
                block1.CheckTypeSpecified = false;
            }

            if (check.DataEntryMode.HasValue)
            {
                block1.DataEntryMode          = check.DataEntryMode.Value;
                block1.DataEntryModeSpecified = true;
            }
            else
            {
                block1.DataEntryModeSpecified = false;
            }

            if (check.CheckHolder != null)
            {
                block1.ConsumerInfo = new ConsumerInfoType
                {
                    Address1     = check.CheckHolder.Address != null ? check.CheckHolder.Address.Address : null,
                    CheckName    = check.CheckHolder.CheckName,
                    City         = check.CheckHolder.Address != null ? check.CheckHolder.Address.City : null,
                    CourtesyCard = check.CheckHolder.CourtesyCard,
                    DLNumber     = check.CheckHolder.DlNumber,
                    DLState      = check.CheckHolder.DlState,
                    EmailAddress = check.CheckHolder.Email,
                    FirstName    = check.CheckHolder.FirstName,
                    LastName     = check.CheckHolder.LastName,
                    PhoneNumber  = check.CheckHolder.Phone,
                    State        = check.CheckHolder.Address != null ? check.CheckHolder.Address.State : null,
                    Zip          = check.CheckHolder.Address != null ? check.CheckHolder.Address.Zip : null,
                    IdentityInfo = new IdentityInfoType {
                        DOBYear = check.CheckHolder.DobYear != null?check.CheckHolder.DobYear.ToString() : null, SSNL4 = check.CheckHolder.Ssl4 != null ? check.CheckHolder.Ssl4 : null
                    }
                };
            }

            /* Submit the transaction. */
            var rsp = DoTransaction(transaction).Ver10;

            HpsGatewayResponseValidation.CheckResponse(rsp, ItemChoiceType2.CheckSale);

            var saleRsp = (PosCheckSaleRspType)rsp.Transaction.Item;

            if (saleRsp.RspCode != 0)
            {
                throw new HpsCheckException(rsp.Header.GatewayTxnId, GetResponseDetails(saleRsp.CheckRspInfo), saleRsp.RspCode, saleRsp.RspMessage);
            }

            /* Start to fill out a new transaction response (HpsCheckResponse). */
            var response = new HpsCheckResponse
            {
                Header            = HydrateTransactionHeader(rsp.Header),
                TransactionId     = rsp.Header.GatewayTxnId,
                AuthorizationCode = saleRsp.AuthCode,
                ResponseCode      = saleRsp.RspCode.ToString(CultureInfo.InvariantCulture),
                ResponseText      = saleRsp.RspMessage,
                Details           = GetResponseDetails(saleRsp.CheckRspInfo)
            };

            return(response);
        }
        /// <summary>
        /// A <b>Sale</b> transaction is used to record a sale against the gift card. If successful, the card
        /// amount is subtracted from the gift card amount.
        /// </summary>
        /// <param name="giftCard">The gift card information.</param>
        /// <param name="amount">The amount of purchase to be used in rewards calculation.</param>
        /// <param name="currency">Identifies the currency of a financial transaction ("usd" or "points")</param>
        /// <param name="gratuity">The portion of the purchase amount that is a gratuity</param>
        /// <param name="tax">The portion of the purchase amount that is tax</param>
        /// <returns>The <see cref="HpsGiftCardReward"/>.</returns>
        public HpsGiftCardSale Sale(HpsGiftCard giftCard, decimal amount, string currency = "usd",
                                    decimal?gratuity = null, decimal?tax = null)
        {
            currency = currency.ToLower();
            HpsInputValidation.CheckAmount(amount);

            /* Build the transaction request. */
            var transaction = new PosRequestVer10Transaction
            {
                Item = new PosGiftCardSaleReqType
                {
                    Block1 = new GiftCardSaleReqBlock1Type
                    {
                        Amt      = amount,
                        CardData = HydrateGiftCardData(giftCard)
                    }
                },
                ItemElementName = ItemChoiceType1.GiftCardSale
            };

            var block = ((PosGiftCardSaleReqType)transaction.Item).Block1;

            if (currency == "usd" || currency == "points")
            {
                block.Currency          = currency == "usd" ? currencyType.USD : currencyType.POINTS;
                block.CurrencySpecified = true;
            }

            if (gratuity != null)
            {
                block.GratuityAmtInfo          = gratuity.Value;
                block.GratuityAmtInfoSpecified = true;
            }

            if (tax != null)
            {
                block.TaxAmtInfo          = tax.Value;
                block.TaxAmtInfoSpecified = true;
            }

            /* Submit the transaction. */
            var rsp = DoTransaction(transaction).Ver10;

            HpsGatewayResponseValidation.CheckResponse(rsp, ItemChoiceType2.GiftCardSale);

            var saleRsp = (PosGiftCardSaleRspType)rsp.Transaction.Item;

            HpsIssuerResponseValidation.CheckResponse(rsp.Header.GatewayTxnId,
                                                      saleRsp.RspCode.ToString(CultureInfo.InvariantCulture), saleRsp.RspText, HpsCardType.Gift);

            /* Start to fill out a new transaction response. */
            var response = new HpsGiftCardSale
            {
                Header                = HydrateTransactionHeader(rsp.Header),
                TransactionId         = rsp.Header.GatewayTxnId,
                AuthorizationCode     = saleRsp.AuthCode,
                BalanceAmount         = saleRsp.BalanceAmt,
                SplitTenderCardAmount = saleRsp.SplitTenderCardAmt,
                SplitTenderBalanceDue = saleRsp.SplitTenderBalanceDueAmt,
                PointsBalanceAmount   = saleRsp.PointsBalanceAmt,
                ResponseCode          = saleRsp.RspCode.ToString(CultureInfo.InvariantCulture),
                ResponseText          = saleRsp.RspText
            };

            return(response);
        }
        public override HpsTransaction Execute()
        {
            base.Execute();

            var block1 = new CreditOfflineSaleReqBlock1Type {
                AllowDup          = allowDuplicates ? booleanType.Y : booleanType.N,
                AllowDupSpecified = true,
                Amt = amount.Value
            };

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

            block1.ConvenienceAmtInfoSpecified = convenienceAmt.HasValue;
            if (block1.ConvenienceAmtInfoSpecified)
            {
                block1.ConvenienceAmtInfo = convenienceAmt.Value;
                HpsInputValidation.CheckAmount(block1.ConvenienceAmtInfo);
            }
            block1.ShippingAmtInfoSpecified = shippingAmt.HasValue;
            if (block1.ShippingAmtInfoSpecified)
            {
                block1.ShippingAmtInfo = shippingAmt.Value;
                HpsInputValidation.CheckAmount(block1.ShippingAmtInfo);
            }

            if (cardHolder != null)
            {
                block1.CardHolderData = service.HydrateCardHolderData(cardHolder);
            }

            var cardData = new CardDataType();

            if (card != null)
            {
                cardData.Item = service.HydrateCardManualEntry(card, cardPresent, readerPresent);
                if (card.EncryptionData != null)
                {
                    cardData.EncryptionData = service.HydrateEncryptionData(card.EncryptionData);
                }
            }
            if (token != null)
            {
                cardData.Item = service.HydrateTokenData(token, cardPresent, readerPresent);
            }
            if (trackData != null)
            {
                cardData.Item = service.HydrateCardTrackData(trackData);
                if (trackData.EncryptionData != null)
                {
                    cardData.EncryptionData = service.HydrateEncryptionData(trackData.EncryptionData);
                }
            }
            cardData.TokenRequest = requestMultiUseToken ? booleanType.Y : booleanType.N;
            block1.CardData       = cardData;

            if (cpcReq)
            {
                block1.CPCReq          = booleanType.Y;
                block1.CPCReqSpecified = true;
            }

            if (details != null)
            {
                block1.AdditionalTxnFields = service.HydrateAdditionalTxnFields(details);
            }
            if (autoSubstantiation != null)
            {
                block1.AutoSubstantiation = service.HydrateAutoSubstantiation(autoSubstantiation);
            }
            if (directMarketData != null)
            {
                block1.DirectMktData = service.HydrateDirectMktData(directMarketData);
            }
            block1.OfflineAuthCode = offlineAuthCode;

            if (tagData != null)
            {
                block1.TagData = service.HydrateTagData(tagData);
            }

            var transaction = new PosRequestVer10Transaction {
                Item = new PosCreditOfflineSaleReqType {
                    Block1 = block1
                },
                ItemElementName = ItemChoiceType1.CreditOfflineSale
            };

            var            clientTransactionId = service.GetClientTransactionId(details);
            var            response            = service.SubmitTransaction(transaction, clientTransactionId);
            HpsTransaction trans = new HpsTransaction().FromResponse(response);

            trans.ResponseCode = "00";
            trans.ResponseText = string.Empty;
            return(trans);
        }