Exemplo n.º 1
0
        /// <summary>Helper method for activate transactions (supporting multiple activation methods).</summary>
        /// <param name="transaction">The gateway response.</param>
        /// <returns>The <see cref="HpsGiftCardActivate"/>.</returns>
        private HpsGiftCardResponse SubmitActivation(PosRequestVer10Transaction transaction)
        {
            var rsp = DoTransaction(transaction).Ver10;

            HpsGatewayResponseValidation.CheckResponse(rsp, ItemChoiceType2.GiftCardActivate);

            var activationRsp = (PosGiftCardActivateRspType)rsp.Transaction.Item;

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

            /* Start to fill out a new transaction response (HpsGiftCardTransactionResponse). */
            var activation = new HpsGiftCardResponse
            {
                Header              = HydrateTransactionHeader(rsp.Header),
                TransactionId       = rsp.Header.GatewayTxnId,
                AuthorizationCode   = activationRsp.AuthCode,
                BalanceAmount       = activationRsp.BalanceAmt,
                PointsBalanceAmount = activationRsp.PointsBalanceAmt,
                Rewards             = activationRsp.Rewards,
                Notes        = activationRsp.Notes,
                ResponseCode = activationRsp.RspCode.ToString(CultureInfo.InvariantCulture),
                ResponseText = activationRsp.RspText
            };

            return(activation);
        }
        private void ProcessIssuerResponse(PosResponseVer10 response, ItemChoiceType1 expectedType, decimal?amount)
        {
            int transactionId = response.Header.GatewayTxnId;

            if (!(response.Transaction.Item is AuthRspStatusType))
            {
                return;
            }

            var transaction = (AuthRspStatusType)response.Transaction.Item;

            if (transaction.RspCode == "91")
            {
                try {
                    //this.Reverse(amount).Execute();
                }
                catch (HpsGatewayException e) {
                    if (e.Details.GatewayResponseCode == 3)
                    {
                        HpsIssuerResponseValidation.CheckResponse(transactionId, transaction.RspCode, transaction.RspText);
                    }
                    throw new HpsCreditException(transactionId, HpsExceptionCodes.IssuerTimeoutReversalError, "Error occurred while reversing a charge due to an issuer timeout.", e);
                }
                catch (HpsException e) {
                    throw new HpsCreditException(transactionId, HpsExceptionCodes.IssuerTimeoutReversalError, "Error occurred while reversing a charge due to an issuer timeout.", e);
                }
            }
            HpsIssuerResponseValidation.CheckResponse(transactionId, transaction.RspCode, transaction.RspText);
        }
Exemplo n.º 3
0
        public PosResponseVer10 SubmitTransaction(PosRequestVer10Transaction transaction, long?clientTransactionId = null)
        {
            var rsp = DoTransaction(transaction, clientTransactionId).Ver10;

            HpsGatewayResponseValidation.CheckResponse(rsp, (ItemChoiceType2)transaction.ItemElementName);

            string rspCode = string.Empty, rspText = string.Empty;

            if (rsp.Transaction != null)
            {
                var trans = rsp.Transaction.Item;

                var rspCodeField = trans.GetType().GetProperty("RspCode");
                if (rspCodeField != null)
                {
                    rspCode = rspCodeField.GetValue(trans).ToString();
                }

                var rspTextField = transaction.GetType().GetProperty("RspText");
                if (rspTextField != null)
                {
                    rspText = rspTextField.GetValue(trans).ToString();
                }
            }
            HpsIssuerResponseValidation.CheckResponse(rsp.Header.GatewayTxnId, rspCode, rspText);

            return(rsp);
        }
Exemplo n.º 4
0
        internal HpsEbtAuthorization SubmitTransaction(PosRequestVer10Transaction transaction, long?clientTransactionId = null)
        {
            var rsp = DoTransaction(transaction, clientTransactionId).Ver10;

            HpsGatewayResponseValidation.CheckResponse(rsp, (ItemChoiceType2)transaction.ItemElementName);

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

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

            return(new HpsEbtAuthorization().FromResponse(rsp));
        }
Exemplo n.º 5
0
        /// <summary>
        /// A <b>Alias</b> transaction is used to manage an account number alias, such as a phone number,
        /// for a stored value account. The transaction can be used to Add an alias to an existing account,
        /// Delete an alias from an existing account or Create a new stored value account and add an alias
        /// to the new account.
        /// </summary>
        /// <param name="action">Type of Alias action requested.</param>
        /// <param name="giftCard">The gift card information (leave null for CREATE action).</param>
        /// <param name="alias">Alternate identifier used to reference a stored value account.</param>
        /// <returns>The <see cref="HpsGiftCardAlias"/>.</returns>
        public HpsGiftCardAlias Alias(HpsGiftCardAliasAction action, HpsGiftCard giftCard, string alias)
        {
            var gatewayAction = GiftCardAliasReqBlock1TypeAction.ADD;

            switch (action)
            {
            case HpsGiftCardAliasAction.Create: gatewayAction = GiftCardAliasReqBlock1TypeAction.CREATE; break;

            case HpsGiftCardAliasAction.Delete: gatewayAction = GiftCardAliasReqBlock1TypeAction.DELETE; break;
            }

            /* Build the transaction request. */
            var transaction = new PosRequestVer10Transaction
            {
                Item = new PosGiftCardAliasReqType
                {
                    Block1 = new GiftCardAliasReqBlock1Type
                    {
                        Action   = gatewayAction,
                        Alias    = alias,
                        CardData = HydrateGiftCardData(giftCard)
                    }
                },
                ItemElementName = ItemChoiceType1.GiftCardAlias
            };

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

            HpsGatewayResponseValidation.CheckResponse(rsp, ItemChoiceType2.GiftCardAlias);

            var aliasRsp = (PosGiftCardAliasRspType)rsp.Transaction.Item;

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

            /* Start to fill out a new transaction response (HpsGiftCardAddValue). */
            var response = new HpsGiftCardAlias
            {
                Header        = HydrateTransactionHeader(rsp.Header),
                TransactionId = rsp.Header.GatewayTxnId,
                GiftCard      = new HpsGiftCard
                {
                    Value = aliasRsp.CardData.CardNbr
                },
                ResponseCode = aliasRsp.RspCode.ToString(CultureInfo.InvariantCulture),
                ResponseText = aliasRsp.RspText
            };

            return(response);
        }
