public string Build(Element envelope, ManagementBuilder builder, Credentials credentials) { var body = et.SubElement(envelope, "soapenv:Body"); var methodElement = et.SubElement(body, "bil:ReversePayment"); var requestElement = et.SubElement(methodElement, "bil:ReversePaymentRequest"); ValidateReversal(builder); BuildCredentials(requestElement, credentials); if (builder.Amount > 0M) { et.SubElement(requestElement, "bdms:BaseAmountToRefund", builder.Amount); } var billsToReverse = et.SubElement(requestElement, "bdms:BillsToReverse"); if (builder.Bills != null && builder.Bills.Count() > 0) { BuildBillTransactions(billsToReverse, builder.Bills, "bdms:ReversalBillTransaction", "bdms:AmountToReverse"); } et.SubElement(requestElement, "bdms:EndUserBrowserType", browserType); et.SubElement(requestElement, "bdms:EndUserIPAddress", builder.CustomerIpAddress); et.SubElement(requestElement, "bdms:ExpectedFeeAmountToRefund", builder.ConvenienceAmount); et.SubElement(requestElement, "bdms:OrderIDOfReversal", builder.OrderId); // PLACEHOLDER ReversalReason et.SubElement(requestElement, "bdms:Transaction_ID", (builder.PaymentMethod as TransactionReference)?.TransactionId); return(et.ToString(envelope)); }
public Transaction ProcessSecure3d(Secure3dBuilder builder) { TransactionType transType = builder.TransactionType; if (transType.Equals(TransactionType.VerifyEnrolled)) { AuthorizationBuilder authBuilder = new AuthorizationBuilder(transType, builder.PaymentMethod) .WithAmount(builder.Amount) .WithCurrency(builder.Currency) .WithOrderId(builder.OrderId); return(ProcessAuthorization(authBuilder)); } else if (transType.Equals(TransactionType.VerifySignature)) { // get our three d secure object ThreeDSecure secureEcom = builder.ThreeDSecure; // create our transaction reference TransactionReference reference = new TransactionReference { OrderId = secureEcom.OrderId }; ManagementBuilder managementBuilder = new ManagementBuilder(transType) .WithAmount(secureEcom.Amount) .WithCurrency(secureEcom.Currency) .WithPayerAuthenticationResponse(builder.PayerAuthenticationResponse) .WithPaymentMethod(reference); return(ManageTransaction(managementBuilder)); } throw new UnsupportedTransactionException(string.Format("Unknown transaction type {0}", transType)); }
private Transaction CreditVoiceAuth(decimal amount) { CreditTrackData track = TestCards.VisaSwipe(); Transaction transaction = Transaction.FromNetwork( 10m, "TYPE04", new NtsData(FallbackCode.None, AuthorizerCode.Voice_Authorized), track ); ManagementBuilder builder = transaction.Capture(amount) .WithCurrency("USD"); if (configName.Equals("NoBatch")) { builder.WithBatchNumber(batchProvider.GetBatchNumber(), batchProvider.GetSequenceNumber()); } Transaction response = builder.Execute(configName); Assert.IsNotNull(response); System.Diagnostics.Debug.WriteLine("Voice Capture:"); System.Diagnostics.Debug.WriteLine(response.HostResponseDate); System.Diagnostics.Debug.WriteLine(response.SystemTraceAuditNumber); return(response); }
/// <summary> /// Invokes a request against the BillPay gateway using the ManagementBuilder /// </summary> /// <param name="builder">The <see cref="ManagementBuilder">ManagementBuilder</see> containing the required information to build the request</param> /// <returns>A Transaction response</returns> public Transaction ManageTransaction(ManagementBuilder builder) { return(new ManagementRequest(Credentials, ServiceUrl, Timeout) .WithRequestLogger(RequestLogger) .WithWebProxy(WebProxy) .Execute(builder, IsBillDataHosted)); }
protected void ValidateReversal(ManagementBuilder builder) { var validationErrors = new List <string>(); if (!(builder.PaymentMethod is TransactionReference reference) || string.IsNullOrWhiteSpace(reference.TransactionId)) { validationErrors.Add("A transaction to reverse must be provided."); }
public static BatchSummary CloseBatch(BatchCloseType closeType, string configName) { Transaction response = new ManagementBuilder(TransactionType.BatchClose) .WithBatchCloseType(closeType) .Execute(configName); return(response.BatchSummary); }
public static BatchSummary CloseBatch(int batchNumber, int sequenceNumber, string configName) { Transaction response = new ManagementBuilder(TransactionType.BatchClose) .WithBatchNumber(batchNumber, sequenceNumber) .Execute(configName); return(response.BatchSummary); }
public static BatchSummary CloseBatch(int transactionTotal, decimal totalCredits, decimal totalDebits, string configName) { Transaction response = new ManagementBuilder(TransactionType.BatchClose) .WithBatchTotals(transactionTotal, totalDebits, totalCredits) .Execute(configName); return(response.BatchSummary); }
public Transaction ManageTransaction(ManagementBuilder builder) { var et = new ElementTree(); string timestamp = GenerationUtils.GenerateTimestamp(); string orderId = builder.OrderId ?? GenerationUtils.GenerateOrderId(); string transactionType = MapManageRequestType(builder.TransactionType); // Build Request var request = et.Element("request") .Set("timestamp", timestamp) .Set("type", transactionType); et.SubElement(request, "merchantid").Text(MerchantId); et.SubElement(request, "account", AccountId); et.SubElement(request, "channel", Channel); et.SubElement(request, "orderid", orderId); et.SubElement(request, "pasref", builder.TransactionId); if (builder.Amount.HasValue) { et.SubElement(request, "amount", builder.Amount.ToNumericCurrencyString()).Set("currency", builder.Currency); } else if (builder.TransactionType == TransactionType.Capture) { throw new BuilderException("Amount cannot be null for capture."); } // payer authentication response if (builder.TransactionType == TransactionType.VerifySignature) { et.SubElement(request, "pares", builder.PayerAuthenticationResponse); } // rebate hash if (builder.TransactionType == TransactionType.Refund) { et.SubElement(request, "authcode").Text(builder.AuthorizationCode); et.SubElement(request, "refundhash", GenerationUtils.GenerateHash(RebatePassword ?? string.Empty)); } // reason code if (builder.ReasonCode != null) { et.SubElement(request, "reasoncode").Text(builder.ReasonCode.ToString()); } // TODO: needs to be multiple if (builder.Description != null) { var comments = et.SubElement(request, "comments"); et.SubElement(comments, "comment", builder.Description).Set("id", "1"); } et.SubElement(request, "sha1hash", GenerationUtils.GenerateHash(SharedSecret, timestamp, MerchantId, orderId, builder.Amount.ToNumericCurrencyString(), builder.Currency, "")); var response = DoTransaction(et.ToString(request)); return(MapResponse(response, MapAcceptedCodes(transactionType))); }
/// <summary> /// Captures the original transaction. /// </summary> /// <param name="amount">The amount to capture</param> public ManagementBuilder Capture(decimal?amount = null) { var builder = new ManagementBuilder(TransactionType.Capture) .WithPaymentMethod(TransactionReference) .WithAmount(amount); if (MultiCapture) { builder.WithMultiCapture(MultiCaptureSequence.Value, MultiCapturePaymentCount.Value); } return(builder); }
public Transaction ManageTransaction(ManagementBuilder builder) { var et = new ElementTree(); TransactionType transactionType = builder.TransactionType; var transaction = et.Element(MapRequestType(builder)) .Set("xmlns", "http://schemas.merchantwarehouse.com/merchantware/v45/"); // Credentials var credentials = et.SubElement(transaction, "Credentials"); et.SubElement(credentials, "MerchantName").Text(MerchantName); et.SubElement(credentials, "MerchantSiteId").Text(MerchantSiteId); et.SubElement(credentials, "MerchantKey").Text(MerchantKey); // Payment Data if (transactionType.Equals(TransactionType.Refund)) { var paymentData = et.SubElement(transaction, "PaymentData"); et.SubElement(paymentData, "Source").Text("PreviousTransaction"); et.SubElement(paymentData, "Token", builder.TransactionId); } // Request var request = et.SubElement(transaction, "Request"); if (!transactionType.Equals(TransactionType.Refund)) { et.SubElement(request, "Token", builder.TransactionId); } et.SubElement(request, "Amount", builder.Amount.ToCurrencyString()); et.SubElement(request, "InvoiceNumber", builder.InvoiceNumber); et.SubElement(request, "RegisterNumber", RegisterNumber); et.SubElement(request, "MerchantTransactionId", builder.ClientTransactionId); et.SubElement(request, "CardAcceptorTerminalId", TerminalId); if (transactionType.Equals(TransactionType.TokenDelete) || transactionType.Equals(TransactionType.TokenUpdate)) { var card = builder.PaymentMethod as CreditCardData; et.SubElement(request, "VaultToken", card.Token); if (transactionType.Equals(TransactionType.TokenUpdate)) { et.SubElement(request, "ExpirationDate", card.ShortExpiry); } } var response = DoTransaction(BuildEnvelope(et, transaction)); return(MapResponse(builder, response)); }
/// <summary> /// Detokenizes payment method /// </summary> /// <param name="configName"></param> /// <returns></returns> ITokenizable ITokenizable.Detokenize(string configName) { if (string.IsNullOrEmpty(Token)) { throw new BuilderException("Token cannot be null"); } var transaction = new ManagementBuilder(TransactionType.Detokenize) .WithPaymentMethod(this) .Execute(configName); CardType = transaction.CardType; return(this); }
public Transaction ManageTransaction(ManagementBuilder builder) { var request = new TransitRequest(MapTransactionType(builder)) .Set("developerID", DeveloperId) .Set("deviceID", DeviceId) .Set("transactionKey", TransactionKey) .Set("transactionAmount", builder.Amount.ToCurrencyString()) .Set("tip", builder.Gratuity.ToCurrencyString()) .Set("transactionID", builder.TransactionId) .Set("isPartialShipment", builder.MultiCapture ? "Y" : null); string response = DoTransaction(request.BuildRequest(builder)); return(MapResponse(builder, response)); }
public Transaction ManageTransaction(ManagementBuilder builder) { if (string.IsNullOrEmpty(AccessToken)) { SignIn(); } GpApiRequest request = GpApiManagementRequestBuilder.BuildRequest(builder, this); if (request != null) { var response = DoTransaction(request.Verb, request.Endpoint, request.RequestBody, request.QueryStringParams, builder.IdempotencyKey); return(GpApiMapping.MapResponse(response)); } return(null); }
public Transaction ManageTransaction(ManagementBuilder builder) { var request = new TransitRequestBuilder(MapTransactionType(builder)) .Set("developerID", DeveloperId) .Set("deviceID", DeviceId) .Set("transactionKey", TransactionKey) .Set("transactionAmount", builder.Amount.ToCurrencyString()) .Set("tip", builder.Gratuity.ToCurrencyString()) .Set("transactionID", builder.TransactionId) .Set("isPartialShipment", builder.MultiCapture ? "Y" : null) .SetPartialShipmentData(builder.MultiCaptureSequence, builder.MultiCapturePaymentCount) .Set("externalReferenceID", builder.ClientTransactionId) .Set("voidReason", EnumConverter.GetMapping(Target.Transit, builder.VoidReason)); string response = DoTransaction(request.BuildRequest(builder)); return(MapResponse(builder, response)); }
private Transaction CreditReverse(Transaction saleToReverse, decimal amount) { ManagementBuilder builder = saleToReverse.Reverse(amount) .WithCurrency("USD"); if (configName.Equals("NoBatch")) { builder.WithBatchNumber(batchProvider.GetBatchNumber(), batchProvider.GetSequenceNumber()); } Transaction response = builder.Execute(configName); Assert.IsNotNull(response); System.Diagnostics.Debug.WriteLine("Reverse:"); System.Diagnostics.Debug.WriteLine(response.HostResponseDate); System.Diagnostics.Debug.WriteLine(response.SystemTraceAuditNumber); return(response); }
public Transaction ManageTransaction(ManagementBuilder builder) { string response = string.Empty; if (builder.TransactionType == TransactionType.Capture) { var data = new JsonDoc() .Set("amount", builder.Amount.ToNumericCurrencyString()) .Set("gratuity_amount", builder.Gratuity.ToNumericCurrencyString()); response = DoTransaction(HttpMethod.Post, $"/ucp/transactions/{builder.TransactionId}/capture", data.ToString()); } else if (builder.TransactionType == TransactionType.Refund) { var data = new JsonDoc() .Set("amount", builder.Amount.ToNumericCurrencyString()); response = DoTransaction(HttpMethod.Post, $"/ucp/transactions/{builder.TransactionId}/refund", data.ToString()); } else if (builder.TransactionType == TransactionType.Reversal) { var data = new JsonDoc() .Set("amount", builder.Amount.ToNumericCurrencyString()); response = DoTransaction(HttpMethod.Post, $"/ucp/transactions/{builder.TransactionId}/reversal", data.ToString()); } else if (builder.TransactionType == TransactionType.TokenUpdate && builder.PaymentMethod is CreditCardData) { var cardData = builder.PaymentMethod as CreditCardData; var card = new JsonDoc() .Set("expiry_month", cardData.ExpMonth.HasValue ? cardData.ExpMonth.ToString().PadLeft(2, '0') : string.Empty) .Set("expiry_year", cardData.ExpYear.HasValue ? cardData.ExpYear.ToString().PadLeft(4, '0').Substring(2, 2) : string.Empty); var payload = new JsonDoc() .Set("card", card); response = DoTransaction(new HttpMethod("PATCH"), $"/ucp/payment-methods/{(builder.PaymentMethod as ITokenizable).Token}/edit", payload.ToString()); } else if (builder.TransactionType == TransactionType.TokenDelete && builder.PaymentMethod is ITokenizable) { response = DoTransaction(HttpMethod.Post, $"/ucp/payment-methods/{(builder.PaymentMethod as ITokenizable).Token}/delete"); } return(MapResponse(response)); }
private Transaction ReversePayment(ManagementBuilder builder) { var et = new ElementTree(); var envelope = CreateSOAPEnvelope(et, "ReversePayment"); var request = new ReversePaymentRequest(et) .Build(envelope, builder, Credentials); var response = DoTransaction(request, publicEndpoint); var result = new ReversalResponse() .WithResponseTagName("ReversePaymentResponse") .WithResponse(response) .Map(); if (result.ResponseCode == "0") { return(result); } throw new GatewayException(message: "There was an error attempting to reverse the payment", responseCode: result.ResponseCode, responseMessage: result.ResponseMessage); }
/// <summary> /// Detokenizes payment method /// </summary> /// <param name="configName"></param> /// <returns></returns> public CreditCardData Detokenize(string configName = "default") { if (string.IsNullOrEmpty(Token)) { throw new BuilderException("Token cannot be null"); } var transaction = new ManagementBuilder(TransactionType.Detokenize) .WithPaymentMethod(this) .Execute(configName); var card = this.MemberwiseClone() as CreditCardData; card.Number = transaction.CardNumber; card.CardType = transaction.CardType; card.ExpMonth = transaction.CardExpMonth; card.ExpYear = transaction.CardExpYear; return(card); }
public bool VerifySignature(string authorizationResponse, MerchantDataCollection merchantData = null, string configName = "default") { // ensure we have an object if (ThreeDSecure == null) { ThreeDSecure = new ThreeDSecure(); } // if we have some merchantData use it if (merchantData != null) { ThreeDSecure.MerchantData = merchantData; } Transaction response = new ManagementBuilder(TransactionType.VerifySignature) .WithAmount(ThreeDSecure.Amount) .WithCurrency(ThreeDSecure.Currency) .WithPayerAuthenticationResponse(authorizationResponse) .WithPaymentMethod(new TransactionReference { OrderId = ThreeDSecure.OrderId }) .Execute(configName); ThreeDSecure.Status = response.ThreeDSecure.Status; ThreeDSecure.Cavv = response.ThreeDSecure.Cavv; ThreeDSecure.Algorithm = response.ThreeDSecure.Algorithm; ThreeDSecure.Xid = response.ThreeDSecure.Xid; if (new List <string> { "A", "Y" }.Contains(ThreeDSecure.Status) && response.ResponseCode == "00") { ThreeDSecure.Eci = response.ThreeDSecure.Eci; return(true); } else { ThreeDSecure.Eci = CardType == "MC" ? 0 : 7; return(false); } }
internal Transaction Execute(ManagementBuilder builder, bool isBillDataHosted) { switch (builder.TransactionType) { case TransactionType.Refund: case TransactionType.Reversal: case TransactionType.Void: return(ReversePayment(builder)); case TransactionType.TokenUpdate: if (builder.PaymentMethod is CreditCardData card) { return(UpdateToken(card)); } throw new UnsupportedTransactionException(); default: throw new UnsupportedTransactionException(); } }
private string MapManageRequestType(ManagementBuilder builder) { TransactionType trans = builder.TransactionType; switch (trans) { case TransactionType.Capture: if (builder.MultiCapture == true) { return("multisettle"); } else { return("settle"); } case TransactionType.Hold: return("hold"); case TransactionType.Refund: if (builder.AlternativePaymentType != null) { return("payment-credit"); } return("rebate"); case TransactionType.Release: return("release"); case TransactionType.Void: case TransactionType.Reversal: return("void"); case TransactionType.VerifySignature: return("3ds-verifysig"); default: return("unknown"); } }
public abstract Transaction ManageTransaction(ManagementBuilder builder);
public Transaction ManageTransaction(ManagementBuilder builder) { var et = new ElementTree(); string timestamp = GenerationUtils.GenerateTimestamp(); string orderId = builder.OrderId ?? GenerationUtils.GenerateOrderId(); string transactionType = MapManageRequestType(builder); // Build Request var request = et.Element("request") .Set("timestamp", timestamp) .Set("type", transactionType); et.SubElement(request, "merchantid").Text(MerchantId); et.SubElement(request, "account", AccountId); et.SubElement(request, "channel", Channel); et.SubElement(request, "orderid", orderId); et.SubElement(request, "pasref", builder.TransactionId); if (builder.Amount.HasValue) { var amtElement = et.SubElement(request, "amount", builder.Amount.ToNumericCurrencyString()); if (!builder.MultiCapture) { amtElement.Set("currency", builder.Currency); } } else if (builder.TransactionType == TransactionType.Capture) { throw new BuilderException("Amount cannot be null for capture."); } // Capture Authcode if (builder.TransactionType == TransactionType.Capture && builder.MultiCapture == true) { et.SubElement(request, "authcode").Text(builder.AuthorizationCode); } et.SubElement(request, "channel", Channel); et.SubElement(request, "orderid", orderId); et.SubElement(request, "pasref", builder.TransactionId); // Check is APM for Refund if (builder.AlternativePaymentType != null) { et.SubElement(request, "paymentmethod", builder.AlternativePaymentType); } // payer authentication response if (builder.TransactionType == TransactionType.VerifySignature) { et.SubElement(request, "pares", builder.PayerAuthenticationResponse); } // reason code if (builder.ReasonCode != null) { et.SubElement(request, "reasoncode").Text(builder.ReasonCode.ToString()); } // TODO: needs to be multiple if (builder.Description != null) { var comments = et.SubElement(request, "comments"); et.SubElement(comments, "comment", builder.Description).Set("id", "1"); } // tssinfo if (builder.CustomerId != null || builder.ClientTransactionId != null) { var tssInfo = et.SubElement(request, "tssinfo"); et.SubElement(tssInfo, "custnum", builder.CustomerId); et.SubElement(tssInfo, "varref", builder.ClientTransactionId); } // data supplimentary if (builder.SupplementaryData != null) { var supplementaryData = et.SubElement(request, "supplementarydata"); Dictionary <string, List <string[]> > suppData = builder.SupplementaryData; foreach (string key in suppData.Keys) { List <string[]> dataSets = suppData[key]; foreach (string[] data in dataSets) { Element item = et.SubElement(supplementaryData, "item").Set("type", key); for (int i = 1; i <= data.Length; i++) { et.SubElement(item, "field" + i.ToString().PadLeft(2, '0'), data[i - 1]); } } } } et.SubElement(request, "sha1hash", GenerationUtils.GenerateHash(SharedSecret, timestamp, MerchantId, orderId, builder.Amount.ToNumericCurrencyString(), builder.Currency, builder.AlternativePaymentType != null?builder.AlternativePaymentType.ToString():null)); // rebate hash if (builder.TransactionType == TransactionType.Refund) { if (builder.AuthorizationCode != null) { et.SubElement(request, "authcode").Text(builder.AuthorizationCode); } et.SubElement(request, "refundhash", GenerationUtils.GenerateHash(builder.AlternativePaymentType != null ? RefundPassword : RebatePassword)); } var response = DoTransaction(et.ToString(request)); return(MapResponse(response, MapAcceptedCodes(transactionType))); }
public static BatchSummary CloseBatch() { var response = new ManagementBuilder(TransactionType.BatchClose).Execute(); return(response.BatchSummary); }
public Transaction ManageTransaction(ManagementBuilder builder) { throw new NotImplementedException(); }
internal static GpApiRequest BuildRequest(ManagementBuilder builder, GpApiConnector gateway) { if (builder.TransactionType == TransactionType.Capture) { var data = new JsonDoc() .Set("amount", builder.Amount.ToNumericCurrencyString()) .Set("gratuity_amount", builder.Gratuity.ToNumericCurrencyString()); return(new GpApiRequest { Verb = HttpMethod.Post, Endpoint = $"/transactions/{builder.TransactionId}/capture", RequestBody = data.ToString(), }); } else if (builder.TransactionType == TransactionType.Refund) { var data = new JsonDoc() .Set("amount", builder.Amount.ToNumericCurrencyString()); return(new GpApiRequest { Verb = HttpMethod.Post, Endpoint = $"/transactions/{builder.TransactionId}/refund", RequestBody = data.ToString(), }); } else if (builder.TransactionType == TransactionType.Reversal) { var data = new JsonDoc() .Set("amount", builder.Amount.ToNumericCurrencyString()); return(new GpApiRequest { Verb = HttpMethod.Post, Endpoint = $"/transactions/{builder.TransactionId}/reversal", RequestBody = data.ToString(), }); } else if (builder.TransactionType == TransactionType.TokenUpdate && builder.PaymentMethod is CreditCardData) { var cardData = builder.PaymentMethod as CreditCardData; var card = new JsonDoc() .Set("expiry_month", cardData.ExpMonth.HasValue ? cardData.ExpMonth.ToString().PadLeft(2, '0') : string.Empty) .Set("expiry_year", cardData.ExpYear.HasValue ? cardData.ExpYear.ToString().PadLeft(4, '0').Substring(2, 2) : string.Empty); var data = new JsonDoc() .Set("card", card); return(new GpApiRequest { Verb = new HttpMethod("PATCH"), Endpoint = $"/payment-methods/{(builder.PaymentMethod as ITokenizable).Token}", RequestBody = data.ToString(), }); } else if (builder.TransactionType == TransactionType.TokenDelete && builder.PaymentMethod is ITokenizable) { return(new GpApiRequest { Verb = HttpMethod.Delete, Endpoint = $"/payment-methods/{(builder.PaymentMethod as ITokenizable).Token}", }); } else if (builder.TransactionType == TransactionType.Detokenize && builder.PaymentMethod is ITokenizable) { return(new GpApiRequest { Verb = HttpMethod.Post, Endpoint = $"/payment-methods/{(builder.PaymentMethod as ITokenizable).Token}/detokenize", }); } else if (builder.TransactionType == TransactionType.DisputeAcceptance) { return(new GpApiRequest { Verb = HttpMethod.Post, Endpoint = $"/disputes/{builder.DisputeId}/acceptance", }); } else if (builder.TransactionType == TransactionType.DisputeChallenge) { var data = new JsonDoc() .Set("documents", builder.DisputeDocuments); return(new GpApiRequest { Verb = HttpMethod.Post, Endpoint = $"/disputes/{builder.DisputeId}/challenge", RequestBody = data.ToString(), }); } else if (builder.TransactionType == TransactionType.BatchClose) { return(new GpApiRequest { Verb = HttpMethod.Post, Endpoint = $"/batches/{builder.BatchReference}", }); } else if (builder.TransactionType == TransactionType.Reauth) { var data = new JsonDoc() .Set("amount", builder.Amount.ToNumericCurrencyString()); return(new GpApiRequest { Verb = HttpMethod.Post, Endpoint = $"/transactions/{builder.TransactionId}/reauthorization", RequestBody = data.ToString(), }); } return(null); }
internal static GpApiRequest BuildRequest(ManagementBuilder builder, GpApiConnector gateway) { var merchantUrl = !string.IsNullOrEmpty(gateway.GpApiConfig.MerchantId) ? $"/merchants/{gateway.GpApiConfig.MerchantId}" : string.Empty; if (builder.TransactionType == TransactionType.Capture) { var data = new JsonDoc() .Set("amount", builder.Amount.ToNumericCurrencyString()) .Set("gratuity_amount", builder.Gratuity.ToNumericCurrencyString()) .Set("currency_conversion", builder.DccRateData?.DccId ?? null); return(new GpApiRequest { Verb = HttpMethod.Post, Endpoint = $"{merchantUrl}/transactions/{builder.TransactionId}/capture", RequestBody = data.ToString(), }); } else if (builder.TransactionType == TransactionType.Refund) { var data = new JsonDoc() .Set("amount", builder.Amount.ToNumericCurrencyString()) .Set("currency_conversion", builder.DccRateData == null ? null : new JsonDoc() .Set("id", builder.DccRateData?.DccId)); return(new GpApiRequest { Verb = HttpMethod.Post, Endpoint = $"{merchantUrl}/transactions/{builder.TransactionId}/refund", RequestBody = data.ToString(), }); } else if (builder.TransactionType == TransactionType.Reversal) { var data = new JsonDoc() .Set("amount", builder.Amount.ToNumericCurrencyString()) .Set("currency_conversion", builder.DccRateData?.DccId ?? null); return(new GpApiRequest { Verb = HttpMethod.Post, Endpoint = $"{merchantUrl}/transactions/{builder.TransactionId}/reversal", RequestBody = data.ToString(), }); } else if (builder.TransactionType == TransactionType.TokenUpdate) { if (!(builder.PaymentMethod is CreditCardData)) { throw new GatewayException("Payment method doesn't support this action!"); } var cardData = builder.PaymentMethod as CreditCardData; var card = new JsonDoc() .Set("expiry_month", cardData.ExpMonth.HasValue ? cardData.ExpMonth.ToString().PadLeft(2, '0') : string.Empty) .Set("expiry_year", cardData.ExpYear.HasValue ? cardData.ExpYear.ToString().PadLeft(4, '0').Substring(2, 2) : string.Empty); var data = new JsonDoc() .Set("usage_mode", !string.IsNullOrEmpty(builder.PaymentMethodUsageMode.ToString()) ? EnumConverter.GetMapping(Target.GP_API, builder.PaymentMethodUsageMode) : null) .Set("name", !string.IsNullOrEmpty(cardData.CardHolderName) ? cardData.CardHolderName : null) .Set("card", card); return(new GpApiRequest { Verb = new HttpMethod("PATCH"), Endpoint = $"{merchantUrl}/payment-methods/{(builder.PaymentMethod as ITokenizable).Token}", RequestBody = data.ToString(), }); } else if (builder.TransactionType == TransactionType.TokenDelete && builder.PaymentMethod is ITokenizable) { return(new GpApiRequest { Verb = HttpMethod.Delete, Endpoint = $"{merchantUrl}/payment-methods/{(builder.PaymentMethod as ITokenizable).Token}", }); } else if (builder.TransactionType == TransactionType.DisputeAcceptance) { return(new GpApiRequest { Verb = HttpMethod.Post, Endpoint = $"{merchantUrl}/disputes/{builder.DisputeId}/acceptance", }); } else if (builder.TransactionType == TransactionType.DisputeChallenge) { var data = new JsonDoc() .Set("documents", builder.DisputeDocuments); return(new GpApiRequest { Verb = HttpMethod.Post, Endpoint = $"{merchantUrl}/disputes/{builder.DisputeId}/challenge", RequestBody = data.ToString(), }); } else if (builder.TransactionType == TransactionType.BatchClose) { return(new GpApiRequest { Verb = HttpMethod.Post, Endpoint = $"{merchantUrl}/batches/{builder.BatchReference}", }); } else if (builder.TransactionType == TransactionType.Reauth) { var data = new JsonDoc() .Set("amount", builder.Amount.ToNumericCurrencyString()); if (builder.PaymentMethod.PaymentMethodType == PaymentMethodType.ACH) { data.Set("description", builder.Description); if (builder.BankTransferDetails != null) { var eCheck = builder.BankTransferDetails; var paymentMethod = new JsonDoc() .Set("narrative", eCheck.MerchantNotes); var bankTransfer = new JsonDoc() .Set("account_number", eCheck.AccountNumber) .Set("account_type", (eCheck.AccountType != null) ? EnumConverter.GetMapping(Target.GP_API, eCheck.AccountType) : null) .Set("check_reference", eCheck.CheckReference); var bank = new JsonDoc() .Set("code", eCheck.RoutingNumber) .Set("name", eCheck.BankName); bankTransfer.Set("bank", bank); paymentMethod.Set("bank_transfer", bankTransfer); data.Set("payment_method", paymentMethod); } } return(new GpApiRequest { Verb = HttpMethod.Post, Endpoint = $"{merchantUrl}/transactions/{builder.TransactionId}/reauthorization", RequestBody = data.ToString(), }); } else if (builder.TransactionType == TransactionType.Confirm) { if (builder.PaymentMethod is TransactionReference && builder.PaymentMethod.PaymentMethodType == PaymentMethodType.APM) { var transactionReference = (TransactionReference)builder.PaymentMethod; var apmResponse = transactionReference.AlternativePaymentResponse; var apm = new JsonDoc() .Set("provider", apmResponse?.ProviderName) .Set("provider_payer_reference", apmResponse?.ProviderReference); var payment_method = new JsonDoc() .Set("apm", apm); var data = new JsonDoc() .Set("payment_method", payment_method); return(new GpApiRequest { Verb = HttpMethod.Post, Endpoint = $"{merchantUrl}/transactions/{builder.TransactionId}/confirmation", RequestBody = data.ToString(), }); } } else if (builder.TransactionType == TransactionType.Auth) { var payload = new JsonDoc(); payload.Set("amount", builder.Amount); if (builder.LodgingData != null) { var lodging = builder.LodgingData; if (lodging.Items != null) { var lodginItems = new List <LodgingItems>(); foreach (var item in lodging.Items) { lodginItems.Add(new LodgingItems { Types = item.Types, Reference = item.Reference, TotalAmount = item.TotalAmount, paymentMethodProgramCodes = item.paymentMethodProgramCodes }); } var lodgingData = new JsonDoc() .Set("booking_reference", lodging.bookingReference) .Set("duration_days", lodging.StayDuration) .Set("date_checked_in", lodging.CheckInDate?.ToString("yyyy-MM-dd")) .Set("date_checked_out", lodging.CheckOutDate?.ToString("yyyy-MM-dd")) .Set("daily_rate_amount", lodging.Rate.ToNumericCurrencyString()) .Set("charge_items", lodginItems); payload.Set("lodging", lodgingData); } return(new GpApiRequest { Verb = HttpMethod.Post, Endpoint = $"{merchantUrl}/transactions/{builder.TransactionId}/incremental", RequestBody = payload.ToString(), }); } } else if (builder.TransactionType == TransactionType.Edit) { var card = new JsonDoc() .Set("tag", builder.TagData); var payment_method = new JsonDoc() .Set("card", card); var payload = new JsonDoc() .Set("amount", builder.Amount.ToNumericCurrencyString()) .Set("gratuity_amount", builder.Gratuity.ToNumericCurrencyString()) .Set("payment_method", payment_method); return(new GpApiRequest { Verb = HttpMethod.Post, Endpoint = $"{merchantUrl}/transactions/{builder.TransactionId}/adjustment", RequestBody = payload.ToString(), }); } else if (builder.TransactionType == TransactionType.PayLinkUpdate) { var payLinkData = builder.PayLinkData; var payload = new JsonDoc() .Set("usage_mode", EnumConverter.GetMapping(Target.GP_API, payLinkData.UsageMode) ?? null) .Set("usage_limit", payLinkData.UsageLimit ?? null) .Set("name", payLinkData.Name ?? null) .Set("description", builder.Description ?? null) .Set("type", payLinkData.Type.ToString() ?? null) .Set("status", payLinkData.Status.ToString() ?? null) .Set("shippable", payLinkData.IsShippable?.ToString() ?? null) .Set("shipping_amount", payLinkData.ShippingAmount.ToNumericCurrencyString()); var transaction = new JsonDoc() .Set("amount", builder.Amount.ToNumericCurrencyString() ?? null); payload.Set("transactions", transaction) .Set("expiration_date", payLinkData.ExpirationDate ?? null) .Set("images", payLinkData.Images ?? null); return(new GpApiRequest { Verb = new HttpMethod("PATCH"), Endpoint = $"{merchantUrl}/links/{builder.PaymentLinkId}", RequestBody = payload.ToString(), }); } return(null); }