This is an attempt to obtain transactions of my paypal account so I can later insert these into a database for safekeeping on my server. The code below is suppose to get the transactions, between two dates, and return them to me, so I can got through them and obtain the most important information such as email, amount, etc.
It comes back with nothing, when I login to my paypal I can clearly see I have plenty of transactions in this month and the previous month.
What does it to get this list:
public static void GetPayment(CommandArgs args)
{
var config = new Dictionary<string, string>();
config.Add("mode", PayPal.Api.BaseConstants.LiveMode);
config.Add("clientId", "Ady0Bn3J1ik4Bpc29-rTbDYGKaQIY");
config.Add("clientSecret", "EDSRVBfnRLNsBO4k4ewBBUWnXHjJgWJ");
config[PayPal.Api.BaseConstants.HttpConnectionTimeoutConfig] = "30000";
config[PayPal.Api.BaseConstants.HttpConnectionRetryConfig] = "3";
string accessToken = new PayPal.Api.OAuthTokenCredential(config).GetAccessToken();
args.Player.SendInfoMessage("Access Token Obtained");
var apiContext = new PayPal.Api.APIContext(accessToken) { Config = config };
args.Player.SendInfoMessage("Access Token Successful");
var payments = PayPal.Api.Payment.List(apiContext, null, "", null, "", "", DateTime.Now.AddDays(-25).ToString(), DateTime.Now.ToString());
args.Player.SendInfoMessage("{0}", payments.count);
//var payment = PayPal.Api.Payment.Get(apiContext, invoices.invoices[0].id);
}
I attempted to use this code for Transactions:
Dictionary<string, string> config = new Dictionary<string, string>();
config.Add("mode", "live");
config.Add("account1.apiUsername", "marcus1****");
config.Add("account1.apiPassword", "3EB8K");
config.Add("account1.apiSignature", "AFcWx8rxJyxut23nTV");
PayPal.PayPalAPIInterfaceService.PayPalAPIInterfaceServiceService search = new PayPal.PayPalAPIInterfaceService.PayPalAPIInterfaceServiceService(config);
PayPal.PayPalAPIInterfaceService.Model.TransactionSearchReq s = new PayPal.PayPalAPIInterfaceService.Model.TransactionSearchReq();
s.TransactionSearchRequest.StartDate = DateTime.Now.AddDays(-25).ToString();
s.TransactionSearchRequest.EndDate = DateTime.Now.ToString();
var newsearch = search.TransactionSearch(s, "marcus101rr_api1.gmail.com");
args.Player.SendInfoMessage("Found: {0}", newsearch.PaymentTransactions.Count());
Related
The problem is that i couldn't charge gocardless customer immediately in sandbox account. Once i've created payment through .net sdk, it automatically set charge day in 6 days after now. Below how i create new gocardless payment for customer:
var createResponse = await _goCardlessClient.Payments.CreateAsync(new PaymentCreateRequest()
{
Amount = 10,
Currency = PaymentCreateRequest.PaymentCurrency.GBP,
Links = new PaymentCreateRequest.PaymentLinks()
{
Mandate = "mandateId goes here",
},
Metadata = new Dictionary<string, string>()
{
{ metadata goes here }
},
IdempotencyKey = Guid.NewGuid().ToString()
});
When i'm trying to explicitly set charge date in the following way:
var createResponse = await _goCardlessClient.Payments.CreateAsync(new PaymentCreateRequest()
{
Amount = 10,
Currency = PaymentCreateRequest.PaymentCurrency.GBP,
ChargeDate = DateTime.UtcNow.ToString("yyyy-MM-dd"),
Links = new PaymentCreateRequest.PaymentLinks()
{
Mandate = "mandateId goes here",
},
Metadata = new Dictionary<string, string>()
{
{ metadata goes here }
},
IdempotencyKey = Guid.NewGuid().ToString()
});
i get an exceptions says that:
charge_date must be on or after mandate's next_possible_customer_charge_date
And in official documentation i couldn't find any info about how to set next_possible_customer_charge_data explicitly for sandbox. Does anyone sort it out?
Trying to get all the categories from Ebay to shove into the database. I've tried increasing the timeout value of the underlying api context, but I still get a timeout after about two minutes - what else do I need to do?
var c = new eBay.Service.Call.GetCategoriesCall(this.apiContext);
c.CategorySiteID = ((int)siteId).ToString(); // siteId is an eBay SiteCode enum value
var version = c.GetCategoriesVersion();
c.DetailLevelList = new DetailLevelCodeTypeCollection();
c.DetailLevelList.Add(DetailLevelCodeType.ReturnAll);
c.ViewAllNodes = !onlyLeafCategories;
c.Timeout = 1000*60*20;
c.GetCategories(); // this causes a connection closed / timeout
Try this code, it works for me :
// get all categories from eBay
ApiContext context = GetApiContext();
GetCategoriesCall apiCall = new GetCategoriesCall(context)
{
EnableCompression = true,
ViewAllNodes = true
};
apiCall.DetailLevelList.Add(DetailLevelCodeType.ReturnAll);
apiCall.GetCategories();
public static ApiContext GetApiContext()
{
//apiContext is a singleton,
//to avoid duplicate configuration reading
if (apiContext != null)
{
return apiContext;
}
else
{
apiContext = new ApiContext();
//set Api Server Url
apiContext.SoapApiServerUrl = "https://api.ebay.com/wsapi";
//set Api Token to access eBay Api Server
ApiCredential apiCredential = new ApiCredential();
apiCredential.eBayToken ="YOUR_TOKEN";
apiContext.ApiCredential = apiCredential;
//set eBay Site target to US
apiContext.Site = eBay.Service.Core.Soap.SiteCodeType.US;
return apiContext;
}
}
I create sample a windows form application.
I download pay pal sdk in visual studio.
I create paypal sandbox test account
whre to add the credential details?
where we put app id:
Sandbox test AppID:
APP-80W284485P519543T
I have copy some code for winform app while click a button that is.
Dictionary<string, string> sdkConfig = new Dictionary<string, string>();
sdkConfig.Add("mode", "sandbox");
accessToken = new OAuthTokenCredential("AQkquBDf1zctJOWGKWUEtKXm6qVhueUEMvXO_-MCI4DQQ4-LWvkDLIN2fGsd", "EL1tVxAjhT7cJimnz5-Nsx9k2reTKSVfErNQF-CmrwJgxRtylkGTKlU4RvrX", sdkConfig).GetAccessToken();
HttpContext CurrContext = HttpContext.Current;
APIContext apiContext = new APIContext(accessToken);
Item item = new Item();
item.name = _ItemDescription;
item.currency = "USD";
item.price = _Amount;
item.quantity = "1";
item.sku = _UPC;
List<Item> itms = new List<Item>();
itms.Add(item);
ItemList itemList = new ItemList();
itemList.items = itms;
Address billingAddress = new Address();
billingAddress.city = "Chennai";
billingAddress.country_code = "US";
billingAddress.line1 = "11/12";
billingAddress.line2 = "Andavar nager main street";
billingAddress.postal_code = "600089";
billingAddress.state = "Tamil nadu";
CreditCard crdtCard = new CreditCard();
crdtCard.billing_address = billingAddress;
crdtCard.cvv2 = 2222;
crdtCard.expire_month = 4;
crdtCard.expire_year = 2020;
crdtCard.first_name = "Arul";
crdtCard.last_name = "Murugan";
crdtCard.number = "4032039053301695";
crdtCard.type = "visa";
Details details = new Details();
details.tax = "0";
details.shipping = "0";
details.subtotal = _Amount;
Amount amont = new Amount();
amont.currency = "USD";
amont.total = _Amount;
amont.details = details;
Transaction tran = new Transaction();
tran.amount = amont;
tran.description = _ItemDescription;
tran.item_list = itemList;
List<Transaction> transactions = new List<Transaction>();
transactions.Add(tran);
FundingInstrument fundInstrument = new FundingInstrument();
fundInstrument.credit_card = crdtCard;
List<FundingInstrument> fundingInstrumentList = new List<FundingInstrument>();
fundingInstrumentList.Add(fundInstrument);
PayerInfo pi = new PayerInfo();
pi.email = "sysumurugan-facilitator#gmail.com";
pi.first_name = "Arul";
pi.last_name = "Murugan";
Payer payr = new Payer();
payr.funding_instruments = fundingInstrumentList;
payr.payment_method = "credit_card";
payr.payer_info = pi;
pi.shipping_address = new ShippingAddress
{
city = "San Mateo",
country_code = "US",
line1 = "SO TEST",
line2 = "",
postal_code = "94002",
state = "CA",
};
Payment paymnt = new Payment();
paymnt.intent = "sale";
paymnt.payer = payr;
paymnt.transactions = transactions;
try
{
Payment createdPayment = paymnt.Create(apiContext);
CurrContext.Items.Add("ResponseJson", JObject.Parse(createdPayment.ConvertToJson()).ToString(Formatting.Indented));
}
catch (PayPal.Exception.PayPalException ex)
{
if (ex.InnerException is PayPal.Exception.ConnectionException)
{
CurrContext.Response.Write(((PayPal.Exception.ConnectionException)ex.InnerException).Response);
}
else
{
CurrContext.Response.Write(ex.Message);
}
}
catch (Exception es)
{
MessageBox.Show( es.ToString());
}
CurrContext.Items.Add("RequestJson", JObject.Parse(paymnt.ConvertToJson()).ToString(Formatting.Indented));
my reference link is
http://pastebin.com/H7VuPQs4
Parsing a PayPal REST Credit Card Transaction Response (JSON),
C# PayPal REST API Checkout with Credit Card
please explian to me any other way for credit card transaction for POS(Point Of Sale) through win form application.
The PayPal .NET SDK is meant for server applications (e.g. ASP.NET) where application credentials are stored in a secure manner. Using the SDK directly from a WinForms application running on a POS system presents a security risk because your merchant account credentials are not stored in a secure manner. Ideally, the POS system should be communicating back to a secure server somewhere that performs the processing.
With that said, this use case is what PayPal Here is designed for.
I am needing some assistance with paypal Parallel payments C# I have tried the Classic API and the REST API that paypal has. I am running into cycles and don't know what else to do, I have tried to get chained payments working and I have google'd and there is a huge lack of support so Im now trying Parallel. Let you know i get an 500 internal Server error..
ReceiverList receiverList = new ReceiverList();
receiverList.receiver = new List<Receiver>();
Receiver secondaryReceiver = new Receiver((decimal?)2.00);
secondaryReceiver.email = "xxxxxxxxx#gmail.com";
secondaryReceiver.primary = false;
secondaryReceiver.paymentType = "GOODS";
receiverList.receiver.Add(secondaryReceiver);
Receiver primaryReceiver = new Receiver((decimal?)10.00);
primaryReceiver.email = "xxxxxxxxxxxxxxxxxx-facilitator#gmail.com ";
primaryReceiver.primary = true;
primaryReceiver.paymentType = "GOODS";
primaryReceiver.invoiceId = "123456789";
receiverList.receiver.Add(primaryReceiver);
RequestEnvelope requestEnvelope = new RequestEnvelope("en_US");
string actionType = "Pay";
string returnUrl = "https://devtools-paypal.com/guide/ap_chained_payment/dotnet?success=true";
string cancelUrl = "https://devtools-paypal.com/guide/ap_chained_payment/dotnet?cancel=true";
string currencyCode = "USD";
PayRequest payRequest = new PayRequest(requestEnvelope, actionType, cancelUrl, currencyCode, receiverList, returnUrl);
payRequest.ipnNotificationUrl = "http://replaceIpnUrl.com";
payRequest.feesPayer = "PRIMARYRECEIVER";
payRequest.trackingId = "123456789";
Dictionary<string, string> paypalConfig = new Dictionary<string, string>();
paypalConfig.Add("account1.apiUsername", "xxxxxxxxxxxxxxx-facilitator_api1.gmail.com");
paypalConfig.Add("account1.apiPassword", "xxxxxxxxxxxxxxxxxxx");
paypalConfig.Add("account1.apiSignature", "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
paypalConfig.Add("account1.applicationId", "APP-80W284485P519543T");
paypalConfig.Add("IPNEndpoint", "https://www.paypal.com/cgi-bin/webscr");
paypalConfig.Add("url", "https://www.paypal.com/webscr&cmd=_express-checkout&token=");
paypalConfig.Add("endpoint", "https://api-3t.paypal.com/2.0/");
paypalConfig.Add("mode", "sandbox");
PayPal.AdaptivePayments.AdaptivePaymentsService service = new PayPal.AdaptivePayments.AdaptivePaymentsService(paypalConfig);
PayResponse response = service.Pay(payRequest);
string redirectUrl = null;
if (!response.responseEnvelope.ack.ToString().Trim().ToUpper().Equals(AckCode.FAILURE.ToString()) && !response.responseEnvelope.ack.ToString().Trim().ToUpper().Equals(AckCode.FAILUREWITHWARNING.ToString()))
{
redirectUrl = "https://www.sandbox.paypal.com/webscr?cmd=_ap-payment&paykey=" + response.payKey;
}
Now as for the web.config I dont know exactly how to do it or really what to do. i Have found a few things but need of help.
Thanks
Working Platform: ASP.NET 4.0 C# ( Framework Agnostic )
Google GData is my dependency
using Google.GData.Client;
using Google.GData.Extensions;
using Google.GData.Documents;
I have two pages Auth and List.
Auth redirects to Google Server like this
public ActionResult Auth()
{
var target = Request.Url.ToString().ToLowerInvariant().Replace("auth", "list");
var scope = "https://docs.google.com/feeds/";
bool secure = false, session = true;
var authSubUrl = AuthSubUtil.getRequestUrl(target, scope, secure, session);
return new RedirectResult(authSubUrl);
}
Now it reaches the List Page if Authentication is successful.
public ActionResult List()
{
if (Request.QueryString["token"] != null)
{
String singleUseToken = Request.QueryString["token"];
string consumerKey = "www.blahblah.net";
string consumerSecret = "my_key";
string sessionToken = AuthSubUtil.exchangeForSessionToken(singleUseToken, null).ToString();
var authFactory = new GOAuthRequestFactory("writely", "qwd-asd-01");
authFactory.Token = sessionToken;
authFactory.ConsumerKey = consumerKey;
authFactory.ConsumerSecret = consumerSecret;
//authFactory.TokenSecret = "";
try
{
var service = new DocumentsService(authFactory.ApplicationName) { RequestFactory = authFactory };
var query = new DocumentsListQuery();
query.Title = "project";
var feed = service.Query(query);
var result = feed.Entries.ToList().ConvertAll(a => a.Title.Text);
return View(result);
}
catch (GDataRequestException gdre)
{
throw;
}
}
}
This fails at the line var feed = service.Query(query); with the error
Execution of request failed: https://docs.google.com/feeds/default/private/full?title=project
The HttpStatusCode recieved on the catch block is HttpStatusCode.Unauthorized
What is wrong with this code? Do I need to get TokenSecret? If so how?
You need to request a token from Google and use it to intialize your DocumentsService instance.
Here's an example using Google's ContactsService. It should be the same for the DocumentsService.
Service service = new ContactsService("My Contacts Application");
service.setUserCredentials("your_email_address_here#gmail.com", "yourpassword");
var token = service.QueryClientLoginToken();
service.SetAuthenticationToken(token);
But as you mentioned, you are using AuthSub. I jumped the gun a bit too fast.
I see that you are requesting a session token. According to the documentation of the API you must use the session token to authenticate requests to the service by placing the token in the Authorization header. After you've set the session token, you can use the Google Data APIs client library.
Here's a complete example (by Google) on how to use AuthSub with the .NET client library:
http://code.google.com/intl/nl-NL/apis/gdata/articles/authsub_dotnet.html
Let me include a shortened example:
GAuthSubRequestFactory authFactory =
new GAuthSubRequestFactory("cl", "TesterApp");
authFactory.Token = (String) Session["token"];
CalendarService service = new CalendarService(authFactory.ApplicationName);
service.RequestFactory = authFactory;
EventQuery query = new EventQuery();
query.Uri = new Uri("http://www.google.com/calendar/feeds/default/private/full");
EventFeed calFeed = service.Query(query);
foreach (Google.GData.Calendar.EventEntry entry in calFeed.Entries)
{
//...
}
And if I see correctly your example code pretty follows the same steps, except that you set the ConsumerKey and ConsumerSecret for the AuthFactory which is not done in the example by Google.
Used the 3-legged OAuth in the Google Data Protocol Client Libraries
Sample Code
string CONSUMER_KEY = "www.bherila.net";
string CONSUMER_SECRET = "RpKF7ykWt8C6At74TR4_wyIb";
string APPLICATION_NAME = "bwh-wssearch-01";
string SCOPE = "https://docs.google.com/feeds/";
public ActionResult Auth()
{
string callbackURL = String.Format("{0}{1}", Request.Url.ToString(), "List");
OAuthParameters parameters = new OAuthParameters()
{
ConsumerKey = CONSUMER_KEY,
ConsumerSecret = CONSUMER_SECRET,
Scope = SCOPE,
Callback = callbackURL,
SignatureMethod = "HMAC-SHA1"
};
OAuthUtil.GetUnauthorizedRequestToken(parameters);
string authorizationUrl = OAuthUtil.CreateUserAuthorizationUrl(parameters);
Session["parameters"] = parameters;
ViewBag.AuthUrl = authorizationUrl;
return View();
}
public ActionResult List()
{
if (Session["parameters"] != null)
{
OAuthParameters parameters = Session["parameters"] as OAuthParameters;
OAuthUtil.UpdateOAuthParametersFromCallback(Request.Url.Query, parameters);
try
{
OAuthUtil.GetAccessToken(parameters);
GOAuthRequestFactory authFactory = new GOAuthRequestFactory("writely", APPLICATION_NAME, parameters);
var service = new DocumentsService(authFactory.ApplicationName);
service.RequestFactory = authFactory;
var query = new DocumentsListQuery();
//query.Title = "recipe";
var feed = service.Query(query);
var docs = new List<string>();
foreach (DocumentEntry entry in feed.Entries)
{
docs.Add(entry.Title.Text);
}
//var result = feed.Entries.ToList().ConvertAll(a => a.Title.Text);
return View(docs);
}
catch (GDataRequestException gdre)
{
HttpWebResponse response = (HttpWebResponse)gdre.Response;
//bad auth token, clear session and refresh the page
if (response.StatusCode == HttpStatusCode.Unauthorized)
{
Session.Clear();
Response.Write(gdre.Message);
}
else
{
Response.Write("Error processing request: " + gdre.ToString());
}
throw;
}
}
else
{
return RedirectToAction("Index");
}
}
This 2-legged sample never worked for me for google docs.