Skip to content

Commit

Permalink
Use GetOkExists for price amounts
Browse files Browse the repository at this point in the history
This allows for a `0` price to be set as a price `amount` in Stripe.

`GetOk` considers `0` as a null value for integers, because it's unclear whether it was intentionally set or unset.
`GetOkExists` allows us to get whatever value was set, even if it's `0`.

Fixes franckverrot#42
  • Loading branch information
adamstegman committed Jun 23, 2021
1 parent 2d8db1a commit f6189ec
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions stripe/resource_stripe_price.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,11 +206,11 @@ func resourceStripePriceCreate(d *schema.ResourceData, m interface{}) error {
params.Recurring = recurringParams
}

if unitAmount, ok := d.GetOk("unit_amount"); ok {
if unitAmount, ok := d.GetOkExists("unit_amount"); ok {
params.UnitAmount = stripe.Int64(int64(unitAmount.(int)))
}

if unitAmountDecimal, ok := d.GetOk("unit_amount_decimal"); ok {
if unitAmountDecimal, ok := d.GetOkExists("unit_amount_decimal"); ok {
params.UnitAmountDecimal = stripe.Float64(unitAmountDecimal.(float64))
}

Expand Down

0 comments on commit f6189ec

Please sign in to comment.