internal override ITerminalResponse ProcessTransaction(TerminalAuthBuilder builder) { var transactionType = MapTransactionType(builder.TransactionType); var response = SendMessage <SipDeviceResponse>(BuildProcessTransaction(builder), transactionType); return(response); }
private IDeviceMessage BuildProcessTransaction(TerminalAuthBuilder builder) { ElementTree et = new ElementTree(); var create = et.Element("CreateTransaction").Set("xmlns", "http://transport.merchantware.net/v4/"); et.SubElement(create, "merchantName").Text(_gatewayConfig.MerchantName); et.SubElement(create, "merchantSiteId").Text(_gatewayConfig.MerchantSiteId); et.SubElement(create, "merchantKey").Text(_gatewayConfig.MerchantKey); var request = et.SubElement(create, "request"); et.SubElement(request, "TransactionType", MapRequestType(builder)); et.SubElement(request, "Amount", builder.Amount.ToCurrencyString()); et.SubElement(request, "ClerkId", _gatewayConfig.ClerkId ?? _gatewayConfig.RegisterNumber); // TODO: This should come from the config somewhere et.SubElement(request, "OrderNumber", builder.InvoiceNumber); et.SubElement(request, "Dba", _gatewayConfig.DBA); // TODO: This should come from the config somewhere et.SubElement(request, "SoftwareName", "GP SDK"); // TODO: This should come from the config somewhere et.SubElement(request, "SoftwareVersion", "2.*"); // TODO: This should come from the config somewhere et.SubElement(request, "TransactionId", builder.ClientTransactionId); et.SubElement(request, "TerminalId", _gatewayConfig.TerminalId); et.SubElement(request, "PoNumber", builder.PoNumber); et.SubElement(request, "ForceDuplicate", builder.AllowDuplicates); byte[] payload = Encoding.UTF8.GetBytes(BuildEnvelope(et, create)); return(new DeviceMessage(payload)); }
internal override ITerminalResponse ProcessTransaction(TerminalAuthBuilder builder) { IDeviceMessage message = BuildProcessTransaction(builder); var response = _connector.Send(message); throw new NotImplementedException(); }
private string MapRequestType(TerminalAuthBuilder builder) { TransactionType transType = builder.TransactionType; switch (transType) { case TransactionType.Auth: { if (builder.TransactionModifier.Equals(TransactionModifier.Offline)) { return("ForceCapture"); } return("Authorize"); } case TransactionType.BatchClose: { return("SettleBatch"); } case TransactionType.Capture: { return("Capture"); } case TransactionType.Edit: { return("AdjustTip"); } //AttachSignature //FindBoardedCard case TransactionType.Refund: { return("Refund"); } case TransactionType.Sale: { return("Sale"); } case TransactionType.TokenDelete: { return("UnboardCard"); } case TransactionType.TokenUpdate: { return("UpdateBoardedCard"); } case TransactionType.Verify: { return("BoardCard"); } case TransactionType.Void: { return("Void"); } default: { throw new UnsupportedTransactionException(); } } }
internal override TerminalResponse ProcessTransaction(TerminalAuthBuilder builder) { int requestId = builder.ReferenceNumber; if (requestId == default(int) && RequestIdProvider != null) { requestId = RequestIdProvider.GetRequestId(); } ElementTree et = new ElementTree(); var transactionType = MapTransactionType(builder.TransactionType); Element request = et.Element("SIP"); et.SubElement(request, "Version").Text("1.0"); et.SubElement(request, "ECRId").Text("1004"); et.SubElement(request, "Request").Text(transactionType); et.SubElement(request, "RequestId", requestId); et.SubElement(request, "CardGroup", builder.PaymentMethodType.ToString()); et.SubElement(request, "ConfirmAmount").Text("0"); et.SubElement(request, "BaseAmount").Text(builder.Amount.ToNumericCurrencyString()); if (builder.Gratuity != null) { et.SubElement(request, "TipAmount").Text(builder.Gratuity.ToNumericCurrencyString()); } else { et.SubElement(request, "TipAmount").Text("0"); } // EBT amount if (builder.PaymentMethodType == PaymentMethodType.EBT) { et.SubElement(request, "EBTAmount").Text(builder.Amount.ToNumericCurrencyString()); } // total et.SubElement(request, "TotalAmount").Text(builder.Amount.ToNumericCurrencyString()); var response = SendMessage <SipDeviceResponse>(et.ToString(request), transactionType); return(response); }
internal override ITerminalResponse ProcessTransaction(TerminalAuthBuilder builder) { var request = BuildProcessTransaction(builder); switch (builder.PaymentMethodType) { case PaymentMethodType.Credit: return(DoCredit(request)); case PaymentMethodType.Debit: return(DoDebit(request)); case PaymentMethodType.Gift: return(DoGift(request)); case PaymentMethodType.EBT: return(DoEBT(request)); default: throw new UnsupportedTransactionException(); } }
internal override TerminalResponse ProcessTransaction(TerminalAuthBuilder builder) { // create sub groups var amounts = new AmountRequest(); var account = new AccountRequest(); var avs = new AvsRequest(); var trace = new TraceRequest { ReferenceNumber = builder.ReferenceNumber.ToString() }; var cashier = new CashierSubGroup(); var commercial = new CommercialRequest(); var ecom = new EcomSubGroup(); var extData = new ExtDataSubGroup(); // amounts sub group amounts.TransactionAmount = "{0:c}".FormatWith(builder.Amount).ToNumeric(); amounts.CashBackAmount = "{0:c}".FormatWith(builder.CashBackAmount).ToNumeric(); amounts.TipAmount = "{0:c}".FormatWith(builder.Gratuity).ToNumeric(); amounts.TaxAmount = "{0:c}".FormatWith(builder.TaxAmount).ToNumeric(); // account sub group if (builder.PaymentMethod != null) { if (builder.PaymentMethod is CreditCardData) { var card = builder.PaymentMethod as CreditCardData; if (string.IsNullOrEmpty(card.Token)) { account.AccountNumber = card.Number; account.EXPD = "{0}{1}".FormatWith(card.ExpMonth, card.ExpYear); if (builder.TransactionType != TransactionType.Verify && builder.TransactionType != TransactionType.Refund) { account.CvvCode = card.Cvn; } } else { extData[EXT_DATA.TOKEN] = card.Token; } } else if (builder.PaymentMethod is TransactionReference) { var reference = builder.PaymentMethod as TransactionReference; if (!string.IsNullOrEmpty(reference.AuthCode)) { trace.AuthCode = reference.AuthCode; } if (!string.IsNullOrEmpty(reference.TransactionId)) { extData[EXT_DATA.HOST_REFERENCE_NUMBER] = reference.TransactionId; } } else if (builder.PaymentMethod is GiftCard) { var card = builder.PaymentMethod as GiftCard; account.AccountNumber = card.Number; } else if (builder.PaymentMethod is EBTCardData) { var card = builder.PaymentMethod as EBTCardData; } } if (builder.AllowDuplicates) { account.DupOverrideFlag = "1"; } // Avs Sub Group if (builder.Address != null) { avs.ZipCode = builder.Address.PostalCode; avs.Address = builder.Address.StreetAddress1; } // Trace Sub Group trace.InvoiceNumber = builder.InvoiceNumber; // Commercial Group commercial.CustomerCode = builder.CustomerCode; commercial.PoNumber = builder.PoNumber; commercial.TaxExempt = builder.TaxExempt; commercial.TaxExemptId = builder.TaxExemptId; // Additional Info sub group if (builder.RequestMultiUseToken) { extData[EXT_DATA.TOKEN_REQUEST] = "1"; } if (builder.SignatureCapture) { extData[EXT_DATA.SIGNATURE_CAPTURE] = "1"; } string transType = MapTransactionType(builder.TransactionType, builder.RequestMultiUseToken); switch (builder.PaymentMethodType) { case PaymentMethodType.Credit: return(DoCredit(transType, amounts, account, trace, avs, cashier, commercial, ecom, extData)); case PaymentMethodType.Debit: return(DoDebit(transType, amounts, account, trace, cashier, extData)); case PaymentMethodType.Gift: var messageId = builder.Currency == CurrencyType.CURRENCY ? PAX_MSG_ID.T06_DO_GIFT : PAX_MSG_ID.T08_DO_LOYALTY; return(DoGift(messageId, transType, amounts, account, trace, cashier, extData)); case PaymentMethodType.EBT: if (builder.Currency != null) { account.EbtType = builder.Currency.ToString().Substring(0, 1); } return(DoEBT(transType, amounts, account, trace, cashier)); default: throw new UnsupportedTransactionException(); } }
internal abstract byte[] SerializeRequest(TerminalAuthBuilder builder);
internal abstract ITerminalResponse ProcessTransaction(TerminalAuthBuilder builder);
internal override byte[] SerializeRequest(TerminalAuthBuilder builder) { return(BuildProcessTransaction(builder).GetSendBuffer()); }
internal override ITerminalResponse ProcessTransaction(TerminalAuthBuilder builder) { IDeviceMessage request = BuildProcessTransaction(builder); return(DoRequest(request)); }
internal IDeviceMessage BuildProcessTransaction(TerminalAuthBuilder builder) { string message = string.Empty; // Pay@Table functionalities if (_settings.ConnectionMode.Equals(ConnectionModes.PAY_AT_TABLE)) { if (builder.PayAtTableResponse != null && builder.AdditionalMessage != null) { StringBuilder payAtTableResp = new StringBuilder(); string privData = builder.PayAtTableResponse.ToString(); if (privData.Length < 10) { for (int i = privData.Length; i < 10; i++) { privData += (char)ControlCodes.SP; } } decimal?patAmount = ValidateAmount(builder.Amount); string patCurrency = ValidateCurrency(builder.CurrencyCode); int additionalMsg = (int?)builder.AdditionalMessage ?? 0; payAtTableResp.Append(PAYATTABLE_RESP.PAT_EPOS_NUMBER); payAtTableResp.Append(PAYATTABLE_RESP.PAT_STATUS); payAtTableResp.Append(patAmount?.ToString("00000000")); payAtTableResp.Append(additionalMsg); payAtTableResp.Append(patCurrency); payAtTableResp.Append(privData); message = payAtTableResp.ToString(); } else if (!string.IsNullOrEmpty(builder.FilePath)) { message = TerminalUtilities.GetTextContent(builder.FilePath); } else { throw new BuilderException("PayAtTable Response type and Additional message cannot be null."); } } else { // Standard functionalities int referenceNumber = builder.ReferenceNumber; decimal?amount = builder.Amount; int returnRep = 1; int paymentMode = 0; int paymentType = (int)((IngenicoInterface)_interface).paymentMethod; string currencyCode = "826"; string privateData = "EXT0100000"; int immediateAnswer = 0; int forceOnline = 0; string extendedData = "0000000000"; decimal?cashbackAmount = builder.CashBackAmount; string authCode = builder.AuthCode; string tableId = builder.TableNumber; // Validations if (referenceNumber == default(int) && RequestIdProvider != null) { referenceNumber = RequestIdProvider.GetRequestId(); } amount = ValidateAmount(amount); // Tax free Refund handling if (paymentType == (int)PaymentType.Refund && builder.TaxFreeType == TaxFreeType.CASH) { paymentType = (int)PaymentType.TaxFreeCashRefund; } else if (paymentType == (int)PaymentType.Refund && builder.TaxFreeType == TaxFreeType.CREDIT) { paymentType = (int)PaymentType.TaxFreeCreditRefund; } paymentMode = ValidatePaymentMode(builder.PaymentMode); currencyCode = ValidateCurrency((string.IsNullOrEmpty(builder.CurrencyCode) ? currencyCode : builder.CurrencyCode)); if (!string.IsNullOrEmpty(tableId)) { ValidateTableId(tableId); extendedData = INGENICO_REQ_CMD.TABLE_WITH_ID.FormatWith(tableId); } else if (!string.IsNullOrEmpty(authCode)) { extendedData = INGENICO_REQ_CMD.AUTHCODE.FormatWith(authCode); } else if (cashbackAmount != null) { ValidateCashbackAmount(cashbackAmount); cashbackAmount *= 100; extendedData = INGENICO_REQ_CMD.CASHBACK.FormatWith(Convert.ToInt64(Math.Round(cashbackAmount.Value, MidpointRounding.AwayFromZero))); } // Concat all data to create a request string. var sb = new StringBuilder(); sb.Append(referenceNumber.ToString("00").Substring(0, 2)); sb.Append(amount?.ToString("00000000")); sb.Append(returnRep); sb.Append(paymentMode); sb.Append(paymentType); sb.Append(currencyCode); sb.Append(privateData); sb.Append("A01" + immediateAnswer); sb.Append("B01" + forceOnline); sb.Append(extendedData); message = sb.ToString(); } return(TerminalUtilities.BuildRequest(message, _settings.ConnectionMode)); }
internal override byte[] SerializeRequest(TerminalAuthBuilder builder) { return(Encoding.UTF8.GetBytes(BuildProcessTransaction(builder))); }
internal IDeviceMessage BuildProcessTransaction(TerminalAuthBuilder builder) { var pmt = builder.PaymentMethodType; var transType = builder.TransactionType; var transModifier = builder.TransactionModifier; bool isTipAdjust = IsTipAdjust(transType, builder.Gratuity); bool isCardHSAFSA = IsCardHSAFSA(builder.AutoSubstantiation); if (pmt != PaymentMethodType.Credit && pmt != PaymentMethodType.Debit && pmt != PaymentMethodType.EBT) { throw new UnsupportedTransactionException("The supplied payment method type is not supported"); } int requestId = builder.ReferenceNumber; if (requestId == default(int) && RequestIdProvider != null) { requestId = RequestIdProvider.GetRequestId(); } var doc = new JsonDoc(); doc.Set("message", "MSG"); var baseRequest = doc.SubElement("data"); baseRequest.Set("command", MapTransactionType(transType, transModifier, builder.RequestMultiUseToken, builder.Gratuity)); baseRequest.Set("EcrId", builder.EcrId.ToString()); baseRequest.Set("requestId", requestId.ToString()); if (transType != TransactionType.Balance) { var txnData = baseRequest.SubElement("data"); var txnParams = txnData.SubElement("params"); txnParams.Set("clerkId", builder.ClerkId); if (transType == TransactionType.Tokenize || transType == TransactionType.Verify) { txnParams.Set("cardIsHSAFSA", isCardHSAFSA ? "1" : "0"); } if (!IsTokenRequestApplicable(isTipAdjust, transType)) { txnParams.Set("tokenRequest", builder.RequestMultiUseToken ? "1" : "0"); } if (builder.PaymentMethod is CreditCardData) { txnParams.Set("tokenValue", ((CreditCardData)builder.PaymentMethod).Token); } if (builder.RequestMultiUseToken && (transType == TransactionType.Sale || transType == TransactionType.Refund || transType == TransactionType.Verify || transType == TransactionType.Auth)) { if (builder.CardOnFileIndicator != null) { txnParams.Set("cardOnFileIndicator", EnumConverter.GetMapping(Target.UPA, builder.CardOnFileIndicator)); } txnParams.Set("cardBrandTransId", builder.CardBrandTransId); } txnParams.Set("lineItemLeft", builder.LineItemLeft); txnParams.Set("lineItemRight", builder.LineItemRight); txnParams.Set("directMktInvoiceNbr", builder.InvoiceNumber); if (builder.ShippingDate != DateTime.MinValue) { txnParams.Set("directMktShipMonth", builder.ShippingDate.Month.ToString("00")); txnParams.Set("directMktShipDay", builder.ShippingDate.Day.ToString("00")); } if (transType != TransactionType.Verify && transType != TransactionType.Refund && !isTipAdjust && transType != TransactionType.Tokenize) { var transaction = txnData.SubElement("transaction"); if (transType == TransactionType.Auth) { transaction.Set("amount", ToCurrencyString(builder.Amount)); } else { transaction.Set("baseAmount", ToCurrencyString(builder.Amount)); transaction.Set("cashBackAmount", ToCurrencyString(builder.CashBackAmount)); transaction.Set("tipAmount", ToCurrencyString(builder.Gratuity)); transaction.Set("taxIndicator", builder.TaxExempt); transaction.Set("invoiceNbr", builder.InvoiceNumber); transaction.Set("processCPC", builder.ProcessCPC); transaction.Set("taxAmount", ToCurrencyString(builder.TaxAmount)); } transaction.Set("referenceNumber", builder.TerminalRefNumber); transaction.Set("cardIsHSAFSA", isCardHSAFSA ? "1" : "0"); transaction.Set("prescriptionAmount", ToCurrencyString(builder.PrescriptionAmount)); transaction.Set("clinicAmount", ToCurrencyString(builder.ClinicAmount)); transaction.Set("dentalAmount", ToCurrencyString(builder.DentalAmount)); transaction.Set("visionOpticalAmount", ToCurrencyString(builder.VisionOpticalAmount)); } if (transType == TransactionType.Refund) { var transaction = txnData.SubElement("transaction"); transaction.Set("totalAmount", ToCurrencyString(builder.Amount)); } if (isTipAdjust) { var transaction = txnData.SubElement("transaction"); transaction.Set("tranNo", builder.TerminalRefNumber); transaction.Set("tipAmount", ToCurrencyString(builder.Gratuity)); } } return(TerminalUtilities.BuildUpaRequest(doc.ToString())); }
internal override ITerminalResponse ProcessTransaction(TerminalAuthBuilder builder) { var request = BuildProcessTransaction(builder); return(DoTransaction(request)); }