public static PayLinkSummary MapPayLinkSummary(JsonDoc doc) { var summary = new PayLinkSummary(); summary.Id = doc.GetValue <string>("id"); summary.MerchantId = doc.GetValue <string>("merchant_id"); summary.MerchantName = doc.GetValue <string>("merchant_name"); summary.AccountId = doc.GetValue <string>("account_id"); summary.AccountName = doc.GetValue <string>("account_name"); summary.Url = doc.GetValue <string>("url"); summary.Status = GetPayLinkStatus(doc); summary.Type = GetPayLinkType(doc); summary.AllowedPaymentMethods = GetAllowedPaymentMethods(doc); summary.UsageMode = GetPaymentMethodUsageMode(doc); summary.UsageCount = doc.GetValue <string>("usage_count"); summary.Reference = doc.GetValue <string>("reference"); summary.Name = doc.GetValue <string>("name"); summary.Description = doc.GetValue <string>("description"); summary.Shippable = doc.GetValue <string>("shippable"); summary.ViewedCount = doc.GetValue <string>("viewed_count"); summary.ExpirationDate = doc.GetValue <DateTime?>("expiration_date", DateConverter); summary.Images = doc.GetArray <string>("images").ToArray();//GetImages(doc); //ToDo if (doc.Has("transactions")) { summary.Transactions = new List <TransactionSummary>(); foreach (var transaction in doc.GetArray <JsonDoc>("transactions") ?? Enumerable.Empty <JsonDoc>()) { summary.Transactions.Add(CreateTransactionSummary(transaction)); } } return(summary); }
internal virtual void MapResponseValues(JsonDoc doc) { Token = doc.GetValue <string>("token"); Type = doc.GetValue <string>("type"); AppId = doc.GetValue <string>("app_id"); AppName = doc.GetValue <string>("app_name"); TimeCreated = doc.GetValue <DateTime>("time_created"); SecondsToExpire = doc.GetValue <int>("seconds_to_expire"); Email = doc.GetValue <string>("email"); if (doc.Has("scope")) { JsonDoc scope = doc.Get("scope"); MerchantId = scope.GetValue <string>("merchant_id"); MerchantName = scope.GetValue <string>("merchant_name"); if (scope.Has("accounts")) { var accounts = new List <GpApiAccount>(); foreach (JsonDoc account in scope.GetArray <JsonDoc>("accounts")) { accounts.Add(new GpApiAccount { Id = account.GetValue <string>("id"), Name = account.GetValue <string>("name"), }); } Accounts = accounts.ToArray(); } } }
public virtual void ProcessValidation(JsonDoc doc, List <string> validationErrors) { foreach (var propInfo in GetType().GetRuntimeProperties()) { var fieldName = string.Format("{0}{1}", Prefix, propInfo.Name); var validations = doc.GetArray <string>(fieldName) as List <string>; if (validations != null) { if (validations.Contains(string.Format("Application configuration field {0} within the application configuration is not set to be editable (shown).", fieldName))) { continue; } if (validations.Contains("This field is required.")) { validationErrors.Add(string.Format("{0} is required.", fieldName)); } else { var propValue = propInfo.GetValue(this)?.ToString(); if (!string.IsNullOrWhiteSpace(propValue)) { continue; // handle validations on a per field basis? } continue; } } } }
private static List <PaymentMethodName> GetAllowedPaymentMethods(JsonDoc doc) { List <PaymentMethodName> List = null; if (doc.Has("allowed_payment_methods")) { List = new List <PaymentMethodName>(); foreach (var item in doc.GetArray <string>("allowed_payment_methods")) { PaymentMethodName methodName = EnumConverter.FromMapping <PaymentMethodName>(Target.GP_API, item); List.Add(methodName); } } return(List); }
public static DisputeSummary MapDisputeSummary(JsonDoc doc) { var summary = new DisputeSummary { CaseId = doc.GetValue <string>("id"), CaseIdTime = doc.GetValue <DateTime?>("time_created", DateConverter), CaseStatus = doc.GetValue <string>("status"), CaseStage = doc.GetValue <string>("stage"), CaseAmount = doc.GetValue <string>("amount").ToAmount(), CaseCurrency = doc.GetValue <string>("currency"), ReasonCode = doc.GetValue <string>("reason_code"), Reason = doc.GetValue <string>("reason_description"), Result = doc.GetValue <string>("result"), CaseMerchantId = doc.Get("system")?.GetValue <string>("mid"), CaseTerminalId = doc.Get("system")?.GetValue <string>("tid"), MerchantHierarchy = doc.Get("system")?.GetValue <string>("hierarchy"), MerchantName = doc.Get("system")?.GetValue <string>("name"), MerchantDbaName = doc.Get("system")?.GetValue <string>("dba"), LastAdjustmentAmount = doc.GetValue <string>("last_adjustment_amount").ToAmount(), LastAdjustmentCurrency = doc.GetValue <string>("last_adjustment_currency"), LastAdjustmentFunding = doc.GetValue <string>("last_adjustment_funding"), TransactionMaskedCardNumber = doc.Get("payment_method")?.Get("card")?.GetValue <string>("number"), TransactionARN = doc.Get("payment_method")?.Get("card")?.GetValue <string>("arn"), TransactionCardType = doc.Get("payment_method")?.Get("card")?.GetValue <string>("brand"), }; if (!string.IsNullOrEmpty(doc.GetValue <string>("time_to_respond_by"))) { summary.RespondByDate = doc.GetValue <DateTime?>("time_to_respond_by", DateConverter); } var counter = 0; foreach (var item in doc.GetArray <JsonDoc>("documents") ?? Enumerable.Empty <JsonDoc>()) { if (string.IsNullOrEmpty(item.GetValue <string>("id"))) { var document = new DisputeDocument { Id = doc.GetValue <string>("id"), Type = !string.IsNullOrEmpty(doc.GetValue <string>("type")) ? doc.GetValue <string>("type") : null, }; summary.Documents[counter] = document; counter++; } } return(summary); }
public static T MapReportResponse <T>(string rawResponse, ReportType reportType) where T : class { T result = Activator.CreateInstance <T>(); JsonDoc json = JsonDoc.Parse(rawResponse); switch (reportType) { case ReportType.FindBankPayment: SetPagingInfo(result as PagedResult <TransactionSummary>, json); foreach (var doc in json.GetArray <JsonDoc>("payments") ?? Enumerable.Empty <JsonDoc>()) { (result as PagedResult <TransactionSummary>).Add(MapTransactionSummary(doc)); } break; default: break; } return(result); }
private Transaction MapResponse(string rawResponse) { JsonDoc doc = JsonDoc.Parse(rawResponse); ThreeDSecure secureEcom = new ThreeDSecure(); // check enrolled secureEcom.ServerTransactionId = doc.GetValue <string>("server_trans_id"); if (doc.Has("enrolled")) { secureEcom.Enrolled = doc.GetValue <string>("enrolled"); } secureEcom.IssuerAcsUrl = doc.GetValue <string>("method_url", "challenge_request_url"); // get authentication data secureEcom.AcsTransactionId = doc.GetValue <string>("acs_trans_id"); secureEcom.DirectoryServerTransactionId = doc.GetValue <string>("ds_trans_id"); secureEcom.AuthenticationType = doc.GetValue <string>("authentication_type"); secureEcom.AuthenticationValue = doc.GetValue <string>("authentication_value"); secureEcom.Eci = doc.GetValue <int>("eci"); secureEcom.Status = doc.GetValue <string>("status"); secureEcom.StatusReason = doc.GetValue <string>("status_reason"); secureEcom.AuthenticationSource = doc.GetValue <string>("authentication_source"); secureEcom.MessageCategory = doc.GetValue <string>("message_category"); secureEcom.MessageVersion = doc.GetValue <string>("message_version"); secureEcom.AcsInfoIndicator = doc.GetArray <string>("acs_info_indicator"); secureEcom.DecoupledResponseIndicator = doc.GetValue <string>("decoupled_response_indicator"); secureEcom.WhitelistStatus = doc.GetValue <string>("whitelist_status"); secureEcom.ExemptReason = doc.GetValue <string>("eos_reason"); if (secureEcom.ExemptReason == ExemptReason.APPLY_EXEMPTION.ToString()) { secureEcom.ExemptStatus = ExemptStatus.TRANSACTION_RISK_ANALYSIS; } // challenge mandated if (doc.Has("challenge_mandated")) { secureEcom.ChallengeMandated = doc.GetValue <bool>("challenge_mandated"); } // initiate authentication secureEcom.CardHolderResponseInfo = doc.GetValue <string>("cardholder_response_info"); // device_render_options if (doc.Has("device_render_options")) { JsonDoc renderOptions = doc.Get("device_render_options"); secureEcom.SdkInterface = renderOptions.GetValue <string>("sdk_interface"); secureEcom.SdkUiType = renderOptions.GetArray <string>("sdk_ui_type"); } // message_extension if (doc.Has("message_extension")) { secureEcom.MessageExtensions = new List <MessageExtension>(); foreach (JsonDoc messageExtension in doc.GetEnumerator("message_extension")) { MessageExtension msgExtension = new MessageExtension { CriticalityIndicator = messageExtension.GetValue <string>("criticality_indicator"), MessageExtensionData = messageExtension.GetValue <JsonDoc>("data")?.ToString(), MessageExtensionId = messageExtension.GetValue <string>("id"), MessageExtensionName = messageExtension.GetValue <string>("name") }; secureEcom.MessageExtensions.Add(msgExtension); } } // versions secureEcom.DirectoryServerEndVersion = doc.GetValue <string>("ds_protocol_version_end"); secureEcom.DirectoryServerStartVersion = doc.GetValue <string>("ds_protocol_version_start"); secureEcom.AcsEndVersion = doc.GetValue <string>("acs_protocol_version_end"); secureEcom.AcsStartVersion = doc.GetValue <string>("acs_protocol_version_start"); // payer authentication request if (doc.Has("method_data")) { JsonDoc methodData = doc.Get("method_data"); secureEcom.PayerAuthenticationRequest = methodData.GetValue <string>("encoded_method_data"); } else if (doc.Has("encoded_creq")) { secureEcom.PayerAuthenticationRequest = doc.GetValue <string>("encoded_creq"); } Transaction response = new Transaction { ThreeDSecure = secureEcom }; return(response); }
public static T MapReportResponse <T>(string rawResponse, ReportType reportType) where T : class { T result = Activator.CreateInstance <T>(); JsonDoc json = JsonDoc.Parse(rawResponse); if (reportType == ReportType.TransactionDetail && result is TransactionSummary) { result = MapTransactionSummary(json) as T; } else if ((reportType == ReportType.FindTransactionsPaged || reportType == ReportType.FindSettlementTransactionsPaged) && result is PagedResult <TransactionSummary> ) { SetPagingInfo(result as PagedResult <TransactionSummary>, json); foreach (var doc in json.GetArray <JsonDoc>("transactions") ?? Enumerable.Empty <JsonDoc>()) { (result as PagedResult <TransactionSummary>).Add(MapTransactionSummary(doc)); } } else if (reportType == ReportType.DepositDetail && result is DepositSummary) { result = MapDepositSummary(json) as T; } else if (reportType == ReportType.FindDepositsPaged && result is PagedResult <DepositSummary> ) { SetPagingInfo(result as PagedResult <DepositSummary>, json); foreach (var doc in json.GetArray <JsonDoc>("deposits") ?? Enumerable.Empty <JsonDoc>()) { (result as PagedResult <DepositSummary>).Add(MapDepositSummary(doc)); } } else if (reportType == ReportType.DisputeDetail && result is DisputeSummary) { result = MapDisputeSummary(json) as T; } else if (reportType == ReportType.DocumentDisputeDetail && result is DisputeDocument) { result = MapDisputeDocument(json) as T; } else if (reportType == ReportType.FindDisputesPaged && result is PagedResult <DisputeSummary> ) { SetPagingInfo(result as PagedResult <DisputeSummary>, json); foreach (var doc in json.GetArray <JsonDoc>("disputes") ?? Enumerable.Empty <JsonDoc>()) { (result as PagedResult <DisputeSummary>).Add(MapDisputeSummary(doc)); } } else if (reportType == ReportType.SettlementDisputeDetail && result is DisputeSummary) { result = MapSettlementDisputeSummary(json) as T; } else if (reportType == ReportType.FindSettlementDisputesPaged && result is PagedResult <DisputeSummary> ) { SetPagingInfo(result as PagedResult <DisputeSummary>, json); foreach (var doc in json.GetArray <JsonDoc>("disputes") ?? Enumerable.Empty <JsonDoc>()) { (result as PagedResult <DisputeSummary>).Add(MapSettlementDisputeSummary(doc)); } } else if (reportType == ReportType.StoredPaymentMethodDetail && result is StoredPaymentMethodSummary) { result = MapStoredPaymentMethodSummary(json) as T; } else if (reportType == ReportType.FindStoredPaymentMethodsPaged && result is PagedResult <StoredPaymentMethodSummary> ) { SetPagingInfo(result as PagedResult <StoredPaymentMethodSummary>, json); foreach (var doc in json.GetArray <JsonDoc>("payment_methods") ?? Enumerable.Empty <JsonDoc>()) { (result as PagedResult <StoredPaymentMethodSummary>).Add(MapStoredPaymentMethodSummary(doc)); } } else if (reportType == ReportType.ActionDetail && result is ActionSummary) { result = MapActionSummary(json) as T; } else if (reportType == ReportType.FindActionsPaged && result is PagedResult <ActionSummary> ) { SetPagingInfo(result as PagedResult <ActionSummary>, json); foreach (var doc in json.GetArray <JsonDoc>("actions") ?? Enumerable.Empty <JsonDoc>()) { (result as PagedResult <ActionSummary>).Add(MapActionSummary(doc)); } } else if (reportType == ReportType.FindPayLinkPaged && result is PagedResult <PayLinkSummary> ) { SetPagingInfo(result as PagedResult <PayLinkSummary>, json); foreach (var doc in json.GetArray <JsonDoc>("links") ?? Enumerable.Empty <JsonDoc>()) { (result as PagedResult <PayLinkSummary>).Add(MapPayLinkSummary(doc)); } } else if (reportType == ReportType.PayLinkDetail && result is PayLinkSummary) { result = MapPayLinkSummary(json) as T; } return(result); }