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

Support stripe_coupon#applies_to #43

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
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ go 1.12

require (
github.com/hashicorp/terraform v0.12.6
github.com/stripe/stripe-go/v71 v71.39.0
github.com/stripe/stripe-go/v72 v72.33.0
)
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -301,8 +301,8 @@ github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.5.1 h1:nOGnQDM7FYENwehXlg/kFVnos3rEvtKTjRvOWSzb6H4=
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
github.com/stripe/stripe-go/v71 v71.39.0 h1:koL28dKJfP5aunjBU7EuCgI/TpMy/sgqrTjK4D3XO5M=
github.com/stripe/stripe-go/v71 v71.39.0/go.mod h1:BXYwMQe+xjYomcy5/qaTGyoyVMTP3wDCHa7DVFvg8+Y=
github.com/stripe/stripe-go/v72 v72.33.0 h1:7EQFx6OB0+Ze7wXMCt/VvhXk/0R478XQVtS66YFTp48=
github.com/stripe/stripe-go/v72 v72.33.0/go.mod h1:QwqJQtduHubZht9mek5sds9CtQcKFdsykV9ZepRWwo0=
github.com/svanharmelen/jsonapi v0.0.0-20180618144545-0c0828c3f16d/go.mod h1:BSTlc8jOjh0niykqEGVXOLXdi9o0r0kR8tCYiMvjFgw=
github.com/tarm/serial v0.0.0-20180830185346-98f6abe2eb07/go.mod h1:kDXzergiv9cbyO7IOYJZWg1U88JhDg3PB6klq9Hg2pA=
github.com/terraform-providers/terraform-provider-openstack v1.15.0/go.mod h1:2aQ6n/BtChAl1y2S60vebhyJyZXBsuAI5G4+lHrT1Ew=
Expand Down
4 changes: 2 additions & 2 deletions stripe/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package stripe
import (
"log"

"github.com/stripe/stripe-go/v71"
"github.com/stripe/stripe-go/v71/client"
"github.com/stripe/stripe-go/v72"
"github.com/stripe/stripe-go/v72/client"
)

// Config stores Stripe's API configuration
Expand Down
40 changes: 37 additions & 3 deletions stripe/resource_stripe_coupon.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
"time"

"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 resourceStripeCoupon() *schema.Resource {
Expand All @@ -26,6 +26,12 @@ func resourceStripeCoupon() *schema.Resource {
Type: schema.TypeString,
Required: true, // require it as the default one is more trouble than it's worth
},
"applies_to": &schema.Schema{
Type: schema.TypeSet,
Elem: &schema.Schema{Type: schema.TypeString},
Optional: true,
ForceNew: true,
},
"amount_off": &schema.Schema{
Type: schema.TypeInt,
Optional: true,
Expand Down Expand Up @@ -156,6 +162,14 @@ func resourceStripeCouponCreate(d *schema.ResourceData, m interface{}) error {
params.RedeemBy = stripe.Int64(redeemByTime.Unix())
}

if appliesTo, ok := d.GetOk("applies_to"); ok {
params.AppliesTo = &stripe.CouponAppliesToParams{}

for _, productID := range appliesTo.(*schema.Set).List() {
params.AppliesTo.Products = append(params.AppliesTo.Products, stripe.String(productID.(string)))
}
}

params.Metadata = expandMetadata(d)

coupon, err := client.Coupons.New(params)
Expand All @@ -174,7 +188,11 @@ func resourceStripeCouponCreate(d *schema.ResourceData, m interface{}) error {

func resourceStripeCouponRead(d *schema.ResourceData, m interface{}) error {
client := m.(*client.API)
coupon, err := client.Coupons.Get(d.Id(), nil)

params := &stripe.CouponParams{}
params.AddExpand("applies_to")

coupon, err := client.Coupons.Get(d.Id(), params)

if err != nil {
d.SetId("")
Expand All @@ -193,6 +211,7 @@ func resourceStripeCouponRead(d *schema.ResourceData, m interface{}) error {
d.Set("times_redeemed", coupon.TimesRedeemed)
d.Set("valid", coupon.Valid)
d.Set("created", coupon.Valid)
setCouponAppliesTo(d, coupon)
}

return err
Expand Down Expand Up @@ -229,3 +248,18 @@ func resourceStripeCouponDelete(d *schema.ResourceData, m interface{}) error {

return err
}

func setCouponAppliesTo(d *schema.ResourceData, coupon *stripe.Coupon) {
var productIDs *schema.Set

if appliesTo := coupon.AppliesTo; appliesTo != nil {
productIDs = schema.NewSet(schema.HashString, []interface{}{})

for _, productID := range appliesTo.Products {
productIDs.Add(productID)
}

}

d.Set("applies_to", productIDs)
}
4 changes: 2 additions & 2 deletions stripe/resource_stripe_plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (

"github.com/hashicorp/terraform/helper/schema"
"github.com/hashicorp/terraform/helper/validation"
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 resourceStripePlan() *schema.Resource {
Expand Down
4 changes: 2 additions & 2 deletions stripe/resource_stripe_price.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
"strconv"

"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
4 changes: 2 additions & 2 deletions stripe/resource_stripe_product.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package stripe

import (
"github.com/hashicorp/terraform/helper/schema"
"github.com/stripe/stripe-go/v71"
"github.com/stripe/stripe-go/v71/client"
"github.com/stripe/stripe-go/v72"
"github.com/stripe/stripe-go/v72/client"

"fmt"
"log"
Expand Down
4 changes: 2 additions & 2 deletions stripe/resource_stripe_tax_rate.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"log"

"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 resourceStripeTaxRate() *schema.Resource {
Expand Down
4 changes: 2 additions & 2 deletions stripe/resource_stripe_webhook_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package stripe

import (
"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"

"log"
)
Expand Down
1 change: 0 additions & 1 deletion vendor/github.com/stripe/stripe-go/v71/VERSION

This file was deleted.

65 changes: 0 additions & 65 deletions vendor/github.com/stripe/stripe-go/v71/bitcoinreceiver.go

This file was deleted.

This file was deleted.

50 changes: 0 additions & 50 deletions vendor/github.com/stripe/stripe-go/v71/bitcointransaction.go

This file was deleted.

This file was deleted.

Loading