Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Price Tax Behavior #61

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down
27 changes: 25 additions & 2 deletions stripe/resource_stripe_price.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
}),
),
}
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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(), &params)
if err != nil {
return err
Expand Down
14 changes: 13 additions & 1 deletion vendor/github.com/stripe/stripe-go/v71/price.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.