PayPal Express - How to integrate Card payments? - c#

Question background:
I've been developing with the PayPal C# API and have implemented an 'Express Checkout' solution. This works perfectly but I can only pay with a PayPal account. I of course want the ability to also pay with Cards.
Code:
Parameters set as part of my request to the API:
encoder["METHOD"] = "SetExpressCheckout";
encoder["RETURNURL"] = returnURL;
encoder["CANCELURL"] = cancelURL;
encoder["BRANDNAME"] = "Test App";
encoder["PAYMENTREQUEST_0_AMT"] = "120.00";
encoder["PAYMENTREQUEST_0_ITEMAMT"] = "120.00";
encoder["PAYMENTREQUEST_0_PAYMENTACTION"] = "Sale";
encoder["PAYMENTREQUEST_0_CURRENCYCODE"] = "USD";
encoder["L_PAYMENTREQUEST_0_NAME1"] = "test1";
encoder["L_PAYMENTREQUEST_0_AMT1"] = "20.00";
encoder["L_PAYMENTREQUEST_0_QTY1"] = "1";
encoder["L_PAYMENTREQUEST_0_NAME2"] = "test2";
encoder["L_PAYMENTREQUEST_0_AMT2"] = "20.00";
encoder["L_PAYMENTREQUEST_0_QTY2"] = "2";
encoder["L_PAYMENTREQUEST_0_NAME3"] = "test3";
encoder["L_PAYMENTREQUEST_0_AMT3"] = "20.00";
encoder["L_PAYMENTREQUEST_0_QTY3"] = "3";
Current Implementation:
Users are taken to PayPal to pay through their account then returned to my site:
What I require:
I need the user to be able to pay both through their account or with a card if they do not have a PayPal account, then be returned to my site. Is this possible through the Express checkout? If so then how do I implement it?:

You need to make sure "PayPal Account Optional" is enabled in your PayPal account profile under Website Payment Preferences.
Then in your SetExpressCheckoutRequest you need to include the following parameters:
SOLUTIONTYPE=Sole
LANDINGPAGE=Billing
USERSELECTEDFUNDINGSOURCE=CreditCard
Then you also need to make sure you have the API version updated to at least 109.0. That should give you what you're after.

Related

Processing 3rd Party Payments via Paypal C# Rest API

I have a website in which I process my user's customer's payments into their(my users) paypal account. I've created a paypal application and under the 3rd party settings I included the ability to process debit and credit card payments. Using a 3rd party account, I granted access through the third party permissions to my username. Through those steps I believe I have I've granted proper access on the paypal side.
Here is my c# code where I setup the configuration:
Dictionary<string, string> PaypalConfig = new Dictionary<string, string>();
PaypalConfig.Add("account1.apiUsername", "my api username");
PaypalConfig.Add("account1.apiPassword", "my api password");
PaypalConfig.Add("account1.apiSignature", "my api signature");
PaypalConfig.Add("subject", "email address of my user");
PaypalConfig.Add("account1.applicationId", "my app id");
PaypalConfig.Add("mode", "live");
OAuthTokenCredential tokenCredential = new OAuthTokenCredential("my client id", "my client secret", PaypalConfig);
string accessToken = tokenCredential.GetAccessToken();
//Code to fill in the transaction details
//Create Payment
Payment payment = new Payment();
payment.intent = "sale";
payment.payer = payer;
payment.transactions = transactions;
Payment createdPayment = payment.Create(accessToken);
When I run a transaction, the payment comes back approved but seems it is ignoring the subject, and money is deposited into MY ACCOUNT.
I found documentation on sending an invoice for a third party at https://developer.paypal.com/docs/classic/invoicing/ht_invoicing-3p/, but in the REST API I really do not see anything mentioned about processing 3rd party payments. It seems that I am missing something in regards to using the 3rd party account. Any help is appreciated!
Why dont you use simple redirect option to process the payments, this way, all you need to mention is your user's merchant email.
You need to pass the variables in the following format:
private void PayPal()
{
string _MerchantEmail = "youremailwithpaypal#domain.com";
string _ReturnURL = "https://www.yourwebsite.com/paymentsuccess";
string _CancelURL = "https://www.yourwebsite.com/paymentfailed";
string _CurrencyCode = "USD";
int _Amount = 100;
string _ItemName = "itme1"; //We are using this field to pass the order number
int _Discount = 10;
double _Tax = 1.5;
string _PayPalURL = $"https://www.paypal.com/cgi-bin/webscr?cmd=_xclick&business={_MerchantEmail}&return={_ReturnURL}&cancel_return={_CancelURL}&currency_code={_CurrencyCode}&amount={_Amount}&item_name={_ItemName}&discount_amount={_Discount}&tax={_Tax}";
Response.Redirect(_PayPalURL);
}
You might also need a callback URL for PayPal IPN to verify the payments status. But for your question above this should work as we are already using this code in our website.

Post message from Website to Facebook wall