Exemplo n.º 6
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));
        }
Exemplo n.º 7
0
        /// <summary>
        /// A <b>Balance</b> transaction is used to check the balance of a gift card.
        /// </summary>
        /// <param name="giftCard">The gift card information.</param>
        /// <returns>The <see cref="HpsGiftCardBalance"/>.</returns>
        public HpsGiftCardResponse GetBalance(HpsGiftCard giftCard)
        {
            /* Build the transaction request. */
            var transaction = new PosRequestVer10Transaction
            {
                Item = new PosGiftCardBalanceReqType
                {
                    Block1 = new GiftCardBalanceReqBlock1Type
                    {
                        CardData = HydrateGiftCardData(giftCard)
                    }
                },
                ItemElementName = ItemChoiceType1.GiftCardBalance
            };

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

            HpsGatewayResponseValidation.CheckResponse(rsp, ItemChoiceType2.GiftCardBalance);

            var balanceRsp = (PosGiftCardBalanceRspType)rsp.Transaction.Item;

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

            /* Start to fill out a new transaction response (HpsGiftCardAddValue). */
            var response = new HpsGiftCardResponse
            {
                Header              = HydrateTransactionHeader(rsp.Header),
                TransactionId       = rsp.Header.GatewayTxnId,
                AuthorizationCode   = balanceRsp.AuthCode,
                BalanceAmount       = balanceRsp.BalanceAmt,
                PointsBalanceAmount = balanceRsp.PointsBalanceAmt,
                Rewards             = balanceRsp.Rewards,
                Notes        = balanceRsp.Notes,
                ResponseCode = balanceRsp.RspCode.ToString(CultureInfo.InvariantCulture),
                ResponseText = balanceRsp.RspText
            };

            return(response);
        }
Exemplo n.º 8
0
        /// <summary>
        /// A <b>Void</b> transaction is used to cancel a previously approved Sale, Activate, Add Value, Deactivate, or Replace.
        /// If successful, the gift card is credited with the amount of the sale.
        /// </summary>
        /// <param name="transactionId">Transaction identifier assigned by Portico Gateway of the Sale transaction to void.</param>
        /// <returns>The <see cref="HpsGiftCardReward"/>.</returns>
        public HpsGiftCardResponse VoidTransaction(int transactionId)
        {
            /* Build the transaction request. */
            var transaction = new PosRequestVer10Transaction
            {
                Item = new PosGiftCardVoidReqType
                {
                    Block1 = new GiftCardVoidReqBlock1Type
                    {
                        GatewayTxnId = transactionId
                    }
                },
                ItemElementName = ItemChoiceType1.GiftCardVoid
            };

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

            HpsGatewayResponseValidation.CheckResponse(rsp, ItemChoiceType2.GiftCardVoid);

            var voidRsp = (PosGiftCardVoidRspType)rsp.Transaction.Item;

            HpsIssuerResponseValidation.CheckResponse(rsp.Header.GatewayTxnId,
                                                      voidRsp.RspCode.ToString(CultureInfo.InvariantCulture), voidRsp.RspText);

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

            return(response);
        }
Exemplo n.º 9
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));
        }
Exemplo n.º 10
0
        /// <summary>Helper method for reversal transactions (supporting multiple reversal methods).</summary>
        /// <param name="transaction">The gateway response.</param>
        /// <returns>The <see cref="HpsGiftCardActivate"/>.</returns>
        private HpsGiftCardResponse SubmitReversal(PosRequestVer10Transaction transaction)
        {
            var rsp = DoTransaction(transaction).Ver10;

            HpsGatewayResponseValidation.CheckResponse(rsp, ItemChoiceType2.GiftCardReversal);

            var reversalRsp = (PosGiftCardReversalRspType)rsp.Transaction.Item;

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

            /* Start to fill out a new transaction response. */
            var reversal = new HpsGiftCardResponse
            {
                Header            = HydrateTransactionHeader(rsp.Header),
                TransactionId     = rsp.Header.GatewayTxnId,
                AuthorizationCode = reversalRsp.AuthCode,
                BalanceAmount     = reversalRsp.BalanceAmt,
                ResponseCode      = reversalRsp.RspCode.ToString(CultureInfo.InvariantCulture),
                ResponseText      = reversalRsp.RspText
            };

            return(reversal);
        }
Exemplo n.º 11
0
        /// <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);
        }