franckverrot / terraform-provider-stripe

A Terraform Provider for Stripe
https://registry.terraform.io/providers/franckverrot/stripe/latest
Mozilla Public License 2.0
242 stars 51 forks source link

Cannot set price unit_amount to 0 #42

Open adamstegman opened 3 years ago

adamstegman commented 3 years ago

When I try to create a price with a unit_amount of 0, or unit_amount_decimal of 0.0, I get the following error:

Error: {"status":400,"message":"If the billing scheme is set to per_unit, the amount parameter must be set.","param":"amount","request_id":"req_abcdefghijklmn","type":"invalid_request_error"}

When I look at Stripe logs, the field is left out of the request entirely:

{
  "active": "true",
  "billing_scheme": "per_unit",
  "currency": "usd",
  "product": "prod_abcdefghijklmn",
  "recurring": {
    "interval": "year",
    "interval_count": "1",
    "usage_type": "licensed"
  }
}

This is incorrect - an amount of 0 is valid and I can use the API directly to create the price.

adamstegman commented 3 years ago

I'm not familiar with terraform plugins, but looking at https://github.com/franckverrot/terraform-provider-stripe/blob/25ead0465e52a4fe0411a1d3908cdffc7167689b/vendor/github.com/hashicorp/terraform/helper/schema/resource_data.go#L102 it seems like GetOk incorrectly returns a non-existent value in this case. Maybe GetOkExists should be used instead, since it does not check the zero-value?

KostyaZgara commented 3 years ago

When this fix will be available?