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.
Related
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);
I am using the .NET API for Recurly, and I am trying to add an addon to a subscription. Here is my code that I used to create the addon:
var addOnReq = new AddOnCreate()
{
Code = "myCode",
Name = "myName",
DefaultQuantity = 1,
Currencies = new List<AddOnPricing>() {
new AddOnPricing() {
Currency = "USD",
UnitAmount = 100,
UnitAmountDecimal = "100.00"
}
}
};
AddOn addOn = RecurlyClient.CreatePlanAddOn("myPlanId", addOnReq);
And here is the code I am trying to execute when adding the addon to a subscription of the plan in which the addon was added:
var changeReq = new SubscriptionChangeCreate()
{
Timeframe = RecurlyConstants.ChangeTimeframe.Now,
AddOns = new List<SubscriptionAddOnUpdate>() {
new SubscriptionAddOnUpdate() {
Code = "myCode"
}
}
};
foreach (var addOnn in changeReq.AddOns)
{
addOnn.UnitAmount = 100;
}
SubscriptionChange change = RecurlyClient.CreateSubscriptionChange("mySubscriptionId", changeReq);
This is the error I get back in an exception:
Add-ons add on is invalid
What am I doing wrong? Any support is appreciated.
This is a fixed based add on. The recurly documentation is not proving to be helpful, I think.
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.
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?
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