### Install Golang Color Library Source: https://github.com/lukasaron/terraform-provider-stripe/blob/main/vendor/github.com/fatih/color/README.md Use 'go get' to install the color library. This is the initial setup step. ```bash go get github.com/fatih/color ``` -------------------------------- ### Install go-version Source: https://github.com/lukasaron/terraform-provider-stripe/blob/main/vendor/github.com/hashicorp/go-version/README.md Install the go-version library using go get. ```bash $ go get github.com/hashicorp/go-version ``` -------------------------------- ### Install go-isatty Source: https://github.com/lukasaron/terraform-provider-stripe/blob/main/vendor/github.com/mattn/go-isatty/README.md Install the go-isatty package using the go get command. ```bash go get github.com/mattn/go-isatty ``` -------------------------------- ### Install tagparser Source: https://github.com/lukasaron/terraform-provider-stripe/blob/main/vendor/github.com/vmihailenco/tagparser/v2/README.md Use `go get` to install the tagparser library. ```shell go get github.com/vmihailenco/tagparser/v2 ``` -------------------------------- ### Install msgpack/v5 Source: https://github.com/lukasaron/terraform-provider-stripe/blob/main/vendor/github.com/vmihailenco/msgpack/v5/README.md Install the msgpack/v5 library using go get. Ensure you are using Go modules. ```shell go mod init github.com/my/repo ``` ```shell go get github.com/vmihailenco/msgpack/v5 ``` -------------------------------- ### Install Levenshtein Package Source: https://github.com/lukasaron/terraform-provider-stripe/blob/main/vendor/github.com/agext/levenshtein/README.md Use 'go get' to install the package. This command fetches and installs the specified package, making it available for use in your Go projects. ```go go get github.com/agext/levenshtein ``` -------------------------------- ### Full Product Example Source: https://github.com/lukasaron/terraform-provider-stripe/blob/main/docs/resources/stripe_product.md This example shows how to create a Stripe product with several optional arguments, including unit label, description, and URL. ```APIDOC ## stripe_product.product (Full) ### Description Creates a Stripe product with additional configuration options. ### Arguments * `name` - (Required) String. The product’s name, meant to be displayable to the customer. * `unit_label` - (Optional) String. A label that represents units of this product. * `description` - (Optional) String. The product’s description, meant to be displayable to the customer. * `url` - (Optional) String. A URL of a publicly-accessible webpage for this product. ### Example ```hcl resource "stripe_product" "product" { name = "full product" unit_label = "piece" description = "fantastic product" url = "https://www.terraform.io" } ``` ``` -------------------------------- ### Install msgpack Go Package Source: https://github.com/lukasaron/terraform-provider-stripe/blob/main/vendor/github.com/vmihailenco/msgpack/README.md Use 'go get' to install or update the msgpack package. ```shell go get -u github.com/vmihailenco/msgpack ``` -------------------------------- ### Install copystructure Source: https://github.com/lukasaron/terraform-provider-stripe/blob/main/vendor/github.com/mitchellh/copystructure/README.md Use `go get` to install the copystructure library. This is the standard method for obtaining Go packages. ```bash $ go get github.com/mitchellh/copystructure ``` -------------------------------- ### Install mapstructure Go Library Source: https://github.com/lukasaron/terraform-provider-stripe/blob/main/vendor/github.com/mitchellh/mapstructure/README.md Use standard go get command to install the mapstructure library. ```bash go get github.com/mitchellh/mapstructure ``` -------------------------------- ### Install go-colorable Package Source: https://github.com/lukasaron/terraform-provider-stripe/blob/main/vendor/github.com/mattn/go-colorable/README.md Install the go-colorable package using the go get command. This is a prerequisite for using the package in your Go projects. ```bash go get github.com/mattn/go-colorable ``` -------------------------------- ### Install Beta Version of Stripe Go SDK Source: https://github.com/lukasaron/terraform-provider-stripe/blob/main/vendor/github.com/stripe/stripe-go/v78/README.md Install a beta version of the stripe-go package using the commit notation with the `go get` command. Be aware of potential breaking changes between beta versions. ```bash go get -u github.com/stripe/stripe-go/v78@v77.1.0-beta.1 ``` -------------------------------- ### Minimal Product Example Source: https://github.com/lukasaron/terraform-provider-stripe/blob/main/docs/resources/stripe_product.md This example demonstrates the creation of a minimal Stripe product with only the required 'name' argument. ```APIDOC ## stripe_product.product (Minimal) ### Description Creates a minimal Stripe product. ### Arguments * `name` - (Required) String. The product’s name, meant to be displayable to the customer. ### Example ```hcl resource "stripe_product" "product" { name = "minimalist product" } ``` ``` -------------------------------- ### Quickstart: Marshal and Unmarshal Data in Go Source: https://github.com/lukasaron/terraform-provider-stripe/blob/main/vendor/github.com/vmihailenco/msgpack/v5/README.md Demonstrates basic usage of msgpack for encoding (Marshal) and decoding (Unmarshal) a Go struct. Includes error handling. ```go import "github.com/vmihailenco/msgpack/v5" func ExampleMarshal() { type Item struct { Foo string } b, err := msgpack.Marshal(&Item{Foo: "bar"}) if err != nil { panic(err) } var item Item err = msgpack.Unmarshal(b, &item) if err != nil { panic(err) } fmt.Println(item.Foo) // Output: bar } ``` -------------------------------- ### Creating a Promotion Code Source: https://github.com/lukasaron/terraform-provider-stripe/blob/main/docs/resources/stripe_promotion_code.md This example demonstrates how to create a basic promotion code associated with a coupon. ```APIDOC ## Create Promotion Code ### Description Creates a promotion code for a given coupon. ### Method POST ### Endpoint /v1/promotion_codes ### Parameters #### Request Body - **coupon** (string) - Required - The coupon for this promotion code. - **code** (string) - Optional - The customer-facing code. If left blank, a code will be generated automatically. - **active** (boolean) - Optional - Whether the promotion code is currently active. Defaults to `true`. - **customer** (string) - Optional - The customer that this promotion code can be used by. If not set, it can be used by all customers. - **max_redemptions** (integer) - Optional - A positive integer specifying the number of times the promotion code can be redeemed. - **expires_at** (string) - Optional - The timestamp at which this promotion code will expire. Expected format is `RFC3339`. - **restrictions** (object) - Optional - Settings that restrict the redemption of the promotion code. - **first_time_transaction** (boolean) - Required - Indicates if the Promotion Code should only be redeemed for Customers without any successful payments or invoices. - **minimum_amount** (integer) - Optional - Minimum amount required to redeem this Promotion Code (e.g., a purchase must be $100 or more). - **minimum_amount_currency** (string) - Optional - Three-letter ISO code for `minimum_amount`. - **metadata** (map[string]) - Optional - Set of key-value pairs that you can attach to an object. ### Request Example ```json { "coupon": "coupon_id", "code": "FREE", "max_redemptions": 5, "expires_at": "2025-08-03T08:37:18+00:00", "restrictions": { "first_time_transaction": true, "minimum_amount": 100, "minimum_amount_currency": "aud" } } ``` ### Response #### Success Response (200) - **id** (string) - The unique identifier for the object. - **coupon** (string) - The coupon for this promotion code. - **code** (string) - The customer-facing code. - **active** (boolean) - Whether the promotion code is currently active. - **customer** (string) - The customer that this promotion code can be used by. - **max_redemptions** (integer) - A positive integer specifying the number of times the promotion code can be redeemed. - **expires_at** (string) - The timestamp at which this promotion code will expire. - **restrictions** (object) - Settings that restrict the redemption of the promotion code. - **metadata** (map[string]) - Set of key-value pairs that you can attach to an object. #### Response Example ```json { "id": "promo_code_id", "coupon": "coupon_id", "code": "FREE", "active": true, "customer": null, "max_redemptions": 5, "expires_at": "2025-08-03T08:37:18+00:00", "restrictions": { "first_time_transaction": true, "minimum_amount": 100, "minimum_amount_currency": "aud" }, "metadata": {} } ``` ``` -------------------------------- ### Quickstart: Marshal and Unmarshal Struct Source: https://github.com/lukasaron/terraform-provider-stripe/blob/main/vendor/github.com/vmihailenco/msgpack/README.md Demonstrates basic usage of msgpack.Marshal and msgpack.Unmarshal to encode and decode a Go struct. Ensure error handling for production code. ```go func ExampleMarshal() { type Item struct { Foo string } b, err := msgpack.Marshal(&Item{Foo: "bar"}) if err != nil { panic(err) } var item Item err = msgpack.Unmarshal(b, &item) if err != nil { panic(err) } fmt.Println(item.Foo) // Output: bar } ``` -------------------------------- ### Create a coupon with percentage off Source: https://github.com/lukasaron/terraform-provider-stripe/blob/main/docs/resources/stripe_coupon.md Example of creating a coupon that provides a percentage off. ```APIDOC ## Resource: stripe_coupon ### Description Creates a coupon that provides a percentage off. ### Arguments * `name` - (Optional) String. Name of the coupon. * `percent_off` - (Optional) Float. Percentage to be taken off the subtotal. * `duration` - (Optional) String. How long the discount lasts (`forever`, `once`, `repeating`). ### Example ```hcl resource "stripe_coupon" "coupon" { name = "33.3% discount" percent_off = 33.3 duration = "forever" } ``` ``` -------------------------------- ### Install gRPC-Go Source: https://github.com/lukasaron/terraform-provider-stripe/blob/main/vendor/google.golang.org/grpc/README.md Add this import to your Go code to automatically fetch gRPC-Go dependencies during build, run, or test commands. ```go import "google.golang.org/grpc" ``` -------------------------------- ### Get App Engine Go SDK Package Source: https://github.com/lukasaron/terraform-provider-stripe/blob/main/vendor/google.golang.org/appengine/CONTRIBUTING.md Use 'go get' to download the App Engine Go SDK package. Ensure you use the '-d' flag to only download sources without installing. ```go go get -d google.golang.org/appengine ``` -------------------------------- ### HCL Native Syntax Example Source: https://github.com/lukasaron/terraform-provider-stripe/blob/main/vendor/github.com/hashicorp/hcl/v2/README.md Illustrates the native HCL syntax with attributes and nested blocks for defining a service configuration. ```hcl io_mode = "async" service "http" "web_proxy" { listen_addr = "127.0.0.1:8080" process "main" { command = ["/usr/local/bin/awesome-app", "server"] } process "mgmt" { command = ["/usr/local/bin/awesome-app", "mgmt"] } } ``` -------------------------------- ### Create a New Customer Source: https://github.com/lukasaron/terraform-provider-stripe/blob/main/vendor/github.com/stripe/stripe-go/v78/README.md Example of creating a new Stripe customer with specified parameters like description, email, and preferred locales. ```go params := &stripe.CustomerParams{ Description: stripe.String("Stripe Developer"), Email: stripe.String("gostripe@stripe.com"), PreferredLocales: stripe.StringSlice([]string{"en", "es"}), } c, err := customer.New(params) ``` -------------------------------- ### Yamux Server Setup and Stream Acceptance Source: https://github.com/lukasaron/terraform-provider-stripe/blob/main/vendor/github.com/hashicorp/yamux/README.md Illustrates how to set up a Yamux server session to accept incoming TCP connections and handle new streams. It shows how to read data from an accepted stream. ```go func server() { // Accept a TCP connection conn, err := listener.Accept() if err != nil { panic(err) } // Setup server side of yamux session, err := yamux.Server(conn, nil) if err != nil { panic(err) } // Accept a stream stream, err := session.Accept() if err != nil { panic(err) } // Listen for a message buf := make([]byte, 4) stream.Read(buf) } ``` -------------------------------- ### Create a coupon with amount off Source: https://github.com/lukasaron/terraform-provider-stripe/blob/main/docs/resources/stripe_coupon.md Example of creating a coupon that provides a fixed amount off. ```APIDOC ## Resource: stripe_coupon ### Description Creates a coupon that provides a fixed amount off. ### Arguments * `name` - (Optional) String. Name of the coupon. * `amount_off` - (Optional) Int. Amount to be taken off the subtotal. * `currency` - (Optional) String. Required if `amount_off` is set. ISO currency code. * `duration` - (Optional) String. How long the discount lasts (`forever`, `once`, `repeating`). * `max_redemptions` - (Optional) Int. Maximum number of times the coupon can be redeemed. ### Example ```hcl resource "stripe_coupon" "coupon" { name = "$10 amount off" amount_off = 1000 currency = "aud" duration = "once" max_redemptions = 10 } ``` ``` -------------------------------- ### Shipping Rate with Currency Options Source: https://github.com/lukasaron/terraform-provider-stripe/blob/main/docs/resources/stripe_shipping_rate.md An example demonstrating how to configure a shipping rate with multiple currency options. ```APIDOC ## Resource: stripe_shipping_rate ### Description Creates a shipping rate with multiple currency options for the fixed amount. ### Arguments * `display_name` - (Required) String. The name of the shipping rate, meant to be displayable to the customer. * `fixed_amount` - (Required) List(Resource). Describes a fixed amount to charge for shipping. * `amount` - (Required) Int. A non-negative integer in cents representing how much to charge. * `currency` - (Required) String. Three-letter ISO currency code, in lowercase. * `currency_option` - (Optional) List(Resource). Additional currency options for the fixed amount. * `currency` - (Required) String. Three-letter ISO currency code, in lowercase. * `amount` - (Required) Int. A non-negative integer in cents representing how much to charge. * `tax_behavior` - (Optional) String. Specifies whether the price is considered inclusive of taxes or exclusive of taxes. ### Note When multiple `currency_options` are defined, sorting by the `currency` field is mandatory. ### Example Usage ```hcl // shipping rate with currency options // !!! Currency options have to be sorted alphabetically // !!! by the currency field resource "stripe_shipping_rate" "shipping" { display_name = "shipping rate" fixed_amount { amount = 1000 currency = "aud" currency_option { currency = "eur" amount = 350 } currency_option { currency = "usd" amount = 500 } } } ``` ``` -------------------------------- ### Wrap String Example in Go Source: https://github.com/lukasaron/terraform-provider-stripe/blob/main/vendor/github.com/mitchellh/go-wordwrap/README.md Demonstrates basic usage of the WrapString function to wrap a given string to a specified width. Ensure the 'fmt' package is imported for printing. ```go wrapped := wordwrap.WrapString("foo bar baz", 3) fmt.Println(wrapped) ``` -------------------------------- ### Get Stripe Go Package Source: https://github.com/lukasaron/terraform-provider-stripe/blob/main/vendor/github.com/stripe/stripe-go/v78/README.md Alternatively, explicitly fetch the stripe-go package into your project using go get. ```bash go get -u github.com/stripe/stripe-go/v78 ``` -------------------------------- ### Yamux Client Setup and Stream Usage Source: https://github.com/lukasaron/terraform-provider-stripe/blob/main/vendor/github.com/hashicorp/yamux/README.md Demonstrates how to set up a Yamux client session over a TCP connection and open a new stream for communication. The stream can be used like a standard net.Conn. ```go func client() { // Get a TCP connection conn, err := net.Dial(...) if err != nil { panic(err) } // Setup client side of yamux session, err := yamux.Client(conn, nil) if err != nil { panic(err) } // Open a new stream stream, err := session.Open() if err != nil { panic(err) } // Stream implements net.Conn stream.Write([]byte("ping")) } ``` -------------------------------- ### Create a Sample Stripe Meter Source: https://github.com/lukasaron/terraform-provider-stripe/blob/main/docs/resources/stripe_meter.md This example demonstrates how to create a basic billing meter with display name, event name, customer mapping, default aggregation, and value settings. ```hcl resource "stripe_meter" "sample_meter" { display_name = "A Sample meter" event_name = "sample_meter" customer_mapping { event_payload_key = "stripe_customer_id" type = "by_id" } default_aggregation { formula = "sum" } value_settings { event_payload_key = "value" } } ``` -------------------------------- ### HCL JSON Representation Example Source: https://github.com/lukasaron/terraform-provider-stripe/blob/main/vendor/github.com/hashicorp/hcl/v2/README.md Shows the JSON equivalent of the HCL native syntax configuration, demonstrating the mapping of attributes and blocks. ```json { "io_mode": "async", "service": { "http": { "web_proxy": { "listen_addr": "127.0.0.1:8080", "process": { "main": { "command": ["/usr/local/bin/awesome-app", "server"] }, "mgmt": { "command": ["/usr/local/bin/awesome-app", "mgmt"] }, } } } } } ``` -------------------------------- ### Basic Portal Configuration Source: https://github.com/lukasaron/terraform-provider-stripe/blob/main/docs/resources/stripe_portal_configuration.md Creates a basic portal configuration with payment method updates disabled. Use this for a minimal setup. ```hcl resource "stripe_portal_configuration" "portal_configuration" { business_profile { privacy_policy_url = "https://example.com/privacy" terms_of_service_url = "https://example.com/terms" } features { payment_method_update { enabled = false } } } ``` -------------------------------- ### Testing Webhook Signing Source: https://github.com/lukasaron/terraform-provider-stripe/blob/main/vendor/github.com/stripe/stripe-go/v78/README.md Provides an example of how to use `webhook.GenerateTestSignedPayload` and `webhook.ConstructEvent` to mock and verify signed webhook events for testing purposes. ```APIDOC ## Testing Webhook signing You can use `stripe.webhook.GenerateTestSignedPayload` to mock webhook events that come from Stripe: ```go payload := map[string]interface{}{ "id": "evt_test_webhook", "object": "event", "api_version": stripe.APIVersion, } testSecret := "whsec_test_secret" payloadBytes, err := json.Marshal(payload) signedPayload := webhook.GenerateTestSignedPayload(&webhook.UnsignedPayload{Payload: payloadBytes, Secret: testSecret}) event, err := webhook.ConstructEvent(signedPayload.Payload, signedPayload.Header, signedPayload.Secret) if event.ID == payload["id"] { // Do something with the mocked signed event } else { // Handle invalid event payload } ``` ``` -------------------------------- ### Enable Datastore Key Conversion for Basic/Manual Scaling Source: https://github.com/lukasaron/terraform-provider-stripe/blob/main/vendor/google.golang.org/appengine/README.md Enable automatic conversion from cloud.google.com/go/datastore keys to google.golang.org/appengine/datastore keys by calling EnableKeyConversion in the /_ah/start handler. This setup applies to all handlers in the service. ```go http.HandleFunc("/_ah/start", func(w http.ResponseWriter, r *http.Request) { datastore.EnableKeyConversion(appengine.NewContext(r)) }) ``` -------------------------------- ### Shipping Rate with Multiple Currency Options Source: https://github.com/lukasaron/terraform-provider-stripe/blob/main/docs/resources/stripe_shipping_rate.md This example demonstrates setting up a shipping rate with multiple currency options. It's crucial that the currency options are sorted alphabetically by the currency field to avoid provider issues. ```hcl resource "stripe_shipping_rate" "shipping" { display_name = "shipping rate" fixed_amount { amount = 1000 currency = "aud" currency_option { currency = "eur" amount = 350 } currency_option { currency = "usd" amount = 500 } } } ``` -------------------------------- ### Create a coupon with specific applicability and expiry Source: https://github.com/lukasaron/terraform-provider-stripe/blob/main/docs/resources/stripe_coupon.md Example of creating a coupon with a fixed amount off, an expiry date, and limited to specific products. ```APIDOC ## Resource: stripe_coupon ### Description Creates a coupon with specific applicability and expiry. ### Arguments * `name` - (Optional) String. Name of the coupon. * `amount_off` - (Optional) Int. Amount to be taken off the subtotal. * `duration` - (Optional) String. How long the discount lasts (`forever`, `once`, `repeating`). * `redeem_by` - (Optional) String. Date after which the coupon can no longer be redeemed (RFC3339 format). * `applies_to` - (Optional) List(String). A list of product IDs this coupon applies to. ### Example ```hcl resource "stripe_coupon" "coupon" { name = "applies to prod with ID 123 till a date" amount_off = 2000 duration = "once" redeem_by = "2025-07-23T03:27:06+00:00" applies_to = [stripe_product.product.id] } ``` ``` -------------------------------- ### Example Usage of `with` Function in HCL Syntax Source: https://github.com/lukasaron/terraform-provider-stripe/blob/main/vendor/github.com/hashicorp/hcl/v2/ext/customdecode/README.md Demonstrates how to use the `with` function in native HCL syntax to evaluate an expression with locally defined variables. Be cautious as this makes expressions context-sensitive. ```hcl foo = with({name = "Cory"}, "${greeting}, ${name}!") ``` -------------------------------- ### Full Portal Configuration with All Options Source: https://github.com/lukasaron/terraform-provider-stripe/blob/main/docs/resources/stripe_portal_configuration.md A comprehensive billing portal configuration utilizing all available options, including customer updates, subscription management with cancellation reasons, and product/price selection for updates. This example demonstrates advanced customization. ```hcl resource "stripe_portal_configuration" "portal_configuration" { business_profile { headline = "My special headline" privacy_policy_url = "https://example.com/privacy" terms_of_service_url = "https://example.com/terms" } default_return_url = "https://example.com/special_headline" features { customer_update { enabled = true allowed_updates = ["email", "address", "shipping", "phone", "tax_id"] } invoice_history { enabled = true } payment_method_update { enabled = true } subscription_cancel { enabled = true cancellation_reason { enabled = true options = ["too_expensive", "missing_features", "switched_service", "unused", "customer_service", "too_complex", "low_quality", "other"] } mode = "at_period_end" proration_behavior = "none" } subscription_update { enabled = true default_allowed_updates = ["price", "quantity", "promotion_code"] proration_behavior = "none" products { product = "my_product_id" prices = ["my_price_id1", "my_price_id2"] } } } metadata = { foo = "bar" } } ``` -------------------------------- ### Initialize Go Modules Source: https://github.com/lukasaron/terraform-provider-stripe/blob/main/vendor/github.com/stripe/stripe-go/v78/README.md Ensure your project is set up with Go Modules by running this command in the project root. ```sh go mod init ``` -------------------------------- ### Initializing pointer fields with helper functions Source: https://github.com/lukasaron/terraform-provider-stripe/blob/main/vendor/github.com/stripe/stripe-go/v78/v32_migration_guide.md Demonstrates how to initialize pointer fields using helper functions like `stripe.Int64` to set explicit zero values. ```go UsageRecord { Quantity: stripe.Int64(0), } ``` -------------------------------- ### Template Literal Strip Marker Example Source: https://github.com/lukasaron/terraform-provider-stripe/blob/main/vendor/github.com/hashicorp/hcl/v2/hclsyntax/spec.md Demonstrates the use of strip markers (~) within template literals to remove adjacent whitespace. The first example shows stripping around an interpolation, while the second shows stripping around a directive. ```hcl hello ${~ "world" } ``` ```hcl %{ if true ~} hello %{~ endif } ``` -------------------------------- ### Shipping Rate with Delivery Estimate Source: https://github.com/lukasaron/terraform-provider-stripe/blob/main/docs/resources/stripe_shipping_rate.md An example of creating a shipping rate that includes estimated delivery times. ```APIDOC ## Resource: stripe_shipping_rate ### Description Creates a shipping rate with a display name, fixed amount, and delivery estimate. ### Arguments * `display_name` - (Required) String. The name of the shipping rate, meant to be displayable to the customer. * `fixed_amount` - (Required) List(Resource). Describes a fixed amount to charge for shipping. * `amount` - (Required) Int. A non-negative integer in cents representing how much to charge. * `currency` - (Required) String. Three-letter ISO currency code, in lowercase. * `delivery_estimate` - (Optional) List(Resource). The estimated range for how long shipping will take. * `minimum` - (Required) List(Resource). The lower bound of the estimated range. * `unit` - (Required) String. A unit of time (`hour`, `day`, `business_day`, `week`, `month`). * `value` - (Required) Int. Must be greater than 0. * `maximum` - (Required) List(Resource). The upper bound of the estimated range. * `unit` - (Required) String. A unit of time (`hour`, `day`, `business_day`, `week`, `month`). * `value` - (Required) Int. Must be greater than 0. ### Example Usage ```hcl resource "stripe_shipping_rate" "shipping_rate" { display_name = "shipping rate" fixed_amount { amount = 1000 currency = "aud" } delivery_estimate { minimum { unit = "hour" value = 24 } maximum { unit = "day" value = 4 } } } ``` ``` -------------------------------- ### Minimal Stripe Product Creation Source: https://github.com/lukasaron/terraform-provider-stripe/blob/main/docs/resources/stripe_product.md This snippet demonstrates the minimum configuration required to create a product resource. ```hcl resource "stripe_product" "product" { name = "minimalist product" } ``` -------------------------------- ### HCL JSON Interpolation Example Source: https://github.com/lukasaron/terraform-provider-stripe/blob/main/vendor/github.com/hashicorp/hcl/v2/README.md Illustrates how HCL expressions and interpolation are represented within JSON strings. ```json { "sum": "${1 + addend}", "message": "Hello, ${name}!", "shouty_message": "${upper(message)}" } ``` -------------------------------- ### Minimal Shipping Rate Source: https://github.com/lukasaron/terraform-provider-stripe/blob/main/docs/resources/stripe_shipping_rate.md A basic example of creating a shipping rate with a display name and a fixed amount. ```APIDOC ## Resource: stripe_shipping_rate ### Description Creates a shipping rate with a display name and a fixed amount. ### Arguments * `display_name` - (Required) String. The name of the shipping rate, meant to be displayable to the customer. * `fixed_amount` - (Required) List(Resource). Describes a fixed amount to charge for shipping. * `amount` - (Required) Int. A non-negative integer in cents representing how much to charge. * `currency` - (Required) String. Three-letter ISO currency code, in lowercase. ### Example Usage ```hcl resource "stripe_shipping_rate" "shipping_rate" { display_name = "minimal shipping rate" fixed_amount { amount = 1000 currency = "aud" } } ``` ``` -------------------------------- ### Initialize and Use Mocked Stripe Client in Go Source: https://github.com/lukasaron/terraform-provider-stripe/blob/main/vendor/github.com/stripe/stripe-go/v78/README.md Demonstrates how to use a mocked Stripe backend to initialize and call methods on the client for unit testing. Ensure the mock controller is finished and mock expectations are set correctly. ```go import ( "example/hello/mocks" "testing" "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" "github.com/stripe/stripe-go/v78" "github.com/stripe/stripe-go/v78/account" ) func UseMockedStripeClient(t *testing.T) { // Create a mock controller mockCtrl := gomock.NewController(t) defer mockCtrl.Finish() // Create a mock stripe backend mockBackend := mocks.NewMockBackend(mockCtrl) client := account.Client{B: mockBackend, Key: "key_123"} // Set up a mock call mockBackend.EXPECT().Call("GET", "/v1/accounts/acc_123", gomock.Any(), gomock.Any(), gomock.Any()). // Return nil error Return(nil). Do(func(method string, path string, key string, params stripe.ParamsContainer, v *stripe.Account) { // Set the return value for the method *v = stripe.Account{ ID: "acc_123", } }).Times(1) // Call the client method acc, _ := client.GetByID("acc_123", nil) // Asset the result assert.Equal(t, acc.ID, "acc_123") } ``` -------------------------------- ### Stripe Go: Resource Operations With a Client Source: https://github.com/lukasaron/terraform-provider-stripe/blob/main/vendor/github.com/stripe/stripe-go/v78/README.md Recommended for managing multiple API keys. Initializes a client with `client.API` and uses its resource methods. The `Init` method accepts an optional second parameter for overriding backends, useful for mocking. ```go import ( "github.com/stripe/stripe-go/v78" "github.com/stripe/stripe-go/v78/client" ) // Setup sc := &client.API{} sc.Init("sk_key", nil) // the second parameter overrides the backends used if needed for mocking // Create $resource$, err := sc.$Resource$s.New(&stripe.$Resource$Params{}) // Get $resource$, err = sc.$Resource$s.Get(id, &stripe.$Resource$Params{}) // Update $resource$, err = sc.$Resource$s.Update(id, &stripe.$Resource$Params{}) // Delete $resource$Deleted, err := sc.$Resource$s.Del(id, &stripe.$Resource$Params{}) // List i := sc.$Resource$s.List(&stripe.$Resource$ListParams{}) for i.Next() { $resource$ := i.$Resource$() } if err := i.Err(); err != nil { // handle } ``` -------------------------------- ### UsageRecord initialization (unset vs. zero) Source: https://github.com/lukasaron/terraform-provider-stripe/blob/main/vendor/github.com/stripe/stripe-go/v78/v32_migration_guide.md Demonstrates the ambiguity in the previous system where an uninitialized field and an explicitly zero field were indistinguishable. ```go // Initialized with no quantity UsageRecord {} // Initialized with an explicitly zero UsageRecord { Quantity: 0, } ``` -------------------------------- ### Disable Global Color Output Source: https://github.com/lukasaron/terraform-provider-stripe/blob/main/vendor/github.com/fatih/color/README.md Use this to disable all colorized output globally, for example, when a command-line flag is set to disable colors. ```go var flagNoColor = flag.Bool("no-color", false, "Disable color output") if *flagNoColor { color.NoColor = true // disables colorized output } ``` -------------------------------- ### HCL Expression Examples Source: https://github.com/lukasaron/terraform-provider-stripe/blob/main/vendor/github.com/hashicorp/hcl/v2/README.md Demonstrates various expression types supported in HCL, including arithmetic, string interpolation, and function calls. ```hcl # Arithmetic with literals and application-provided variables sum = 1 + addend # String interpolation and templates message = "Hello, ${name}!" # Application-provided functions shouty_message = upper(message) ``` -------------------------------- ### Resource Operations With a Client Source: https://github.com/lukasaron/terraform-provider-stripe/blob/main/vendor/github.com/stripe/stripe-go/v78/README.md Illustrates how to perform resource operations using a client instance, which is recommended when dealing with multiple API keys or requiring more complex client configurations. ```APIDOC ## Resource Operations With a Client ### Description Manage Stripe resources using a dedicated client instance. This is the recommended approach for applications handling multiple API keys or requiring isolated client configurations. ### Setup ```go import ( "github.com/stripe/stripe-go/v78" "github.com/stripe/stripe-go/v78/client" ) // Initialize a new client sc := &client.API{} sc.Init("sk_key", nil) // The second parameter can override backends for mocking ``` ### Operations #### Create Resource ```go $resource$, err := sc.$Resource$s.New(&stripe.$Resource$Params{}) ``` #### Get Resource ```go $resource$, err = sc.$Resource$s.Get(id, &stripe.$Resource$Params{}) ``` #### Update Resource ```go $resource$, err = sc.$Resource$s.Update(id, &stripe.$Resource$Params{}) ``` #### Delete Resource ```go $resource$Deleted, err := sc.$Resource$s.Del(id, &stripe.$Resource$Params{}) ``` #### List Resources ```go i := sc.$Resource$s.List(&stripe.$Resource$ListParams{}) for i.Next() { $resource$ := i.$Resource$() } if err := i.Err(); err != nil { // handle error } ``` ``` -------------------------------- ### Enable Datastore Key Conversion for Automatic Scaling Source: https://github.com/lukasaron/terraform-provider-stripe/blob/main/vendor/google.golang.org/appengine/README.md For automatic scaling, where /_ah/start is not supported, call datastore.EnableKeyConversion before using code that requires key conversion. This can be done in each handler or via middleware. EnableKeyConversion is safe for concurrent use and subsequent calls are ignored. ```go datastore.EnableKeyConversion(appengine.NewContext(r)) ``` -------------------------------- ### Create a basic promotion code for a coupon Source: https://github.com/lukasaron/terraform-provider-stripe/blob/main/docs/resources/stripe_promotion_code.md Use this snippet to create a simple promotion code linked to an existing coupon. Ensure the coupon is defined before applying this resource. ```hcl resource "stripe_promotion_code" "code" { // coupon needs to be defined coupon = stripe_coupon.coupon.id code = "FREE" } ``` -------------------------------- ### Add Actor with http.Server Graceful Shutdown Source: https://github.com/lukasaron/terraform-provider-stripe/blob/main/vendor/github.com/oklog/run/README.md Adds an actor that starts an HTTP server. The interrupt function performs a graceful shutdown with a timeout. ```go httpServer := &http.Server{ Addr: "localhost:8080", Handler: ..., } g.Add(func() error { return httpServer.ListenAndServe() }, func(error) { ctx, cancel := context.WithTimeout(context.TODO(), 3*time.Second) defer cancel() httpServer.Shutdown(ctx) }) ``` -------------------------------- ### Change Directory to App Engine Source Source: https://github.com/lukasaron/terraform-provider-stripe/blob/main/vendor/google.golang.org/appengine/CONTRIBUTING.md Navigate to the downloaded App Engine Go SDK source directory using 'cd'. This is necessary before making any code changes. ```bash cd $GOPATH/src/google.golang.org/appengine ``` -------------------------------- ### Stripe Coupon Resource Source: https://context7.com/lukasaron/terraform-provider-stripe/llms.txt Examples of creating Stripe coupons with different discount types (percent-off, amount-off), durations, redemption limits, and product applicability. ```APIDOC ## Resource: stripe_coupon ### 20% off forever resource "stripe_coupon" "twenty_pct_forever" { name = "20% Off Forever" percent_off = 20.0 duration = "forever" } ### $10 off once, max 500 redemptions, expires 2026-01-01 resource "stripe_coupon" "ten_off_launch" { name = "$10 Launch Promo" amount_off = 1000 # $10.00 in cents currency = "usd" duration = "once" max_redemptions = 500 redeem_by = "2026-01-01T00:00:00+00:00" } ### 3-month repeating coupon scoped to one product resource "stripe_coupon" "product_discount" { name = "3-Month Widget Discount" percent_off = 15.0 duration = "repeating" duration_in_months = 3 applies_to = [stripe_product.widget.id] } ``` -------------------------------- ### HCL Input for Custom Keyword Type Source: https://github.com/lukasaron/terraform-provider-stripe/blob/main/vendor/github.com/hashicorp/hcl/v2/ext/customdecode/README.md Example of HCL input that conforms to the custom keyword type. This input will be successfully decoded into a cty.Value of keywordType. ```hcl keyword = foo ``` -------------------------------- ### Minimal Shipping Rate Configuration Source: https://github.com/lukasaron/terraform-provider-stripe/blob/main/docs/resources/stripe_shipping_rate.md This is a basic example of a shipping rate with a display name and a fixed amount. Ensure the currency is a three-letter ISO code. ```hcl resource "stripe_shipping_rate" "shipping_rate" { display_name = "minimal shipping rate" fixed_amount { amount = 1000 currency = "aud" } } ``` -------------------------------- ### Stripe Tax Rate Resource Source: https://context7.com/lukasaron/terraform-provider-stripe/llms.txt Examples of defining Stripe tax rates, specifying whether they are inclusive or exclusive of tax, percentage, country, and tax type. ```APIDOC ## Resource: stripe_tax_rate ### Inclusive GST (Australia) resource "stripe_tax_rate" "au_gst" { display_name = "GST" inclusive = true percentage = 10.0 active = true country = "AU" jurisdiction = "AU" description = "Australian Goods and Services Tax" tax_type = "gst" } ### Exclusive VAT (UK) resource "stripe_tax_rate" "uk_vat" { display_name = "VAT" inclusive = false percentage = 20.0 active = true country = "GB" jurisdiction = "GB" description = "United Kingdom Value Added Tax" tax_type = "vat" } ``` -------------------------------- ### Portal Configuration with Custom Headline and Metadata Source: https://github.com/lukasaron/terraform-provider-stripe/blob/main/docs/resources/stripe_portal_configuration.md Configures a billing portal with a custom headline and metadata for enhanced branding and tracking. Invoice history is disabled in this example. ```hcl resource "stripe_portal_configuration" "portal_configuration" { business_profile { headline = "My special headline" privacy_policy_url = "https://example.com/privacy" terms_of_service_url = "https://example.com/terms" } default_return_url = "https://example.com/special_headline" features { invoice_history { enabled = false } payment_method_update { enabled = true } } metadata = { campaign = "special headline" } } ``` -------------------------------- ### Parse and Compare Versions Source: https://github.com/lukasaron/terraform-provider-stripe/blob/main/vendor/github.com/hashicorp/go-version/README.md Create new version objects and compare them using LessThan, GreaterThan, or Equal methods. Handles metadata. ```go v1, err := version.NewVersion("1.2") v2, err := version.NewVersion("1.5+metadata") // Comparison example. There is also GreaterThan, Equal, and just // a simple Compare that returns an int allowing easy >=, <=, etc. if v1.LessThan(v2) { fmt.Printf("%s is less than %s", v1, v2) } ``` -------------------------------- ### Importing HCL v1 and v2 in Go Source: https://github.com/lukasaron/terraform-provider-stripe/blob/main/vendor/github.com/hashicorp/hcl/v2/README.md Shows how to import both HCL v1 and v2 packages into a Go program using semantic versioning. ```go import ( hcl1 "github.com/hashicorp/hcl" hcl2 "github.com/hashicorp/hcl/v2" ) ``` -------------------------------- ### Template For Directive Syntax Source: https://github.com/lukasaron/terraform-provider-stripe/blob/main/vendor/github.com/hashicorp/hcl/v2/hclsyntax/spec.md Defines the syntax for the template for directive, which iterates over a collection and repeats a sub-template for each element. It requires a start and end marker, and specifies the iteration variables. ```ebnf TemplateFor = ( ("%{" | "%{~") "for" Identifier ("," Identifier) "in" Expression ("}" | "~}") Template ("%{" | "%{~") "endfor" ("}" | "~}") ); ``` -------------------------------- ### Create a promotion code with redemption limits and expiration Source: https://github.com/lukasaron/terraform-provider-stripe/blob/main/docs/resources/stripe_promotion_code.md Configure a promotion code with a maximum number of redemptions and a specific expiration timestamp. The `expires_at` value should be in RFC3339 format. ```hcl resource "stripe_promotion_code" "code" { // coupon needs to be defined coupon = stripe_coupon.coupon.id code = "FREE" max_redemptions = 5 expires_at = "2025-08-03T08:37:18+00:00" } ``` -------------------------------- ### Stripe Shipping Rate Resource Source: https://context7.com/lukasaron/terraform-provider-stripe/llms.txt Examples of configuring Stripe shipping rates with display names, fixed amounts (including multi-currency options), delivery estimates, and tax information. ```APIDOC ## Resource: stripe_shipping_rate ### Standard shipping with delivery window and multi-currency resource "stripe_shipping_rate" "standard" { display_name = "Standard Shipping" fixed_amount { amount = 599 # $5.99 currency = "usd" # currency_options MUST be sorted alphabetically by currency currency_option { currency = "aud" amount = 899 tax_behavior = "exclusive" } currency_option { currency = "eur" amount = 499 } } delivery_estimate { minimum { unit = "business_day" value = 3 } maximum { unit = "business_day" value = 7 } } tax_code = "txcd_92010001" # Stripe shipping tax code tax_behavior = "exclusive" metadata = { carrier = "USPS" } } ``` -------------------------------- ### Helper functions for initializing pointer fields Source: https://github.com/lukasaron/terraform-provider-stripe/blob/main/vendor/github.com/stripe/stripe-go/v78/v32_migration_guide.md Lists the new helper functions available for initializing pointer fields in parameter structs. ```go stripe.Bool stripe.Float64 stripe.Int64 stripe.String ``` -------------------------------- ### Create Stripe Client for Google AppEngine Source: https://github.com/lukasaron/terraform-provider-stripe/blob/main/vendor/github.com/stripe/stripe-go/v78/README.md Instantiate a per-request Stripe client using Google AppEngine's urlfetch for environments where http.DefaultClient is unavailable. ```go import ( "fmt" "net/http" "google.golang.org/appengine" "google.golang.org/appengine/urlfetch" "github.com/stripe/stripe-go/v78" "github.com/stripe/stripe-go/v78/client" ) func handler(w http.ResponseWriter, r *http.Request) { c := appengine.NewContext(r) httpClient := urlfetch.Client(c) sc := client.New("sk_test_123", stripe.NewBackends(httpClient)) params := &stripe.CustomerParams{ Description: stripe.String("Stripe Developer"), Email: stripe.String("gostripe@stripe.com"), } customer, err := sc.Customers.New(params) if err != nil { fmt.Fprintf(w, "Could not create customer: %v", err) } fmt.Fprintf(w, "Customer created: %v", customer.ID) } ``` -------------------------------- ### Stripe Promotion Code Resource Source: https://context7.com/lukasaron/terraform-provider-stripe/llms.txt Examples of creating Stripe promotion codes linked to coupons, with options for specific codes, expiration dates, redemption limits, and customer restrictions. ```APIDOC ## Resource: stripe_promotion_code ### Simple reusable code resource "stripe_promotion_code" "launch20" { coupon = stripe_coupon.twenty_pct_forever.id code = "LAUNCH20" } ### Time-limited, max-redemption code for new customers only resource "stripe_promotion_code" "newuser10" { coupon = stripe_coupon.ten_off_launch.id code = "NEWUSER10" max_redemptions = 1000 expires_at = "2026-06-30T23:59:59+00:00" restrictions { first_time_transaction = true minimum_amount = 5000 # min $50.00 cart minimum_amount_currency = "usd" } } ### Restrict code to one specific customer resource "stripe_promotion_code" "vip_code" { coupon = stripe_coupon.twenty_pct_forever.id code = "VIP-ACME-2025" customer = stripe_customer.acme.id } ``` -------------------------------- ### Initialize Stripe API with Access Token Source: https://github.com/lukasaron/terraform-provider-stripe/blob/main/vendor/github.com/stripe/stripe-go/v78/README.md Initialize the Stripe client API with an access token for authentication. ```go import ( "github.com/stripe/stripe-go/v78" "github.com/stripe/stripe-go/v78/client" ) stripe := &client.API{} stripe.Init("access_token", nil) ``` -------------------------------- ### Decoding JSON with Unknown Structure Source: https://github.com/lukasaron/terraform-provider-stripe/blob/main/vendor/github.com/mitchellh/mapstructure/README.md Example demonstrating how to decode JSON into a map[string]interface{} to inspect fields before decoding into a specific structure. This is useful when the structure of the data varies. ```json { "type": "person", "name": "Mitchell" } ``` -------------------------------- ### Configuring Logging Source: https://github.com/lukasaron/terraform-provider-stripe/blob/main/vendor/github.com/stripe/stripe-go/v78/README.md Explains how to configure logging for the Stripe Go library, both globally and on a per-backend basis. It covers setting log levels and using custom logger implementations. ```APIDOC ## Configuring Logging ### Description Control the logging behavior of the Stripe Go library. By default, only error messages are logged to stderr. You can configure global logging or per-backend logging, and use custom logger implementations. ### Global Logging Configuration ```go import "github.com/stripe/stripe-go/v78" // Set the global logger level to Info stripe.DefaultLeveledLogger = &stripe.LeveledLogger{ Level: stripe.LevelInfo, } ``` ### Per-Backend Logging Configuration ```go import ( "github.com/stripe/stripe-go/v78" "github.com/stripe/stripe-go/v78/client" ) config := &stripe.BackendConfig{ LeveledLogger: &stripe.LeveledLogger{ Level: stripe.LevelInfo, }, } // Initialize client with custom backend configuration sc := &client.API{} sc.Init("sk_key", &stripe.Backends{ API: stripe.GetBackendWithConfig(stripe.APIBackend, config), }) ``` ### Custom Logger Interface The library expects loggers to conform to the `LeveledLoggerInterface`: ```go type LeveledLoggerInterface interface { Debugf(format string, v ...interface{}) Errorf(format string, v ...interface{}) Infof(format string, v ...interface{}) Warnf(format string, v ...interface{}) } ``` Loggers like Logrus and Zap's SugaredLogger can be used directly if they implement this interface. ```