Paypal API - GetVerifiedStatus C# - c#

I tried both 'Sandbox' and 'Live' and that didn't change anything.
ACK code is giving "Failure" & as for the "accountStatus" It's giving me (same goes with CountryCode & UserInfo fields) :
Object reference not set to an instance of an object.
Here is the code and I'm using PayPal Adaptive Accounts SDK btw :
Dictionary<string, string> config = new Dictionary<string, string>();
config.Add("mode", "live");
config.Add("account1.apiUsername", "xxxxxx_api1.outlook.com");
config.Add("account1.apiPassword", "BDxxxxxxVMH8CC422");
config.Add("account1.apiSignature", "AnUrp2fCnv5wuh1OOXxxxxxxtsA4ek2pihCAfCZodv21T9TY6Yidln");
AdaptiveAccountsService service = null;
GetVerifiedStatusResponse resp = null;
GetVerifiedStatusRequest getVerifiedStatusRequest = new GetVerifiedStatusRequest
{
emailAddress = "xxxxxx#outlook.com",
firstName = "MyName",
lastName = "MyLastName",
matchCriteria = "NAME"
};
service = new AdaptiveAccountsService(config);
resp = service.GetVerifiedStatus(getVerifiedStatusRequest);
TextBox1.Text = resp.responseEnvelope.ack.ToString() + resp.accountStatus.ToString();

Related

Sentry - adding arbitrary key/value pairs to the user context

In the following documentation, it states that you can
...provide arbitrary key/value pairs beyond the reserved names and those will be stored with the user
In C# code, I have the following:
var _user = new {
Login = "fred",
EmailAddress = "fred#here.com",
Name = "Fred Flintstone"
}
SentrySdk.ConfigureScope( scope => {
scope.User = new Sentry.Protocol.User()
{
Id = _user.Login,
Email = _user.EmailAddress,
Username = _user.Login
};
});
Is there a way to add Name (or any other field)? Or is the documentation just referring to tags?
You can add your custom user data via the Other property.
The latest version of the Sentry.Protocol has Other as a IReadOnlyDictionary which means you need to assign a new instance like:
var sut = new User
{
Id = "user-id",
Email = "test#sentry.io",
IpAddress = "::1",
Username = "user-name",
Other = new Dictionary<string, string>
{
{"Name", "your name"},
{"anything else", "whatever"},
}
};
This PR is making Other mutable so you can add data like:
var user = new User();
user.Other.Add("key", "value");

How to check if a customer exists before adding them through the QuickBooks Online API?

I have successfully connected my ASP.NET MVC5 C# project to QuickBooks Online through Oauth, and the "IPP .NET SDK for QuickBooks V3" NuGet Package.
I can add new customers, and everything works fine. However, if I try to add a customer that already exists, it throws the following error: "ValidationException was thrown".
My question is, what is the best way to check if the customer already exists in QuickBooks before trying to add them, so as to avoid the exception?
This is the code I have that adds the new customer to QuickBooks:
OAuthRequestValidator oauthValidator = new OAuthRequestValidator(accessToken, accessTokenSecret, consumerKey, consumerSecret);
ServiceContext context = new ServiceContext(realmId, intuitServicesType, oauthValidator);
DataService dataService = new DataService(context);
var customer = new Customer();
customer.GivenName = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(submission.FirstName.ToLower());
customer.FamilyName = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(submission.LastName.ToLower());
customer.BillAddr = new PhysicalAddress()
{
Line1 = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(submission.Address.ToLower()),
City = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(submission.City.ToLower()),
CountrySubDivisionCode = submission.State,
PostalCode = submission.ZipCode
};
customer.PrimaryEmailAddr = new EmailAddress() { Address = submission.EmailAddress.ToLower(), Default = true };
customer.PrimaryPhone = new TelephoneNumber() { FreeFormNumber = submission.Phone };
dataService.Add(customer);
Editted to add my solution with the answer from #Keith Palmer
OAuthRequestValidator oauthValidator = new OAuthRequestValidator(accessToken, accessTokenSecret, consumerKey, consumerSecret);
ServiceContext context = new ServiceContext(realmId, intuitServicesType, oauthValidator);
// Check if the customer already exists in QuickBooks
QueryService<Customer> customerQueryService = new QueryService<Customer>(context);
int customerCount = customerQueryService.Where(c => c.GivenName == submission.FirstName && c.FamilyName == submission.LastName).Count();
if (customerCount == 0)
{
// If not, then add the new customer.
DataService dataService = new DataService(context);
var customer = new Customer();
customer.GivenName = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(submission.FirstName.ToLower());
customer.FamilyName = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(submission.LastName.ToLower());
customer.BillAddr = new PhysicalAddress()
{
Line1 = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(submission.Address.ToLower()),
City = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(submission.City.ToLower()),
CountrySubDivisionCode = submission.State,
PostalCode = submission.ZipCode
};
customer.PrimaryEmailAddr = new EmailAddress() { Address = submission.EmailAddress.ToLower(), Default = true };
customer.PrimaryPhone = new TelephoneNumber() { FreeFormNumber = submission.Phone };
dataService.Add(customer);
}
else
{
TempData["Warning"] = "The customer already exists in QuickBooks.";
return RedirectToAction("Estimates", "Admin");
}
Query for the customer to see if they exist before adding them.
What you query for (Name, Email, etc.) is dependent on how you want to implement your application/what your customer wants.
Per the docs:
https://developer.intuit.com/docs/0100_quickbooks_online/0400_tools/0005_sdks/0010.net_tools/0030_query_filters
Your code should look something like this:
IEnumerable customers = invoiceQueryService.Where(c => c.Balance > 1000);
You can refer to the object reference to see which fields you can filter by:
https://developer.intuit.com/docs/api/accounting/customer

