Paypal Rest API not triggering webhooks - c#

I've seen a lot of people with this same question and none of the answers solve my issue. I'm making a sale using the Paypal .Net SDK. In my sale I use this code and it works and the process is successfully completed. Then I my success page I execute the payment like this:
public ActionResult Success(string paymentId, string token, string PayerID)
{
var config = ConfigManager.Instance.GetProperties();
var accessToken = new OAuthTokenCredential(config).GetAccessToken();
var apiContext = new APIContext(accessToken);
apiContext.Config = config;
var paymentExecution = new PaymentExecution() { payer_id = PayerID };
var payment = new Payment() { id = paymentId };
// Execute the payment.
var executedPayment = payment.Execute(apiContext, paymentExecution);
return View();
}
This code is executed without any problem.
My only problem is that my webhook is never triggered. I created the webhook, in the paypal developer dashboard, with all events. When I test with the webhook simulator it gets triggered but when I do the normal process it never does.
What am I doing wrong?
Thanks for any help.

I'm facing the same issue, however I haven't gone live.
By this answer, it is an issue on Paypal's sandbox side: https://stackoverflow.com/a/44984794/1393652
Hope it will be solved soon.

Related

Post message with Facebook SDK .NET

I have created a facebook page and a facebook application for my website and now I need to post messages onto the facebook page with help of facebook SDK .NET.
This is what I got so far :
public static bool UploadPost(string message)
{
dynamic result;
//https://developers.facebook.com/tools/explorer/
//https://developers.facebook.com/tools/access_token/
FacebookClient client = new FacebookClient("secret access token");
result = client.Get("oauth/access_token", new
{
client_id = "[Client ID number]",
client_secret = "[Client sercret",
grant_type = "client_credentials",
});
result = client.Post("[facebook app Id]/feed", new { message = "Test Message from app" });
//result.id;
result = client.Get("[facebook app Id]");
return false;
}
When running this I get : Additional information: (OAuthException - #200) (#200) The user hasn't authorized the application to perform this action on client.Post. If I remove the client.Post row every thing works good, the correct data is fetched.
I have tried follow some helps on facebook SDK .NET website but it is still not working.
The main problem now is that I get permission exception. I was hoping that my facebook app hade enouth permissions to publish post from my website to the facebook page.
Here is a step wise tutorial to register your application with facebook and get an app Id for your application.
Then for permissions ::
private const string ExtendedPermissions = "user_about_me,read_stream,publish_stream";
This is a string of permissions. Pass it on further for getting correct permissions to post messages on page. Post using your standard code for posting no FB pages.
Cheers. Hope it helps.
Are you trying to post to [facebook app id]?
I would recomend to post to "me/feed" and test if that works.
Also, to post to Facebook you have to have the publish_stream permission
private async Task Authenticate()
{
string message = String.Empty;
try
{
session = await App.FacebookSessionClient.LoginAsync("user_about_me,read_stream,publish_actions");
App.AccessToken = session.AccessToken;
App.FacebookId = session.FacebookId;
Dispatcher.BeginInvoke(() => NavigationService.Navigate(new Uri("/Pages/LandingPage.xaml", UriKind.Relative)));
}
catch (InvalidOperationException e)
{
message = "Login failed! Exception details: " + e.Message;
MessageBox.Show(message);
}
}
Should work :)
The following should work.
var fb = new FacebookClient("access_token");
fb.PostCompleted += (o, e) => {
if(e.Error == null) {
var result = (IDictionary<string, object>)e.GetResultData();
var newPostId = (string)result.id;
}
};
var parameters = new Dictionary<string, object>();
parameters["message"] = "My first wall post using Facebook SDK for .NET";
fb.PostAsync("me/feed", parameters);
This was taken directly from the documentation.
By creating a extended page token and use it to make the post everything works just fine. See this : How to get Page Access Token by code?
Im surprised that this simple task was so hard to get running and that there was vary little help to get.

PayPal Express Checkout SOAP API: Refunds

