From b50b46dac4bef8f8baf949a3ceff618e9252d9ae Mon Sep 17 00:00:00 2001 From: Jon Armen Date: Fri, 3 Jun 2022 19:53:28 -0400 Subject: [PATCH] Adding Price Tax Behavior --- README.md | 1 + main.tf | 1 + stripe/resource_stripe_price.go | 27 +++++++++++++++++-- .../github.com/stripe/stripe-go/v71/price.go | 14 +++++++++- 4 files changed, 40 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index d745aba7..dab68d4a 100644 --- a/README.md +++ b/README.md @@ -134,6 +134,7 @@ resource "stripe_coupon" "mlk_day_coupon_25pc_off" { - [x] recurring - [x] unit_amount - [x] billing_scheme + - [x] tax_behavior - [x] unit_amount_decimal - [x] tiers (Stripe API doesn't provide the API to update this at the moment, so the deletion should be done via dashboard page) - [x] tiers mode diff --git a/main.tf b/main.tf index 7efa5472..714b1099 100644 --- a/main.tf +++ b/main.tf @@ -150,6 +150,7 @@ resource "stripe_price" "my_price" { usage_type = "licensed" } billing_scheme = "per_unit" + tax_behavior = "exclusive" } resource "stripe_price" "my_graduated_price" { diff --git a/stripe/resource_stripe_price.go b/stripe/resource_stripe_price.go index cdf29502..51220e2a 100644 --- a/stripe/resource_stripe_price.go +++ b/stripe/resource_stripe_price.go @@ -6,9 +6,10 @@ import ( "log" "strconv" + "github.com/hashicorp/terraform/helper/customdiff" "github.com/hashicorp/terraform/helper/schema" - stripe "github.com/stripe/stripe-go/v71" - "github.com/stripe/stripe-go/v71/client" + stripe "github.com/stripe/stripe-go/v72" + "github.com/stripe/stripe-go/v72/client" ) func resourceStripePrice() *schema.Resource { @@ -78,6 +79,10 @@ func resourceStripePrice() *schema.Resource { Optional: true, ForceNew: true, }, + "tax_behavior": &schema.Schema{ + Type: schema.TypeString, + Optional: true, + }, "created": &schema.Schema{ Type: schema.TypeInt, Computed: true, @@ -137,6 +142,15 @@ func resourceStripePrice() *schema.Resource { ForceNew: true, }, }, + CustomizeDiff: customdiff.All( + customdiff.ForceNewIfChange("tax_behavior", func (old, new, meta interface{}) bool { + // Once specified as either inclusive or exclusive, tax behavior cannot be changed. + if old.(string) == "inclusive" || old.(string) == "exclusive" { + return old.(string) != new.(string) + } + return false + }), + ), } } @@ -218,6 +232,10 @@ func resourceStripePriceCreate(d *schema.ResourceData, m interface{}) error { params.BillingScheme = stripe.String(billingScheme.(string)) } + if taxBehavior, ok := d.GetOk("tax_behavior"); ok { + params.TaxBehavior = stripe.String(taxBehavior.(string)) + } + price, err := client.Prices.New(params) if err != nil { return err @@ -253,6 +271,7 @@ func resourceStripePriceRead(d *schema.ResourceData, m interface{}) error { // Stripe's API doesn't return tiers. // d.Set("tier", flattenPriceTiers(price.Tiers)) d.Set("billing_scheme", price.BillingScheme) + d.Set("tax_behavior", price.TaxBehavior) } return err @@ -311,6 +330,10 @@ func resourceStripePriceUpdate(d *schema.ResourceData, m interface{}) error { params.Nickname = stripe.String(d.Get("nickname").(string)) } + if d.HasChange("tax_behavior") { + params.TaxBehavior = stripe.String(d.Get("tax_behavior").(string)) + } + _, err := client.Prices.Update(d.Id(), ¶ms) if err != nil { return err diff --git a/vendor/github.com/stripe/stripe-go/v71/price.go b/vendor/github.com/stripe/stripe-go/v71/price.go index 79ad2622..6415e923 100644 --- a/vendor/github.com/stripe/stripe-go/v71/price.go +++ b/vendor/github.com/stripe/stripe-go/v71/price.go @@ -4,7 +4,7 @@ import ( "encoding/json" "strconv" - "github.com/stripe/stripe-go/v71/form" + "github.com/stripe/stripe-go/v72/form" ) // PriceBillingScheme is the list of allowed values for a price's billing scheme. @@ -16,6 +16,16 @@ const ( PriceBillingSchemeTiered PriceBillingScheme = "tiered" ) +// PriceTaxBehavior is the list of allowed values for a price's tax behavior. +type PriceTaxBehavior string + +// List of values that PriceTaxBehavior can take. +const { + PriceTaxBehaviorInclusive PriceTaxBehavior = "inclusive" + PriceTaxBehaviorExclusive PriceTaxBehavior = "exclusive" + PriceTaxBehaviorUnspecified PriceTaxBehavior = "unspecified" +} + // PriceRecurringAggregateUsage is the list of allowed values for a price's aggregate usage. type PriceRecurringAggregateUsage string @@ -124,6 +134,7 @@ type PriceParams struct { Params `form:"*"` Active *bool `form:"active"` BillingScheme *string `form:"billing_scheme"` + TaxBehavior *string `from:"tax_behavior"` Currency *string `form:"currency"` LookupKey *string `form:"lookup_key"` Nickname *string `form:"nickname"` @@ -188,6 +199,7 @@ type Price struct { APIResource Active bool `json:"active"` BillingScheme PriceBillingScheme `json:"billing_scheme"` + TaxBehavior PriceTaxBehavior `json:"tax_behavior"` Created int64 `json:"created"` Currency Currency `json:"currency"` Deleted bool `json:"deleted"`