stripe/stripe-java

Cannot Unset Invoice Settings Custom Field of a Given Customer

lpellegr opened this issue · 1 comments

Describe the bug

While trying to unset/delete an invoice settings custom field of a given customer by settings the custom field value to an empty string as suggested by the docs, I am getting the following error:

Exception in thread "main" com.stripe.exception.InvalidRequestException: You passed an empty string for 'invoice_settings[custom_fields][0][value]'. We assume empty values are an attempt to unset a parameter; however 'invoice_settings[custom_fields][0][value]' cannot be unset. You should remove 'invoice_settings[custom_fields][0][value]' from your request or supply a non-empty value.; code: parameter_invalid_empty; request-id: req_ypgFLTDg5eZgZe
at com.stripe.net.LiveStripeResponseGetter.handleApiError(LiveStripeResponseGetter.java:182)
at com.stripe.net.LiveStripeResponseGetter.handleError(LiveStripeResponseGetter.java:143)
at com.stripe.net.LiveStripeResponseGetter.request(LiveStripeResponseGetter.java:67)

To Reproduce

Create a customer with an invoice settings custom field with "VAT ID" as field key and "TEST" as value. Then, try to unset/delete this custom field by passing an empty string as suggested by the docs.

Expected behavior

I expect the custom field to be unset or deleted.

Code snippets

Customer customer = Customer.retrieve("cus_M4bawWPQy2pCWq");
System.out.println(customer.getInvoiceSettings().getCustomFields());
CustomerUpdateParams.InvoiceSettings.CustomField customField =
        new CustomerUpdateParams.InvoiceSettings.CustomField.Builder()
                .setName("VAT ID")
                .setValue("")
                .build();

CustomerUpdateParams customerUpdateParams =
        CustomerUpdateParams.builder()
                .setInvoiceSettings(
                        CustomerUpdateParams.InvoiceSettings.builder()
                                .setCustomFields(List.of(customField))
                                .build())
                .build();

customer.update(customerUpdateParams);

OS

Linux

Java version

Java 21

stripe-java version

v24.6.0

API version

2023-10-16

Additional context

Live chat support had no idea about the problem and how to solve it.

@lpellegr You need to unset the whole hash in that case and it's a bit convoluted today. You should use this code:

CustomerUpdateParams params =
  CustomerUpdateParams.builder()
    .setInvoiceSettings(
      CustomerUpdateParams.InvoiceSettings.builder()
        .putExtraParam("custom_fields", "")
        .build())
    .build();