internal IDeviceMessage BuildReportTransaction(TerminalReportBuilder builder) { var requestId = builder.SearchBuilder.ReferenceNumber; if (requestId == default(string) && RequestIdProvider != null) { requestId = RequestIdProvider.GetRequestId().ToString(); } var doc = new JsonDoc(); doc.Set("message", "MSG"); var baseRequest = doc.SubElement("data"); baseRequest.Set("command", MapReportType(builder.ReportType)); if (!(builder.SearchBuilder.EcrId == null)) { baseRequest.Set("EcrId", builder.SearchBuilder.EcrId); } baseRequest.Set("requestId", requestId.ToString()); if (builder.ReportType == TerminalReportType.GetOpenTabDetails) { return(TerminalUtilities.BuildUpaRequest(doc.ToString())); } var txnData = baseRequest.SubElement("data"); var txnParams = txnData.SubElement("params"); txnParams.Set("reportOutput", builder.SearchBuilder.ReportOutput); txnParams.Set("batch", builder.SearchBuilder.Batch); return(TerminalUtilities.BuildUpaRequest(doc.ToString())); }
private string ConvertResponse(JsonDoc request, Transaction trans) { var merchantId = request.GetValue <string>("MERCHANT_ID"); var account = request.GetValue <string>("ACCOUNT"); // begin building response var response = new JsonDoc(JsonEncoders.Base64Encoder); response.Set("MERCHANT_ID", merchantId); response.Set("ACCOUNT", request.GetValue <string>("ACCOUNT")); response.Set("ORDER_ID", trans.OrderId); response.Set("TIMESTAMP", trans.Timestamp); response.Set("RESULT", trans.ResponseCode); response.Set("PASREF", trans.TransactionId); response.Set("AUTHCODE", trans.AuthorizationCode); response.Set("AVSPOSTCODERESULT", trans.AvsResponseCode); response.Set("CVNRESULT", trans.CvnResponseCode); response.Set("HPP_LANG", request.GetValue <string>("HPP_LANG")); response.Set("SHIPPING_CODE", request.GetValue <string>("SHIPPING_CODE")); response.Set("SHIPPING_CO", request.GetValue <string>("SHIPPING_CO")); response.Set("BILLING_CODE", request.GetValue <string>("BILLING_CODE")); response.Set("BILLING_CO", request.GetValue <string>("BILLING_CO")); response.Set("ECI", request.GetValue <string>("ECI")); response.Set("CAVV", request.GetValue <string>("CAVV")); response.Set("XID", request.GetValue <string>("XID")); response.Set("MERCHANT_RESPONSE_URL", request.GetValue <string>("MERCHANT_RESPONSE_URL")); response.Set("CARD_PAYMENT_BUTTON", request.GetValue <string>("CARD_PAYMENT_BUTTON")); response.Set("MESSAGE", trans.ResponseMessage); response.Set("AMOUNT", trans.AuthorizedAmount); response.Set("SHA1HASH", GenerationUtils.GenerateHash(_sharedSecret, trans.Timestamp, merchantId, trans.OrderId, trans.ResponseCode, trans.ResponseMessage, trans.TransactionId, trans.AuthorizationCode)); return(response.ToString()); }
public static DeviceMessage BuildUpaAdminRequest(int requestId, string ecrId, string txnType, string lineItemLeft = null, string lineItemRight = null, int?displayOption = null) { var doc = new JsonDoc(); doc.Set("message", UpaMessageType.Msg); var data = doc.SubElement("data"); data.Set("command", txnType); data.Set("EcrId", ecrId); data.Set("requestId", requestId); if ((!string.IsNullOrEmpty(lineItemLeft) || !string.IsNullOrEmpty(lineItemRight)) || displayOption.HasValue) { var request = data.SubElement("data"); var requestParams = request.SubElement("params"); requestParams.Set("lineItemLeft", lineItemLeft); requestParams.Set("lineItemRight", lineItemRight); if (displayOption.HasValue) { requestParams.Set("displayOption", displayOption); } } return(BuildUpaRequest(doc.ToString())); }
private void SendAckMessageToDevice() { var doc = new JsonDoc(); doc.Set("message", UpaMessageType.Ack); var message = TerminalUtilities.BuildUpaRequest(doc.ToString()); var ackBuffer = message.GetSendBuffer(); _stream.Write(ackBuffer, 0, ackBuffer.Length); }
private string ConvertResponse(JsonDoc request, Transaction trans) { var merchantId = request.GetValue <string>("MERCHANT_ID"); var account = request.GetValue <string>("ACCOUNT"); // begin building response var response = new JsonDoc(JsonEncoders.Base64Encoder); response.Set("MERCHANT_ID", merchantId); response.Set("ACCOUNT", request.GetValue <string>("ACCOUNT")); response.Set("ORDER_ID", trans.OrderId); response.Set("TIMESTAMP", trans.Timestamp); response.Set("RESULT", trans.ResponseCode); response.Set("PASREF", trans.TransactionId); response.Set("AUTHCODE", trans.AuthorizationCode); response.Set("AVSPOSTCODERESULT", trans.AvsResponseCode); response.Set("CVNRESULT", trans.CvnResponseCode); response.Set("HPP_LANG", request.GetValue <string>("HPP_LANG")); response.Set("SHIPPING_CODE", request.GetValue <string>("SHIPPING_CODE")); response.Set("SHIPPING_CO", request.GetValue <string>("SHIPPING_CO")); response.Set("BILLING_CODE", request.GetValue <string>("BILLING_CODE")); response.Set("BILLING_CO", request.GetValue <string>("BILLING_CO")); response.Set("ECI", request.GetValue <string>("ECI")); response.Set("CAVV", request.GetValue <string>("CAVV")); response.Set("XID", request.GetValue <string>("XID")); response.Set("MERCHANT_RESPONSE_URL", request.GetValue <string>("MERCHANT_RESPONSE_URL")); response.Set("CARD_PAYMENT_BUTTON", request.GetValue <string>("CARD_PAYMENT_BUTTON")); response.Set("MESSAGE", trans.ResponseMessage); response.Set("AMOUNT", trans.AuthorizedAmount); response.Set("SHA1HASH", GenerationUtils.GenerateHash(_sharedSecret, trans.Timestamp, merchantId, trans.OrderId, trans.ResponseCode, trans.ResponseMessage, trans.TransactionId, trans.AuthorizationCode)); response.Set("DCC_INFO_REQUST", request.GetValue <string>("DCC_INFO")); response.Set("HPP_FRAUDFILTER_MODE", request.GetValue <string>("HPP_FRAUDFILTER_MODE")); if (trans?.FraudResponse?.Rules != null) { response.Set("HPP_FRAUDFILTER_RESULT", trans.FraudResponse?.Result); foreach (var rule in trans.FraudResponse.Rules) { response.Set("HPP_FRAUDFILTER_RULE_" + rule.Id, rule.Action); } } if (trans?.AlternativePaymentResponse != null) { AlternativePaymentResponse alternativePaymentResponse = trans.AlternativePaymentResponse; response.Set("HPP_CUSTOMER_FIRSTNAME", request.GetValue <string>("HPP_CUSTOMER_FIRSTNAME")); response.Set("HPP_CUSTOMER_LASTNAME", request.GetValue <string>("HPP_CUSTOMER_LASTNAME")); response.Set("HPP_CUSTOMER_COUNTRY", request.GetValue <string>("HPP_CUSTOMER_COUNTRY")); response.Set("PAYMENTMETHOD", alternativePaymentResponse.ProviderName); response.Set("PAYMENTPURPOSE", alternativePaymentResponse.PaymentPurpose); response.Set("HPP_CUSTOMER_BANK_ACCOUNT", alternativePaymentResponse.BankAccount); } return(response.ToString()); }
internal static PayrollRequest SignIn(string username, string password, PayrollEncoder encoder) { var request = new JsonDoc() .Set("Username", username) .Set("Password", encoder.Encode(password)); return(new PayrollRequest { Endpoint = "/api/pos/session/signin", RequestBody = request.ToString() }); }
internal static GpApiRequest BuildRequest(Secure3dBuilder builder, GpApiConnector gateway) { var merchantUrl = !string.IsNullOrEmpty(gateway.GpApiConfig.MerchantId) ? $"/merchants/{gateway.GpApiConfig.MerchantId}" : string.Empty; if (builder.TransactionType == TransactionType.VerifyEnrolled) { var storedCredential = new JsonDoc() .Set("model", EnumConverter.GetMapping(Target.GP_API, builder.StoredCredential?.Type)) .Set("reason", EnumConverter.GetMapping(Target.GP_API, builder.StoredCredential?.Reason)) .Set("sequence", EnumConverter.GetMapping(Target.GP_API, builder.StoredCredential?.Sequence)); var paymentMethod = new JsonDoc(); if (builder.PaymentMethod is ITokenizable tokenized && !string.IsNullOrEmpty(tokenized.Token)) { paymentMethod.Set("id", tokenized.Token); } else if (builder.PaymentMethod is ICardData cardData) { var card = new JsonDoc() .Set("number", cardData.Number) .Set("expiry_month", cardData.ExpMonth?.ToString().PadLeft(2, '0')) .Set("expiry_year", cardData.ExpYear?.ToString().PadLeft(4, '0').Substring(2, 2)); paymentMethod.Set("card", card); } var notifications = new JsonDoc() .Set("challenge_return_url", gateway.GpApiConfig.ChallengeNotificationUrl) .Set("three_ds_method_return_url", gateway.GpApiConfig.MethodNotificationUrl); var data = new JsonDoc() .Set("account_name", gateway.GpApiConfig.AccessTokenInfo.TransactionProcessingAccountName) .Set("reference", builder.ReferenceNumber ?? Guid.NewGuid().ToString()) .Set("channel", EnumConverter.GetMapping(Target.GP_API, gateway.GpApiConfig.Channel)) .Set("amount", builder.Amount.ToNumericCurrencyString()) .Set("currency", builder.Currency) .Set("country", gateway.GpApiConfig.Country) .Set("preference", builder.ChallengeRequestIndicator?.ToString()) .Set("source", builder.AuthenticationSource.ToString()) .Set("initator", EnumConverter.GetMapping(Target.GP_API, builder.StoredCredential?.Initiator)) .Set("stored_credential", storedCredential.HasKeys() ? storedCredential : null) .Set("payment_method", paymentMethod) .Set("notifications", notifications.HasKeys() ? notifications : null); return(new GpApiRequest { Verb = HttpMethod.Post, Endpoint = $"{merchantUrl}/authentications", RequestBody = data.ToString(), }); }
internal static GpApiRequest SignIn(string appId, string appKey, string nonce, int?secondsToExpire = null, IntervalToExpire?intervalToExpire = null) { var request = new JsonDoc() .Set("app_id", appId) .Set("nonce", nonce) .Set("grant_type", "client_credentials") .Set("secret", GenerateSecret(nonce, appKey)) .Set("seconds_to_expire", secondsToExpire) .Set("interval_to_expire", EnumConverter.GetMapping(Target.GP_API, intervalToExpire)); return(new GpApiRequest { Endpoint = "/ucp/accesstoken", RequestBody = request.ToString() }); }
internal static GpApiRequest SignIn(string appId, string appKey, int?secondsToExpire = null, IntervalToExpire?intervalToExpire = null, string[] permissions = null) { string nonce = DateTime.UtcNow.ToString("MM/dd/yyyy hh:mm:ss.fff tt"); var request = new JsonDoc() .Set("app_id", appId) .Set("nonce", nonce) .Set("grant_type", "client_credentials") .Set("secret", GenerateSecret(nonce, appKey)) .Set("seconds_to_expire", secondsToExpire) .Set("interval_to_expire", EnumConverter.GetMapping(Target.GP_API, intervalToExpire)) .Set("permissions", permissions); return(new GpApiRequest { Verb = HttpMethod.Post, Endpoint = "/accesstoken", RequestBody = request.ToString() }); }
public T ProcessReport <T>(ReportBuilder <T> builder) where T : class { var request = new JsonDoc(); string requestId = "10004"; // TODO: Generate this? string reportType = MapReportType(builder.ReportType); // transaction reporting if (builder is TransactionReportBuilder <T> ) { var trb = builder as TransactionReportBuilder <T>; request.Set("requestId", requestId); request.Set("transactionId", trb.TransactionId); request.Set("userId", UserId); request.Set("reportType", reportType); request.Set("startDepositDate", trb.SearchBuilder.StartDepositDate?.ToString("dd/MM/yyyy")); request.Set("endDepositDate", trb.SearchBuilder.EndDepositDate?.ToString("dd/MM/yyyy")); request.Set("mId", trb.SearchBuilder.MerchantId); request.Set("hierarchy", trb.SearchBuilder.Hierarchy); request.Set("timezone", trb.SearchBuilder.Timezone); request.Set("depositReference", trb.SearchBuilder.DepositReference); request.Set("orderId", trb.SearchBuilder.OrderId); request.Set("cardNumber", string.Format("{0}{1}", trb.SearchBuilder.CardNumberFirstSix ?? "", trb.SearchBuilder.CardNumberLastFour ?? "")); request.Set("startTransactionLocalTime", trb.SearchBuilder.LocalTransactionStartTime?.ToString("dd/MM/yyyy hh:mm:ss")); request.Set("endTransactionLocalTime", trb.SearchBuilder.LocalTransactionEndTime?.ToString("dd/MM/yyyy hh:mm:ss")); request.Set("paymentAmount", trb.SearchBuilder.Amount.ToNumericCurrencyString()); request.Set("bankAccountNumber", trb.SearchBuilder.BankAccountNumber); request.Set("caseNumber", trb.SearchBuilder.CaseNumber); request.Set("caseId", trb.SearchBuilder.CaseId); } Headers["reporting_type"] = reportType; var response = DoTransaction(HttpMethod.Post, reportType + "/", request.ToString()); return(MapResponse <T>(response, builder.ReportType)); }
internal IDeviceMessage BuildManageTransaction(TerminalManageBuilder builder) { var transType = builder.TransactionType; var transModifier = builder.TransactionModifier; 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"); // Possibly update the requestToken parameter in the future if necessary baseRequest.Set("command", MapTransactionType(transType, transModifier, false, builder.Gratuity)); baseRequest.Set("EcrId", builder.EcrId.ToString()); baseRequest.Set("requestId", requestId.ToString()); var txnData = baseRequest.SubElement("data"); var transaction = txnData.SubElement("transaction"); transaction.Set("referenceNumber", builder.TransactionId ?? StringUtils.PadLeft(builder.TerminalRefNumber, 4, '0')); transaction.Set("amount", ToCurrencyString(builder.Amount)); transaction.Set("taxAmount", ToCurrencyString(builder.TaxAmount)); transaction.Set("tipAmount", ToCurrencyString(builder.Gratuity)); transaction.Set("taxIndicator", builder.TaxExempt); transaction.Set("invoiceNbr", builder.InvoiceNumber); transaction.Set("processCPC", builder.ProcessCPC); return(TerminalUtilities.BuildUpaRequest(doc.ToString())); }
public string SerializeRequest(AuthorizationBuilder builder) { // check for hpp config if (HostedPaymentConfig == null) { throw new ApiException("Hosted configuration missing, Please check you configuration."); } var encoder = (HostedPaymentConfig.Version == HppVersion.VERSION_2) ? null : JsonEncoders.Base64Encoder; var request = new JsonDoc(encoder); var orderId = builder.OrderId ?? GenerationUtils.GenerateOrderId(); var timestamp = builder.Timestamp ?? GenerationUtils.GenerateTimestamp(); // check for right transaction types if (builder.TransactionType != TransactionType.Sale && builder.TransactionType != TransactionType.Auth && builder.TransactionType != TransactionType.Verify) { throw new UnsupportedTransactionException("Only Charge and Authorize are supported through hpp."); } request.Set("MERCHANT_ID", MerchantId); request.Set("ACCOUNT", AccountId); request.Set("CHANNEL", Channel); request.Set("ORDER_ID", orderId); if (builder.Amount != null) { request.Set("AMOUNT", builder.Amount.ToNumericCurrencyString()); } request.Set("CURRENCY", builder.Currency); request.Set("TIMESTAMP", timestamp); request.Set("AUTO_SETTLE_FLAG", (builder.TransactionType == TransactionType.Sale) ? "1" : builder.MultiCapture == true ? "MULTI" : "0"); request.Set("COMMENT1", builder.Description); // request.Set("COMMENT2", ); if (HostedPaymentConfig.RequestTransactionStabilityScore.HasValue) { request.Set("RETURN_TSS", HostedPaymentConfig.RequestTransactionStabilityScore.Value ? "1" : "0"); } if (HostedPaymentConfig.DynamicCurrencyConversionEnabled.HasValue) { request.Set("DCC_ENABLE", HostedPaymentConfig.DynamicCurrencyConversionEnabled.Value ? "1" : "0"); } if (builder.HostedPaymentData != null) { AlternativePaymentType[] PaymentTypes = builder.HostedPaymentData.PresetPaymentMethods; if (PaymentTypes != null) { PaymentValues = string.Join("|", PaymentTypes); } request.Set("CUST_NUM", builder.HostedPaymentData.CustomerNumber); if (HostedPaymentConfig.DisplaySavedCards.HasValue && builder.HostedPaymentData.CustomerKey != null) { request.Set("HPP_SELECT_STORED_CARD", builder.HostedPaymentData.CustomerKey); } if (builder.HostedPaymentData.OfferToSaveCard.HasValue) { request.Set("OFFER_SAVE_CARD", builder.HostedPaymentData.OfferToSaveCard.Value ? "1" : "0"); } if (builder.HostedPaymentData.CustomerExists.HasValue) { request.Set("PAYER_EXIST", builder.HostedPaymentData.CustomerExists.Value ? "1" : "0"); } if (!HostedPaymentConfig.DisplaySavedCards.HasValue) { request.Set("PAYER_REF", builder.HostedPaymentData.CustomerKey); } request.Set("PMT_REF", builder.HostedPaymentData.PaymentKey); request.Set("PROD_ID", builder.HostedPaymentData.ProductId); request.Set("HPP_CUSTOMER_COUNTRY", builder.HostedPaymentData.Country); request.Set("HPP_CUSTOMER_FIRSTNAME", builder.HostedPaymentData.CustomerFirstName); request.Set("HPP_CUSTOMER_LASTNAME", builder.HostedPaymentData.CustomerLastName); request.Set("MERCHANT_RESPONSE_URL", builder.HostedPaymentData.ReturnUrl); request.Set("HPP_TX_STATUS_URL", builder.HostedPaymentData.StatusUpdateUrl); request.Set("PM_METHODS", PaymentValues); } if (builder.ShippingAddress != null) { request.Set("SHIPPING_CODE", builder.ShippingAddress.PostalCode); request.Set("SHIPPING_CO", builder.ShippingAddress.Country); } if (builder.BillingAddress != null) { request.Set("BILLING_CODE", builder.BillingAddress.PostalCode); request.Set("BILLING_CO", builder.BillingAddress.Country); } request.Set("CUST_NUM", builder.CustomerId); request.Set("VAR_REF", builder.ClientTransactionId); request.Set("HPP_LANG", HostedPaymentConfig.Language); request.Set("MERCHANT_RESPONSE_URL", HostedPaymentConfig.ResponseUrl); request.Set("CARD_PAYMENT_BUTTON", HostedPaymentConfig.PaymentButtonText); if (HostedPaymentConfig.CardStorageEnabled.HasValue) { request.Set("CARD_STORAGE_ENABLE", HostedPaymentConfig.CardStorageEnabled.Value ? "1" : "0"); } if (builder.TransactionType == TransactionType.Verify) { request.Set("VALIDATE_CARD_ONLY", builder.TransactionType == TransactionType.Verify ? "1" : "0"); } if (HostedPaymentConfig.FraudFilterMode != FraudFilterMode.NONE) { request.Set("HPP_FRAUDFILTER_MODE", HostedPaymentConfig.FraudFilterMode.ToString()); } if (builder.RecurringType != null || builder.RecurringSequence != null) { request.Set("RECURRING_TYPE", builder.RecurringType.ToString().ToLower()); request.Set("RECURRING_SEQUENCE", builder.RecurringSequence.ToString().ToLower()); } request.Set("HPP_VERSION", HostedPaymentConfig.Version); request.Set("HPP_POST_DIMENSIONS", HostedPaymentConfig.PostDimensions); request.Set("HPP_POST_RESPONSE", HostedPaymentConfig.PostResponse); var toHash = new List <string> { timestamp, MerchantId, orderId, (builder.Amount != null) ? builder.Amount.ToNumericCurrencyString() : null, builder.Currency }; if (HostedPaymentConfig.CardStorageEnabled.HasValue || (builder.HostedPaymentData != null && builder.HostedPaymentData.OfferToSaveCard.HasValue) || HostedPaymentConfig.DisplaySavedCards.HasValue) { toHash.Add(builder.HostedPaymentData.CustomerKey ?? null); toHash.Add(builder.HostedPaymentData.PaymentKey ?? null); } if (HostedPaymentConfig.FraudFilterMode != FraudFilterMode.NONE) { toHash.Add(HostedPaymentConfig.FraudFilterMode.ToString()); } request.Set("SHA1HASH", GenerationUtils.GenerateHash(SharedSecret, toHash.ToArray())); return(request.ToString()); }
internal static GpApiRequest BuildRequest(AuthorizationBuilder builder, GpApiConnector gateway) { var merchantUrl = !string.IsNullOrEmpty(gateway.GpApiConfig.MerchantId) ? $"/merchants/{gateway.GpApiConfig.MerchantId}" : string.Empty; var paymentMethod = new JsonDoc() .Set("entry_mode", GetEntryMode(builder, gateway.GpApiConfig.Channel)); // [MOTO, ECOM, IN_APP, CHIP, SWIPE, MANUAL, CONTACTLESS_CHIP, CONTACTLESS_SWIPE] paymentMethod.Set("narrative", !string.IsNullOrEmpty(builder.DynamicDescriptor) ? builder.DynamicDescriptor : null); if (builder.PaymentMethod is CreditCardData && (builder.TransactionModifier == TransactionModifier.EncryptedMobile || builder.TransactionModifier == TransactionModifier.DecryptedMobile)) { var digitalWallet = new JsonDoc(); var creditCardData = (builder.PaymentMethod as CreditCardData); //Digital Wallet if (builder.TransactionModifier == TransactionModifier.EncryptedMobile) { digitalWallet .Set("payment_token", JsonDoc.Parse(creditCardData.Token)); } else if (builder.TransactionModifier == TransactionModifier.DecryptedMobile) { var tokenFormat = DigitalWalletTokenFormat.CARD_NUMBER; digitalWallet .Set("token", creditCardData.Token) .Set("token_format", DigitalWalletTokenFormat.CARD_NUMBER) .Set("expiry_month", creditCardData.ExpMonth.HasValue ? creditCardData.ExpMonth.ToString().PadLeft(2, '0') : null) .Set("expiry_year", creditCardData.ExpYear.HasValue ? creditCardData.ExpYear.ToString().PadLeft(4, '0').Substring(2, 2) : null) .Set("cryptogram", creditCardData.Cryptogram) .Set("eci", creditCardData.Eci); } digitalWallet.Set("provider", (builder.PaymentMethod as CreditCardData).MobileType); paymentMethod.Set("digital_wallet", digitalWallet); } else { if (builder.PaymentMethod is ICardData) { var cardData = builder.PaymentMethod as ICardData; var card = new JsonDoc() .Set("number", cardData.Number) .Set("expiry_month", cardData.ExpMonth.HasValue ? cardData.ExpMonth.ToString().PadLeft(2, '0') : null) .Set("expiry_year", cardData.ExpYear.HasValue ? cardData.ExpYear.ToString().PadLeft(4, '0').Substring(2, 2) : null) //.Set("track", "") .Set("tag", builder.TagData) .Set("cvv", cardData.Cvn) .Set("avs_address", builder.BillingAddress?.StreetAddress1) .Set("avs_postal_code", builder.BillingAddress?.PostalCode) .Set("authcode", builder.OfflineAuthCode) .Set("brand_reference", builder.CardBrandTransactionId); card.Set("chip_condition", EnumConverter.GetMapping(Target.GP_API, builder.EmvChipCondition)); // [PREV_SUCCESS, PREV_FAILED] if (!(builder.TransactionType == TransactionType.Tokenize || builder.TransactionType == TransactionType.Verify)) { card.Set("cvv_indicator", cardData.CvnPresenceIndicator != 0 ? EnumConverter.GetMapping(Target.GP_API, cardData.CvnPresenceIndicator) : null); // [ILLEGIBLE, NOT_PRESENT, PRESENT] card.Set("funding", builder.PaymentMethod?.PaymentMethodType == PaymentMethodType.Debit ? "DEBIT" : "CREDIT"); // [DEBIT, CREDIT] } var hasToken = builder.PaymentMethod is ITokenizable tokenData && !string.IsNullOrEmpty(tokenData.Token); if (!hasToken) { paymentMethod.Set("card", card); } if (builder.TransactionType == TransactionType.Tokenize) { var tokenizationData = new JsonDoc() .Set("account_name", gateway.GpApiConfig.AccessTokenInfo.TokenizationAccountName) .Set("reference", builder.ClientTransactionId ?? Guid.NewGuid().ToString()) .Set("usage_mode", EnumConverter.GetMapping(Target.GP_API, builder.PaymentMethodUsageMode)) .Set("card", card); return(new GpApiRequest { Verb = HttpMethod.Post, Endpoint = $"{merchantUrl}/payment-methods", RequestBody = tokenizationData.ToString(), }); } else if (builder.TransactionType == TransactionType.DccRateLookup) { // tokenized payment method if (builder.PaymentMethod is ITokenizable) { string token = ((ITokenizable)builder.PaymentMethod).Token; if (!string.IsNullOrEmpty(token)) { paymentMethod.Set("id", token); } } var RequestData = new JsonDoc() .Set("account_name", gateway.GpApiConfig.AccessTokenInfo.TransactionProcessingAccountName) .Set("channel", EnumConverter.GetMapping(Target.GP_API, gateway.GpApiConfig.Channel)) .Set("reference", builder.ClientTransactionId ?? Guid.NewGuid().ToString()) .Set("amount", builder.Amount.ToNumericCurrencyString()) .Set("currency", builder.Currency) .Set("country", gateway.GpApiConfig.Country) .Set("payment_method", paymentMethod); return(new GpApiRequest { Verb = HttpMethod.Post, Endpoint = $"{merchantUrl}/currency-conversions", RequestBody = RequestData.ToString(), }); } else if (builder.TransactionType == TransactionType.Verify) { if (builder.RequestMultiUseToken && string.IsNullOrEmpty((builder.PaymentMethod as ITokenizable).Token)) { var tokenizationData = new JsonDoc() .Set("account_name", gateway.GpApiConfig.AccessTokenInfo.TokenizationAccountName) .Set("reference", builder.ClientTransactionId ?? Guid.NewGuid().ToString()) .Set("usage_mode", EnumConverter.GetMapping(Target.GP_API, builder.PaymentMethodUsageMode)) .Set("fingerprint_mode", builder.CustomerData?.DeviceFingerPrint ?? null) .Set("card", card); return(new GpApiRequest { Verb = HttpMethod.Post, Endpoint = $"{merchantUrl}/payment-methods", RequestBody = tokenizationData.ToString(), }); } else { var verificationData = new JsonDoc() .Set("account_name", gateway.GpApiConfig.AccessTokenInfo.TransactionProcessingAccountName) .Set("channel", EnumConverter.GetMapping(Target.GP_API, gateway.GpApiConfig.Channel)) .Set("reference", builder.ClientTransactionId ?? Guid.NewGuid().ToString()) .Set("currency", builder.Currency) .Set("country", gateway.GpApiConfig.Country) .Set("payment_method", paymentMethod); if (builder.PaymentMethod is ITokenizable && !string.IsNullOrEmpty((builder.PaymentMethod as ITokenizable).Token)) { verificationData.Remove("payment_method"); verificationData.Set("payment_method", new JsonDoc() .Set("entry_mode", GetEntryMode(builder, gateway.GpApiConfig.Channel)) .Set("id", (builder.PaymentMethod as ITokenizable).Token) .Set("fingerprint_mode", builder.CustomerData?.DeviceFingerPrint ?? null) ); } return(new GpApiRequest { Verb = HttpMethod.Post, Endpoint = $"{merchantUrl}/verifications", RequestBody = verificationData.ToString(), }); } } } else if (builder.PaymentMethod is ITrackData) { var track = builder.PaymentMethod as ITrackData; var card = new JsonDoc() .Set("track", track.Value) .Set("tag", builder.TagData) .Set("avs_address", builder.BillingAddress?.StreetAddress1) .Set("avs_postal_code", builder.BillingAddress?.PostalCode) .Set("authcode", builder.OfflineAuthCode); if (builder.TransactionType == TransactionType.Verify) { paymentMethod.Set("card", card); var verificationData = new JsonDoc() .Set("account_name", gateway.GpApiConfig.AccessTokenInfo.TransactionProcessingAccountName) .Set("channel", EnumConverter.GetMapping(Target.GP_API, gateway.GpApiConfig.Channel)) .Set("reference", builder.ClientTransactionId ?? Guid.NewGuid().ToString()) .Set("currency", builder.Currency) .Set("country", gateway.GpApiConfig.Country) .Set("payment_method", paymentMethod) .Set("fingerprint_mode", builder.CustomerData?.DeviceFingerPrint ?? null); return(new GpApiRequest { Verb = HttpMethod.Post, Endpoint = $"{merchantUrl}/verifications", RequestBody = verificationData.ToString(), }); } if (builder.TransactionType == TransactionType.Sale || builder.TransactionType == TransactionType.Refund) { if (string.IsNullOrEmpty(track.Value)) { card.Set("number", track.Pan); card.Set("expiry_month", track.Expiry?.Substring(2, 2)); card.Set("expiry_year", track.Expiry?.Substring(0, 2)); } if (string.IsNullOrEmpty(builder.TagData)) { card.Set("chip_condition", EnumConverter.GetMapping(Target.GP_API, builder.EmvChipCondition)); // [PREV_SUCCESS, PREV_FAILED] } } if (builder.TransactionType == TransactionType.Sale) { card.Set("funding", builder.PaymentMethod?.PaymentMethodType == PaymentMethodType.Debit ? "DEBIT" : "CREDIT"); // [DEBIT, CREDIT] } paymentMethod.Set("card", card); } // tokenized payment method if (builder.PaymentMethod is ITokenizable) { string token = ((ITokenizable)builder.PaymentMethod).Token; if (!string.IsNullOrEmpty(token)) { paymentMethod.Set("id", token); } } } // payment method storage mode if (builder.RequestMultiUseToken) { //ToDo: there might be a typo: should be storage_mode paymentMethod.Set("storage_mode", "ON_SUCCESS"); } // pin block if (builder.PaymentMethod is IPinProtected) { paymentMethod.Get("card")?.Set("pin_block", ((IPinProtected)builder.PaymentMethod).PinBlock); } // authentication if (builder.PaymentMethod is CreditCardData) { paymentMethod.Set("name", (builder.PaymentMethod as CreditCardData).CardHolderName); var secureEcom = (builder.PaymentMethod as CreditCardData).ThreeDSecure; if (secureEcom != null) { var authentication = new JsonDoc().Set("id", secureEcom.ServerTransactionId); paymentMethod.Set("authentication", authentication); } paymentMethod.Set("fingerprint_mode", builder.CustomerData?.DeviceFingerPrint ?? null); } if (builder.PaymentMethod is EBT) { paymentMethod.Set("name", (builder.PaymentMethod as EBT).CardHolderName); } if (builder.PaymentMethod is eCheck) { eCheck check = (builder.PaymentMethod as eCheck); paymentMethod.Set("name", check.CheckHolderName); var bankTransfer = new JsonDoc() .Set("account_number", check.AccountNumber) .Set("account_type", (check.AccountType != null) ? EnumConverter.GetMapping(Target.GP_API, check.AccountType) : null) .Set("check_reference", check.CheckReference) .Set("sec_code", check.SecCode) .Set("narrative", check.MerchantNotes); var bank = new JsonDoc() .Set("code", check.RoutingNumber) .Set("name", check.BankName); var address = new JsonDoc() .Set("line_1", check.BankAddress?.StreetAddress1) .Set("line_2", check.BankAddress?.StreetAddress2) .Set("line_3", check.BankAddress?.StreetAddress3) .Set("city", check.BankAddress?.City) .Set("postal_code", check.BankAddress?.PostalCode) .Set("state", check.BankAddress?.State) .Set("country", check.BankAddress?.CountryCode); bank.Set("address", address); bankTransfer.Set("bank", bank); paymentMethod.Set("bank_transfer", bankTransfer); } if (builder.PaymentMethod is AlternativePaymentMethod) { var alternatepaymentMethod = (AlternativePaymentMethod)builder.PaymentMethod; paymentMethod.Set("name", alternatepaymentMethod.AccountHolderName); var apm = new JsonDoc() .Set("provider", alternatepaymentMethod.AlternativePaymentMethodType?.ToString()?.ToLower()) .Set("address_override_mode", alternatepaymentMethod.AddressOverrideMode); paymentMethod.Set("apm", apm); } // encryption if (builder.PaymentMethod is IEncryptable) { var encryptionData = ((IEncryptable)builder.PaymentMethod).EncryptionData; if (encryptionData != null) { var encryption = new JsonDoc() .Set("version", encryptionData.Version); if (!string.IsNullOrEmpty(encryptionData.KTB)) { encryption.Set("method", "KTB"); encryption.Set("info", encryptionData.KTB); } else if (!string.IsNullOrEmpty(encryptionData.KSN)) { encryption.Set("method", "KSN"); encryption.Set("info", encryptionData.KSN); } if (encryption.Has("info")) { paymentMethod.Set("encryption", encryption); } } } if (builder.TransactionType == TransactionType.Create && builder.PayLinkData is PayLinkData) { var payLinkData = builder.PayLinkData; var requestData = new JsonDoc() .Set("usage_limit", payLinkData.UsageLimit.ToString()) .Set("usage_mode", EnumConverter.GetMapping(Target.GP_API, payLinkData.UsageMode)) .Set("images", payLinkData.Images) .Set("description", builder.Description ?? null) .Set("type", payLinkData.Type?.ToString()) .Set("expiration_date", payLinkData.ExpirationDate ?? null); var transaction = new JsonDoc() .Set("country", gateway.GpApiConfig.Country) .Set("amount", builder.Amount.ToNumericCurrencyString()) .Set("channel", EnumConverter.GetMapping(Target.GP_API, gateway.GpApiConfig.Channel)) .Set("currency", builder.Currency) .Set("allowed_payment_methods", GetAllowedPaymentMethod(payLinkData.AllowedPaymentMethods)); requestData.Set("transactions", transaction) .Set("reference", builder.ClientTransactionId ?? Guid.NewGuid().ToString()) .Set("shipping_amount", payLinkData.ShippingAmount.ToNumericCurrencyString()) .Set("shippable", payLinkData.IsShippable?.ToString() ?? false.ToString()) .Set("account_name", gateway.GpApiConfig.AccessTokenInfo.TransactionProcessingAccountName) .Set("name", payLinkData.Name ?? null); var notification = new JsonDoc() .Set("cancel_url", payLinkData.CancelUrl) .Set("return_url", payLinkData.ReturnUrl) .Set("status_url", payLinkData.StatusUpdateUrl); requestData.Set("notifications", notification) .Set("status", payLinkData.Status.ToString()); return(new GpApiRequest { Verb = HttpMethod.Post, Endpoint = $"{merchantUrl}/links", RequestBody = requestData.ToString(), }); } var data = new JsonDoc() .Set("account_name", gateway.GpApiConfig.AccessTokenInfo.TransactionProcessingAccountName) .Set("type", builder.TransactionType == TransactionType.Refund ? "REFUND" : "SALE") // [SALE, REFUND] .Set("channel", EnumConverter.GetMapping(Target.GP_API, gateway.GpApiConfig.Channel)) // [CP, CNP] .Set("capture_mode", GetCaptureMode(builder)) // [AUTO, LATER, MULTIPLE] //.Set("remaining_capture_count", "") //Pending Russell .Set("authorization_mode", builder.AllowPartialAuth ? "PARTIAL" : null) .Set("amount", builder.Amount.ToNumericCurrencyString()) .Set("currency", builder.Currency) .Set("reference", builder.ClientTransactionId ?? Guid.NewGuid().ToString()) .Set("description", builder.Description) //.Set("order_reference", builder.OrderId) .Set("gratuity_amount", builder.Gratuity.ToNumericCurrencyString()) .Set("cashback_amount", builder.CashBackAmount.ToNumericCurrencyString()) .Set("surcharge_amount", builder.SurchargeAmount.ToNumericCurrencyString()) .Set("convenience_amount", builder.ConvenienceAmount.ToNumericCurrencyString()) .Set("country", gateway.GpApiConfig.Country) //.Set("language", EnumConverter.GetMapping(Target.GP_API, Language)) .Set("ip_address", builder.CustomerIpAddress) //.Set("site_reference", "") // .Set("currency_conversion", !string.IsNullOrEmpty(builder.DccRateData?.DccId) ? new JsonDoc().Set("id", builder.DccRateData.DccId) : null) .Set("payment_method", paymentMethod) .Set("link", !string.IsNullOrEmpty(builder.PaymentLinkId) ? new JsonDoc() .Set("id", builder.PaymentLinkId) : null); if (builder.PaymentMethod is eCheck || builder.PaymentMethod is AlternativePaymentMethod) { data.Set("payer", SetPayerInformation(builder)); } // set order reference if (!string.IsNullOrEmpty(builder.OrderId)) { var order = new JsonDoc() .Set("reference", builder.OrderId); data.Set("order", order); } if (builder.PaymentMethod is AlternativePaymentMethod) { setOrderInformation(builder, ref data); var alternatepaymentMethod = (AlternativePaymentMethod)builder.PaymentMethod; var notifications = new JsonDoc() .Set("return_url", alternatepaymentMethod?.ReturnUrl) .Set("status_url", alternatepaymentMethod?.StatusUpdateUrl) .Set("cancel_url", alternatepaymentMethod?.CancelUrl); data.Set("notifications", notifications); } // stored credential if (builder.StoredCredential != null) { data.Set("initiator", EnumConverter.GetMapping(Target.GP_API, builder.StoredCredential.Initiator)); var storedCredential = new JsonDoc() .Set("model", EnumConverter.GetMapping(Target.GP_API, builder.StoredCredential.Type)) .Set("reason", EnumConverter.GetMapping(Target.GP_API, builder.StoredCredential.Reason)) .Set("sequence", EnumConverter.GetMapping(Target.GP_API, builder.StoredCredential.Sequence)); data.Set("stored_credential", storedCredential); } return(new GpApiRequest { Verb = HttpMethod.Post, Endpoint = $"{merchantUrl}/transactions", RequestBody = data.ToString(), }); }
internal static GpApiRequest BuildRequest(AuthorizationBuilder builder, GpApiConnector gateway) { var paymentMethod = new JsonDoc() .Set("entry_mode", GetEntryMode(builder)); // [MOTO, ECOM, IN_APP, CHIP, SWIPE, MANUAL, CONTACTLESS_CHIP, CONTACTLESS_SWIPE] if (builder.PaymentMethod is ICardData) { var cardData = builder.PaymentMethod as ICardData; var card = new JsonDoc() .Set("number", cardData.Number) .Set("expiry_month", cardData.ExpMonth.HasValue ? cardData.ExpMonth.ToString().PadLeft(2, '0') : null) .Set("expiry_year", cardData.ExpYear.HasValue ? cardData.ExpYear.ToString().PadLeft(4, '0').Substring(2, 2) : null) //.Set("track", "") .Set("tag", builder.TagData) .Set("cvv", cardData.Cvn) .Set("cvv_indicator", EnumConverter.GetMapping(Target.GP_API, cardData.CvnPresenceIndicator)) // [ILLEGIBLE, NOT_PRESENT, PRESENT] .Set("avs_address", builder.BillingAddress?.StreetAddress1) .Set("avs_postal_code", builder.BillingAddress?.PostalCode) .Set("funding", builder.PaymentMethod?.PaymentMethodType == PaymentMethodType.Debit ? "DEBIT" : "CREDIT") // [DEBIT, CREDIT] .Set("authcode", builder.OfflineAuthCode); //.Set("brand_reference", "") card.Set("chip_condition", EnumConverter.GetMapping(Target.GP_API, builder.EmvChipCondition)); // [PREV_SUCCESS, PREV_FAILED] paymentMethod.Set("card", card); var tokenizationData = new JsonDoc() .Set("account_name", gateway.TokenizationAccountName) .Set("reference", builder.ClientTransactionId ?? Guid.NewGuid().ToString()) .Set("usage_mode", EnumConverter.GetMapping(Target.GP_API, builder.TokenUsageMode)) .Set("name", "") .Set("card", card); if (builder.TransactionType == TransactionType.Tokenize) { return(new GpApiRequest { Verb = HttpMethod.Post, Endpoint = "/payment-methods", RequestBody = tokenizationData.ToString(), }); } else if (builder.TransactionType == TransactionType.Verify) { if (builder.RequestMultiUseToken && string.IsNullOrEmpty((builder.PaymentMethod as ITokenizable).Token)) { return(new GpApiRequest { Verb = HttpMethod.Post, Endpoint = "/payment-methods", RequestBody = tokenizationData.ToString(), }); } else { var verificationData = new JsonDoc() .Set("account_name", gateway.TransactionProcessingAccountName) .Set("channel", EnumConverter.GetMapping(Target.GP_API, gateway.Channel)) .Set("reference", builder.ClientTransactionId ?? Guid.NewGuid().ToString()) .Set("currency", builder.Currency) .Set("country", gateway.Country) .Set("payment_method", paymentMethod); if (builder.PaymentMethod is ITokenizable && !string.IsNullOrEmpty((builder.PaymentMethod as ITokenizable).Token)) { verificationData.Remove("payment_method"); verificationData.Set("payment_method", new JsonDoc() .Set("entry_mode", GetEntryMode(builder)) .Set("id", (builder.PaymentMethod as ITokenizable).Token) ); } return(new GpApiRequest { Verb = HttpMethod.Post, Endpoint = "/verifications", RequestBody = verificationData.ToString(), }); } } } else if (builder.PaymentMethod is ITrackData) { var track = builder.PaymentMethod as ITrackData; var card = new JsonDoc() .Set("track", track.Value) .Set("tag", builder.TagData) .Set("avs_address", builder.BillingAddress?.StreetAddress1) .Set("avs_postal_code", builder.BillingAddress?.PostalCode) .Set("authcode", builder.OfflineAuthCode); if (builder.TransactionType == TransactionType.Verify) { paymentMethod.Set("card", card); var verificationData = new JsonDoc() .Set("account_name", gateway.TransactionProcessingAccountName) .Set("channel", EnumConverter.GetMapping(Target.GP_API, gateway.Channel)) .Set("reference", builder.ClientTransactionId ?? Guid.NewGuid().ToString()) .Set("currency", builder.Currency) .Set("country", gateway.Country) .Set("payment_method", paymentMethod); return(new GpApiRequest { Verb = HttpMethod.Post, Endpoint = "/verifications", RequestBody = verificationData.ToString(), }); } if (builder.TransactionType == TransactionType.Sale || builder.TransactionType == TransactionType.Refund) { if (string.IsNullOrEmpty(track.Value)) { card.Set("number", track.Pan); card.Set("expiry_month", track.Expiry?.Substring(2, 2)); card.Set("expiry_year", track.Expiry?.Substring(0, 2)); } if (string.IsNullOrEmpty(builder.TagData)) { card.Set("chip_condition", EnumConverter.GetMapping(Target.GP_API, builder.EmvChipCondition)); // [PREV_SUCCESS, PREV_FAILED] } } if (builder.TransactionType == TransactionType.Sale) { card.Set("funding", builder.PaymentMethod?.PaymentMethodType == PaymentMethodType.Debit ? "DEBIT" : "CREDIT"); // [DEBIT, CREDIT] } paymentMethod.Set("card", card); } // payment method storage mode if (builder.RequestMultiUseToken) { //ToDo: there might be a typo: should be storage_mode paymentMethod.Set("storage_model", "ON_SUCCESS"); } // tokenized payment method if (builder.PaymentMethod is ITokenizable) { string token = ((ITokenizable)builder.PaymentMethod).Token; if (!string.IsNullOrEmpty(token)) { paymentMethod.Set("id", token); } } // pin block if (builder.PaymentMethod is IPinProtected) { paymentMethod.Get("card")?.Set("pin_block", ((IPinProtected)builder.PaymentMethod).PinBlock); } // authentication if (builder.PaymentMethod is CreditCardData) { paymentMethod.Set("name", (builder.PaymentMethod as CreditCardData).CardHolderName); var secureEcom = (builder.PaymentMethod as CreditCardData).ThreeDSecure; if (secureEcom != null) { var three_ds = new JsonDoc() // Indicates the version of 3DS .Set("message_version", secureEcom.MessageVersion) // An indication of the degree of the authentication and liability shift obtained for this transaction. // It is determined during the 3D Secure process. .Set("eci", secureEcom.Eci) // The authentication value created as part of the 3D Secure process. .Set("value", secureEcom.AuthenticationValue) // The reference created by the 3DSecure provider to identify the specific authentication attempt. .Set("server_trans_ref", secureEcom.ServerTransactionId) // The reference created by the 3DSecure Directory Server to identify the specific authentication attempt. .Set("ds_trans_ref", secureEcom.DirectoryServerTransactionId); var authentication = new JsonDoc().Set("three_ds", three_ds); paymentMethod.Set("authentication", authentication); } } // encryption if (builder.PaymentMethod is IEncryptable) { var encryptionData = ((IEncryptable)builder.PaymentMethod).EncryptionData; if (encryptionData != null) { var encryption = new JsonDoc() .Set("version", encryptionData.Version); if (!string.IsNullOrEmpty(encryptionData.KTB)) { encryption.Set("method", "KTB"); encryption.Set("info", encryptionData.KTB); } else if (!string.IsNullOrEmpty(encryptionData.KSN)) { encryption.Set("method", "KSN"); encryption.Set("info", encryptionData.KSN); } if (encryption.Has("info")) { paymentMethod.Set("encryption", encryption); } } } var data = new JsonDoc() .Set("account_name", gateway.TransactionProcessingAccountName) .Set("type", builder.TransactionType == TransactionType.Refund ? "REFUND" : "SALE") // [SALE, REFUND] .Set("channel", EnumConverter.GetMapping(Target.GP_API, gateway.Channel)) // [CP, CNP] .Set("capture_mode", GetCaptureMode(builder)) // [AUTO, LATER, MULTIPLE] //.Set("remaining_capture_count", "") //Pending Russell .Set("authorization_mode", builder.AllowPartialAuth ? "PARTIAL" : null) .Set("amount", builder.Amount.ToNumericCurrencyString()) .Set("currency", builder.Currency) .Set("reference", builder.ClientTransactionId ?? Guid.NewGuid().ToString()) .Set("description", builder.Description) //.Set("order_reference", builder.OrderId) .Set("gratuity_amount", builder.Gratuity.ToNumericCurrencyString()) .Set("cashback_amount", builder.CashBackAmount.ToNumericCurrencyString()) .Set("surcharge_amount", builder.SurchargeAmount.ToNumericCurrencyString()) .Set("convenience_amount", builder.ConvenienceAmount.ToNumericCurrencyString()) .Set("country", gateway.Country) //.Set("language", EnumConverter.GetMapping(Target.GP_API, Language)) .Set("ip_address", builder.CustomerIpAddress) //.Set("site_reference", "") // .Set("payment_method", paymentMethod); // set order reference if (!string.IsNullOrEmpty(builder.OrderId)) { var order = new JsonDoc() .Set("reference", builder.OrderId); data.Set("order", order); } // stored credential if (builder.StoredCredential != null) { data.Set("initiator", EnumConverter.GetMapping(Target.GP_API, builder.StoredCredential.Initiator)); var storedCredential = new JsonDoc() .Set("model", EnumConverter.GetMapping(Target.GP_API, builder.StoredCredential.Type)) .Set("reason", EnumConverter.GetMapping(Target.GP_API, builder.StoredCredential.Reason)) .Set("sequence", EnumConverter.GetMapping(Target.GP_API, builder.StoredCredential.Sequence)); data.Set("stored_credential", storedCredential); } return(new GpApiRequest { Verb = HttpMethod.Post, Endpoint = "/transactions", RequestBody = data.ToString(), }); }
public Transaction ProcessOpenBanking(BankPaymentBuilder builder) { string timestamp = builder.Timestamp ?? GenerationUtils.GenerateTimestamp(); string orderId = builder.OrderId ?? GenerationUtils.GenerateOrderId(); var amount = builder.Amount != null?builder.Amount.ToNumericCurrencyString() : null; JsonDoc request = new JsonDoc(); var paymentMethod = builder.PaymentMethod as BankPayment; switch (builder.TransactionType) { case TransactionType.Sale: var bankPaymentType = paymentMethod.BankPaymentType != null ? paymentMethod.BankPaymentType : GetBankPaymentType(builder.Currency); string hash = GenerationUtils.GenerateHash(SharedSecret, ShaHashType, timestamp, MerchantId, orderId, amount, builder.Currency, !string.IsNullOrEmpty(paymentMethod.SortCode) && bankPaymentType.Equals(BankPaymentType.FASTERPAYMENTS) ? paymentMethod.SortCode : "", !string.IsNullOrEmpty(paymentMethod.AccountNumber) && bankPaymentType.Equals(BankPaymentType.FASTERPAYMENTS) ? paymentMethod.AccountNumber : "", !string.IsNullOrEmpty(paymentMethod.Iban) && bankPaymentType.Equals(BankPaymentType.SEPA) ? paymentMethod.Iban : ""); SetAuthorizationHeader(hash); request.Set("request_timestamp", timestamp) .Set("merchant_id", MerchantId) .Set("account_id", AccountId); JsonDoc order = new JsonDoc(); order.Set("id", orderId) .Set("currency", builder.Currency) .Set("amount", amount) .Set("description", builder.Description); JsonDoc payment = new JsonDoc(); JsonDoc destination = new JsonDoc(); destination.Set("account_number", bankPaymentType.Equals(BankPaymentType.FASTERPAYMENTS) ? paymentMethod.AccountNumber : null) .Set("sort_code", bankPaymentType.Equals(BankPaymentType.FASTERPAYMENTS) ? paymentMethod.SortCode : null) .Set("iban", bankPaymentType.Equals(BankPaymentType.SEPA) ? paymentMethod.Iban : null) .Set("name", paymentMethod.AccountName); JsonDoc remittance_reference = new JsonDoc(); remittance_reference.Set("type", builder.RemittanceReferenceType != null ? builder.RemittanceReferenceType.ToString() : null) .Set("value", builder.RemittanceReferenceValue); payment.Set("scheme", bankPaymentType.ToString()) .Set("destination", destination); if (remittance_reference.HasKeys()) { payment.Set("remittance_reference", remittance_reference); } request.Set("order", order) .Set("payment", payment) .Set("return_url", paymentMethod.ReturnUrl) .Set("status_url", paymentMethod.StatusUpdateUrl); break; default: break; } try { string rawResponse = DoTransaction(HttpMethod.Post, "/payments", request.ToString()); return(OpenBankingMapping.MapResponse(rawResponse)); } catch (GatewayException gatewayException) { throw gatewayException; } }
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)); }
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); }
public Transaction ProcessSecure3d(Secure3dBuilder builder) { TransactionType transType = builder.TransactionType; IPaymentMethod paymentMethod = builder.PaymentMethod; ISecure3d secure3d = (ISecure3d)paymentMethod; string timestamp = DateTime.Now.ToString("yyyy-MM-dd'T'hh:mm:ss.ffffff"); JsonDoc request = new JsonDoc(); if (transType.Equals(TransactionType.VerifyEnrolled)) { request.Set("request_timestamp", timestamp); request.Set("merchant_id", MerchantId); request.Set("account_id", AccountId); request.Set("method_notification_url", MethodNotificationUrl); string hashValue = string.Empty; if (paymentMethod is CreditCardData cardData) { request.Set("number", cardData.Number); request.Set("scheme", MapCardScheme(cardData.CardType.ToUpper())); hashValue = cardData.Number; } else if (paymentMethod is RecurringPaymentMethod storedCard) { request.Set("payer_reference", storedCard.CustomerKey); request.Set("payment_method_reference", storedCard.Key); hashValue = storedCard.CustomerKey; } string hash = GenerationUtils.GenerateHash(SharedSecret, timestamp, MerchantId, hashValue); SetAuthHeader(hash); string rawResponse = DoTransaction(HttpMethod.Post, "protocol-versions", request.ToString()); return(MapResponse(rawResponse)); } else if (transType.Equals(TransactionType.VerifySignature)) { string hash = GenerationUtils.GenerateHash(SharedSecret, timestamp, MerchantId, builder.ServerTransactionId); SetAuthHeader(hash); var queryValues = new Dictionary <string, string>(); queryValues.Add("merchant_id", MerchantId); queryValues.Add("request_timestamp", timestamp); string rawResponse = DoTransaction(HttpMethod.Get, string.Format("authentications/{0}", builder.ServerTransactionId), null, queryValues); return(MapResponse(rawResponse)); } else if (transType.Equals(TransactionType.InitiateAuthentication)) { string orderId = builder.OrderId; if (string.IsNullOrEmpty(orderId)) { orderId = GenerationUtils.GenerateOrderId(); } ThreeDSecure secureEcom = secure3d.ThreeDSecure; request.Set("request_timestamp", timestamp); request.Set("authentication_source", builder.AuthenticationSource.ToString()); request.Set("authentication_request_type", builder.AuthenticationRequestType.ToString()); request.Set("message_category", builder.MessageCategory.ToString()); request.Set("message_version", "2.1.0"); request.Set("server_trans_id", secureEcom.ServerTransactionId); request.Set("merchant_id", MerchantId); request.Set("account_id", AccountId); request.Set("challenge_notification_url", ChallengeNotificationUrl); request.Set("method_url_completion", builder.MethodUrlCompletion.ToString()); request.Set("merchant_contact_url", MerchantContactUrl); request.Set("merchant_initiated_request_type", builder.MerchantInitiatedRequestType?.ToString()); request.Set("whitelist_status", builder.WhitelistStatus); request.Set("decoupled_flow_request", builder.DecoupledFlowRequest); request.Set("decoupled_flow_timeout", builder.DecoupledFlowTimeout); request.Set("decoupled_notification_url", builder.DecoupledNotificationUrl); request.Set("enable_exemption_optimization", builder.EnableExemptionOptimization); // card details string hashValue = string.Empty; JsonDoc cardDetail = request.SubElement("card_detail"); if (paymentMethod is CreditCardData cardData) { hashValue = cardData.Number; cardDetail.Set("number", cardData.Number); cardDetail.Set("scheme", cardData.CardType.ToUpper()); cardDetail.Set("expiry_month", cardData.ExpMonth.ToString()); cardDetail.Set("expiry_year", cardData.ExpYear.ToString().Substring(2)); cardDetail.Set("full_name", cardData.CardHolderName); if (!string.IsNullOrEmpty(cardData.CardHolderName)) { string[] names = cardData.CardHolderName.Split(' '); if (names.Length >= 1) { cardDetail.Set("first_name", names[0]); } if (names.Length >= 2) { cardDetail.Set("last_name", string.Join(" ", names.Skip(1))); } } } else if (paymentMethod is RecurringPaymentMethod storedCard) { hashValue = storedCard.CustomerKey; cardDetail.Set("payer_reference", storedCard.CustomerKey); cardDetail.Set("payment_method_reference", storedCard.Key); } // order details JsonDoc order = request.SubElement("order"); order.Set("amount", builder.Amount.ToNumericCurrencyString()); order.Set("currency", builder.Currency); order.Set("id", orderId); order.Set("address_match_indicator", builder.AddressMatchIndicator ? "true" : "false"); order.Set("date_time_created", builder.OrderCreateDate?.ToString("yyyy-MM-dd'T'hh:mm'Z'")); order.Set("gift_card_count", builder.GiftCardCount); order.Set("gift_card_currency", builder.GiftCardCurrency); order.Set("gift_card_amount", builder.GiftCardAmount.ToNumericCurrencyString()); order.Set("delivery_email", builder.DeliveryEmail); order.Set("delivery_timeframe", builder.DeliveryTimeframe?.ToString()); order.Set("shipping_method", builder.ShippingMethod?.ToString()); order.Set("shipping_name_matches_cardholder_name", builder.ShippingNameMatchesCardHolderName); order.Set("preorder_indicator", builder.PreOrderIndicator?.ToString()); order.Set("reorder_indicator", builder.ReorderIndicator?.ToString()); order.Set("transaction_type", builder.OrderTransactionType?.ToString()); order.Set("preorder_availability_date", builder.PreOrderAvailabilityDate?.ToString("yyyy-MM-dd")); // shipping address Address shippingAddress = builder.ShippingAddress; if (shippingAddress != null) { JsonDoc shippingAddressElement = order.SubElement("shipping_address"); shippingAddressElement.Set("line1", shippingAddress.StreetAddress1); shippingAddressElement.Set("line2", shippingAddress.StreetAddress2); shippingAddressElement.Set("line3", shippingAddress.StreetAddress3); shippingAddressElement.Set("city", shippingAddress.City); shippingAddressElement.Set("postal_code", shippingAddress.PostalCode); shippingAddressElement.Set("state", shippingAddress.State); shippingAddressElement.Set("country", shippingAddress.CountryCode); } // payer JsonDoc payer = request.SubElement("payer"); payer.Set("email", builder.CustomerEmail); payer.Set("id", builder.CustomerAccountId); payer.Set("account_age", builder.AccountAgeIndicator?.ToString()); payer.Set("account_creation_date", builder.AccountCreateDate?.ToString("yyyy-MM-dd")); payer.Set("account_change_indicator", builder.AccountChangeIndicator?.ToString()); payer.Set("account_change_date", builder.AccountChangeDate?.ToString("yyyy-MM-dd")); payer.Set("account_password_change_indicator", builder.PasswordChangeIndicator?.ToString()); payer.Set("account_password_change_date", builder.PasswordChangeDate?.ToString("yyyy-MM-dd")); payer.Set("payment_account_age_indicator", builder.PaymentAgeIndicator?.ToString()); payer.Set("payment_account_creation_date", builder.PaymentAccountCreateDate?.ToString("yyyy-MM-dd")); payer.Set("purchase_count_last_6months", builder.NumberOfPurchasesInLastSixMonths); payer.Set("transaction_count_last_24hours", builder.NumberOfTransactionsInLast24Hours); payer.Set("transaction_count_last_year", builder.NumberOfTransactionsInLastYear); payer.Set("provision_attempt_count_last_24hours", builder.NumberOfAddCardAttemptsInLast24Hours); payer.Set("shipping_address_creation_indicator", builder.ShippingAddressUsageIndicator?.ToString()); payer.Set("shipping_address_creation_date", builder.ShippingAddressCreateDate?.ToString("yyyy-MM-dd")); // suspicious activity if (builder.PreviousSuspiciousActivity != null) { payer.Set("suspicious_account_activity", builder.PreviousSuspiciousActivity.Value ? "SUSPICIOUS_ACTIVITY" : "NO_SUSPICIOUS_ACTIVITY"); } // home phone if (!string.IsNullOrEmpty(builder.HomeNumber)) { payer.SubElement("home_phone") .Set("country_code", builder.HomeCountryCode) .Set("subscriber_number", builder.HomeNumber); } // work phone if (!string.IsNullOrEmpty(builder.WorkNumber)) { payer.SubElement("work_phone") .Set("country_code", builder.WorkCountryCode) .Set("subscriber_number", builder.WorkNumber); } // payer login data if (builder.HasPayerLoginData) { request.SubElement("payer_login_data") .Set("authentication_data", builder.CustomerAuthenticationData) .Set("authentication_timestamp", builder.CustomerAuthenticationTimestamp?.ToString("yyyy-MM-dd'T'HH:mm:ss.fff'Z'")) .Set("authentication_type", builder.CustomerAuthenticationMethod?.ToString()); } // prior authentication data if (builder.HasPriorAuthenticationData) { request.SubElement("payer_prior_three_ds_authentication_data") .Set("authentication_method", builder.PriorAuthenticationMethod?.ToString()) .Set("acs_transaction_id", builder.PriorAuthenticationTransactionId) .Set("authentication_timestamp", builder.PriorAuthenticationTimestamp?.ToString("yyyy-MM-dd'T'HH:mm:ss.fff'Z'")) .Set("authentication_data", builder.PriorAuthenticationData); } // recurring authorization data if (builder.HasRecurringAuthData) { request.SubElement("recurring_authorization_data") .Set("max_number_of_instalments", builder.MaxNumberOfInstallments) .Set("frequency", builder.RecurringAuthorizationFrequency) .Set("expiry_date", builder.RecurringAuthorizationExpiryDate?.ToString("yyyy-MM-dd")); } // billing details Address billingAddress = builder.BillingAddress; if (billingAddress != null) { JsonDoc billingAddressElement = payer.SubElement("billing_address"); billingAddressElement.Set("line1", billingAddress.StreetAddress1); billingAddressElement.Set("line2", billingAddress.StreetAddress2); billingAddressElement.Set("line3", billingAddress.StreetAddress3); billingAddressElement.Set("city", billingAddress.City); billingAddressElement.Set("postal_code", billingAddress.PostalCode); billingAddressElement.Set("state", billingAddress.State); billingAddressElement.Set("country", billingAddress.CountryCode); } // mobile phone if (!string.IsNullOrEmpty(builder.MobileNumber)) { JsonDoc mobilePhone = payer.SubElement("mobile_phone"); mobilePhone.Set("country_code", builder.MobileCountryCode); mobilePhone.Set("subscriber_number", builder.MobileNumber); } // browser_data BrowserData broswerData = builder.BrowserData; if (broswerData != null) { JsonDoc browserDataElement = request.SubElement("browser_data"); browserDataElement.Set("accept_header", broswerData.AcceptHeader); browserDataElement.Set("color_depth", broswerData.ColorDepth.ToString()); browserDataElement.Set("ip", broswerData.IpAddress); browserDataElement.Set("java_enabled", broswerData.JavaEnabled); browserDataElement.Set("javascript_enabled", broswerData.JavaScriptEnabled); browserDataElement.Set("language", broswerData.Language); browserDataElement.Set("screen_height", broswerData.ScreenHeight); browserDataElement.Set("screen_width", broswerData.ScreenWidth); browserDataElement.Set("challenge_window_size", broswerData.ChallengeWindowSize.ToString()); browserDataElement.Set("timezone", broswerData.Timezone); browserDataElement.Set("user_agent", broswerData.UserAgent); } // mobile fields if (builder.HasMobileFields) { JsonDoc sdkInformationElement = request.SubElement("sdk_information") .Set("application_id", builder.ApplicationId) .Set("ephemeral_public_key", builder.EphemeralPublicKey) .Set("maximum_timeout", builder.MaximumTimeout) .Set("reference_number", builder.ReferenceNumber) .Set("sdk_trans_id", builder.SdkTransactionId) .Set("encoded_data", builder.EncodedData) ; // device render options if (builder.SdkInterface != null || builder.SdkUiTypes != null) { var dro = sdkInformationElement.SubElement("device_render_options"); dro.Set("sdk_interface", builder.SdkInterface?.ToString()); if (builder.SdkUiTypes != null) { var uiTypes = new List <string>(); foreach (var sdkuiType in builder.SdkUiTypes) { uiTypes.Add(sdkuiType.ToString()); } dro.Set("sdk_ui_type", uiTypes.ToArray()); } } } string hash = GenerationUtils.GenerateHash(SharedSecret, timestamp, MerchantId, hashValue, secureEcom.ServerTransactionId); SetAuthHeader(hash); string rawResponse = DoTransaction(HttpMethod.Post, "authentications", request.ToString()); return(MapResponse(rawResponse)); } throw new ApiException(string.Format("Unknown transaction type {0}.", transType)); }
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())); }
public T ProcessRecurring <T>(RecurringBuilder <T> builder) where T : class { var request = new JsonDoc(); if (builder.TransactionType == TransactionType.Create || builder.TransactionType == TransactionType.Edit) { if (builder.Entity is Customer) { BuildCustomer(request, builder.Entity as Customer); } else if (builder.Entity is RecurringPaymentMethod) { BuildPaymentMethod(request, builder.Entity as RecurringPaymentMethod, builder.TransactionType); } else if (builder.Entity is Schedule) { BuildSchedule(request, builder.Entity as Schedule, builder.TransactionType); } } else if (builder.TransactionType == TransactionType.Search) { foreach (var entry in builder.SearchCriteria) { request.Set(entry.Key, entry.Value); } } var response = DoTransaction(MapMethod(builder.TransactionType), MapUrl(builder), request.ToString()); return(MapResponse <T>(response)); }
public Transaction ProcessAuthorization(AuthorizationBuilder builder) { if (string.IsNullOrEmpty(SessionToken)) { SignIn(); } var paymentMethod = new JsonDoc() .Set("entry_mode", GetEntryMode(builder)); // [MOTO, ECOM, IN_APP, CHIP, SWIPE, MANUAL, CONTACTLESS_CHIP, CONTACTLESS_SWIPE] if (builder.PaymentMethod is ICardData) { var cardData = builder.PaymentMethod as ICardData; var card = new JsonDoc() .Set("number", cardData.Number) .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) //.Set("track", "") .Set("tag", builder.TagData) .Set("cvv", cardData.Cvn) .Set("avs_address", builder.BillingAddress?.StreetAddress1) .Set("avs_postal_code", builder.BillingAddress?.PostalCode) .Set("funding", builder.PaymentMethod?.PaymentMethodType == PaymentMethodType.Debit ? "DEBIT" : "CREDIT") // [DEBIT, CREDIT] .Set("authcode", builder.OfflineAuthCode); //.Set("brand_reference", "") if (builder.TransactionType == TransactionType.Verify) { if (builder.RequestMultiUseToken) { var tokenizationData = new JsonDoc() .Set("account_name", TokenizationAccountName) .Set("reference", builder.ClientTransactionId ?? Guid.NewGuid().ToString()) .Set("name", "") .Set("card", card); var tokenizationResponse = DoTransaction(HttpMethod.Post, "/ucp/payment-methods", tokenizationData.ToString()); return(MapResponse(tokenizationResponse)); } else { var tokenizationResponse = DoTransaction(HttpMethod.Get, $"/ucp/payment-methods/{(builder.PaymentMethod as ITokenizable).Token}"); return(MapResponse(tokenizationResponse)); } } if (builder.EmvLastChipRead != null) { card.Set("chip_condition", EnumConverter.GetMapping(Target.GP_API, builder.EmvLastChipRead)); // [PREV_SUCCESS, PREV_FAILED] } if (cardData.CvnPresenceIndicator == CvnPresenceIndicator.Present || cardData.CvnPresenceIndicator == CvnPresenceIndicator.Illegible || cardData.CvnPresenceIndicator == CvnPresenceIndicator.NotOnCard) { card.Set("cvv_indicator", EnumConverter.GetMapping(Target.GP_API, cardData.CvnPresenceIndicator)); // [ILLEGIBLE, NOT_PRESENT, PRESENT] } paymentMethod.Set("card", card); } else if (builder.PaymentMethod is ITrackData) { var track = builder.PaymentMethod as ITrackData; var card = new JsonDoc() .Set("track", track.Value) .Set("tag", builder.TagData) //.Set("cvv", cardData.Cvn) //.Set("cvv_indicator", "") // [ILLEGIBLE, NOT_PRESENT, PRESENT] .Set("avs_address", builder.BillingAddress?.StreetAddress1) .Set("avs_postal_code", builder.BillingAddress?.PostalCode) .Set("authcode", builder.OfflineAuthCode); //.Set("brand_reference", "") if (builder.TransactionType == TransactionType.Sale) { card.Set("number", track.Pan); card.Set("expiry_month", track.Expiry?.Substring(2, 2)); card.Set("expiry_year", track.Expiry?.Substring(0, 2)); card.Set("chip_condition", EnumConverter.GetMapping(Target.GP_API, builder.EmvLastChipRead)); // [PREV_SUCCESS, PREV_FAILED] card.Set("funding", builder.PaymentMethod?.PaymentMethodType == PaymentMethodType.Debit ? "DEBIT" : "CREDIT"); // [DEBIT, CREDIT] } paymentMethod.Set("card", card); } // pin block if (builder.PaymentMethod is IPinProtected) { paymentMethod.Get("card")?.Set("pin_block", ((IPinProtected)builder.PaymentMethod).PinBlock); } // authentication if (builder.PaymentMethod is CreditCardData) { paymentMethod.Set("name", (builder.PaymentMethod as CreditCardData).CardHolderName); var secureEcom = (builder.PaymentMethod as CreditCardData).ThreeDSecure; if (secureEcom != null) { var authentication = new JsonDoc() .Set("xid", secureEcom.Xid) .Set("cavv", secureEcom.Cavv) .Set("eci", secureEcom.Eci); //.Set("mac", ""); //A message authentication code submitted to confirm integrity of the request. paymentMethod.Set("authentication", authentication); } } // encryption if (builder.PaymentMethod is IEncryptable) { var encryptionData = ((IEncryptable)builder.PaymentMethod).EncryptionData; if (encryptionData != null) { var encryption = new JsonDoc() .Set("version", encryptionData.Version); if (!string.IsNullOrEmpty(encryptionData.KTB)) { encryption.Set("method", "KTB"); encryption.Set("info", encryptionData.KTB); } else if (!string.IsNullOrEmpty(encryptionData.KSN)) { encryption.Set("method", "KSN"); encryption.Set("info", encryptionData.KSN); } if (encryption.Has("info")) { paymentMethod.Set("encryption", encryption); } } } var data = new JsonDoc() .Set("account_name", TransactionProcessingAccountName) .Set("type", builder.TransactionType == TransactionType.Refund ? "REFUND" : "SALE") // [SALE, REFUND] .Set("channel", EnumConverter.GetMapping(Target.GP_API, Channel)) // [CP, CNP] .Set("capture_mode", GetCaptureMode(builder)) // [AUTO, LATER, MULTIPLE] //.Set("remaining_capture_count", "") //Pending Russell .Set("authorization_mode", builder.AllowPartialAuth ? "PARTIAL" : "WHOLE") // [PARTIAL, WHOLE] .Set("amount", builder.Amount.ToNumericCurrencyString()) .Set("currency", builder.Currency) .Set("reference", builder.ClientTransactionId ?? Guid.NewGuid().ToString()) .Set("description", builder.Description) .Set("order_reference", builder.OrderId) //.Set("initiator", "") // [PAYER, MERCHANT] //default to PAYER .Set("gratuity_amount", builder.Gratuity.ToNumericCurrencyString()) .Set("cashback_amount", builder.CashBackAmount.ToNumericCurrencyString()) .Set("surcharge_amount", builder.SurchargeAmount.ToNumericCurrencyString()) .Set("convenience_amount", builder.ConvenienceAmount.ToNumericCurrencyString()) .Set("country", builder.BillingAddress?.Country ?? "US") //.Set("language", EnumConverter.GetMapping(Target.GP_API, Language)) .Set("ip_address", builder.CustomerIpAddress) //.Set("site_reference", "") // .Set("payment_method", paymentMethod); var response = DoTransaction(HttpMethod.Post, "/ucp/transactions", data.ToString()); return(MapResponse(response)); }
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 <T>(ReportBuilder <T> builder, GpApiConnector gateway) where T : class { var merchantUrl = !string.IsNullOrEmpty(gateway.GpApiConfig.MerchantId) ? $"/merchants/{gateway.GpApiConfig.MerchantId}" : string.Empty; if (builder is TransactionReportBuilder <T> trb) { var request = new GpApiRequest(); switch (builder.ReportType) { case ReportType.TransactionDetail: return(new GpApiRequest { Verb = HttpMethod.Get, Endpoint = $"{merchantUrl}/transactions/{trb.TransactionId}", }); case ReportType.FindTransactionsPaged: request = new GpApiRequest { Verb = HttpMethod.Get, Endpoint = $"{merchantUrl}/transactions", }; request.AddQueryStringParam("page", trb.Page?.ToString()); request.AddQueryStringParam("page_size", trb.PageSize?.ToString()); request.AddQueryStringParam("order_by", EnumConverter.GetMapping(Target.GP_API, trb.TransactionOrderBy)); request.AddQueryStringParam("order", EnumConverter.GetMapping(Target.GP_API, trb.Order)); request.AddQueryStringParam("id", trb.TransactionId); request.AddQueryStringParam("type", EnumConverter.GetMapping(Target.GP_API, trb.SearchBuilder.PaymentType)); request.AddQueryStringParam("channel", EnumConverter.GetMapping(Target.GP_API, trb.SearchBuilder.Channel)); request.AddQueryStringParam("amount", trb.SearchBuilder.Amount.ToNumericCurrencyString()); request.AddQueryStringParam("currency", trb.SearchBuilder.Currency); request.AddQueryStringParam("number_first6", trb.SearchBuilder.CardNumberFirstSix); request.AddQueryStringParam("number_last4", trb.SearchBuilder.CardNumberLastFour); request.AddQueryStringParam("token_first6", trb.SearchBuilder.TokenFirstSix); request.AddQueryStringParam("token_last4", trb.SearchBuilder.TokenLastFour); request.AddQueryStringParam("account_name", trb.SearchBuilder.AccountName); request.AddQueryStringParam("brand", trb.SearchBuilder.CardBrand); request.AddQueryStringParam("brand_reference", trb.SearchBuilder.BrandReference); request.AddQueryStringParam("authcode", trb.SearchBuilder.AuthCode); request.AddQueryStringParam("reference", trb.SearchBuilder.ReferenceNumber); request.AddQueryStringParam("status", EnumConverter.GetMapping(Target.GP_API, trb.SearchBuilder.TransactionStatus)); request.AddQueryStringParam("from_time_created", trb.StartDate?.ToString("yyyy-MM-dd")); request.AddQueryStringParam("to_time_created", trb.EndDate?.ToString("yyyy-MM-dd")); request.AddQueryStringParam("country", trb.SearchBuilder.Country); request.AddQueryStringParam("batch_id", trb.SearchBuilder.BatchId); request.AddQueryStringParam("entry_mode", EnumConverter.GetMapping(Target.GP_API, trb.SearchBuilder.PaymentEntryMode)); request.AddQueryStringParam("name", trb.SearchBuilder.Name); request.AddQueryStringParam("payment_method", EnumConverter.GetMapping(Target.GP_API, trb.SearchBuilder.PaymentMethodName)); return(request); case ReportType.FindSettlementTransactionsPaged: request = new GpApiRequest { Verb = HttpMethod.Get, Endpoint = $"{merchantUrl}/settlement/transactions", }; request.AddQueryStringParam("page", trb.Page?.ToString()); request.AddQueryStringParam("page_size", trb.PageSize?.ToString()); request.AddQueryStringParam("order_by", EnumConverter.GetMapping(Target.GP_API, trb.TransactionOrderBy)); request.AddQueryStringParam("order", EnumConverter.GetMapping(Target.GP_API, trb.Order)); request.AddQueryStringParam("number_first6", trb.SearchBuilder.CardNumberFirstSix); request.AddQueryStringParam("number_last4", trb.SearchBuilder.CardNumberLastFour); request.AddQueryStringParam("deposit_status", EnumConverter.GetMapping(Target.GP_API, trb.SearchBuilder.DepositStatus)); request.AddQueryStringParam("account_name", gateway.GpApiConfig.AccessTokenInfo.DataAccountName); request.AddQueryStringParam("brand", trb.SearchBuilder.CardBrand); request.AddQueryStringParam("arn", trb.SearchBuilder.AquirerReferenceNumber); request.AddQueryStringParam("brand_reference", trb.SearchBuilder.BrandReference); request.AddQueryStringParam("authcode", trb.SearchBuilder.AuthCode); request.AddQueryStringParam("reference", trb.SearchBuilder.ReferenceNumber); request.AddQueryStringParam("status", EnumConverter.GetMapping(Target.GP_API, trb.SearchBuilder.TransactionStatus)); request.AddQueryStringParam("from_time_created", trb.StartDate?.ToString("yyyy-MM-dd")); request.AddQueryStringParam("to_time_created", trb.EndDate?.ToString("yyyy-MM-dd")); request.AddQueryStringParam("deposit_id", trb.SearchBuilder.DepositReference); request.AddQueryStringParam("from_deposit_time_created", trb.SearchBuilder.StartDepositDate?.ToString("yyyy-MM-dd")); request.AddQueryStringParam("to_deposit_time_created", trb.SearchBuilder.EndDepositDate?.ToString("yyyy-MM-dd")); request.AddQueryStringParam("from_batch_time_created", trb.SearchBuilder.StartBatchDate?.ToString("yyyy-MM-dd")); request.AddQueryStringParam("to_batch_time_created", trb.SearchBuilder.EndBatchDate?.ToString("yyyy-MM-dd")); request.AddQueryStringParam("system.mid", trb.SearchBuilder.MerchantId); request.AddQueryStringParam("system.hierarchy", trb.SearchBuilder.SystemHierarchy); return(request); case ReportType.DepositDetail: return(new GpApiRequest { Verb = HttpMethod.Get, Endpoint = $"{merchantUrl}/settlement/deposits/{trb.SearchBuilder.DepositReference}", }); case ReportType.FindDepositsPaged: request = new GpApiRequest { Verb = HttpMethod.Get, Endpoint = $"{merchantUrl}/settlement/deposits", }; request.AddQueryStringParam("page", trb.Page?.ToString()); request.AddQueryStringParam("page_size", trb.PageSize?.ToString()); request.AddQueryStringParam("order_by", EnumConverter.GetMapping(Target.GP_API, trb.DepositOrderBy)); request.AddQueryStringParam("order", EnumConverter.GetMapping(Target.GP_API, trb.Order)); request.AddQueryStringParam("account_name", gateway.GpApiConfig.AccessTokenInfo.DataAccountName); request.AddQueryStringParam("from_time_created", trb.StartDate?.ToString("yyyy-MM-dd")); request.AddQueryStringParam("to_time_created", trb.EndDate?.ToString("yyyy-MM-dd")); request.AddQueryStringParam("id", trb.SearchBuilder.DepositReference); request.AddQueryStringParam("status", EnumConverter.GetMapping(Target.GP_API, trb.SearchBuilder.DepositStatus)); request.AddQueryStringParam("amount", trb.SearchBuilder.Amount.ToNumericCurrencyString()); request.AddQueryStringParam("masked_account_number_last4", trb.SearchBuilder.AccountNumberLastFour); request.AddQueryStringParam("system.mid", trb.SearchBuilder.MerchantId); request.AddQueryStringParam("system.hierarchy", trb.SearchBuilder.SystemHierarchy); return(request); case ReportType.DisputeDetail: return(new GpApiRequest { Verb = HttpMethod.Get, Endpoint = $"{merchantUrl}/disputes/{trb.SearchBuilder.DisputeId}", }); case ReportType.DocumentDisputeDetail: var apiRequest = new GpApiRequest { Verb = HttpMethod.Get, Endpoint = $"{merchantUrl}/disputes/{trb.SearchBuilder.DisputeId}/documents/{trb.SearchBuilder.DisputeDocumentId}", }; return(apiRequest); case ReportType.FindDisputesPaged: request = new GpApiRequest { Verb = HttpMethod.Get, Endpoint = $"{merchantUrl}/disputes", }; request.AddQueryStringParam("page", trb.Page?.ToString()); request.AddQueryStringParam("page_size", trb.PageSize?.ToString()); request.AddQueryStringParam("order_by", EnumConverter.GetMapping(Target.GP_API, trb.DisputeOrderBy)); request.AddQueryStringParam("order", EnumConverter.GetMapping(Target.GP_API, trb.Order)); request.AddQueryStringParam("arn", trb.SearchBuilder.AquirerReferenceNumber); request.AddQueryStringParam("brand", trb.SearchBuilder.CardBrand); request.AddQueryStringParam("status", EnumConverter.GetMapping(Target.GP_API, trb.SearchBuilder.DisputeStatus)); request.AddQueryStringParam("stage", EnumConverter.GetMapping(Target.GP_API, trb.SearchBuilder.DisputeStage)); request.AddQueryStringParam("from_stage_time_created", trb.SearchBuilder.StartStageDate?.ToString("yyyy-MM-dd")); request.AddQueryStringParam("to_stage_time_created", trb.SearchBuilder.EndStageDate?.ToString("yyyy-MM-dd")); request.AddQueryStringParam("system.mid", trb.SearchBuilder.MerchantId); request.AddQueryStringParam("system.hierarchy", trb.SearchBuilder.SystemHierarchy); return(request); case ReportType.SettlementDisputeDetail: return(new GpApiRequest { Verb = HttpMethod.Get, Endpoint = $"{merchantUrl}/settlement/disputes/{trb.SearchBuilder.SettlementDisputeId}", }); case ReportType.FindSettlementDisputesPaged: request = new GpApiRequest { Verb = HttpMethod.Get, Endpoint = $"{merchantUrl}/settlement/disputes", }; request.AddQueryStringParam("account_name", gateway.GpApiConfig.AccessTokenInfo.DataAccountName); request.AddQueryStringParam("deposit_id", trb.SearchBuilder.DepositReference); request.AddQueryStringParam("page", trb.Page?.ToString()); request.AddQueryStringParam("page_size", trb.PageSize?.ToString()); request.AddQueryStringParam("order_by", EnumConverter.GetMapping(Target.GP_API, trb.DisputeOrderBy)); request.AddQueryStringParam("order", EnumConverter.GetMapping(Target.GP_API, trb.Order)); request.AddQueryStringParam("arn", trb.SearchBuilder.AquirerReferenceNumber); request.AddQueryStringParam("brand", trb.SearchBuilder.CardBrand); request.AddQueryStringParam("STATUS", EnumConverter.GetMapping(Target.GP_API, trb.SearchBuilder.DisputeStatus)); request.AddQueryStringParam("stage", EnumConverter.GetMapping(Target.GP_API, trb.SearchBuilder.DisputeStage)); request.AddQueryStringParam("from_stage_time_created", trb.SearchBuilder.StartStageDate?.ToString("yyyy-MM-dd")); request.AddQueryStringParam("to_stage_time_created", trb.SearchBuilder.EndStageDate?.ToString("yyyy-MM-dd")); request.AddQueryStringParam("from_deposit_time_created", trb.SearchBuilder.StartDepositDate?.ToString("yyyy-MM-dd")); request.AddQueryStringParam("to_deposit_time_created", trb.SearchBuilder.EndDepositDate?.ToString("yyyy-MM-dd")); request.AddQueryStringParam("system.mid", trb.SearchBuilder.MerchantId); request.AddQueryStringParam("system.hierarchy", trb.SearchBuilder.SystemHierarchy); return(request); case ReportType.StoredPaymentMethodDetail: return(new GpApiRequest { Verb = HttpMethod.Get, Endpoint = $"{merchantUrl}/payment-methods/{trb.SearchBuilder.StoredPaymentMethodId}", }); case ReportType.FindStoredPaymentMethodsPaged: if (trb.SearchBuilder.PaymentMethod is CreditCardData) { var creditCardData = trb.SearchBuilder.PaymentMethod as CreditCardData; var card = new JsonDoc() .Set("number", creditCardData.Number) .Set("expiry_month", creditCardData.ExpMonth.HasValue ? creditCardData.ExpMonth.ToString().PadLeft(2, '0') : null) .Set("expiry_year", creditCardData.ExpYear.HasValue ? creditCardData.ExpYear.ToString().PadLeft(4, '0').Substring(2, 2) : null); var payload = new JsonDoc() .Set("account_name", gateway.GpApiConfig.AccessTokenInfo.TokenizationAccountName) .Set("reference", trb.SearchBuilder.ReferenceNumber) .Set("card", card != null ? card : null); request = new GpApiRequest { Verb = HttpMethod.Post, Endpoint = $"{merchantUrl}/payment-methods/search", RequestBody = payload.ToString() }; return(request); } request = new GpApiRequest { Verb = HttpMethod.Get, Endpoint = $"{merchantUrl}/payment-methods", }; request.AddQueryStringParam("page", trb.Page?.ToString()); request.AddQueryStringParam("page_size", trb.PageSize?.ToString()); request.AddQueryStringParam("order_by", EnumConverter.GetMapping(Target.GP_API, trb.StoredPaymentMethodOrderBy)); request.AddQueryStringParam("order", EnumConverter.GetMapping(Target.GP_API, trb.Order)); request.AddQueryStringParam("id", trb.SearchBuilder.StoredPaymentMethodId); request.AddQueryStringParam("number_last4", trb.SearchBuilder.CardNumberLastFour); request.AddQueryStringParam("reference", trb.SearchBuilder.ReferenceNumber); request.AddQueryStringParam("status", EnumConverter.GetMapping(Target.GP_API, trb.SearchBuilder.StoredPaymentMethodStatus)); request.AddQueryStringParam("from_time_created", trb.SearchBuilder.StartDate?.ToString("yyyy-MM-dd")); request.AddQueryStringParam("to_time_created", trb.SearchBuilder.EndDate?.ToString("yyyy-MM-dd")); request.AddQueryStringParam("from_time_last_updated", trb.SearchBuilder.StartLastUpdatedDate?.ToString("yyyy-MM-dd")); request.AddQueryStringParam("to_time_last_updated", trb.SearchBuilder.EndLastUpdatedDate?.ToString("yyyy-MM-dd")); return(request); case ReportType.ActionDetail: return(new GpApiRequest { Verb = HttpMethod.Get, Endpoint = $"{merchantUrl}/actions/{trb.SearchBuilder.ActionId}", }); case ReportType.FindActionsPaged: request = new GpApiRequest { Verb = HttpMethod.Get, Endpoint = $"{merchantUrl}/actions", }; request.AddQueryStringParam("page", trb.Page?.ToString()); request.AddQueryStringParam("page_size", trb.PageSize?.ToString()); request.AddQueryStringParam("order_by", EnumConverter.GetMapping(Target.GP_API, trb.ActionOrderBy)); request.AddQueryStringParam("order", EnumConverter.GetMapping(Target.GP_API, trb.Order)); request.AddQueryStringParam("id", trb.SearchBuilder.ActionId); request.AddQueryStringParam("type", trb.SearchBuilder.ActionType); request.AddQueryStringParam("resource", trb.SearchBuilder.Resource); request.AddQueryStringParam("resource_status", trb.SearchBuilder.ResourceStatus); request.AddQueryStringParam("resource_id", trb.SearchBuilder.ResourceId); request.AddQueryStringParam("from_time_created", trb.SearchBuilder.StartDate?.ToString("yyyy-MM-dd")); request.AddQueryStringParam("to_time_created", trb.SearchBuilder.EndDate?.ToString("yyyy-MM-dd")); request.AddQueryStringParam("merchant_name", trb.SearchBuilder.MerchantName); request.AddQueryStringParam("account_name", trb.SearchBuilder.AccountName); request.AddQueryStringParam("app_name", trb.SearchBuilder.AppName); request.AddQueryStringParam("version", trb.SearchBuilder.Version); request.AddQueryStringParam("response_code", trb.SearchBuilder.ResponseCode); request.AddQueryStringParam("http_response_code", trb.SearchBuilder.HttpResponseCode); return(request); case ReportType.PayLinkDetail: return(new GpApiRequest { Verb = HttpMethod.Get, Endpoint = $"{merchantUrl}/links/{trb.SearchBuilder.PayLinkId}", }); case ReportType.FindPayLinkPaged: request = new GpApiRequest { Verb = HttpMethod.Get, Endpoint = $"{merchantUrl}/links", }; request.AddQueryStringParam("from_time_created", trb.SearchBuilder.StartDate?.ToString("yyyy-MM-dd")); request.AddQueryStringParam("to_time_created", trb.SearchBuilder.EndDate?.ToString("yyyy-MM-dd")); request.AddQueryStringParam("order", EnumConverter.GetMapping(Target.GP_API, trb.Order)); request.AddQueryStringParam("order_by", EnumConverter.GetMapping(Target.GP_API, trb.ActionOrderBy)); return(request); } } return(null); }