Subscription payment must be up and running for SCA - c#

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?

Related

Stripe - how add product on the connected account?

I try add payment method to my project where customer can buy product from other user. But i have problem because when i use it:
LineItems = new List<SessionLineItemOptions>
{
new SessionLineItemOptions
{
Price = "{{PRICE_ID}}",
Quantity = 1,
},
},
Mode = "payment",
SuccessUrl = "https://example.com/success",
CancelUrl = "https://example.com/cancel",
PaymentIntentData = new SessionPaymentIntentDataOptions
{
ApplicationFeeAmount = 123,
},
};
var requestOptions = new RequestOptions
{
StripeAccount = "{{CONNECTED_ACCOUNT_ID}}",
};
var service = new SessionService();
Session session = service.Create(options, requestOptions);
PRICE_ID can't be price's on my main stripe account and i must create product and price on the connected account.
In the case of creating a product on the main account, I do it like this:
var options = new ProductCreateOptions
{
Id = ProductId.ToString(),
Name = "Product_name",
DefaultPriceData = new ProductDefaultPriceDataOptions
{
UnitAmount = price,
Currency = "pln"
},
Expand = new List<string> { "default_price" },
};
_productService.Create(options);
How create product and price on the connected account with my api?
The Stripe API has a Stripe-Account header where you can pass in the ID of one of your connected accounts to make the call as that account. In C# that would look like this:
{
Id = ProductId.ToString(),
Name = "Product_name",
DefaultPriceData = new ProductDefaultPriceDataOptions
{
UnitAmount = price,
Currency = "pln"
},
Expand = new List<string> { "default_price" },
StripeAccount = "acct_123456789",
};
_productService.Create(options);

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.

Invoicer PDF gives null but Membership does not give PDF null

My problem as it is right now. It is that I must have made such that a customer can buy an item that is only paid once. Thus assigned Invoice id and PDf to the database.
As it is right now I only get hold of Invoice id while PDF is null.
I've read a little more about this.
Invoice Id return with null after change using Stripe
var options = new ProductCreateOptions
{
Name = "Starter Setup",
};
var service = new ProductService();
var product = service.Create(options);
var optionsA = new PriceCreateOptions
{
Product = product.Id,
UnitAmount = 2000,
Currency = "usd",
};
var serviceA = new PriceService();
var price = serviceA.Create(optionsA);
var optionsB = new CustomerCreateOptions
{
Email = model.Mail,
Name = model.FuldName,
Source = token
};
var serviceB = new CustomerService();
var customer = serviceB.Create(optionsB);
var optionsC = new InvoiceItemCreateOptions
{
Customer = customer.Id,
Price = price.Id,
};
var serviceC = new InvoiceItemService();
var invoiceItem = serviceC.Create(optionsC);
var invoiceId = invoiceItem.Id;
var serviceE = new InvoiceService();
var f = serviceE.Get(invoiceId);
var pdf = f.InvoicePdf;// This here gives zero.
If I do it this way, I'll get this out of it. I get the Invoice ID that I want here but I get nothing on the invoice that shows that it is zero.
{
"id": "ii_1IR4UtFnB7TvDVRrzPwWo8ZW",
"object": "invoiceitem",
"amount": 2000,
"currency": "usd",
"customer": "cus_J3Aqpyt4PwqCcN",
"date": 1614815575,
"description": "Starter Setup",
"discountable": true,
"discounts": [
],
"invoice": null,
"livemode": false,
"metadata": {
},
....
}
With this, my thinking is whether I will in a way be able to make such that I make a membership which then stops immediately but that it says in the invoice that the purchase is only of a single item and not several months.
The way I have done it in relation to membership I have done like this.
var createCustomer = new CustomerCreateOptions
{
Source = token,
Name = model.FuldName,
Email = model.Mail
};
var addService = new CustomerService();
var customer = addService.Create(createCustomer);
var optionsProduct = new ProductCreateOptions
{
Name = $"Single buy - {DateTime.Now} - Kursus Id : {id}",
Type = "service",
};
var serviceProduct = new ProductService();
Product product = serviceProduct.Create(optionsProduct);
var optionsPlan = new PlanCreateOptions
{
Currency = "dkk",
Interval = Helpers.Stripe.interval,
Nickname =
$"Single buy - {DateTime.Now} - Kursus Id : {id}",
Amount = amount,
Product = product.Id,
IntervalCount = 1
};
var servicePlan = new PlanService();
Plan plan = servicePlan.Create(optionsPlan);
var items = new List<SubscriptionItemOptions>()
{
new SubscriptionItemOptions()
{
Plan = plan.Id,
Quantity = 1
},
};
var createSubscruptionA = new SubscriptionCreateOptions
{
Customer = customer.Id,
Items = items,
OffSession = true,
};
var addserviceA = new SubscriptionService();
Subscription subscription = addserviceA.Create(createSubscruptionA);
var invoiceId = subscription.LatestInvoiceId;
var service = new InvoiceService();
var pdf = service.Get(invoiceId).InvoicePdf;
That which I would like to achieve by this. It is that I can get hold of PDF and Invoice id as I will use it for my system in the future etc.
EDIT
var optionsB = new CustomerCreateOptions
{
Email = model.Mail,
Name = model.FuldName,
Source = token
};
var serviceB = new CustomerService();
var customer = serviceB.Create(optionsB);
var optionsC = new InvoiceItemCreateOptions
{
Customer = customer.Id,
Price = price.Id,
};
var serviceC = new InvoiceItemService();
var invoiceItem = serviceC.Create(optionsC);
var invoiceId = invoiceItem.Id;
var invoiceOptions = new InvoiceCreateOptions
{
Customer = customer.Id,
AutoAdvance = true,
};
var invoiceService = new InvoiceService();
var invoice = invoiceService.Create(invoiceOptions);
For one-off Invoices you need to create Invoice Items for the Customer (as you've done), but importantly you then need to create an Invoice that will contain those Items.
This line is not correct for what you're trying to accomplish:
var invoiceId = invoiceItem.Id;
Instead, you need to create the invoice as shown in the docs linked above:
var invoiceOptions = new InvoiceCreateOptions
{
Customer = "cus_123",
AutoAdvance = true,
};
var invoiceService = new InvoiceService();
var invoice = invoiceService.Create(invoiceOptions);
The Invoice object will have an invoice_pdf URL (docs) after you finalize it.
var service = new InvoiceService();
service.FinalizeInvoice(
"in_123"
);

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.

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