I have a website made with ASP.NET webform .NET 4.5 C#. This site contains a forum(homemade by me), parts of this forum needs to be posted to the specific facebook wall(made for this webpage). What I need :
Post just created thread(message) from specific part of the forum to the corsponding facebook wall.
Optional : Sync the forum thread on webpage with message/comments on the specific facebook page
I have looked at these guides :
http://www.codeproject.com/Articles/569920/Publish-a-post-on-Facebook-wall-using-Graph-API
http://www.c-sharpcorner.com/UploadFile/raj1979/post-on-facebook-users-wall-using-Asp-Net-C-Sharp/
But im not sure that this is really the solution for me? I have tried to follow the guide but it does not look the same.
Edit :
dynamic result;
//https://developers.facebook.com/tools/explorer/
//https://developers.facebook.com/tools/access_token/
FacebookClient client = new FacebookClient(ConfigurationManager.AppSettings["FacebookAppToken"]);
//result = client.Get("debug_token", new
//{
// input_token = ConfigurationManager.AppSettings["FacebookAppToken"],
// access_token = ConfigurationManager.AppSettings["FacebookAppToken"]
//});
//result = client.Get("oauth/access_token", new
// {
// client_id = ConfigurationManager.AppSettings["FacebookAppId"],
// client_secret = ConfigurationManager.AppSettings["FacebookAppSecret"],
// grant_type = "client_credentials",
// //redirect_uri = "http://www.MyDomain.net/",
// //code = ""
// });
result = client.Get("oauth/access_token", new
{
client_id = ConfigurationManager.AppSettings["FacebookAppId"],
client_secret = ConfigurationManager.AppSettings["FacebookAppSecret"],
grant_type = "client_credentials"
});
client.AccessToken = result.access_token;
result = client.Post("[IdOfFacebookPage]/feed", new { message = "Test Message from app" });
//result.id;
result = client.Get("[IdOfFacebookPage]");
return false;
Approach to post to a facebook wall:
You need to register in facebook developer tools.
Create a app (fill a form).
Download FGT 5.0.480 (Facebook graph toolkit)
Reference FGT dlls in your web application.
FGT has methods to post to facebook wall but needs appId.
Use the app id of your app created in step 2.
To post to an user's wall through facebook, it is only possible through an app.
Try this asp .net app, which will allow you to post in your wall:
https://apps.facebook.com/aspdotnetsample/?fb_source=search&ref=br_tf
This will allow you to envision what you need.
Your app gets an appId with which you need to generate auth token.
Limitation: The user's wall where you want to post should have added the app created at step 2, this is compulsory and there is no work around.
When the user accesses the app for the first time, it automatically asks for permission to post to wall--> the user needs to accept it.
Hope this gives you an idea on how to go about doing this.
You can then post into the user's wall.
For Banshee's below request using Facebook SDK for .NET:
userId - facebook user id, wall to post the message
This user should have added the app created by you in step 1 else it will say unauthorized access.
dynamic messagePost = new ExpandoObject();
messagePost.picture = "http://www.stackoverflow.com/test.png";
messagePost.link = "http://www.stackoverflow.com";
messagePost.name = "This is a test name";
messagePost.caption = "CAPTION 1";
messagePost.description = "Test desc";
messagePost.message = "message"
var fb = new FacebookClient();
dynamic result = fb.Get("oauth/access_token", new {
client_id = "app_id",
client_secret = "app_secret",
grant_type = "client_credentials"
});
fb.AccessToken = result.access_token;
try
{
var postId = fb.Post(userId + "/feed", messagePost);
}
catch (FacebookOAuthException ex)
{
//handle oauth exception
}
catch (FacebookApiException ex)
{
//handle facebook exception
}
You will need an extended token to publish to a wall.. Steps to get extended token is explained well by Banshee..
Edit: How to get extended token by Banshee:
Please follow this post
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.

Error in transaction processing when using SetPaymentsOptionsRequest

