How to Create a Stripe Charge with a Destination Parameter Using .NET - c#

With Stripe, it is possible to forward a charge using a destination parameter.
This Stripe documentation includes examples for a few languages, but not C#/.NET.
The Stripe API reference does have an example for creating charges, and mentions the optional destination parameter as a Dictionary. What would this dictionary parameter look like?
.NET API Reference for create charge:
var options = new ChargeCreateOptions
{
Amount = 2000,
Currency = "usd",
Description = "Charge for jenny.rosen#example.com",
SourceId = "tok_visa" // obtained with Stripe.js,
};
var service = new ChargeService();
Charge charge = service.Create(options);

It looks like this :
var chargeOptions = new ChargeCreateOptions()
{
Amount = 2000,
Currency = "usd",
SourceId = "tok_visa",
Destination = new ChargeDestinationCreateOptions{
Amount = 100,
Account = "acct_1DjoxfIPiUij0fru"
}
};
ChargeService chargeService = new ChargeService();
Charge charge = chargeService.Create(chargeOptions);
https://github.com/stripe/stripe-dotnet/blob/v22.7.0/src/Stripe.net/Services/Charges/ChargeCreateOptions.cs#L45-L49

Related

STRIPE API - Create payment link to custom account got wrong

How do i create payment link to custom account via stripe.net library?
I have tried with these codes but its created product and payment link to my stripe connected account instead of custom account as i want.
// create payment link
var plinkOpt = new PaymentLinkCreateOptions
{
LineItems = new List<PaymentLinkLineItemOptions>
{
new PaymentLinkLineItemOptions
{
Price = new PriceService().Create(
new PriceCreateOptions
{
Currency = "usd",
Product = new ProductService().Create(new ProductCreateOptions { Name = "myproductname", }).Id,
CustomUnitAmount = new PriceCustomUnitAmountOptions { Enabled = true },
}).Id,
Quantity = 1,
},
},
};
var plinkSer = new PaymentLinkService();
plinkSer.Create(plinkOpt);
I hope to have codes to solve my problem or a solution to do it. Thank you
You need to set the StripeAccount in RequestOptions (API ref):
var options = new RequestOptions
{
StripeAccount = "acct_123"
};
plinkSer.Create(plinkOpt, options);
Edit: However, this should only be used with Standard accounts, not custom accounts.

Nothing to invoice for subscription - create an invoice when the purchase is reviewed