Get Posts (Wall Facebook) of me and my friends

I use
https://developers.facebook.com/tools/access_token/
I create an App. I want get Posts of the wall of me and my friends.
I try me/feed and me/posts but I get nothing.
I have this unit test.
Any suggestions?
[TestMethod]
public void Basic_using_SDK()
{
// http://blog.prabir.me/posts/facebook-csharp-sdk-making-requests
var fb = new Facebook.FacebookClient();
var result = (IDictionary<string, object>)fb.Get("4");
var id = (string)result["id"];
var name = (string)result["name"];
var firstName = (string)result["first_name"];
var lastName = (string)result["last_name"];
var link = (string)result["link"];
var username = (string)result["username"];
var gender = (string)result["gender"];
var male = (string)result["locale"];
var parameters = new Dictionary<string, object>();
parameters["fields"] = "id,name";
result = (IDictionary<string, object>)fb.Get("4", parameters);
id = (string)result["id"];
name = (string)result["name"];
dynamic result2 = fb.Get("4");
id = result2.id;
name = result2.name;
firstName = result2.first_name;
lastName = result2.last_name;
link = result2.link;
username = result2.username;
gender = result2.gender;
male = result2.locale;
dynamic parameters2 = new ExpandoObject();
parameters2.fields = "id,name";
dynamic result3 = fb.Get("4", parameters);
id = result3.id;
name = result3.name;
dynamic me = fb.Get("zuck");
firstName = me.first_name;
lastName = me.last_name;
var client = new FacebookClient(AccessToken);
dynamic me2 = client.Get("me");
string aboutMe = me2.about;
dynamic result4 = client.Get("/me/feed");
foreach (dynamic post in result4.data)
{
var fromName = post.from.name;
Console.WriteLine(fromName);
}
dynamic result5 = client.Get("/me/posts");
for (int i = 0; i < result5.Count; i++)
{
}
// https://www.facebook.com/profile.php?id=xxxxxxx
// https://graph.facebook.com/xxxxxxx
var uidKiquenet = "xxxxx";
var query = string.Format(#"SELECT status_id,message,time,source,uid,place_id
FROM status WHERE uid IN (SELECT uid FROM status WHERE uid = '" + uidKiquenet + "') ORDER BY time DESC");
dynamic parameters6 = new ExpandoObject();
parameters6.q = query;
dynamic results6 = fb.Get("/xxxxx?fields=id,name,age_range,about,email,first_name,gender");
string myMessage = "Hello from Test";
fb.PostTaskAsync("me/feed", new { message = myMessage }).ContinueWith(t =>
{
if (!t.IsFaulted)
{
string message = "Great, your message has been posted to you wall!";
Console.WriteLine(message);
}
});
fb.GetTaskAsync("me").ContinueWith(t =>
{
if (!t.IsFaulted)
{
var result11 = (IDictionary<string, object>)t.Result;
string myDetails = string.Format("Your name is: {0} {1} and your Facebook profile Url is: {3}",
(string)result11["first_name"], (string)result11["last_name"],
(string)result11["link"]);
Console.WriteLine(myDetails);
}
});
// This uses Facebook Query Language
// See https://developers.facebook.com/docs/technical-guides/fql/ for more information.
query = string.Format("SELECT uid,name,pic_square FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1={0}) ORDER BY name ASC", "me()");
fb.GetTaskAsync("fql", new { q = query }).ContinueWith(t =>
{
if (!t.IsFaulted)
{
var result1 = (IDictionary<string, object>)t.Result;
var data = (IList<object>)result1["data"];
var count = data.Count;
var message = string.Format("You have {0} friends", count);
Console.WriteLine(message);
foreach (IDictionary<string, object> friend in data)
Console.WriteLine((string)friend["name"]);
}
});
}
You must authorize with the correct permission in order to get access to feed posts. Try authorizing with user_posts, as it is explained in the docs: https://developers.facebook.com/docs/graph-api/reference/v2.3/user/feed#read
Be aware that this does not get you access to posts of friends, unless they posted on the wall of the authorized user.
About review, you may want to read this: https://developers.facebook.com/docs/facebook-login/review/faqs#what_is_review
Btw, FQL is deprecated and will only work in v2.0 Apps - not in newer ones.
Same thing happened to me . Here is my Solution
I made my project registered on Facebook developer console. Then I did my code same as you but could not get posts / information . After some time i submitted my application for app review to facebook team (it was still in early development phase) and after their feedback I got my code working . So pending Application review can be your issue also . This option is available in application setting . Give it a shot
Update
Another code sample is here
if (Request["code"] == null)
{
Response.Redirect(string.Format("https://graph.facebook.com/oauth/authorize?client_id={0}&redirect_uri={1}&scope={2}",
FB_app_id, Request.Url.AbsoluteUri, FB_scope));
return false;
}
else
{
Dictionary<string, string> tokens = new Dictionary<string, string>();
string url = string.Format("https://graph.facebook.com/oauth/access_token?client_id={0}&redirect_uri={1}&scope={2}&code={3}&client_secret={4}&perms=status_update"
, FB_app_id, Request.Url.AbsoluteUri, FB_scope, Request["code"].ToString(), FB_secret_id);
HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;
using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
{
StreamReader rd = new StreamReader(response.GetResponseStream());
string vals = rd.ReadToEnd();
foreach (string token in vals.Split('&'))
{
tokens.Add(token.Substring(0, token.IndexOf('=')), token.Substring(token.IndexOf("=") + 1, token.Length - token.IndexOf('=') - 1));
}
string access_token = tokens["access_token"];
Session["fb_access_token"] = access_token;
return true;
}
}

error while trying to create a new customer using .net DevKit 2.0

I am getting an error when I try to create a new customer in Quickbooks Desktop.
The error:
Object reference not set to an instance of an object.
The error occurs when I try to create the address for the customer.
Customer qbdCustomer = new Customer();
qbdCustomer.Name = txtCompany.Text;
qbdCustomer.GivenName = txtFName.Text;
qbdCustomer.FamilyName = txtLName.Text;
qbdCustomer.Address[0].Line1 = txtAddress.Text;
qbdCustomer.Address[0].Line2 = txtAddress2.Text;
qbdCustomer.Address[0].City = txtCity.Text;
qbdCustomer.Address[0].CountrySubDivisionCode = drpState.SelectedItem.Value;
qbdCustomer.Address[0].PostalCode = txtZip.Text;
qbdCustomer.Phone[0].FreeFormNumber = txtPhone.Text;
qbdCustomer.Email[0].Address = txtEmail.Text;
Customer customerAdded = (new DataServices(context)).Add(qbdCustomer);
Like I said the error occurs when it gets to the first address line. The Name, GivenName, and FamilyName fields work so it has to be something to do with the array for the address.
I have been stuck on this for a couple days, any help would be greatly appreciated.
Create a PhysicalAddress object and assign it back to the Customer Address property:
Intuit.Ipp.Data.Qbd.PhysicalAddress customerAddress = new Intuit.Ipp.Data.Qbd.PhysicalAddress();
customerAddress.Line1 = txtAddress.Text;
customerAddress.Line2 = txtAddress2.Text;
customerAddress.City = txtCity.Text;
customerAddress.CountrySubDivisionCode = drpState.SelectedItem.Value;
customerAddress.PostalCode = txtZip.Text;
qbdCustomer.Address = new Intuit.Ipp.Data.Qbd.PhysicalAddress[]{ customerAddress };
The same applies to the Phone and Email properties.

How to Create a campaign in MailChimp using ASP.Net

I need to create and send immediately campaigns in MailChimp.com. I used C# wrapper Percepective MCAPI.dll for this purpose.
from the MailChimp API, Its clear that we cannot lists but can create campaigns. I tried code but the campaignID is retured null; no exception thrown atleast. I did set the campaigntype to Auto.
here is my code snippet:
try
{
string apiKey = "api-us2"; // API KEY is valid
string emailAddress = "ravinderpal.singh#abc.net";
listsForEmailInput lstForEmailInput = new listsForEmailInput(apiKey, emailAddress);
listsForEmail cmd = new listsForEmail(lstForEmailInput);
listsForEmailOutput lstEmailOutPut = cmd.Execute();
List lstResults = lstEmailOutPut.result;
string listID = lstResults[0]; // Got Precraeted List ID( Valid Confirmed )
Console.WriteLine("\n" + listID);
// compaign Create
campaignCreateOptions campaignCreateOpt = new campaignCreateOptions();
campaignCreateOpt.list_id = listID;
campaignCreateOpt.subject = " New Campaign from dev_Anil";
campaignCreateOpt.from_email = "anil.k#abc.net";
campaignCreateOpt.from_name = "anil";
Dictionary content = new Dictionary();
content.Add("html", "Helloaasdsa");
content.Add("text", "Hi all !! this is dev_anil");
content.Add("url", "");
content.Add("archive", "");
campaignSegmentOptions csOptions = new campaignSegmentOptions();
csOptions.match = "any"; // Could not set Condition -- need help for this
// Need to set a Dictionary typeOptions because null is not supported
Dictionary typeOptions = new Dictionary();
campaignCreateParms campaignCreateParms = new campaignCreateParms(apiKey, EnumValues.campaign_type.auto, campaignCreateOpt, content, csOptions, typeOptions);
campaignCreateInput campaignCreateInput = new campaignCreateInput(campaignCreateParms);
campaignCreate campaignCreate = new campaignCreate(campaignCreateInput);
campaignCreateOutput ccOutput = campaignCreate.Execute(campaignCreateInput);
string abc = ccOutput.result; // This comes out to null
}
catch(Exception ee)
{
Console.WriteLine("\n\n Exception :" + ee.Message); // no exception
}
can anybody show me the right direction and what is wrong with the code.
any help would be much appreciated.
thanks.
I solved this problem and here is code as solution. here listID is precreated List ID in your account in Mailchimp.
private void CreateCampaignAndSend(string apiKey, string listID)
{
Int32 TemplateID = 100;
string campaignID =string.Empty;
// compaign Create Options
campaignCreateOptions campaignCreateOpt = new campaignCreateOptions();
campaignCreateOpt.list_id = listID;
campaignCreateOpt.subject = "subject";
campaignCreateOpt.from_email = "abc#xyz.com";
campaignCreateOpt.from_name = "abc";
campaignCreateOpt.template_id = TemplateID;
// Content
Dictionary<string, string> content = new Dictionary<string, string>();
content.Add("html_ArticleTitle1", "ArticleTitle1");
content.Add("html_ArticleTitle2","ArticleTitle2");
content.Add("html_ArticleTitle3", "ArticleTitle3");
content.Add("html_Article1", "Article1");
content.Add("html_Article2", "Article2");
// Conditions
List<campaignSegmentCondition> csCondition = new List<campaignSegmentCondition>();
campaignSegmentCondition csC = new campaignSegmentCondition();
csC.field = "interests-" + 123; // where 123 is the Grouping Id from listInterestGroupings()
csC.op = "all";
csC.value = "";
csCondition.Add(csC);
// Options
campaignSegmentOptions csOptions = new campaignSegmentOptions();
csOptions.match = "all";
// Type Options
Dictionary<string, string> typeOptions = new Dictionary<string, string>();
typeOptions.Add("offset-units", "days");
typeOptions.Add("offset-time", "0");
typeOptions.Add("offset-dir", "after");
// Create Campaigns
campaignCreate campaignCreate = new campaignCreate(new campaignCreateInput(apiKey, EnumValues.campaign_type.plaintext, campaignCreateOpt, content, csOptions, typeOptions));
campaignCreateOutput ccOutput = campaignCreate.Execute();
List<Api_Error> error = ccOutput.api_ErrorMessages; // Catching API Errors
if (error.Count <= 0)
{
campaignID = ccOutput.result;
}
else
{
foreach (Api_Error ae in error)
{
Console.WriteLine("\n ERROR Creating Campaign : ERRORCODE\t:" + ae.code + "\t ERROR\t:" + ae.error);
}
}
}
I removed the url and archive from the content. Then the campaign was created just fine:
// campaign Create
campaignCreateOptions campaignCreateOpt = new campaignCreateOptions();
campaignCreateOpt.list_id = listId;
campaignCreateOpt.subject = " New Campaign from Someemone";
campaignCreateOpt.from_email = "someone#home.com";
campaignCreateOpt.from_name = "someone";
Dictionary<string, string> content = new Dictionary<string, string>();
content.Add("html", "Lots of cool stuff here.");
campaignSegmentOptions csOptions = new campaignSegmentOptions();
csOptions.match = "any"; // Could not set Condition -- need help for this
// Need to set a Dictionary typeOptions because null is not supported
Dictionary<string,string> typeOptions = new Dictionary<string, string>();
campaignCreateParms campaignCreateParms = new campaignCreateParms(apiKey, EnumValues.campaign_type.trans, campaignCreateOpt, content, csOptions, typeOptions);
campaignCreateInput campaignCreateInput = new campaignCreateInput(campaignCreateParms);
campaignCreate campaignCreate = new campaignCreate(campaignCreateInput);
campaignCreateOutput ccOutput = campaignCreate.Execute(campaignCreateInput);
string newCampaignId = ccOutput.result; // Not null anymore

Categories

Resources