I'm working on integrating PayPal into a client's ecommerce site. Using the sandbox, we got everything working fine. I now need to add in SetPaymentOptionsRequest to prevent the user from changing his shipping address (they enter it on our site, so they can't change it at PayPal due to different shipping costs calculated on our site). It appears to work fine, but I get a 3005 error when logging into the PayPal sandbox site to confirm the transaction. Below is the relevant code (C#):
public string MakeChainedPayment(params params) {
var request = new PayRequest {
requestEnvelope = new RequestEnvelope("en_us"),
actionType = "CREATE",
cancelUrl = this._cancelUrl,
currencyCode = this._currencyCode,
returnUrl = this._returnUrl,
ipnNotificationUrl = this._ipnNotificationUrl
};
// Some code to generate receivers, not important for this problem, I don't think
var response = this._paymentService.Pay(request);
switch (response.paymentExecStatus) {
// This always returns "CREATED", as I'd want, so good up to here.
case "CREATED":
// If I leave this code out, PayPal works fine, but I need
// this part to do the shipping address verification.
var p = new SetPaymentOptionsRequest();
p.senderOptions = new SenderOptions();
p.senderOptions.addressOverride = false;
p.senderOptions.shippingAddress = new ShippingAddressInfo {
// Setting from params: city, country, zip, state, street1, street2
};
p.payKey = response.payKey;
p.requestEnvelope = request.requestEnvelope;
SetPaymentOptionsResponse r = _paymentService.SetPaymentOptions(payOptsReq);
break;
// This always retuns r.error.Count = 0, r.responseEnvelope.ack = "SUCCESS",
// so I think I'm good to go.
}
if (this._useSandbox) {
return string.Concat("https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_ap-payment&paykey=", response.payKey);
}
return string.Concat("https://www.paypal.com/cgi-bin/webscr?cmd=_ap-payment&paykey=", response.payKey);
}
Paypal returns this message when your Paypal account's email address has not been verified. To verify your Paypal Email account, please follow the following steps:
Log into your Paypal Account. You should be in the “Overview” tab.
Click on your Email address, under “Business account overview”, you will be taken to a Web page listing your Paypal Email addresses.
Select your Primary Adress.
Click on the “Confirm” button.
Follow the rest of the Paypal instructions.
The problem was what I was passing in for the country; I was sending in "USA", and it should be "US".

Post to a friends wall

I have an MVC4 application that uses OAuth to login via facebook. Once logged in the user can then choose a guestlist from their Facebook Friends. This is fine as I am managing to retrieve the facebook Friends and their ID's.
Now I want to be able to post to the Friends wall a message from the application. Is this possible at th moment as there seems to have been a lot of changes to what Facebook allows you to do, if a wall post is not possible, can a private message be sent?
I have no code snippets from this one, just direction would be appreciated.
Thanks
I have used this code for posting on friend wall
var fbApplication = new DefaultFacebookApplication { AppId = fbapp, AppSecret = fbsec };
var current = new FacebookWebContext(fbApplication);
Facebook.Web.FacebookWebClient client = new Facebook.Web.FacebookWebClient(token);
//client.AccessToken = current.AccessToken;
dynamic parameters = new ExpandoObject();
parameters.message = "";
parameters.link = link;
parameters.name = name;
parameters.caption = caption;
parameters.description = desc;
parameters.from = fromId;//your fb ID
//friendId will be the ID of the person,you wants to post on wall
object resTest = client.Post("/" + friendId + "/feed", parameters);
Alternatively you can use Graph API's feed dialog
check this

Facebook C# SDk user registration

I am trying to implement user registration on my mvc3 site using fb. My question is regard this bit of code
FacebookClient fbClient = new FacebookClient(accessToken);
dynamic me = fbClient.Get("me?fields=id,name");
What other parameters can be specified in the request "me?fields=id,name,??". My application requires Email Address, phone number, address and name (first name, last name). I would be grateful if someone could tell me or better yet point to to somewhere I can find documentation on this.
This is a sample of the parameters you get inside dynamic me = fb.Get("me") without user permission:
"id":"894555532"
"name":"John Doe"
"first_name":"John"
"last_name":"Doe"
"link":"http://www.facebook.com/johndoe"
"username":"john"
"bio":"Sample bio"
"quotes":"\"Sample quote""
"work":[{"employer":{"id":"39233323343","name":"Sample Company"}
"position":{"id":"142461033332450","name":"Backend Developer"}
"projects":[{"id":"214103971985333"
"name":"Coors Light, Sample Project"}]}]
"favorite_teams":[{"id":"171522852874952","name":"Juventus"},{"id":"112325268793829","name":"Barcelona F.C."}]
"favorite_athletes":[{"id":"326971266226","name":"Alessandro Del Piero"}]
"gender":"male"
"timezone":-6
"locale":"en_US"
"verified":true
"updated_time""2012-01-24T09:12:17+0000"}
"email" requires user permission
I'm sure there are other things you can get, though there is no official list for c# sdk yet.
This is a sample of how to get all that info:
var fb = new FacebookWebClient();
dynamic me = fb.Get("me");
imgProfilePic.ImageUrl = string.Format("https://graph.facebook.com/{0}/picture", me.id);
lblName.Text = me.name;
lblFirstName.Text = me.first_name;
lblLastName.Text = me.last_name;
Here's an updated / complete list a scopes for Facebook C# SDK:
ads_management
create_event
create_note
email
export_stream
friends_about_me
friends_activities
friends_birthday
friends_checkins
friends_education_history
friends_events
friends_games_activity
friends_groups
friends_hometown
friends_interests
friends_likes
friends_location
friends_location_posts
friends_notes
friends_online_presence
friends_photo_video_tags
friends_photos
friends_questions
friends_relationship_details
friends_relationships
friends_religion_politics
friends_status
friends_subscriptions
friends_videos
friends_website
friends_work_history
manage_friendlists
manage_notifications
manage_pages
offline_access
photo_upload
publish_actions
publish_checkins
publish_stream
read_friendlists
read_insights
read_mailbox
read_requests
read_stream
rsvp_event
share_item
sms
status_update
user_about_me
user_activities
user_birthday
user_checkins
user_education_history
user_events
user_games_activity
user_groups
user_hometown
user_interests
user_likes
user_location
user_location_posts
user_notes
user_online_presence
user_photo_video_tags
user_photos
user_questions
user_relationship_details
user_relationships
user_religion_politics
user_status
user_subscriptions
user_videos
user_website
user_work_history
video_upload xmpp_login

Categories

Resources