Right now I am trying to create an invoice once the purchase has been reviewed.
It is the case that when the customer has bought the membership, I want invoice id to be assigned to my database in relation to the webhook being able to assign pdf invoice to the database with the link.
When I try to make invoice to last in the code. Then I am unfortunately met with this error.
Nothing to invoice for subscription
Stripe Error link
When I look at Stripe logs this comes from errors.
{
"error": {
"code": "invoice_no_subscription_line_items",
"doc_url": "https://stripe.com/docs/error-codes/invoice-no-subscription-line-items",
"message": "Nothing to invoice for subscription",
"param": "subscription",
"type": "invalid_request_error"
}
}
Thus, my Request POST body is like this:
{
"customer": "cus_J2ltIOWhr2BSGX",
"subscription": "sub_J2lto4EVvcfToq"
}
And here can u see how i post request to stripe.
var createCustomer = new CustomerCreateOptions
{
Source = token,
Name = model.FuldName,
Email = model.Mail
};
var addService = new CustomerService();
var customer = await addService.CreateAsync(createCustomer);
var optionsProduct = new ProductCreateOptions
{
Name = $"Membership - {DateTime.Now}",
Type = "service",
};
var serviceProduct = new ProductService();
Product product = await serviceProduct.CreateAsync(optionsProduct);
var optionsA = new PriceCreateOptions
{
UnitAmount = amount,
Currency = "dkk",
Recurring = new PriceRecurringOptions
{
Interval = Helpers.Stripe.interval,
},
Product = product.Id,
};
var serviceA = new PriceService();
var price = await serviceA.CreateAsync(optionsA);
var options = new SubscriptionCreateOptions
{
Customer = customer.Id,
Items = new List<SubscriptionItemOptions>
{
new SubscriptionItemOptions
{
Price = price.Id,
},
},
};
var service = new SubscriptionService();
var subscription = await service.CreateAsync(options);
var optionsI = new InvoiceCreateOptions
{
Customer = customer.Id,
Subscription = subscription.Id
};
var serviceI = new InvoiceService();
var invoice = await serviceI.CreateAsync(optionsI);//I NEED INVOICE ID FROM HERE!
I have tried to look here.
Adding shipping to first subscription invoice using stripe
EIDT:
var createCustomer = new CustomerCreateOptions
{
Source = token,
Name = model.FuldName,
Email = model.Mail
};
var addService = new CustomerService();
var customer = addService.Create(createCustomer);
var options = new ChargeCreateOptions
{
Amount = amount,
Currency = "dkk",
Description = $"Købt kursus {DateTime.Now}",
Customer = customer.Id,
};
var service = new ChargeService();
Charge charge = service.Create(options);
If you're using Subscriptions, the Invoices will be generated automatically for you based on the billing cycle.
If you print out the Subscription object you just created, you can find the Invoice ID under latest_invoice.
-- UPDATE ABOUT ONE-TIME PAYMENTS --
Charges and Invoices are two separate concepts in Stripe's API. A Charge is very simple and it's only purpose is to create and make a payment. Invoices are more complicated and have an added functionality (line items, automatic functionality, taxes, etc.) on top of just making a payment. Either one is fine to use, but it really depends on what your business needs are.
If you want to be using Invoices for one-time payments, you will need to change your code to create them (see https://stripe.com/docs/api/invoices/create). Your code currently only working with Charges - these are not part of Stripe's Billing product and will not generate an Invoice automatically.

Subscription payment must be up and running for SCA

That's how I need to have subscription payment up and running to SCA.
I have spent time reading all the links through etc but I don't really think I can get it up and running as it is shown on the link here:
3D Secure 2 flow
Where the problem lies is with image 2 + 3, none of what is shown on the link happens.
That's how I used the first card that is here on the site. (CARD HERE)
Also : 4000-0000-0000-3220 - 3D Secure 2 authentication must be completed on all transactions. Use this card to test that your integration is ready to support Strong Customer Authentication requirements in Europe.
Code here:
var api = Settings.Stripe.SecretKey_SK;
StripeConfiguration.ApiKey = api;
// Token is created using Checkout or Elements!
// Get the payment token submitted by the form:
var token = model.Source; // Using ASP.
var optionsProduct = new ProductCreateOptions
{
Name = "Medlemskab " + companies.Name,
Type = "service",
};
var serviceProduct = new ProductService();
Product product = serviceProduct.Create(optionsProduct);
var optionsPlan = new PlanCreateOptions
{
Currency = "dkk",
Interval = Interval,
Nickname = "Medlemskab - OrderId: " + OrderId + " InterVal: " + Interval + " Name: " + companies.Name,
Amount = amount,
Product = product.Id,
IntervalCount = getPricInfo.Months,
};
var servicePlan = new PlanService();
Plan plan = servicePlan.Create(optionsPlan);
var options = new SessionCreateOptions
{
SuccessUrl = "https://www.xx.com/Members/Success",
PaymentMethodTypes = new List<string>
{
"card",
},
SubscriptionData = new SessionSubscriptionDataOptions
{
Items = new List<SessionSubscriptionDataItemOptions>
{
new SessionSubscriptionDataItemOptions
{
PlanId = plan.Id
},
},
},
};
var service = new SessionService();
Session session = service.Create(options);
//opret kunden i Stripe Systemet.
var createCustomerStripe = new CustomerCreateOptions
{
Email = model.Email,
Description = "Kunde for " + companiesName + " - Email: " + model.Email,
Source = token,
};
var addService = new CustomerService();
Customer customer = await addService.CreateAsync(createCustomerStripe);
//Tilføj customerId her til for, at kunne få det til, at passe sammen.
var items = new List<SubscriptionItemOption>
{
new SubscriptionItemOption
{
PlanId = plan.Id
}
};
var createSubscruption = new SubscriptionCreateOptions
{
CustomerId = customer.Id,
Items = items
};
createSubscruption.AddExpand("latest_invoice.payment_intent");
var Addservice = new SubscriptionService();
Subscription subscription = Addservice.Create(createSubscruption);
It gets created ie things in logs at Stripe:
See logs here to Stripe
So my question is just: How do I get it resolved so that I will be able to have 3D Secure in relation to SCA so I'm ready there :) and at the same time how can it be that it does not bother at all to be 3D Secure approved right now. Is it because I'm missing some specific place in the code for it to work?

AWS - How to change the cloudwatchclient config service version in AWSSDK for .NET

I am trying to get CPU percentage of a particular amazon EC2 instance using CloudWatch
I am facing this error when executing the code (see below)
The requested version (2010-08-01) of service AmazonEC2 does not exist"
I could not change the ServiceVersion in AmazonCloudWatchClient because it has Read Only property
The default set is 2010-08-01
I need to change the ServiceVersion to 2014-10-01
Please find the configuration below
And the config in text here
var client = new AmazonCloudWatchClient(clientkey,secretkey,new AmazonCloudWatchConfig{ServiceURL="url"})
var dimension = new Dimension
{
Name = "instanceName",
Value = "instanceID"
};
var request = new GetMetricStatisticsRequest
{
Dimensions = new List<Dimension>() { dimension },
EndTime = DateTime.Today,
MetricName = "CPUUtilization",
Namespace = "AWS/EC2",
// Get statistics by day.
Period = (int)TimeSpan.FromDays(1).TotalSeconds,
// Get statistics for the past month.
StartTime = DateTime.Today.Subtract(TimeSpan.FromDays(30)),
Statistics = new List<string>() { "Minimum" },
Unit = StandardUnit.Percent
};
var response = client.GetMetricStatistics(request);
if (response.Datapoints.Count > 0)
{
foreach (var point in response.Datapoints)
{
Console.WriteLine(point.Timestamp.ToShortDateString() +
" " + point.Minimum + "%");
}
}
why do you think you'd need to change the date ?
The property has indeed no setter (see code) so you'll not be able to defined a config with such property.
I understand you dont want to reveal your information but what do you have under
var dimension = new Dimension
{
Name = "instanceName",
Value = "instanceID"
};
The Name should be InstanceName and if you use you instance id as you indicate in the Value it should be InstanceId something like
var dimension = new Dimension
{
Name = "InstanceId"
Value = "i-54cfb999"
};

ebay GetOrders API using OutputSelector and SortOrder - .Net SDK

I am using ebay .Net SDK. Everything is working fine except following requirements:
Using of OutputSelector to boost performance
Unable to use SortingOrder, while showing records.
Total income/amount sold for specified time range i.e. Total amount across all calls of the pagination without looping through pages and aggregating it manually.
Here is the code which I am using:
var apicall = new GetOrdersCall(context);
//apicall.ApiRequest.OutputSelector = new StringCollection(new String[] { "Order.OrderID", "Order.Total" });
apicall.ApiRequest.Pagination = new PaginationType
{
EntriesPerPage = Util.RecordsPerPage(),
PageNumber = int.Parse(Request.Form["pageNumber"])
};
var fltr = new TimeFilter(Convert.ToDateTime(Request.Form["dateFrom"] + "T00:00:00.000Z"), Convert.ToDateTime(Request.Form["dateTo"] + "T23:59:59.999Z"));
var statusCodeType = (OrderStatusCodeType)Enum.Parse(typeof(OrderStatusCodeType), Request.Form["statusCode"]);
var orders = apicall.GetOrders(fltr, TradingRoleCodeType.Seller, statusCodeType);
Please assist me how to use these 3 functionality as well.
After much efforts I got the way for it:
var request = new GetOrdersRequestType
{
//OutputSelector = new StringCollection {"OrderID","Total"},
CreateTimeFrom = Convert.ToDateTime(Request.Form["dateFrom"] + "T00:00:00.000Z"),
CreateTimeTo = Convert.ToDateTime(Request.Form["dateTo"] + "T23:59:59.999Z"),
OrderStatus = (OrderStatusCodeType)Enum.Parse(typeof(OrderStatusCodeType), Request.Form["statusCode"]),
OrderRole = TradingRoleCodeType.Seller,
Pagination = new PaginationType
{
EntriesPerPage = Util.RecordsPerPage(),
PageNumber = int.Parse(Request.Form["pageNumber"])
}
};
var apicall = new GetOrdersCall(context)
{
ApiRequest = request,
OutputSelector =
new string[]
{
"OrderID", "Total", "PaidTime", "eBayPaymentStatus",
"PaymentMethod", "Title", "PageNumber", "PaginationResult.TotalNumberOfPages"
}
};
apicall.Execute();
var orders = apicall.ApiResponse.OrderArray;

Categories

Resources