I use the PayPal Express Checkout SOAP service. For example here's a trimmed down version of the code to redirect the user to PayPal Sandbox when checking out:
var client = new PayPalAPIAAInterfaceClient();
var credentials = new CustomSecurityHeaderType() {
Credentials = new UserIdPasswordType() { ... }
};
var paymentDetails = new PaymentDetailsType() {
OrderTotal = new BasicAmountType() {
Value = string.Format("{0:0.00}", 100m)
}
};
var request = new SetExpressCheckoutReq() {
SetExpressCheckoutRequest = new SetExpressCheckoutRequestType() {
SetExpressCheckoutRequestDetails = new SetExpressCheckoutRequestDetailsType() {
PaymentDetails = new PaymentDetailsType[] { paymentDetails },
CancelURL = "http://www.mysite.com" + Url.Action("Cancelled", "PayPalCheckout"),
ReturnURL = "http://www.mysite.com" + Url.Action("Index", "PayPalCheckout")
},
Version = "60.0"
}
};
var response = client.SetExpressCheckout(ref credentials, request);
return Redirect(string.Format("{0}?cmd=_express-checkout&token={1}", "https://www.sandbox.paypal.com/cgi-bin/webscr", response.Token));
I then handle the data when the user is returned to the ReturnUrl. This was taken from some code I found on another website.
I now need to add a refund facility to my site. I was wondering if anyone else has done this? I've tried searching online but can't seem to find anything that helps. I also tried doing it myself but the API isn't very intuitive.
I'd appreciate the help. Thanks
It would just need to be a RefundTransaction API call that you would need to execute. Are you trying to have your return page issue a refund based on a condition, or are you trying to create a GUI type of interface to allow someone to issue a refund for a transaction? Have you looked at the code samples for this within the SDK's that PayPal offers? You should be able to use this code.

How to use local server for tweetsharp application

