Cannot Convert From ElasticCoreWebApi.Controllers.AcquirerController.AcquirerReportParameters to ElasticCoreWebApi.BLL.ElasticSettledTranaction.AcquirerReportParameter
ElasticCoreWebApi has Reference of ElasticCoreWebApi.BLL operation
ElasticCoreWebApi.AcquirerController has the class
public class AcquiringReportParameters
{
public string reportname { get; set; }
public int merchantId { get; set; }
public string branchCodes { get; set; }
public string fromDate { get; set; }
public string toDate { get; set; }
public string merchantName { get; set; }
public string batchNo { get; set; }
public string terminalId { get; set; }
public string merchantNumber { get; set; }
public string merchantBranchName { get; set; }
public string dRCR { get; set; }
public string mID { get; set; }
public int pageSize { get; set; }
public int pageIndex { get; set; }
}
In Acquirer controller i am calling the second method and passing the parameters like this i have data mapped in the class
AcquiringReportParameters parameters = new AcquiringReportParameters();
ElasticSettlementTransactionBLL ElasticBLL = new ElasticSettlementTransactionBLL();
*var test = await ElasticBLL.GetSettledParameterTransaction(parameters);*
*I am getting error here in the parameter*
ElasticCoreWebApi.BLL.ElasticSettledTransaction.cs has the class
public class AcquiringReportParameters
{
public string reportname { get; set; }
public int merchantId { get; set; }
public string branchCodes { get; set; }
public string fromDate { get; set; }
public string toDate { get; set; }
public string merchantName { get; set; }
public string batchNo { get; set; }
public string terminalId { get; set; }
public string merchantNumber { get; set; }
public string merchantBranchName { get; set; }
public string dRCR { get; set; }
public string mID { get; set; }
public int pageSize { get; set; }
public int pageIndex { get; set; }
}
Here is the method which i was calling
public async Task<string> GetSettledParameterTransaction(AcquiringReportParameters parameters)
I am using this code to attempt to parse my response back from the payment gateway:
var responseMessage = client.PostAsJsonAsync("transaction", transData).Result;
var response = responseMessage.Content.ReadAsStringAsync().Result;
MessageBox.Show(response);
JavaScriptSerializer jsonSerializer = new JavaScriptSerializer();
var objCustomer = jsonSerializer.Deserialize<ReturnValues.RootObject>(response);
This is the class I am trying to create:
public class ReturnValues
{
public class Card
{
public string id { get; set; }
public string card_type { get; set; }
public string first_six { get; set; }
public string last_four { get; set; }
public string masked_card { get; set; }
public string expiration_date { get; set; }
public string status { get; set; }
public string auth_code { get; set; }
public string processor_response_code { get; set; }
public string processor_response_text { get; set; }
public string processor_type { get; set; }
public string processor_id { get; set; }
public string avs_response_code { get; set; }
public string cvv_response_code { get; set; }
public DateTime created_at { get; set; }
public DateTime updated_at { get; set; }
}
public class Response
{
public Card card { get; set; }
}
public class BillingAddress
{
public string first_name { get; set; }
public string last_name { get; set; }
public string company { get; set; }
public string address_line_1 { get; set; }
public string address_line_2 { get; set; }
public string city { get; set; }
public string state { get; set; }
public string postal_code { get; set; }
public string country { get; set; }
public string phone { get; set; }
public string fax { get; set; }
public string email { get; set; }
}
public class ShippingAddress
{
public string first_name { get; set; }
public string last_name { get; set; }
public string company { get; set; }
public string address_line_1 { get; set; }
public string address_line_2 { get; set; }
public string city { get; set; }
public string state { get; set; }
public string postal_code { get; set; }
public string country { get; set; }
public string phone { get; set; }
public string fax { get; set; }
public string email { get; set; }
}
public class Data
{
public string id { get; set; }
public string type { get; set; }
public int amount { get; set; }
public int tax_amount { get; set; }
public bool tax_exempt { get; set; }
public int shipping_amount { get; set; }
public int discount_amount { get; set; }
public string payment_adjustment_type { get; set; }
public int payment_adjustment_value { get; set; }
public string currency { get; set; }
public string description { get; set; }
public string order_id { get; set; }
public string po_number { get; set; }
public string ip_address { get; set; }
public bool email_receipt { get; set; }
public string email_address { get; set; }
public string payment_method { get; set; }
public Response response { get; set; }
public string status { get; set; }
public int response_code { get; set; }
public string customer_id { get; set; }
public BillingAddress billing_address { get; set; }
public ShippingAddress shipping_address { get; set; }
public DateTime created_at { get; set; }
public DateTime updated_at { get; set; }
}
public class RootObject
{
public string status { get; set; }
public string msg { get; set; }
public Data data { get; set; }
}
}
This is the response I am given:
"{\"status\":\"success\",\"msg\":\"success\",\"data\":{\"id\":\"bp2pa41erttupu3q1eng\",\"user_id\":\"bmibms9erttqdc2kigl0\",\"user_name\":\"dev\",\"merchant_id\":\"asdfasdf\",\"idempotency_key\":\"\",\"idempotency_time\":0,\"type\":\"sale\",\"amount\":1000,\"base_amount\":1000,\"amount_authorized\":1000,\"amount_captured\":1000,\"amount_settled\":0,\"amount_refunded\":0,\"payment_adjustment\":0,\"tip_amount\":0,\"settlement_batch_id\":\"\",\"processor_id\":\"bmibnfperttqdc2kigmg\",\"processor_type\":\"tsys_sierra\",\"processor_name\":\"Keyed
Credit
Cards\",\"payment_method\":\"card\",\"payment_type\":\"card\",\"features\":[\"avs\",\"card_verification\",\"levelii\",\"fake_response\"],\"national_tax_amount\":0,\"duty_amount\":0,\"ship_from_postal_code\":\"\",\"summary_commodity_code\":\"\",\"merchant_vat_registration_number\":\"\",\"customer_vat_registration_number\":\"\",\"tax_amount\":0,\"tax_exempt\":false,\"shipping_amount\":0,\"surcharge\":0,\"discount_amount\":0,\"currency\":\"usd\",\"description\":\"This
is a
test\",\"order_id\":\"555555\",\"po_number\":\"666666\",\"ip_address\":\"1.1.1.1\",\"transaction_source\":\"api\",\"email_receipt\":false,\"email_address\":\"\",\"customer_id\":\"\",\"customer_payment_type\":\"\",\"customer_payment_ID\":\"\",\"subscription_id\":\"\",\"referenced_transaction_id\":\"\",\"response_body\":{\"card\":{\"id\":\"bp2pa41erttupu3q1eo0\",\"card_type\":\"visa\",\"first_six\":\"401288\",\"last_four\":\"1881\",\"masked_card\":\"401288******1881\",\"expiration_date\":\"12/21\",\"response\":\"approved\",\"response_code\":100,\"auth_code\":\"TAS000\",\"processor_response_code\":\"00\",\"processor_response_text\":\"APPROVAL
TAS000
\",\"processor_transaction_id\":\"000000000000000\",\"processor_type\":\"tsys_sierra\",\"processor_id\":\"bmgwgtgtherhemg\",\"avs_response_code\":\"M\",\"cvv_response_code\":\"M\",\"processor_specific\":null,\"created_at\":\"2020-02-13T18:27:28.149933095Z\",\"updated_at\":\"2020-02-13T18:27:28.196367669Z\"}},\"custom_fields\":{},\"line_items\":null,\"status\":\"pending_settlement\",\"response\":\"approved\",\"response_code\":100,\"billing_address\":{\"first_name\":\"John\",\"last_name\":\"Doe\",\"company\":\"\",\"address_line_1\":\"123
Some
Street\",\"address_line_2\":\"\",\"city\":\"Bessemer\",\"state\":\"AL\",\"postal_code\":\"35020\",\"country\":\"US\",\"phone\":\"5555555555\",\"fax\":\"\",\"email\":\"test#gmail.com\"},\"shipping_address\":{\"first_name\":\"\",\"last_name\":\"\",\"company\":\"\",\"address_line_1\":\"\",\"address_line_2\":\"\",\"city\":\"\",\"state\":\"\",\"postal_code\":\"\",\"country\":\"\",\"phone\":\"\",\"fax\":\"\",\"email\":\"\"},\"created_at\":\"2020-02-13T18:27:28.104845544Z\",\"updated_at\":\"2020-02-13T18:27:28.200963331Z\",\"captured_at\":\"2020-02-13T18:27:28.200962679Z\",\"settled_at\":null}}\n"
I am getting this message:
System.InvalidOperationException: 'Cannot convert object of type
'System.String' to type 'Test.ReturnValues+Response''
I am not sure what I am doing wrong. I used an online json converter to get my class. It appears to be correct.
Any suggestions?
I used json2csharp.com to generate C# classes and it came up with something different.
public class ReturnValues
{
public class Card
{
public string id { get; set; }
public string card_type { get; set; }
public string first_six { get; set; }
public string last_four { get; set; }
public string masked_card { get; set; }
public string expiration_date { get; set; }
public string response { get; set; }
public int response_code { get; set; }
public string auth_code { get; set; }
public string processor_response_code { get; set; }
public string processor_response_text { get; set; }
public string processor_transaction_id { get; set; }
public string processor_type { get; set; }
public string processor_id { get; set; }
public string avs_response_code { get; set; }
public string cvv_response_code { get; set; }
public object processor_specific { get; set; }
public string created_at { get; set; }
public string updated_at { get; set; }
}
public class ResponseBody
{
public Card card { get; set; }
}
public class CustomFields
{
}
public class BillingAddress
{
public string first_name { get; set; }
public string last_name { get; set; }
public string company { get; set; }
public string address_line_1 { get; set; }
public string address_line_2 { get; set; }
public string city { get; set; }
public string state { get; set; }
public string postal_code { get; set; }
public string country { get; set; }
public string phone { get; set; }
public string fax { get; set; }
public string email { get; set; }
}
public class ShippingAddress
{
public string first_name { get; set; }
public string last_name { get; set; }
public string company { get; set; }
public string address_line_1 { get; set; }
public string address_line_2 { get; set; }
public string city { get; set; }
public string state { get; set; }
public string postal_code { get; set; }
public string country { get; set; }
public string phone { get; set; }
public string fax { get; set; }
public string email { get; set; }
}
public class Data
{
public string id { get; set; }
public string user_id { get; set; }
public string user_name { get; set; }
public string merchant_id { get; set; }
public string idempotency_key { get; set; }
public int idempotency_time { get; set; }
public string type { get; set; }
public int amount { get; set; }
public int base_amount { get; set; }
public int amount_authorized { get; set; }
public int amount_captured { get; set; }
public int amount_settled { get; set; }
public int amount_refunded { get; set; }
public int payment_adjustment { get; set; }
public int tip_amount { get; set; }
public string settlement_batch_id { get; set; }
public string processor_id { get; set; }
public string processor_type { get; set; }
public string processor_name { get; set; }
public string payment_method { get; set; }
public string payment_type { get; set; }
public List<string> features { get; set; }
public int national_tax_amount { get; set; }
public int duty_amount { get; set; }
public string ship_from_postal_code { get; set; }
public string summary_commodity_code { get; set; }
public string merchant_vat_registration_number { get; set; }
public string customer_vat_registration_number { get; set; }
public int tax_amount { get; set; }
public bool tax_exempt { get; set; }
public int shipping_amount { get; set; }
public int surcharge { get; set; }
public int discount_amount { get; set; }
public string currency { get; set; }
public string description { get; set; }
public string order_id { get; set; }
public string po_number { get; set; }
public string ip_address { get; set; }
public string transaction_source { get; set; }
public bool email_receipt { get; set; }
public string email_address { get; set; }
public string customer_id { get; set; }
public string customer_payment_type { get; set; }
public string customer_payment_ID { get; set; }
public string subscription_id { get; set; }
public string referenced_transaction_id { get; set; }
public ResponseBody response_body { get; set; }
public CustomFields custom_fields { get; set; }
public object line_items { get; set; }
public string status { get; set; }
public string response { get; set; }
public int response_code { get; set; }
public BillingAddress billing_address { get; set; }
public ShippingAddress shipping_address { get; set; }
public string created_at { get; set; }
public string updated_at { get; set; }
public string captured_at { get; set; }
public object settled_at { get; set; }
}
public class RootObject
{
public string status { get; set; }
public string msg { get; set; }
public Data data { get; set; }
}
}
It seems to work though. I did a quick compare and there are quite a few differences. Might be worth checking out.
use jsoup it is a free framework it parse the document into json format easily
`list<Element> news;
Document doc = Jsoup.connect("https://en.wikipedia.org/").get();
log(doc.title());
Elements newsHeadlines = doc.select("#mp-itn b a");
for (Element headline : news) {
log("%s\n\t%s",
headline.attr("title"), headline.absUrl("href"));
}`
I am trying to map multiple Userprofile models into a single viewModel. At a time only one user data will be mapped.
In the below code snippet I mentioned the use case that I already tried.
Also, I try to AutoMapper.Map<source,target> but didn't work for me.
//This is one FarmerUser Model
public partial class FarmerProfileModel
{
public long FarmerId { get; set; }
public string FarmerName { get; set; }
public string FatherHusbandName { get; set; }
public string Cnic { get; set; }
public string Gender { get; set; }
public string CellPhone { get; set; }
public string PresentAddress { get; set; }
public string PermanentAddress { get; set; }
public int? EducationCode { get; set; }
public int? MaleDependant { get; set; }
public int? FemaleDependant { get; set; }
public string AlternateName { get; set; }
public string AlternateCellPhoneNo { get; set; }
public string AlternateRelationshipwithFarmer { get; set; }
public int? ReferalCode { get; set; }
public string FarmerImage { get; set; }
public string UnionCouncil { get; set; }
public string MozaName { get; set; }
public int? SmallAnimals { get; set; }
public int? BigAnimals { get; set; }
public int? Tractor { get; set; }
public Guid? UserGuid { get; set; }
public DistrictCodeModel DistrictCodeNavigation { get; set; }
public TehsilCodeModel TehsilCodeNavigation { get; set; }
}
Another Model of the Tso User
public class TsoProfileModel
{
public long Tsoid { get; set; }
public string Tsoname { get; set; }
public string Cnic { get; set; }
public string Email { get; set; }
public string CellPhone { get; set; }
public string AlternateCellPhone { get; set; }
public string Landline { get; set; }
public string Gender { get; set; }
public string Tsoimage { get; set; }
public int? ModifiedBy { get; set; }
public DateTime? ModifiedDateTime { get; set; }
public DateTime? InsertionDate { get; set; }
public string ActiveStatus { get; set; }
public Guid? UserGuid { get; set; }
public TbDistrictCode DistrictCodeNavigation { get; set; }
public TbTehsilCode TehsilCodeNavigation { get; set; }
}
This is my ViewModel in which i am trying to incorporrate my data of Farmer/Tso
public class UserProfileInfo
{
public long? UserId { get; set; }
public string UserName { get; set; }
public string Cnic { get; set; }
public string Email { get; set; }
public string AlternateCellPhone { get; set; }
public string Landline { get; set; }
public string Gender { get; set; }
public string PresentAddress { get; set; }
public string PermanentAddress { get; set; }
public int? EducationCode { get; set; }
public string image { get; set; }
public int? ModifiedBy { get; set; }
public DateTime? ModifiedDateTime { get; set; }
public DateTime? InsertionDate { get; set; }
public string ActiveStatus { get; set; }
public Guid? UserGuid { get; set; }
public string FatherHusbandName { get; set; }
public string CellPhone { get; set; }
public int? MaleDependant { get; set; }
public int? FemaleDependant { get; set; }
public string AlternateName { get; set; }
public string AlternateRelationshipwithFarmer { get; set; }
public int? ReferalCode { get; set; }
public string UnionCouncil { get; set; }
public string MozaName { get; set; }
public int? SmallAnimals { get; set; }
public int? BigAnimals { get; set; }
public int? Tractor { get; set; }
public string Role { get; set; }
public DistrictCodeModel DistrictCodeNavigation { get; set; }
public TehsilCodeModel TehsilCodeNavigation { get; set; }
}
Below is the code I am trying to use.
if (User=="farmer")
{
var tbFarmerInfo = await
_farmerService.GetFarmerByCellPhone(cellno);
var result = _Mapper.Map<UserProfileInfo>(tbFarmerInfo);
result.UserId = tbFarmerInfo.FarmerId;
result.UserName = tbFarmerInfo.FarmerName;
result.image = tbFarmerInfo.FarmerImage;
result.Role = "Farmer";
response.Data = result;
return response;
}
else if (User == "TSO")
{
string cellno = User.Claims.FirstOrDefault(c => c.Type ==
ClaimTypes.Name).Value.TrimStart('0');
var tbTsoInfo = await _tsoService.GetTSOByCellPhone(cellno);
var result = _Mapper.Map<UserProfileInfo>(tbTsoInfo);
result.UserId = tbTsoInfo.Tsoid;
result.UserName = tbTsoInfo.Tsoname;
result.image = tbTsoInfo.Tsoimage;
result.Role = "TSO";
response.Data = result;
return response;
}
The expected result should be that both models can be mapped in the viewModel.
Like, if I map the FarmerProfile it should be mapped and if I want to map TsoProfile it should be mapped too.
I am writing an app for UWP.
I tried to use data binding according to this answer link.
Here are my classes:
public class Billing
{
public string first_name { get; set; }
public string last_name { get; set; }
public string company { get; set; }
public string address_1 { get; set; }
public string address_2 { get; set; }
public string city { get; set; }
public string state { get; set; }
public string postcode { get; set; }
public string country { get; set; }
public string email { get; set; }
public string phone { get; set; }
}
public class Shipping
{
public string first_name { get; set; }
public string last_name { get; set; }
public string company { get; set; }
public string address_1 { get; set; }
public string address_2 { get; set; }
public string city { get; set; }
public string state { get; set; }
public string postcode { get; set; }
public string country { get; set; }
}
public class RootObject
{
public int id { get; set; }
public int parent_id { get; set; }
public string status { get; set; }
public string order_key { get; set; }
public string currency { get; set; }
public string version { get; set; }
public bool prices_include_tax { get; set; }
public string date_created { get; set; }
public string date_modified { get; set; }
public int customer_id { get; set; }
public double discount_total { get; set; }
public double discount_tax { get; set; }
public double shipping_total { get; set; }
public double shipping_tax { get; set; }
public double cart_tax { get; set; }
public double total { get; set; }
public double total_tax { get; set; }
public Billing billing { get; set; }
public Shipping shipping { get; set; }
public string payment_method { get; set; }
public string payment_method_title { get; set; }
public string transaction_id { get; set; }
public string customer_ip_address { get; set; }
public string customer_user_agent { get; set; }
public string created_via { get; set; }
public string customer_note { get; set; }
public string date_completed { get; set; }
public string date_paid { get; set; }
public string cart_hash { get; set; }
public List<object> line_items { get; set; }
public List<object> tax_lines { get; set; }
public List<object> shipping_lines { get; set; }
public List<object> fee_lines { get; set; }
public List<object> coupon_lines { get; set; }
}
public ObservableCollection<RootObject> Orders { get; set; }
Here is the code:
List<RootObject> rootObjectData = JsonConvert.DeserializeObject<List<RootObject>>(products);
foreach (RootObject root in rootObjectData)
{
string date = root.date_created;
string name = root.billing.first_name + root.billing.last_name ;
Orders = new ObservableCollection<RootObject> { new RootObject { date_created = date,billing = name } };
}
With billing = name I have this error: Cannot implicitly convert type 'string' to 'Milano.InWork.Billing'
How can I fix this error?
Maybe this is simple, but I don't find a solution.
Thanks for the help!!
With billing = name I have this error: Cannot implicitly convert type 'string' to 'Milano.InWork.Billing'
Of course this error will occur, your billing in the class RootObject has the data type Billing, which is another class you defined.
Just from your code I think you only want to show the first_name and last_name as string in your root.billing, then you can change the code public Billing billing { get; set; } in your RootObject class to public string billing { get; set; }.
An exception of type
'Newtonsoft.Json.JsonSerializationException' occurred in
Newtonsoft.Json.DLL but was not handled in user code
Additional information: Error converting value {null} to type
'System.Boolean'. Path 'collection[8].downloadable', line 1, position
22866.
or
converter value {null} from path 'track[40].like_count
?
I use Json. How to fix it?
public class User
{
public string full_name { get; set; }
public string country { get; set; }
public string city { get; set; }
public int tracks_count { get; set; }
public int followers_count { get; set; }
public int followings_count { get; set; }
public int public_favorites_count { get; set; }
public int groups_count { get; set; }
public string description { get; set; }
public string plan { get; set; }
public int id { get; set; }
public string uri { get; set; }
public string username { get; set; }
public string kind { get; set; }
public string permalink { get; set; }
public string permalink_url { get; set; }
public string first_name { get; set; }
public string avatar_url { get; set; }
public string last_modified { get; set; }
}
public class __invalid_type__0
{
public string urn { get; set; }
public int entry_time { get; set; }
public string visual_url { get; set; }
public object link { get; set; }
}
public class Visuals2
{
public __invalid_type__0 __invalid_name__0 { get; set; }
}
public class Visuals
{
public string urn { get; set; }
public bool enabled { get; set; }
public Visuals2 visuals { get; set; }
public object tracking { get; set; }
}
public class Collection
{
public User user { get; set; }
public int user_id { get; set; }
public string genre { get; set; }
public string tag_list { get; set; }
public int duration { get; set; }
public bool downloadable { get; set; }
public bool streamable { get; set; }
public int original_content_size { get; set; }
public bool commentable { get; set; }
public string sharing { get; set; }
public bool #public { get; set; }
public string created_at { get; set; }
public string updated_at { get; set; }
public string isrc { get; set; }
public string state { get; set; }
public bool embeddable { get; set; }
public string embeddable_by { get; set; }
public string license { get; set; }
public string waveform_url { get; set; }
public bool feedable { get; set; }
public string label_name { get; set; }
public string release_date { get; set; }
public bool has_downloads_left { get; set; }
public string purchase_title { get; set; }
public string purchase_url { get; set; }
public string policy { get; set; }
public string monetization_model { get; set; }
public Visuals visuals { get; set; }
public string permalink { get; set; }
public string title { get; set; }
public string description { get; set; }
public string track_type { get; set; }
public string last_modified { get; set; }
public string artwork_url { get; set; }
public int id { get; set; }
public string kind { get; set; }
public int comment_count { get; set; }
public int download_count { get; set; }
public string uri { get; set; }
public string stream_url { get; set; }
public int playback_count { get; set; }
public string download_url { get; set; }
public object secret_token { get; set; }
public int reposts_count { get; set; }
public string permalink_url { get; set; }
public int likes_count { get; set; }
}
public class Facet2
{
public string filter { get; set; }
public int count { get; set; }
public string value { get; set; }
}
public class Facet
{
public string name { get; set; }
public List<Facet2> facets { get; set; }
}
public class RootObject
{
public List<Collection> collection { get; set; }
public List<Facet> facets { get; set; }
public int total_results { get; set; }
public string qid { get; set; }
public string query_urn { get; set; }
public string next_href { get; set; }
}