Reputation: 6121
In my workflow I am creating a new customer with a valid payment method and want to set that as default (to apply to subscription billing)
Based on the docs it seems if I'm using PaymentsIntent I need to set DefaultPaymentMethod inside InvoiceSettings and IntelliSense matches everything up as expected. https://stripe.com/docs/api/customers/create#create_customer-invoice_settings-default_payment_method
When I actually create the options object (not even making the Create call) I get the below error
{System.NullReferenceException: Object reference not set to an instance of an object. at ... [offending code below]
var customerOptions = new CustomerCreateOptions
{
Email = user.Email,
Name = user.FirstName + ' ' + user.LastName,
PaymentMethod = model.payment_method,
InvoiceSettings =
{
DefaultPaymentMethod = model.payment_method
}
};
If I remove the InvoiceSettings param everything works perfectly, except their payment method is not set as default. I have also tried with null in DefaultPaymentMethod, same error.
How can I, during customer creation, set their payment method as default?
Upvotes: 0
Views: 972
Reputation: 3105
You'll need to initialize an instance of CustomerInvoiceSettingsOptions
to pass as the InvoiceSettings
which you can do with the following:
var customerOptions = new CustomerCreateOptions
{
Email = user.Email,
Name = user.FirstName + ' ' + user.LastName,
PaymentMethod = model.payment_method,
InvoiceSettings = new CustomerInvoiceSettingsOptions
{
DefaultPaymentMethod = model.payment_method
}
};
Upvotes: 1