I have made a demo which is about authenticate the user through tWitter.
I want to callback to this url http://localhost:56501/home/authorize.
When I tried to set this url in my application settings it's not work. I got the error that url is not valid.
Do someone help me on get it worked on my side.
I have run some code from here https://github.com/danielcrenna/tweetsharp
At first you need to set callback link in the your twitter application (http://dev.twitter.com/apps/). Replase "localhost" with "127.0.0.1". For example, mine looks like - http ://127.0. 0.1:31820 /Home/AuthorizeCallback
Create TwitterService instanse using you ConsumerKey and ConsumerSecret.
var service = new TwitterService(_consumerKey, _consumerSecret);
Following method gets request token:
public ActionResult Login()
{
var requestToken = service.GetRequestToken(CallBackURL);
var url = service.GetAuthenticationUrl(requestToken);
return Redirect(url.ToString());
}
It redirects user to twitter login form. When user enters his credentials and submits form, it redirects to your callback link.
public ActionResult AuthorizeCallback(string oauth_token, string oauth_verifier)
{
var requestToken = new OAuthRequestToken() {Token = oauth_token};
var accessToken = service.GetAccessToken(requestToken, oauth_verifier);
service.AuthenticateWith(accessToken.Token, accessToken.TokenSecret);
var twitteruser = service.VerifyCredentials();
return RedirectToAction("Index");
}
Good luck!

Using RetrieveFeedAsync to get Twitter Search Results in a Metro App

Getting familiar with Metro apps so I thought I would try my hand at some twitter stuff. The following code doesn't work.
public static async Task<IEnumerable<TwitterItem>> Search(string term)
{
var search = new SyndicationClient();
var searchUri = new Uri("http://search.twitter.com/search.atom?q=" + term);
//var searchUri = new Uri("http://windowsteamblog.com/windows/b/developers/atom.aspx");
var results = await search.RetrieveFeedAsync(searchUri);
return from item in results.Items
select new TwitterItem
{
Text = item.Title.Text,
CreatedAt = item.PublishedDate.DateTime,
FromUser = item.Authors[0].Name
};
}
It works if I use the windows team blog url but not the twitter url. No exceptions, it just never comes back. Tried to use fiddler but it does not intercept Metro traffic for some reason. Any thoughts?
I agree with #Jon.
Please debug this code with Fiddler to ensure that you're not producing a malformed url.
Please see this answer for more information about using Fiddler with a Metro app.

IE looping infinitely when using Authorize

I'm developing a Facebook app, and i only want to allow access to certain views if the visitor is authorized through Facebook. This should be a pretty simple task, and i thought is was, until i tried it out in IE. The following code works fine in Chrome and Safari. I want to use Forms authentication, and therefore i have set
<forms loginUrl="~/Account/Login" timeout="2880" />
in web.config. This will direct the visitor to the following ActionResult when entering my app:
public ActionResult Login(string returnUrl)
{
ManagerGame2.Utilities.StaticDataContent.InitStaticData();
var oAuthClient = new FacebookOAuthClient();
oAuthClient.AppId = FacebookApplication.Current.AppId;
oAuthClient.RedirectUri = new Uri(redirectUrl);
var loginUri = oAuthClient.GetLoginUrl(new Dictionary<string, object> { { "state", returnUrl } });
return Redirect(loginUri.AbsoluteUri);
}
Then the user is redirected to a Facebook page, and an access token is sent back into my OAuth ActionResult:
public ActionResult OAuth(string code, string state)
{
FacebookOAuthResult oauthResult;
if (FacebookOAuthResult.TryParse(Request.Url, out oauthResult))
{
if (oauthResult.IsSuccess)
{
var oAuthClient = new FacebookOAuthClient();
oAuthClient.AppId = FacebookApplication.Current.AppId;
oAuthClient.AppSecret = FacebookApplication.Current.AppSecret;
oAuthClient.RedirectUri = new Uri(redirectUrl);
dynamic tokenResult = oAuthClient.ExchangeCodeForAccessToken(code);
string accessToken = tokenResult.access_token;
DateTime expiresOn = DateTime.MaxValue;
if (tokenResult.ContainsKey("expires"))
{
DateTimeConvertor.FromUnixTime(tokenResult.expires);
}
FacebookClient fbClient = new FacebookClient(accessToken);
dynamic me = fbClient.Get("me?fields=id,name");
long facebookID = Convert.ToInt64(me.id);
Account acc = (from x in db.Account.OfType<Account>() where x.FaceBookID == facebookID select x).FirstOrDefault();
if (acc == null)
{
acc = CreateAccount(me);
}
acc.LatestLogin = DateTime.Now;
db.Entry(acc).State = EntityState.Modified;
db.SaveChanges();
MemoryUserStore.CurrentAccount = acc;
UserRoleProvider usp = new UserRoleProvider();
usp.GetRolesForUser(acc.AccountID.ToString());
FormsAuthentication.SetAuthCookie(acc.AccountID.ToString(), false);
if (Url.IsLocalUrl(state))
{
return Redirect(state);
}
return RedirectToAction("Details", "Account", new { id = acc.AccountID });
}
}
return RedirectToAction("Index", "Account");
}
What i am trying to do here, is to first verify if the token i get back from the redirect is valid. If it is, then i pull some data about the visitor, like FacebookID and Name. I then match it with my database, to see if the user already exists, and if not, i create one. I also assign a role for the user in my custom Role provider, but i had the infinite loop problem before this. Then i set
FormsAuthentication.SetAuthCookie(acc.AccountID.ToString(), false);
and i assume this is the core of keeping track of wheter a visitor is authorized or not. As far as i understand, when the visitor is trying to call a ActionResult that requires [Authorize] then the system will check for this cookie.
Well, could someone please clarify why the above code is working in Chrome/Safari, but keeps looping through Login and then OAuth infinitely in IE?
My app is using MVC 3, EF Code First and Facebook C# SDK 5.0.25
Okay, so i figured out that the problem was triggered by the [Authorize] annotation, as expected. The Facebook SDK has a [CanvasAuthorize] annotation, and when i switch to using this, IE works fine and does not login forever.
Before this, i tried using cookieless authentication, but IE still didn't want to play along.
As far as i have figured out, the problem occurs because Facebook apps are inside an IFrame. This supposedly screws something up with cookies and trust. If someone knows why this is, i would appreciate to hear about it.
Also, if anyone knows how to use and maintain roles, easily, with this [CanvasAuthorize], i would be glad to know.
I know this seems obvious but are you sure cookies aren't disabled in IE? There is an option to disable cookies in developer tools.

Categories