I am developing this using ASP.NET and i have used Stripe.NET dll, according to the documentation I had linked up my shopkeeper stripe account with me and got the access code.
Now i have confusion about my customer, he should be added as customer in shopkeeper's stripe account or just his account is linked up with my Stripe account as Shopkeepers.
Can anyone please explain, how it will work ?
var stripeService = new StripeChargeService(sellerStore.StripeMerchantAccessToken); //The token returned from the above method
var stripeChargeOption = new StripeChargeCreateOptions() {
AmountInCents = amountInCents,
Currency = "usd",
CustomerId = buyerPaymentInfo.StripeCustomerToken,
Description = "Locabal",
ApplicationFeeInCents = locabalsCut
};
var response = stripeService.Create(stripeChargeOption);
buyerPaymentInfo.StripeCustomerToken will be Access code or it will be the customer registered in Suppliers account ?
I want to charge customer using his Credit Card
Your help will be highly appreciated.
As per my understanding of Stripe API, you should create a customer in your account and use customer ID which starts with "cus_" in the charge.
If you look at following stripe.net discussion you will see how to create a customer and use it in your charge.
https://github.com/jaymedavis/stripe.net/pull/43#issuecomment-30345043
//This is what we do to create a long-term customer in our system
//user is a user object unique to our system. We save it in our database
//stripeToken is what is generated by the Javascript on the page
var stripeService = new stripeCustomerService(ConfigurationManager.AppSettings["StripeSecret"]);
var stripeTokenOptions = new StripeCustomerCreateOptions { TokenId = stripeToken };
var response = stripeService.Create(stripeTokenOptions);
if (user.PaymentInfo == null)
{
PaymentInfo paymentInfo = new PaymentInfo
{
StripeCustomerToken = response.Id
};
user.PaymentInfo = paymentInfo;
}
else
{
user.PaymentInfo.StripeCustomerToken = response.Id;
}
Related
I have an application that uses a deep integration with Stripe. My platform is occasionally charging the connected accounts and I am storing information about these charges in the metadata of the charge itself.
I want to display this information back to the connected account so I am using the Charge Service to list charges. However I want to filter that list based on some metadata key/value pair so that I don't have to list all of the charges each time, for every connected account.
Is there a clever way of doing this?
Filtering based on metadata is not supported.
Since you are doing this across Connected accounts, a better approach would be to store the Charge ID and metadata on your end so that you don't have to list and paginate through charges, looking for particular metadata.
Stripe recently added Search API that allows search by metadata. Currently, it does not have .NET / C# integration but you can query using HTTP call directly:
Example from their docs:
curl https://api.stripe.com/v1/search/charges \
-u sk_test_daHanKyJOCiXCeBsa65biLML00wylimZ8S: \
--data-urlencode "query=metadata['key']:'value'" \
-H "Stripe-Version: 2020-08-27;search_api_beta=v1" \
-G
I was able to accomplish this with the "TransferGroup" property of the ChargeCreateOptions object. I basically set the TransferGroup property to a unique value for each connected account which I can then query later.
CREATE THE CHARGE
//THERE IS NO ID IN THE REQUEST OPTIONS BECAUSE
//WE ARE USING THE PLATFORM
var requestOptions = new RequestOptions()
{
ApiKey = {API Key}
};
//CHARGE OPTIONS
var chargeOptions = new ChargeCreateOptions
{
Amount = {AMOUNT},
Currency = "usd",
Description = $"Platform Charge",
SourceId = {StripeId},
Metadata = {MetaData},
TransferGroup = {Unique String For Each Connected Account}
};
//CREAT AND RETURN THE CHARGE
var chargeService = new ChargeService();
return chargeService.Create(chargeOptions, requestOptions);
QUERY THE PLATFORM CHARGES BASED ON TRANSFER GROUP
public List<Charge> StripePlatformCharges(string apiKey, int days, string transferGroup)
{
try
{
RequestOptions requestOptions = new RequestOptions()
{
ApiKey = apiKey
};
ChargeListOptions chargeListOptions = new ChargeListOptions()
{
CreatedRange = new DateRangeOptions()
{
GreaterThanOrEqual = DateTime.Now.AddDays(-days)
},
TransferGroup = transferGroup
};
ChargeService chargeService = new ChargeService();
return chargeService.List(chargeListOptions, requestOptions).ToList();
}
catch (Exception ex)
{
throw new Exception("Error getting stripe charges from the platform", ex);
}
}
Stripe recently released a Search API which offers filtering by metadata for certain resources including charges. The documentation is at https://stripe.com/docs/search
C# package used: Google.Apis.Calendar.v3
I am making a sharing a calendar to an not google account.
No invite notification sent to that account event the Response = OK
var rule = new AclRule
{
Role = "owner",
Scope = new AclRule.ScopeData
{
Value = acb#yahoo.com,
Type = "user"
}
};
var service = await GetCalendarService();
var request = service.Acl.Insert(rule, calendarId);
request.SendNotifications = true;
AclRule addedRule = await request.ExecuteAsync();
So could anybody help me about that?
Thanks,
I found that google calendar API dont have any options to send notification to non google email.
Moreover, the calendar must be made as public first. This one can not modify by API. And I dont want to make it as public also.
Here's document from google
I have a web application that runs a schedule job which pulls in the Facebook reviews from a page which I manage. Here is a snippet
public void Execute(IJobExecutionContext context)
{
//get api details from the web.config
var pageId = WebConfigurationManager.AppSettings["FacebookPageId"];
var token = WebConfigurationManager.AppSettings["FacebookAPIToken"];
if (!string.IsNullOrEmpty(token))
{
//create a facebook client object
var client = new FacebookClient(token);
//make a call to facebook to retrieve the json data
dynamic graphJson = client.Get(pageId + "?fields=ratings{review_text,reviewer,rating}").ToString();
//deserialize the json returned from facebook
ReviewDeserializeData reviews = JsonConvert.DeserializeObject<ReviewDeserializeData>(graphJson);
//loop through the deserialized data and pass each review to the import class
foreach (var rating in reviews.ratings.data)
{
var fbRating = new FacebookRating
{
RatingReviewerId = long.Parse(rating.reviewer.id),
StarRating = rating.rating,
ReviewerName = rating.reviewer.name,
ReviewText = rating.review_text
};
ImportFacebookRating.ImportTheFacebookRating(fbRating);
}
}
}
This works great until the Page Access Token expires. I have tried following many articles such as this one https://medium.com/#Jenananthan/how-to-create-non-expiry-facebook-page-token-6505c642d0b1#.24vb5pyiv but i have had no luck fixing the token expiring.
Does anyone know how i can achieve this or is there a way to programmatically generate a new token if the existing one has expired? at the moment i have it stored in the web.config as an app setting.
Thanks
I found the answer here and was able to generate a token that 'Never' Expires Long-lasting FB access-token for server to pull FB page info
I try to use Stripe to charge on behalf of someone. I did the connect part with success, but I tried to create a token/charge after that and it doesn't work.
Some info on parameters used in the code:
"acct_158fBBAOizDDfp9B" - Get from the Connect user;
WebConfig.AppSettings.StripeClientId - My client Id get from Stripe
dashboard;
WebConfig.AppSettings.StripeSecretApiKey - My Stripe
Secret API Key;
"sk_test_5E9d7UHs9CVa3Ansop2JzIxI" - Private API key
get from Connect user.
Here is my code:
StripeRequestOptions requestOptions = new StripeRequestOptions();
requestOptions.StripeConnectAccountId = "acct_158fBBAOizDDfp9B";
var myToken = new StripeTokenCreateOptions();
myToken.Card = new StripeCreditCardOptions()
{
// set these properties if passing full card details (do not
// set these properties if you set TokenId)
Number = "4242424242424242",
ExpirationYear = "2022",
ExpirationMonth = "10",
AddressCountry = "US", // optional
AddressLine1 = "24 Beef Flank St", // optional
AddressLine2 = "Apt 24", // optional
AddressCity = "Biggie Smalls", // optional
AddressState = "NC", // optional
AddressZip = "27617", // optional
Name = "Joe Meatballs", // optional
Cvc = "1223" // optional
};
// set this property if using a customer (stripe connect only)
myToken.CustomerId = WebConfig.AppSettings.StripeClientId; // My client ID get from Stripe dashboard.
//var tokenService = new StripeTokenService(WebConfig.AppSettings.StripeSecretApiKey);
var tokenService = new StripeTokenService("sk_test_5E9d7UHs9CVa3Ansop2JzIxI");
StripeToken stripeToken = tokenService.Create(myToken, requestOptions);
I've got a «You must pass a valid card ID for this customer.» error.
A couple things:
Since you're using Stripe Connect, you can only create tokens using Stripe.js or Stripe Checkout, your server should never have access to the card info. Also I don't know why you're setting the token's customerId to a client id, clients are not customers.
Also the API key should be your API key, since you're using the Stripe account header, the option is either (your API key and the account id of the connected account) or (access token). This is discussed in the authentication portion of the Stripe Connect documentation.
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.