diff --git a/account.go b/account.go index 705ea4c424..aecc9af51b 100644 --- a/account.go +++ b/account.go @@ -169,6 +169,8 @@ type AccountParams struct { ExternalAccount *AccountExternalAccountParams `form:"external_account"` // Information about the person represented by the account. This field is null unless `business_type` is set to `individual`. Individual *PersonParams `form:"individual"` + // Set of [key-value pairs](https://stripe.com/docs/api/metadata) that you can attach to an object. This can be useful for storing additional information about the object in a structured format. Individual keys can be unset by posting an empty value to them. All keys can be unset by posting an empty value to `metadata`. + Metadata map[string]string `form:"metadata"` // Options for customizing how the account functions within Stripe. Settings *AccountSettingsParams `form:"settings"` // Details on the account's acceptance of the [Stripe Services Agreement](https://stripe.com/docs/connect/updating-accounts#tos-acceptance). @@ -177,6 +179,15 @@ type AccountParams struct { Type *string `form:"type"` } +// AddMetadata adds a new key-value pair to the Metadata. +func (p *AccountParams) AddMetadata(key string, value string) { + if p.Metadata == nil { + p.Metadata = make(map[string]string) + } + + p.Metadata[key] = value +} + // An estimate of the monthly revenue of the business. Only accepted for accounts in Brazil and India. type AccountBusinessProfileMonthlyEstimatedRevenueParams struct { // A non-negative integer representing how much to charge in the [smallest currency unit](https://stripe.com/docs/currencies#zero-decimal). @@ -735,8 +746,8 @@ type AccountSettingsPayoutsScheduleParams struct { } // AppendTo implements custom encoding logic for AccountSettingsPayoutsScheduleParams. -func (a *AccountSettingsPayoutsScheduleParams) AppendTo(body *form.Values, keyParts []string) { - if BoolValue(a.DelayDaysMinimum) { +func (p *AccountSettingsPayoutsScheduleParams) AppendTo(body *form.Values, keyParts []string) { + if BoolValue(p.DelayDaysMinimum) { body.Add(form.FormatKey(append(keyParts, "delay_days")), "minimum") } } diff --git a/bankaccount.go b/bankaccount.go index 1c8a1c467e..3bfac14f22 100644 --- a/bankaccount.go +++ b/bankaccount.go @@ -212,6 +212,8 @@ type BankAccountParams struct { ExpMonth *string `form:"exp_month"` // Four digit number representing the card's expiration year. ExpYear *string `form:"exp_year"` + // Set of [key-value pairs](https://stripe.com/docs/api/metadata) that you can attach to an object. This can be useful for storing additional information about the object in a structured format. Individual keys can be unset by posting an empty value to them. All keys can be unset by posting an empty value to `metadata`. + Metadata map[string]string `form:"metadata"` // Cardholder name. Name *string `form:"name"` // The routing number, sort code, or other country-appropriate institution number for the bank account. For US bank accounts, this is required and should be the ACH routing number, not the wire routing number. If you are providing an IBAN for `account_number`, this field is not required. @@ -232,13 +234,13 @@ type BankAccountParams struct { // This is not a pattern that we want to push forward, and this largely exists // because the bank accounts endpoint is a little unusual. There is one other // resource like it, which is cards. -func (a *BankAccountParams) AppendToAsSourceOrExternalAccount(body *form.Values) { +func (p *BankAccountParams) AppendToAsSourceOrExternalAccount(body *form.Values) { // Rather than being called in addition to `AppendTo`, this function // *replaces* `AppendTo`, so we must also make sure to handle the encoding // of `Params` so metadata and the like is included in the encoded payload. - form.AppendTo(body, a.Params) + form.AppendTo(body, p.Params) - isCustomer := a.Customer != nil + isCustomer := p.Customer != nil var sourceType string if isCustomer { @@ -248,42 +250,51 @@ func (a *BankAccountParams) AppendToAsSourceOrExternalAccount(body *form.Values) } // Use token (if exists) or a dictionary containing a user’s bank account details. - if a.Token != nil { - body.Add(sourceType, StringValue(a.Token)) + if p.Token != nil { + body.Add(sourceType, StringValue(p.Token)) - if a.DefaultForCurrency != nil { + if p.DefaultForCurrency != nil { body.Add( "default_for_currency", - strconv.FormatBool(BoolValue(a.DefaultForCurrency)), + strconv.FormatBool(BoolValue(p.DefaultForCurrency)), ) } } else { body.Add(sourceType+"[object]", "bank_account") - body.Add(sourceType+"[country]", StringValue(a.Country)) - body.Add(sourceType+"[account_number]", StringValue(a.AccountNumber)) - body.Add(sourceType+"[currency]", StringValue(a.Currency)) + body.Add(sourceType+"[country]", StringValue(p.Country)) + body.Add(sourceType+"[account_number]", StringValue(p.AccountNumber)) + body.Add(sourceType+"[currency]", StringValue(p.Currency)) // These are optional and the API will fail if we try to send empty // values in for them, so make sure to check that they're actually set // before encoding them. - if a.AccountHolderName != nil { - body.Add(sourceType+"[account_holder_name]", StringValue(a.AccountHolderName)) + if p.AccountHolderName != nil { + body.Add(sourceType+"[account_holder_name]", StringValue(p.AccountHolderName)) } - if a.AccountHolderType != nil { - body.Add(sourceType+"[account_holder_type]", StringValue(a.AccountHolderType)) + if p.AccountHolderType != nil { + body.Add(sourceType+"[account_holder_type]", StringValue(p.AccountHolderType)) } - if a.RoutingNumber != nil { - body.Add(sourceType+"[routing_number]", StringValue(a.RoutingNumber)) + if p.RoutingNumber != nil { + body.Add(sourceType+"[routing_number]", StringValue(p.RoutingNumber)) } - if a.DefaultForCurrency != nil { - body.Add(sourceType+"[default_for_currency]", strconv.FormatBool(BoolValue(a.DefaultForCurrency))) + if p.DefaultForCurrency != nil { + body.Add(sourceType+"[default_for_currency]", strconv.FormatBool(BoolValue(p.DefaultForCurrency))) } } } +// AddMetadata adds a new key-value pair to the Metadata. +func (p *BankAccountParams) AddMetadata(key string, value string) { + if p.Metadata == nil { + p.Metadata = make(map[string]string) + } + + p.Metadata[key] = value +} + type BankAccountListParams struct { ListParams `form:"*"` // The identifier of the parent account under which the bank accounts are diff --git a/billingportal_configuration.go b/billingportal_configuration.go index 4f015c4f72..41a3a291be 100644 --- a/billingportal_configuration.go +++ b/billingportal_configuration.go @@ -197,7 +197,19 @@ type BillingPortalConfigurationParams struct { Features *BillingPortalConfigurationFeaturesParams `form:"features"` // The hosted login page for this configuration. Learn more about the portal login page in our [integration docs](https://stripe.com/docs/billing/subscriptions/integrating-customer-portal#share). LoginPage *BillingPortalConfigurationLoginPageParams `form:"login_page"` + // Set of [key-value pairs](https://stripe.com/docs/api/metadata) that you can attach to an object. This can be useful for storing additional information about the object in a structured format. Individual keys can be unset by posting an empty value to them. All keys can be unset by posting an empty value to `metadata`. + Metadata map[string]string `form:"metadata"` } + +// AddMetadata adds a new key-value pair to the Metadata. +func (p *BillingPortalConfigurationParams) AddMetadata(key string, value string) { + if p.Metadata == nil { + p.Metadata = make(map[string]string) + } + + p.Metadata[key] = value +} + type BillingPortalConfigurationBusinessProfile struct { // The messaging shown to customers in the portal. Headline string `json:"headline"` diff --git a/card.go b/card.go index 7b294668ab..632a8b2590 100644 --- a/card.go +++ b/card.go @@ -136,6 +136,8 @@ type CardParams struct { ExpMonth *string `form:"exp_month"` // Four digit number representing the card's expiration year. ExpYear *string `form:"exp_year"` + // Set of [key-value pairs](https://stripe.com/docs/api/metadata) that you can attach to an object. This can be useful for storing additional information about the object in a structured format. Individual keys can be unset by posting an empty value to them. All keys can be unset by posting an empty value to `metadata`. + Metadata map[string]string `form:"metadata"` // Cardholder name. Name *string `form:"name"` // The card number, as a string without any separators. @@ -157,99 +159,108 @@ type CardParams struct { // This is not a pattern that we want to push forward, and this largely exists // because the cards endpoint is a little unusual. There is one other resource // like it, which is bank account. -func (c *CardParams) AppendToAsCardSourceOrExternalAccount(body *form.Values, keyParts []string) { +func (p *CardParams) AppendToAsCardSourceOrExternalAccount(body *form.Values, keyParts []string) { // Rather than being called in addition to `AppendTo`, this function // *replaces* `AppendTo`, so we must also make sure to handle the encoding // of `Params` so metadata and the like is included in the encoded payload. - form.AppendToPrefixed(body, c.Params, keyParts) + form.AppendToPrefixed(body, p.Params, keyParts) - if c.DefaultForCurrency != nil { + if p.DefaultForCurrency != nil { body.Add( form.FormatKey(append(keyParts, "default_for_currency")), - strconv.FormatBool(BoolValue(c.DefaultForCurrency)), + strconv.FormatBool(BoolValue(p.DefaultForCurrency)), ) } - if c.Token != nil { - if c.Account != nil { - body.Add(form.FormatKey(append(keyParts, "external_account")), StringValue(c.Token)) + if p.Token != nil { + if p.Account != nil { + body.Add(form.FormatKey(append(keyParts, "external_account")), StringValue(p.Token)) } else { - body.Add(form.FormatKey(append(keyParts, cardSource)), StringValue(c.Token)) + body.Add(form.FormatKey(append(keyParts, cardSource)), StringValue(p.Token)) } } - if c.Number != nil { + if p.Number != nil { body.Add(form.FormatKey(append(keyParts, cardSource, "object")), "card") - body.Add(form.FormatKey(append(keyParts, cardSource, "number")), StringValue(c.Number)) + body.Add(form.FormatKey(append(keyParts, cardSource, "number")), StringValue(p.Number)) } - if c.CVC != nil { + if p.CVC != nil { body.Add( form.FormatKey(append(keyParts, cardSource, "cvc")), - StringValue(c.CVC), + StringValue(p.CVC), ) } - if c.Currency != nil { + if p.Currency != nil { body.Add( form.FormatKey(append(keyParts, cardSource, "currency")), - StringValue(c.Currency), + StringValue(p.Currency), ) } - if c.ExpMonth != nil { + if p.ExpMonth != nil { body.Add( form.FormatKey(append(keyParts, cardSource, "exp_month")), - StringValue(c.ExpMonth), + StringValue(p.ExpMonth), ) } - if c.ExpYear != nil { + if p.ExpYear != nil { body.Add( form.FormatKey(append(keyParts, cardSource, "exp_year")), - StringValue(c.ExpYear), + StringValue(p.ExpYear), ) } - if c.Name != nil { + if p.Name != nil { body.Add( form.FormatKey(append(keyParts, cardSource, "name")), - StringValue(c.Name), + StringValue(p.Name), ) } - if c.AddressCity != nil { + if p.AddressCity != nil { body.Add( form.FormatKey(append(keyParts, cardSource, "address_city")), - StringValue(c.AddressCity), + StringValue(p.AddressCity), ) } - if c.AddressCountry != nil { + if p.AddressCountry != nil { body.Add( form.FormatKey(append(keyParts, cardSource, "address_country")), - StringValue(c.AddressCountry), + StringValue(p.AddressCountry), ) } - if c.AddressLine1 != nil { + if p.AddressLine1 != nil { body.Add( form.FormatKey(append(keyParts, cardSource, "address_line1")), - StringValue(c.AddressLine1), + StringValue(p.AddressLine1), ) } - if c.AddressLine2 != nil { + if p.AddressLine2 != nil { body.Add( form.FormatKey(append(keyParts, cardSource, "address_line2")), - StringValue(c.AddressLine2), + StringValue(p.AddressLine2), ) } - if c.AddressState != nil { + if p.AddressState != nil { body.Add( form.FormatKey(append(keyParts, cardSource, "address_state")), - StringValue(c.AddressState), + StringValue(p.AddressState), ) } - if c.AddressZip != nil { + if p.AddressZip != nil { body.Add( form.FormatKey(append(keyParts, cardSource, "address_zip")), - StringValue(c.AddressZip), + StringValue(p.AddressZip), ) } } +// AddMetadata adds a new key-value pair to the Metadata. +func (p *CardParams) AddMetadata(key string, value string) { + if p.Metadata == nil { + p.Metadata = make(map[string]string) + } + + p.Metadata[key] = value +} + type CardListParams struct { ListParams `form:"*"` Account *string `form:"-"` // Included in URL diff --git a/charge.go b/charge.go index 2f2730ddcb..a824fffa96 100644 --- a/charge.go +++ b/charge.go @@ -325,6 +325,8 @@ type ChargeParams struct { // A set of key-value pairs you can attach to a charge giving information about its riskiness. If you believe a charge is fraudulent, include a `user_report` key with a value of `fraudulent`. If you believe a charge is safe, include a `user_report` key with a value of `safe`. Stripe will use the information you send to improve our fraud detection algorithms. FraudDetails *ChargeFraudDetailsParams `form:"fraud_details"` Level3 *ChargeLevel3Params `form:"level3"` + // Set of [key-value pairs](https://stripe.com/docs/api/metadata) that you can attach to an object. This can be useful for storing additional information about the object in a structured format. Individual keys can be unset by posting an empty value to them. All keys can be unset by posting an empty value to `metadata`. + Metadata map[string]string `form:"metadata"` // The Stripe account ID for which these funds are intended. Automatically set if you use the `destination` parameter. For details, see [Creating Separate Charges and Transfers](https://stripe.com/docs/connect/separate-charges-and-transfers#on-behalf-of). OnBehalfOf *string `form:"on_behalf_of"` // Options to configure Radar. See [Radar Session](https://stripe.com/docs/radar/radar-session) for more information. @@ -352,6 +354,15 @@ func (p *ChargeParams) SetSource(sp interface{}) error { return err } +// AddMetadata adds a new key-value pair to the Metadata. +func (p *ChargeParams) AddMetadata(key string, value string) { + if p.Metadata == nil { + p.Metadata = make(map[string]string) + } + + p.Metadata[key] = value +} + // A set of key-value pairs you can attach to a charge giving information about its riskiness. If you believe a charge is fraudulent, include a `user_report` key with a value of `fraudulent`. If you believe a charge is safe, include a `user_report` key with a value of `safe`. Stripe will use the information you send to improve our fraud detection algorithms. type ChargeFraudDetailsParams struct { // Either `safe` or `fraudulent`. diff --git a/checkout_session.go b/checkout_session.go index 21f761fa39..0a83c7d78d 100644 --- a/checkout_session.go +++ b/checkout_session.go @@ -867,6 +867,15 @@ type CheckoutSessionInvoiceCreationInvoiceDataParams struct { RenderingOptions *CheckoutSessionInvoiceCreationInvoiceDataRenderingOptionsParams `form:"rendering_options"` } +// AddMetadata adds a new key-value pair to the Metadata. +func (p *CheckoutSessionInvoiceCreationInvoiceDataParams) AddMetadata(key string, value string) { + if p.Metadata == nil { + p.Metadata = make(map[string]string) + } + + p.Metadata[key] = value +} + // Generate a post-purchase Invoice for one-time payments. type CheckoutSessionInvoiceCreationParams struct { // Set to `true` to enable invoice creation. @@ -899,6 +908,15 @@ type CheckoutSessionLineItemPriceDataProductDataParams struct { TaxCode *string `form:"tax_code"` } +// AddMetadata adds a new key-value pair to the Metadata. +func (p *CheckoutSessionLineItemPriceDataProductDataParams) AddMetadata(key string, value string) { + if p.Metadata == nil { + p.Metadata = make(map[string]string) + } + + p.Metadata[key] = value +} + // The recurring components of a price such as `interval` and `interval_count`. type CheckoutSessionLineItemPriceDataRecurringParams struct { // Specifies billing frequency. Either `day`, `week`, `month` or `year`. @@ -1010,6 +1028,15 @@ type CheckoutSessionPaymentIntentDataParams struct { TransferGroup *string `form:"transfer_group"` } +// AddMetadata adds a new key-value pair to the Metadata. +func (p *CheckoutSessionPaymentIntentDataParams) AddMetadata(key string, value string) { + if p.Metadata == nil { + p.Metadata = make(map[string]string) + } + + p.Metadata[key] = value +} + // Additional fields for Mandate creation type CheckoutSessionPaymentMethodOptionsACSSDebitMandateOptionsParams struct { // A URL for custom mandate text to render during confirmation step. @@ -1454,6 +1481,15 @@ type CheckoutSessionSetupIntentDataParams struct { OnBehalfOf *string `form:"on_behalf_of"` } +// AddMetadata adds a new key-value pair to the Metadata. +func (p *CheckoutSessionSetupIntentDataParams) AddMetadata(key string, value string) { + if p.Metadata == nil { + p.Metadata = make(map[string]string) + } + + p.Metadata[key] = value +} + // When set, provides configuration for Checkout to collect a shipping address from a customer. type CheckoutSessionShippingAddressCollectionParams struct { // An array of two-letter ISO country codes representing which countries Checkout should provide as options for @@ -1521,6 +1557,15 @@ type CheckoutSessionShippingOptionShippingRateDataParams struct { Type *string `form:"type"` } +// AddMetadata adds a new key-value pair to the Metadata. +func (p *CheckoutSessionShippingOptionShippingRateDataParams) AddMetadata(key string, value string) { + if p.Metadata == nil { + p.Metadata = make(map[string]string) + } + + p.Metadata[key] = value +} + // The shipping rate options to apply to this Session. type CheckoutSessionShippingOptionParams struct { // The ID of the Shipping Rate to use for this shipping option. @@ -1586,6 +1631,15 @@ type CheckoutSessionSubscriptionDataParams struct { TrialSettings *CheckoutSessionSubscriptionDataTrialSettingsParams `form:"trial_settings"` } +// AddMetadata adds a new key-value pair to the Metadata. +func (p *CheckoutSessionSubscriptionDataParams) AddMetadata(key string, value string) { + if p.Metadata == nil { + p.Metadata = make(map[string]string) + } + + p.Metadata[key] = value +} + // Controls tax ID collection settings for the session. type CheckoutSessionTaxIDCollectionParams struct { // Set to true to enable Tax ID collection. @@ -1661,6 +1715,8 @@ type CheckoutSessionParams struct { LineItems []*CheckoutSessionLineItemParams `form:"line_items"` // The IETF language tag of the locale Checkout is displayed in. If blank or `auto`, the browser's locale is used. Locale *string `form:"locale"` + // Set of [key-value pairs](https://stripe.com/docs/api/metadata) that you can attach to an object. This can be useful for storing additional information about the object in a structured format. Individual keys can be unset by posting an empty value to them. All keys can be unset by posting an empty value to `metadata`. + Metadata map[string]string `form:"metadata"` // The mode of the Checkout Session. Pass `subscription` if the Checkout Session includes at least one recurring item. Mode *string `form:"mode"` // A subset of parameters to be passed to PaymentIntent creation for Checkout Sessions in `payment` mode. @@ -1715,6 +1771,15 @@ type CheckoutSessionParams struct { TaxIDCollection *CheckoutSessionTaxIDCollectionParams `form:"tax_id_collection"` } +// AddMetadata adds a new key-value pair to the Metadata. +func (p *CheckoutSessionParams) AddMetadata(key string, value string) { + if p.Metadata == nil { + p.Metadata = make(map[string]string) + } + + p.Metadata[key] = value +} + // When retrieving a Checkout Session, there is an includable line_items property containing the first handful of those items. There is also a URL where you can retrieve the full (paginated) list of line items. type CheckoutSessionListLineItemsParams struct { ListParams `form:"*"` diff --git a/coupon.go b/coupon.go index 44c437b965..57f98547e9 100644 --- a/coupon.go +++ b/coupon.go @@ -60,6 +60,8 @@ type CouponParams struct { ID *string `form:"id"` // A positive integer specifying the number of times the coupon can be redeemed before it's no longer valid. For example, you might have a 50% off coupon that the first 20 readers of your blog can use. MaxRedemptions *int64 `form:"max_redemptions"` + // Set of [key-value pairs](https://stripe.com/docs/api/metadata) that you can attach to an object. This can be useful for storing additional information about the object in a structured format. Individual keys can be unset by posting an empty value to them. All keys can be unset by posting an empty value to `metadata`. + Metadata map[string]string `form:"metadata"` // Name of the coupon displayed to customers on, for instance invoices, or receipts. By default the `id` is shown if `name` is not set. Name *string `form:"name"` // A positive float larger than 0, and smaller or equal to 100, that represents the discount the coupon will apply (required if `amount_off` is not passed). @@ -67,6 +69,16 @@ type CouponParams struct { // Unix timestamp specifying the last time at which the coupon can be redeemed. After the redeem_by date, the coupon can no longer be applied to new customers. RedeemBy *int64 `form:"redeem_by"` } + +// AddMetadata adds a new key-value pair to the Metadata. +func (p *CouponParams) AddMetadata(key string, value string) { + if p.Metadata == nil { + p.Metadata = make(map[string]string) + } + + p.Metadata[key] = value +} + type CouponAppliesTo struct { // A list of product IDs this coupon applies to Products []string `json:"products"` diff --git a/creditnote.go b/creditnote.go index 4533796de5..7afa53d82c 100644 --- a/creditnote.go +++ b/creditnote.go @@ -136,6 +136,8 @@ type CreditNoteParams struct { Lines []*CreditNoteLineParams `form:"lines"` // Credit note memo. Memo *string `form:"memo"` + // Set of [key-value pairs](https://stripe.com/docs/api/metadata) that you can attach to an object. This can be useful for storing additional information about the object in a structured format. Individual keys can be unset by posting an empty value to them. All keys can be unset by posting an empty value to `metadata`. + Metadata map[string]string `form:"metadata"` // The integer amount in cents (or local equivalent) representing the amount that is credited outside of Stripe. OutOfBandAmount *int64 `form:"out_of_band_amount"` // Reason for issuing this credit note, one of `duplicate`, `fraudulent`, `order_change`, or `product_unsatisfactory` @@ -148,6 +150,15 @@ type CreditNoteParams struct { ShippingCost *CreditNoteShippingCostParams `form:"shipping_cost"` } +// AddMetadata adds a new key-value pair to the Metadata. +func (p *CreditNoteParams) AddMetadata(key string, value string) { + if p.Metadata == nil { + p.Metadata = make(map[string]string) + } + + p.Metadata[key] = value +} + // Returns a list of credit notes. type CreditNoteListParams struct { ListParams `form:"*"` @@ -198,6 +209,8 @@ type CreditNotePreviewParams struct { Lines []*CreditNotePreviewLineParams `form:"lines"` // The credit note's memo appears on the credit note PDF. Memo *string `form:"memo"` + // Set of [key-value pairs](https://stripe.com/docs/api/metadata) that you can attach to an object. This can be useful for storing additional information about the object in a structured format. Individual keys can be unset by posting an empty value to them. All keys can be unset by posting an empty value to `metadata`. + Metadata map[string]string `form:"metadata"` // The integer amount in cents (or local equivalent) representing the amount that is credited outside of Stripe. OutOfBandAmount *int64 `form:"out_of_band_amount"` // Reason for issuing this credit note, one of `duplicate`, `fraudulent`, `order_change`, or `product_unsatisfactory` @@ -210,6 +223,15 @@ type CreditNotePreviewParams struct { ShippingCost *CreditNotePreviewShippingCostParams `form:"shipping_cost"` } +// AddMetadata adds a new key-value pair to the Metadata. +func (p *CreditNotePreviewParams) AddMetadata(key string, value string) { + if p.Metadata == nil { + p.Metadata = make(map[string]string) + } + + p.Metadata[key] = value +} + // Marks a credit note as void. Learn more about [voiding credit notes](https://stripe.com/docs/billing/invoices/credit-notes#voiding). type CreditNoteVoidCreditNoteParams struct { Params `form:"*"` diff --git a/customer.go b/customer.go index 33cdffaffd..a49d458f34 100644 --- a/customer.go +++ b/customer.go @@ -149,6 +149,8 @@ type CustomerParams struct { InvoicePrefix *string `form:"invoice_prefix"` // Default invoice settings for this customer. InvoiceSettings *CustomerInvoiceSettingsParams `form:"invoice_settings"` + // Set of [key-value pairs](https://stripe.com/docs/api/metadata) that you can attach to an object. This can be useful for storing additional information about the object in a structured format. Individual keys can be unset by posting an empty value to them. All keys can be unset by posting an empty value to `metadata`. + Metadata map[string]string `form:"metadata"` // The customer's full name or business name. Name *string `form:"name"` // The sequence to be used on the customer's next invoice. Defaults to 1. @@ -174,6 +176,15 @@ type CustomerParams struct { Validate *bool `form:"validate"` } +// AddMetadata adds a new key-value pair to the Metadata. +func (p *CustomerParams) AddMetadata(key string, value string) { + if p.Metadata == nil { + p.Metadata = make(map[string]string) + } + + p.Metadata[key] = value +} + // Returns a list of PaymentMethods for a given Customer type CustomerListPaymentMethodsParams struct { ListParams `form:"*"` diff --git a/customerbalancetransaction.go b/customerbalancetransaction.go index 41cd29a818..e4cf70e430 100644 --- a/customerbalancetransaction.go +++ b/customerbalancetransaction.go @@ -35,6 +35,17 @@ type CustomerBalanceTransactionParams struct { Currency *string `form:"currency"` // An arbitrary string attached to the object. Often useful for displaying to users. Description *string `form:"description"` + // Set of [key-value pairs](https://stripe.com/docs/api/metadata) that you can attach to an object. This can be useful for storing additional information about the object in a structured format. Individual keys can be unset by posting an empty value to them. All keys can be unset by posting an empty value to `metadata`. + Metadata map[string]string `form:"metadata"` +} + +// AddMetadata adds a new key-value pair to the Metadata. +func (p *CustomerBalanceTransactionParams) AddMetadata(key string, value string) { + if p.Metadata == nil { + p.Metadata = make(map[string]string) + } + + p.Metadata[key] = value } // Returns a list of transactions that updated the customer's [balances](https://stripe.com/docs/billing/customer/balance). diff --git a/dispute.go b/dispute.go index 4c802933ef..e1aa558864 100644 --- a/dispute.go +++ b/dispute.go @@ -60,10 +60,21 @@ type DisputeParams struct { Params `form:"*"` // Evidence to upload, to respond to a dispute. Updating any field in the hash will submit all fields in the hash for review. The combined character count of all fields is limited to 150,000. Evidence *DisputeEvidenceParams `form:"evidence"` + // Set of [key-value pairs](https://stripe.com/docs/api/metadata) that you can attach to an object. This can be useful for storing additional information about the object in a structured format. Individual keys can be unset by posting an empty value to them. All keys can be unset by posting an empty value to `metadata`. + Metadata map[string]string `form:"metadata"` // Whether to immediately submit evidence to the bank. If `false`, evidence is staged on the dispute. Staged evidence is visible in the API and Dashboard, and can be submitted to the bank by making another request with this attribute set to `true` (the default). Submit *bool `form:"submit"` } +// AddMetadata adds a new key-value pair to the Metadata. +func (p *DisputeParams) AddMetadata(key string, value string) { + if p.Metadata == nil { + p.Metadata = make(map[string]string) + } + + p.Metadata[key] = value +} + // Evidence to upload, to respond to a dispute. Updating any field in the hash will submit all fields in the hash for review. The combined character count of all fields is limited to 150,000. type DisputeEvidenceParams struct { // Any server or activity logs showing proof that the customer accessed or downloaded the purchased digital product. This information should include IP addresses, corresponding timestamps, and any detailed recorded activity. Has a maximum character count of 20,000. diff --git a/feerefund.go b/feerefund.go index 01bc5a6624..87ea2e846d 100644 --- a/feerefund.go +++ b/feerefund.go @@ -23,6 +23,17 @@ type FeeRefundParams struct { ID *string `form:"-"` // Included in URL // A positive integer, in _cents (or local equivalent)_, representing how much of this fee to refund. Can refund only up to the remaining unrefunded amount of the fee. Amount *int64 `form:"amount"` + // Set of [key-value pairs](https://stripe.com/docs/api/metadata) that you can attach to an object. This can be useful for storing additional information about the object in a structured format. Individual keys can be unset by posting an empty value to them. All keys can be unset by posting an empty value to `metadata`. + Metadata map[string]string `form:"metadata"` +} + +// AddMetadata adds a new key-value pair to the Metadata. +func (p *FeeRefundParams) AddMetadata(key string, value string) { + if p.Metadata == nil { + p.Metadata = make(map[string]string) + } + + p.Metadata[key] = value } // You can see a list of the refunds belonging to a specific application fee. Note that the 10 most recent refunds are always available by default on the application fee object. If you need more than those 10, you can use this API method and the limit and starting_after parameters to page through additional refunds. diff --git a/file.go b/file.go index 8da5d4de4e..db89b9c5c6 100644 --- a/file.go +++ b/file.go @@ -58,6 +58,15 @@ type FileFileLinkDataParams struct { Metadata map[string]string `form:"metadata"` } +// AddMetadata adds a new key-value pair to the Metadata. +func (p *FileFileLinkDataParams) AddMetadata(key string, value string) { + if p.Metadata == nil { + p.Metadata = make(map[string]string) + } + + p.Metadata[key] = value +} + // To upload a file to Stripe, you'll need to send a request of type multipart/form-data. The request should contain the file you would like to upload, as well as the parameters for creating a file. // // All of Stripe's officially supported Client libraries should have support for sending multipart/form-data. @@ -116,36 +125,36 @@ type FileList struct { // GetBody gets an appropriate multipart form payload to use in a request body // to create a new file. -func (f *FileParams) GetBody() (*bytes.Buffer, string, error) { +func (p *FileParams) GetBody() (*bytes.Buffer, string, error) { body := &bytes.Buffer{} writer := multipart.NewWriter(body) - if f.Purpose != nil { - err := writer.WriteField("purpose", StringValue(f.Purpose)) + if p.Purpose != nil { + err := writer.WriteField("purpose", StringValue(p.Purpose)) if err != nil { return nil, "", err } } - if f.FileReader != nil && f.Filename != nil { + if p.FileReader != nil && p.Filename != nil { part, err := writer.CreateFormFile( "file", - filepath.Base(StringValue(f.Filename)), + filepath.Base(StringValue(p.Filename)), ) if err != nil { return nil, "", err } - _, err = io.Copy(part, f.FileReader) + _, err = io.Copy(part, p.FileReader) if err != nil { return nil, "", err } } - if f.FileLinkData != nil { + if p.FileLinkData != nil { values := &form.Values{} - form.AppendToPrefixed(values, f.FileLinkData, []string{"file_link_data"}) + form.AppendToPrefixed(values, p.FileLinkData, []string{"file_link_data"}) params, err := url.ParseQuery(values.Encode()) if err != nil { diff --git a/filelink.go b/filelink.go index bed56fff64..f19e19f3a8 100644 --- a/filelink.go +++ b/filelink.go @@ -16,11 +16,22 @@ type FileLinkParams struct { ExpiresAtNow *bool `form:"-"` // See custom AppendTo // The ID of the file. The file's `purpose` must be one of the following: `business_icon`, `business_logo`, `customer_signature`, `dispute_evidence`, `finance_report_run`, `identity_document_downloadable`, `pci_document`, `selfie`, `sigma_scheduled_query`, `tax_document_user_upload`, or `terminal_reader_splashscreen`. File *string `form:"file"` + // Set of [key-value pairs](https://stripe.com/docs/api/metadata) that you can attach to an object. This can be useful for storing additional information about the object in a structured format. Individual keys can be unset by posting an empty value to them. All keys can be unset by posting an empty value to `metadata`. + Metadata map[string]string `form:"metadata"` +} + +// AddMetadata adds a new key-value pair to the Metadata. +func (p *FileLinkParams) AddMetadata(key string, value string) { + if p.Metadata == nil { + p.Metadata = make(map[string]string) + } + + p.Metadata[key] = value } // AppendTo implements custom encoding logic for FileLinkParams. -func (f *FileLinkParams) AppendTo(body *form.Values, keyParts []string) { - if BoolValue(f.ExpiresAtNow) { +func (p *FileLinkParams) AppendTo(body *form.Values, keyParts []string) { + if BoolValue(p.ExpiresAtNow) { body.Add(form.FormatKey(append(keyParts, "expires_at")), "now") } } diff --git a/identity_verificationsession.go b/identity_verificationsession.go index abf9ebcaa0..0edb728dc9 100644 --- a/identity_verificationsession.go +++ b/identity_verificationsession.go @@ -104,6 +104,8 @@ type IdentityVerificationSessionOptionsParams struct { // Related guide: [Verify your users' identity documents](https://stripe.com/docs/identity/verify-identity-documents) type IdentityVerificationSessionParams struct { Params `form:"*"` + // Set of [key-value pairs](https://stripe.com/docs/api/metadata) that you can attach to an object. This can be useful for storing additional information about the object in a structured format. Individual keys can be unset by posting an empty value to them. All keys can be unset by posting an empty value to `metadata`. + Metadata map[string]string `form:"metadata"` // A set of options for the session's verification checks. Options *IdentityVerificationSessionOptionsParams `form:"options"` // The URL that the user will be redirected to upon completing the verification flow. @@ -112,6 +114,15 @@ type IdentityVerificationSessionParams struct { Type *string `form:"type"` } +// AddMetadata adds a new key-value pair to the Metadata. +func (p *IdentityVerificationSessionParams) AddMetadata(key string, value string) { + if p.Metadata == nil { + p.Metadata = make(map[string]string) + } + + p.Metadata[key] = value +} + // Returns a list of VerificationSessions type IdentityVerificationSessionListParams struct { ListParams `form:"*"` diff --git a/invoice.go b/invoice.go index 9c509528e9..b725af344e 100644 --- a/invoice.go +++ b/invoice.go @@ -301,6 +301,15 @@ type InvoiceUpcomingInvoiceItemParams struct { UnitAmountDecimal *float64 `form:"unit_amount_decimal,high_precision"` } +// AddMetadata adds a new key-value pair to the Metadata. +func (p *InvoiceUpcomingInvoiceItemParams) AddMetadata(key string, value string) { + if p.Metadata == nil { + p.Metadata = make(map[string]string) + } + + p.Metadata[key] = value +} + // At any time, you can preview the upcoming invoice for a customer. This will show you all the charges that are pending, including subscription renewal charges, invoice item charges, etc. It will also show you any discounts that are applicable to the invoice. // // Note that when you are viewing an upcoming invoice, you are simply viewing a preview – the invoice has not yet been created. As such, the upcoming invoice will not show up in invoice listing calls, and you cannot use the API to pay or edit the invoice. If you want to change the amount that your customer will be billed, you can add, remove, or update pending invoice items, or update the customer's discount. @@ -356,14 +365,14 @@ type InvoiceUpcomingParams struct { } // AppendTo implements custom encoding logic for InvoiceUpcomingParams. -func (i *InvoiceUpcomingParams) AppendTo(body *form.Values, keyParts []string) { - if BoolValue(i.SubscriptionBillingCycleAnchorNow) { +func (p *InvoiceUpcomingParams) AppendTo(body *form.Values, keyParts []string) { + if BoolValue(p.SubscriptionBillingCycleAnchorNow) { body.Add(form.FormatKey(append(keyParts, "subscription_billing_cycle_anchor")), "now") } - if BoolValue(i.SubscriptionBillingCycleAnchorUnchanged) { + if BoolValue(p.SubscriptionBillingCycleAnchorUnchanged) { body.Add(form.FormatKey(append(keyParts, "subscription_billing_cycle_anchor")), "unchanged") } - if BoolValue(i.SubscriptionTrialEndNow) { + if BoolValue(p.SubscriptionTrialEndNow) { body.Add(form.FormatKey(append(keyParts, "subscription_trial_end")), "now") } } @@ -559,6 +568,15 @@ type InvoiceShippingCostShippingRateDataParams struct { Type *string `form:"type"` } +// AddMetadata adds a new key-value pair to the Metadata. +func (p *InvoiceShippingCostShippingRateDataParams) AddMetadata(key string, value string) { + if p.Metadata == nil { + p.Metadata = make(map[string]string) + } + + p.Metadata[key] = value +} + // Settings for the cost of shipping for this invoice. type InvoiceShippingCostParams struct { // The ID of the shipping rate to use for this order. @@ -629,6 +647,8 @@ type InvoiceParams struct { Footer *string `form:"footer"` // Revise an existing invoice. The new invoice will be created in `status=draft`. See the [revision documentation](https://stripe.com/docs/invoicing/invoice-revisions) for more details. FromInvoice *InvoiceFromInvoiceParams `form:"from_invoice"` + // Set of [key-value pairs](https://stripe.com/docs/api/metadata) that you can attach to an object. This can be useful for storing additional information about the object in a structured format. Individual keys can be unset by posting an empty value to them. All keys can be unset by posting an empty value to `metadata`. + Metadata map[string]string `form:"metadata"` // The account (if any) for which the funds of the invoice payment are intended. If set, the invoice will be presented with the branding and support information of the specified account. See the [Invoices with Connect](https://stripe.com/docs/billing/invoices/connect) documentation for details. OnBehalfOf *string `form:"on_behalf_of"` // Configuration settings for the PaymentIntent that is generated when the invoice is finalized. @@ -649,6 +669,15 @@ type InvoiceParams struct { TransferData *InvoiceTransferDataParams `form:"transfer_data"` } +// AddMetadata adds a new key-value pair to the Metadata. +func (p *InvoiceParams) AddMetadata(key string, value string) { + if p.Metadata == nil { + p.Metadata = make(map[string]string) + } + + p.Metadata[key] = value +} + // Stripe automatically creates and then attempts to collect payment on invoices for customers on subscriptions according to your [subscriptions settings](https://dashboard.stripe.com/account/billing/automatic). However, if you'd like to attempt payment on an invoice out of the normal collection schedule or for some other reason, you can do so. type InvoicePayParams struct { Params `form:"*"` @@ -786,6 +815,15 @@ type InvoiceUpcomingLinesInvoiceItemParams struct { UnitAmountDecimal *float64 `form:"unit_amount_decimal,high_precision"` } +// AddMetadata adds a new key-value pair to the Metadata. +func (p *InvoiceUpcomingLinesInvoiceItemParams) AddMetadata(key string, value string) { + if p.Metadata == nil { + p.Metadata = make(map[string]string) + } + + p.Metadata[key] = value +} + // Define thresholds at which an invoice will be sent, and the subscription advanced to a new billing period. When updating, pass an empty string to remove previously-defined thresholds. type InvoiceUpcomingLinesSubscriptionItemBillingThresholdsParams struct { // Number of units that meets the billing threshold to advance the subscription to a new billing period (e.g., it takes 10 $5 units to meet a $50 [monetary threshold](https://stripe.com/docs/api/subscriptions/update#update_subscription-billing_thresholds-amount_gte)) @@ -840,6 +878,15 @@ type InvoiceUpcomingLinesSubscriptionItemParams struct { TaxRates []*string `form:"tax_rates"` } +// AddMetadata adds a new key-value pair to the Metadata. +func (p *InvoiceUpcomingLinesSubscriptionItemParams) AddMetadata(key string, value string) { + if p.Metadata == nil { + p.Metadata = make(map[string]string) + } + + p.Metadata[key] = value +} + // When retrieving an upcoming invoice, you'll get a lines property containing the total count of line items and the first handful of those items. There is also a URL where you can retrieve the full (paginated) list of line items. type InvoiceUpcomingLinesParams struct { ListParams `form:"*"` @@ -891,14 +938,14 @@ type InvoiceUpcomingLinesParams struct { } // AppendTo implements custom encoding logic for InvoiceUpcomingLinesParams. -func (i *InvoiceUpcomingLinesParams) AppendTo(body *form.Values, keyParts []string) { - if BoolValue(i.SubscriptionBillingCycleAnchorNow) { +func (p *InvoiceUpcomingLinesParams) AppendTo(body *form.Values, keyParts []string) { + if BoolValue(p.SubscriptionBillingCycleAnchorNow) { body.Add(form.FormatKey(append(keyParts, "subscription_billing_cycle_anchor")), "now") } - if BoolValue(i.SubscriptionBillingCycleAnchorUnchanged) { + if BoolValue(p.SubscriptionBillingCycleAnchorUnchanged) { body.Add(form.FormatKey(append(keyParts, "subscription_billing_cycle_anchor")), "unchanged") } - if BoolValue(i.SubscriptionTrialEndNow) { + if BoolValue(p.SubscriptionTrialEndNow) { body.Add(form.FormatKey(append(keyParts, "subscription_trial_end")), "now") } } diff --git a/invoiceitem.go b/invoiceitem.go index 782df8b7e6..393917b94d 100644 --- a/invoiceitem.go +++ b/invoiceitem.go @@ -66,6 +66,8 @@ type InvoiceItemParams struct { Discounts []*InvoiceItemDiscountParams `form:"discounts"` // The ID of an existing invoice to add this invoice item to. When left blank, the invoice item will be added to the next upcoming scheduled invoice. This is useful when adding invoice items in response to an invoice.created webhook. You can only add invoice items to draft invoices and there is a maximum of 250 items per invoice. Invoice *string `form:"invoice"` + // Set of [key-value pairs](https://stripe.com/docs/api/metadata) that you can attach to an object. This can be useful for storing additional information about the object in a structured format. Individual keys can be unset by posting an empty value to them. All keys can be unset by posting an empty value to `metadata`. + Metadata map[string]string `form:"metadata"` // The period associated with this invoice item. When set to different values, the period will be rendered on the invoice. If you have [Stripe Revenue Recognition](https://stripe.com/docs/revenue-recognition) enabled, the period will be used to recognize and defer revenue. See the [Revenue Recognition documentation](https://stripe.com/docs/revenue-recognition/methodology/subscriptions-and-invoicing) for details. Period *InvoiceItemPeriodParams `form:"period"` // The ID of the price object. @@ -88,6 +90,15 @@ type InvoiceItemParams struct { UnitAmountDecimal *float64 `form:"unit_amount_decimal,high_precision"` } +// AddMetadata adds a new key-value pair to the Metadata. +func (p *InvoiceItemParams) AddMetadata(key string, value string) { + if p.Metadata == nil { + p.Metadata = make(map[string]string) + } + + p.Metadata[key] = value +} + // Invoice Items represent the component lines of an [invoice](https://stripe.com/docs/api/invoices). An invoice item is added to an // invoice by creating or updating it with an `invoice` field, at which point it will be included as // [an invoice line item](https://stripe.com/docs/api/invoices/line_item) within diff --git a/issuing_authorization.go b/issuing_authorization.go index b0870c4ea3..b94da35ced 100644 --- a/issuing_authorization.go +++ b/issuing_authorization.go @@ -89,6 +89,17 @@ type IssuingAuthorizationListParams struct { // Retrieves an Issuing Authorization object. type IssuingAuthorizationParams struct { Params `form:"*"` + // Set of [key-value pairs](https://stripe.com/docs/api/metadata) that you can attach to an object. This can be useful for storing additional information about the object in a structured format. Individual keys can be unset by posting an empty value to them. All keys can be unset by posting an empty value to `metadata`. + Metadata map[string]string `form:"metadata"` +} + +// AddMetadata adds a new key-value pair to the Metadata. +func (p *IssuingAuthorizationParams) AddMetadata(key string, value string) { + if p.Metadata == nil { + p.Metadata = make(map[string]string) + } + + p.Metadata[key] = value } // Approves a pending Issuing Authorization object. This request should be made within the timeout window of the [real-time authorization](https://stripe.com/docs/issuing/controls/real-time-authorizations) flow. @@ -97,12 +108,34 @@ type IssuingAuthorizationApproveParams struct { Params `form:"*"` // If the authorization's `pending_request.is_amount_controllable` property is `true`, you may provide this value to control how much to hold for the authorization. Must be positive (use [`decline`](https://stripe.com/docs/api/issuing/authorizations/decline) to decline an authorization request). Amount *int64 `form:"amount"` + // Set of [key-value pairs](https://stripe.com/docs/api/metadata) that you can attach to an object. This can be useful for storing additional information about the object in a structured format. Individual keys can be unset by posting an empty value to them. All keys can be unset by posting an empty value to `metadata`. + Metadata map[string]string `form:"metadata"` +} + +// AddMetadata adds a new key-value pair to the Metadata. +func (p *IssuingAuthorizationApproveParams) AddMetadata(key string, value string) { + if p.Metadata == nil { + p.Metadata = make(map[string]string) + } + + p.Metadata[key] = value } // Declines a pending Issuing Authorization object. This request should be made within the timeout window of the [real time authorization](https://stripe.com/docs/issuing/controls/real-time-authorizations) flow. // You can also respond directly to the webhook request to decline an authorization (preferred). More details can be found [here](https://stripe.com/docs/issuing/controls/real-time-authorizations#authorization-handling). type IssuingAuthorizationDeclineParams struct { Params `form:"*"` + // Set of [key-value pairs](https://stripe.com/docs/api/metadata) that you can attach to an object. This can be useful for storing additional information about the object in a structured format. Individual keys can be unset by posting an empty value to them. All keys can be unset by posting an empty value to `metadata`. + Metadata map[string]string `form:"metadata"` +} + +// AddMetadata adds a new key-value pair to the Metadata. +func (p *IssuingAuthorizationDeclineParams) AddMetadata(key string, value string) { + if p.Metadata == nil { + p.Metadata = make(map[string]string) + } + + p.Metadata[key] = value } // Detailed breakdown of amount components. These amounts are denominated in `currency` and in the [smallest currency unit](https://stripe.com/docs/currencies#zero-decimal). diff --git a/issuing_card.go b/issuing_card.go index ad347c70fe..a1fdb17685 100644 --- a/issuing_card.go +++ b/issuing_card.go @@ -197,6 +197,8 @@ type IssuingCardParams struct { // The currency for the card. Currency *string `form:"currency"` FinancialAccount *string `form:"financial_account"` + // Set of [key-value pairs](https://stripe.com/docs/api/metadata) that you can attach to an object. This can be useful for storing additional information about the object in a structured format. Individual keys can be unset by posting an empty value to them. All keys can be unset by posting an empty value to `metadata`. + Metadata map[string]string `form:"metadata"` // The desired new PIN for this card. PIN *IssuingCardPINParams `form:"pin"` // The card this is meant to be a replacement for (if any). @@ -216,6 +218,15 @@ type IssuingCardParams struct { CancellationReason *string `form:"cancellation_reason"` } +// AddMetadata adds a new key-value pair to the Metadata. +func (p *IssuingCardParams) AddMetadata(key string, value string) { + if p.Metadata == nil { + p.Metadata = make(map[string]string) + } + + p.Metadata[key] = value +} + // The desired new PIN for this card. type IssuingCardPINParams struct { // The card's desired new PIN, encrypted under Stripe's public key. diff --git a/issuing_cardholder.go b/issuing_cardholder.go index ddc766009e..820b9f634a 100644 --- a/issuing_cardholder.go +++ b/issuing_cardholder.go @@ -181,6 +181,8 @@ type IssuingCardholderParams struct { Email *string `form:"email"` // Additional information about an `individual` cardholder. Individual *IssuingCardholderIndividualParams `form:"individual"` + // Set of [key-value pairs](https://stripe.com/docs/api/metadata) that you can attach to an object. This can be useful for storing additional information about the object in a structured format. Individual keys can be unset by posting an empty value to them. All keys can be unset by posting an empty value to `metadata`. + Metadata map[string]string `form:"metadata"` // The cardholder's name. This will be printed on cards issued to them. The maximum length of this field is 24 characters. This field cannot contain any special characters or numbers. Name *string `form:"name"` // The cardholder's phone number. This is required for all cardholders who will be creating EU cards. See the [3D Secure documentation](https://stripe.com/docs/issuing/3d-secure) for more details. @@ -195,6 +197,16 @@ type IssuingCardholderParams struct { // One of `individual` or `company`. See [Choose a cardholder type](https://stripe.com/docs/issuing/other/choose-cardholder) for more details. Type *string `form:"type"` } + +// AddMetadata adds a new key-value pair to the Metadata. +func (p *IssuingCardholderParams) AddMetadata(key string, value string) { + if p.Metadata == nil { + p.Metadata = make(map[string]string) + } + + p.Metadata[key] = value +} + type IssuingCardholderBilling struct { Address *Address `json:"address"` } diff --git a/issuing_dispute.go b/issuing_dispute.go index d696e23ce4..b6412e616f 100644 --- a/issuing_dispute.go +++ b/issuing_dispute.go @@ -229,16 +229,39 @@ type IssuingDisputeParams struct { Amount *int64 `form:"amount"` // Evidence provided for the dispute. Evidence *IssuingDisputeEvidenceParams `form:"evidence"` + // Set of [key-value pairs](https://stripe.com/docs/api/metadata) that you can attach to an object. This can be useful for storing additional information about the object in a structured format. Individual keys can be unset by posting an empty value to them. All keys can be unset by posting an empty value to `metadata`. + Metadata map[string]string `form:"metadata"` // The ID of the issuing transaction to create a dispute for. For transaction on Treasury FinancialAccounts, use `treasury.received_debit`. Transaction *string `form:"transaction"` // Params for disputes related to Treasury FinancialAccounts Treasury *IssuingDisputeTreasuryParams `form:"treasury"` } +// AddMetadata adds a new key-value pair to the Metadata. +func (p *IssuingDisputeParams) AddMetadata(key string, value string) { + if p.Metadata == nil { + p.Metadata = make(map[string]string) + } + + p.Metadata[key] = value +} + // Submits an Issuing Dispute to the card network. Stripe validates that all evidence fields required for the dispute's reason are present. For more details, see [Dispute reasons and evidence](https://stripe.com/docs/issuing/purchases/disputes#dispute-reasons-and-evidence). type IssuingDisputeSubmitParams struct { Params `form:"*"` + // Set of [key-value pairs](https://stripe.com/docs/api/metadata) that you can attach to an object. This can be useful for storing additional information about the object in a structured format. Individual keys can be unset by posting an empty value to them. All keys can be unset by posting an empty value to `metadata`. + Metadata map[string]string `form:"metadata"` } + +// AddMetadata adds a new key-value pair to the Metadata. +func (p *IssuingDisputeSubmitParams) AddMetadata(key string, value string) { + if p.Metadata == nil { + p.Metadata = make(map[string]string) + } + + p.Metadata[key] = value +} + type IssuingDisputeEvidenceCanceled struct { // (ID of a [file upload](https://stripe.com/docs/guides/file-upload)) Additional documentation supporting the dispute. AdditionalDocumentation *File `json:"additional_documentation"` diff --git a/issuing_transaction.go b/issuing_transaction.go index dab16c2522..a1d3033b48 100644 --- a/issuing_transaction.go +++ b/issuing_transaction.go @@ -66,6 +66,17 @@ type IssuingTransactionListParams struct { // Retrieves an Issuing Transaction object. type IssuingTransactionParams struct { Params `form:"*"` + // Set of [key-value pairs](https://stripe.com/docs/api/metadata) that you can attach to an object. This can be useful for storing additional information about the object in a structured format. Individual keys can be unset by posting an empty value to them. All keys can be unset by posting an empty value to `metadata`. + Metadata map[string]string `form:"metadata"` +} + +// AddMetadata adds a new key-value pair to the Metadata. +func (p *IssuingTransactionParams) AddMetadata(key string, value string) { + if p.Metadata == nil { + p.Metadata = make(map[string]string) + } + + p.Metadata[key] = value } // Detailed breakdown of amount components. These amounts are denominated in `currency` and in the [smallest currency unit](https://stripe.com/docs/currencies#zero-decimal). diff --git a/params.go b/params.go index dfd873ab60..cb6fea4888 100644 --- a/params.go +++ b/params.go @@ -189,8 +189,10 @@ type Params struct { // Headers may be used to provide extra header lines on the HTTP request. Headers http.Header `form:"-"` - IdempotencyKey *string `form:"-"` // Passed as header - Metadata map[string]string `form:"metadata"` + IdempotencyKey *string `form:"-"` // Passed as header + + // Deprecated: Please use Metadata in the containing struct instead. + Metadata map[string]string `form:"metadata"` // StripeAccount may contain the ID of a connected account. By including // this field, the request is made as if it originated from the connected @@ -213,7 +215,8 @@ func (p *Params) AddExtra(key, value string) { p.Extra.Add(key, value) } -// AddMetadata adds a new key-value pair to the Metadata. +// AddMetadata is deprecated. +// Deprecated: please use .AddMetadata of the containing Params struct. func (p *Params) AddMetadata(key, value string) { if p.Metadata == nil { p.Metadata = make(map[string]string) diff --git a/paymentintent.go b/paymentintent.go index aed192f01b..1453d79175 100644 --- a/paymentintent.go +++ b/paymentintent.go @@ -949,6 +949,15 @@ type PaymentIntentPaymentMethodDataParams struct { Zip *PaymentIntentPaymentMethodDataZipParams `form:"zip"` } +// AddMetadata adds a new key-value pair to the Metadata. +func (p *PaymentIntentPaymentMethodDataParams) AddMetadata(key string, value string) { + if p.Metadata == nil { + p.Metadata = make(map[string]string) + } + + p.Metadata[key] = value +} + // Additional fields for Mandate creation type PaymentIntentPaymentMethodOptionsACSSDebitMandateOptionsParams struct { // A URL for custom mandate text to render during confirmation step. @@ -1666,6 +1675,8 @@ type PaymentIntentParams struct { Mandate *string `form:"mandate"` // This hash contains details about the Mandate to create. This parameter can only be used with [`confirm=true`](https://stripe.com/docs/api/payment_intents/create#create_payment_intent-confirm). MandateData *PaymentIntentMandateDataParams `form:"mandate_data"` + // Set of [key-value pairs](https://stripe.com/docs/api/metadata) that you can attach to an object. This can be useful for storing additional information about the object in a structured format. Individual keys can be unset by posting an empty value to them. All keys can be unset by posting an empty value to `metadata`. + Metadata map[string]string `form:"metadata"` // The Stripe account ID for which these funds are intended. For details, see the PaymentIntents [use case for connected accounts](https://stripe.com/docs/payments/connected-accounts). OnBehalfOf *string `form:"on_behalf_of"` // ID of the payment method (a PaymentMethod, Card, or [compatible Source](https://stripe.com/docs/payments/payment-methods/transitioning#compatibility) object) to attach to this PaymentIntent. @@ -1711,6 +1722,15 @@ type PaymentIntentParams struct { UseStripeSDK *bool `form:"use_stripe_sdk"` } +// AddMetadata adds a new key-value pair to the Metadata. +func (p *PaymentIntentParams) AddMetadata(key string, value string) { + if p.Metadata == nil { + p.Metadata = make(map[string]string) + } + + p.Metadata[key] = value +} + // Returns a list of PaymentIntents. type PaymentIntentListParams struct { ListParams `form:"*"` @@ -1815,6 +1835,8 @@ type PaymentIntentCaptureParams struct { AmountToCapture *int64 `form:"amount_to_capture"` // The amount of the application fee (if any) that will be requested to be applied to the payment and transferred to the application owner's Stripe account. The amount of the application fee collected will be capped at the total payment amount. For more information, see the PaymentIntents [use case for connected accounts](https://stripe.com/docs/payments/connected-accounts). ApplicationFeeAmount *int64 `form:"application_fee_amount"` + // Set of [key-value pairs](https://stripe.com/docs/api/metadata) that you can attach to an object. This can be useful for storing additional information about the object in a structured format. Individual keys can be unset by posting an empty value to them. All keys can be unset by posting an empty value to `metadata`. + Metadata map[string]string `form:"metadata"` // For non-card charges, you can use this value as the complete description that appears on your customers' statements. Must contain at least one letter, maximum 22 characters. StatementDescriptor *string `form:"statement_descriptor"` // Provides information about a card payment that customers see on their statements. Concatenated with the prefix (shortened descriptor) or statement descriptor that's set on the account to form the complete statement descriptor. Maximum 22 characters for the concatenated descriptor. @@ -1824,6 +1846,15 @@ type PaymentIntentCaptureParams struct { TransferData *PaymentIntentTransferDataParams `form:"transfer_data"` } +// AddMetadata adds a new key-value pair to the Metadata. +func (p *PaymentIntentCaptureParams) AddMetadata(key string, value string) { + if p.Metadata == nil { + p.Metadata = make(map[string]string) + } + + p.Metadata[key] = value +} + // The parameters used to automatically create a Transfer when the payment is captured. // For more information, see the PaymentIntents [use case for connected accounts](https://stripe.com/docs/payments/connected-accounts). type PaymentIntentIncrementAuthorizationTransferDataParams struct { @@ -1863,6 +1894,8 @@ type PaymentIntentIncrementAuthorizationParams struct { ApplicationFeeAmount *int64 `form:"application_fee_amount"` // An arbitrary string attached to the object. Often useful for displaying to users. Description *string `form:"description"` + // Set of [key-value pairs](https://stripe.com/docs/api/metadata) that you can attach to an object. This can be useful for storing additional information about the object in a structured format. Individual keys can be unset by posting an empty value to them. All keys can be unset by posting an empty value to `metadata`. + Metadata map[string]string `form:"metadata"` // For non-card charges, you can use this value as the complete description that appears on your customers' statements. Must contain at least one letter, maximum 22 characters. StatementDescriptor *string `form:"statement_descriptor"` // The parameters used to automatically create a Transfer when the payment is captured. @@ -1870,6 +1903,15 @@ type PaymentIntentIncrementAuthorizationParams struct { TransferData *PaymentIntentIncrementAuthorizationTransferDataParams `form:"transfer_data"` } +// AddMetadata adds a new key-value pair to the Metadata. +func (p *PaymentIntentIncrementAuthorizationParams) AddMetadata(key string, value string) { + if p.Metadata == nil { + p.Metadata = make(map[string]string) + } + + p.Metadata[key] = value +} + // Verifies microdeposits on a PaymentIntent object. type PaymentIntentVerifyMicrodepositsParams struct { Params `form:"*"` diff --git a/paymentlink.go b/paymentlink.go index 084af1c6a0..be65ffb62a 100644 --- a/paymentlink.go +++ b/paymentlink.go @@ -297,6 +297,15 @@ type PaymentLinkInvoiceCreationInvoiceDataParams struct { RenderingOptions *PaymentLinkInvoiceCreationInvoiceDataRenderingOptionsParams `form:"rendering_options"` } +// AddMetadata adds a new key-value pair to the Metadata. +func (p *PaymentLinkInvoiceCreationInvoiceDataParams) AddMetadata(key string, value string) { + if p.Metadata == nil { + p.Metadata = make(map[string]string) + } + + p.Metadata[key] = value +} + // Generate a post-purchase Invoice for one-time payments. type PaymentLinkInvoiceCreationParams struct { // Whether the feature is enabled @@ -422,6 +431,8 @@ type PaymentLinkParams struct { InvoiceCreation *PaymentLinkInvoiceCreationParams `form:"invoice_creation"` // The line items representing what is being sold. Each line item represents an item being sold. Up to 20 line items are supported. LineItems []*PaymentLinkLineItemParams `form:"line_items"` + // Set of [key-value pairs](https://stripe.com/docs/api/metadata) that you can attach to an object. This can be useful for storing additional information about the object in a structured format. Individual keys can be unset by posting an empty value to them. All keys can be unset by posting an empty value to `metadata`. Metadata associated with this Payment Link will automatically be copied to [checkout sessions](https://stripe.com/docs/api/checkout/sessions) created by this payment link. + Metadata map[string]string `form:"metadata"` // The account on behalf of which to charge. OnBehalfOf *string `form:"on_behalf_of"` // A subset of parameters to be passed to PaymentIntent creation for Checkout Sessions in `payment` mode. @@ -452,6 +463,15 @@ type PaymentLinkParams struct { TransferData *PaymentLinkTransferDataParams `form:"transfer_data"` } +// AddMetadata adds a new key-value pair to the Metadata. +func (p *PaymentLinkParams) AddMetadata(key string, value string) { + if p.Metadata == nil { + p.Metadata = make(map[string]string) + } + + p.Metadata[key] = value +} + // When retrieving a payment link, there is an includable line_items property containing the first handful of those items. There is also a URL where you can retrieve the full (paginated) list of line items. type PaymentLinkListLineItemsParams struct { ListParams `form:"*"` diff --git a/paymentmethod.go b/paymentmethod.go index 1b1685e919..9759fabe12 100644 --- a/paymentmethod.go +++ b/paymentmethod.go @@ -473,6 +473,8 @@ type PaymentMethodParams struct { Konbini *PaymentMethodKonbiniParams `form:"konbini"` // If this is an `Link` PaymentMethod, this hash contains details about the Link payment method. Link *PaymentMethodLinkParams `form:"link"` + // Set of [key-value pairs](https://stripe.com/docs/api/metadata) that you can attach to an object. This can be useful for storing additional information about the object in a structured format. Individual keys can be unset by posting an empty value to them. All keys can be unset by posting an empty value to `metadata`. + Metadata map[string]string `form:"metadata"` // If this is an `oxxo` PaymentMethod, this hash contains details about the OXXO payment method. OXXO *PaymentMethodOXXOParams `form:"oxxo"` // If this is a `p24` PaymentMethod, this hash contains details about the P24 payment method. @@ -506,6 +508,15 @@ type PaymentMethodParams struct { PaymentMethod *string `form:"payment_method"` } +// AddMetadata adds a new key-value pair to the Metadata. +func (p *PaymentMethodParams) AddMetadata(key string, value string) { + if p.Metadata == nil { + p.Metadata = make(map[string]string) + } + + p.Metadata[key] = value +} + // Returns a list of PaymentMethods for Treasury flows. If you want to list the PaymentMethods attached to a Customer for payments, you should use the [List a Customer's PaymentMethods](https://stripe.com/docs/api/payment_methods/customer_list) API instead. type PaymentMethodListParams struct { ListParams `form:"*"` diff --git a/paymentsource.go b/paymentsource.go index 1e7fbd1bef..c3b7a9dd39 100644 --- a/paymentsource.go +++ b/paymentsource.go @@ -96,6 +96,8 @@ type PaymentSourceParams struct { ExpMonth *string `form:"exp_month"` // Four digit number representing the card's expiration year. ExpYear *string `form:"exp_year"` + // Set of [key-value pairs](https://stripe.com/docs/api/metadata) that you can attach to an object. This can be useful for storing additional information about the object in a structured format. Individual keys can be unset by posting an empty value to them. All keys can be unset by posting an empty value to `metadata`. + Metadata map[string]string `form:"metadata"` // Cardholder name. Name *string `form:"name"` Owner *PaymentSourceOwnerParams `form:"owner"` @@ -103,6 +105,16 @@ type PaymentSourceParams struct { Source *PaymentSourceSourceParams `form:"*"` // PaymentSourceSourceParams has custom encoding so brought to top level with "*" Validate *bool `form:"validate"` } + +// AddMetadata adds a new key-value pair to the Metadata. +func (p *PaymentSourceParams) AddMetadata(key string, value string) { + if p.Metadata == nil { + p.Metadata = make(map[string]string) + } + + p.Metadata[key] = value +} + type PaymentSourceOwnerParams struct { // Owner's address. Address *AddressParams `form:"address"` diff --git a/payout.go b/payout.go index 72d8537ac0..24dd8216d5 100644 --- a/payout.go +++ b/payout.go @@ -99,6 +99,8 @@ type PayoutParams struct { Description *string `form:"description"` // The ID of a bank account or a card to send the payout to. If no destination is supplied, the default external account for the specified currency will be used. Destination *string `form:"destination"` + // Set of [key-value pairs](https://stripe.com/docs/api/metadata) that you can attach to an object. This can be useful for storing additional information about the object in a structured format. Individual keys can be unset by posting an empty value to them. All keys can be unset by posting an empty value to `metadata`. + Metadata map[string]string `form:"metadata"` // The method used to send this payout, which can be `standard` or `instant`. `instant` is only supported for payouts to debit cards. (See [Instant payouts for marketplaces for more information](https://stripe.com/blog/instant-payouts-for-marketplaces).) Method *string `form:"method"` // The balance type of your Stripe balance to draw this payout from. Balances for different payment sources are kept separately. You can find the amounts with the balances API. One of `bank_account`, `card`, or `fpx`. @@ -107,6 +109,15 @@ type PayoutParams struct { StatementDescriptor *string `form:"statement_descriptor"` } +// AddMetadata adds a new key-value pair to the Metadata. +func (p *PayoutParams) AddMetadata(key string, value string) { + if p.Metadata == nil { + p.Metadata = make(map[string]string) + } + + p.Metadata[key] = value +} + // Returns a list of existing payouts sent to third-party bank accounts or that Stripe has sent you. The payouts are returned in sorted order, with the most recently created payouts appearing first. type PayoutListParams struct { ListParams `form:"*"` @@ -125,6 +136,17 @@ type PayoutListParams struct { // By requesting a reversal via /v1/payouts/:id/reverse, you confirm that the authorized signatory of the selected bank account has authorized the debit on the bank account and that no other authorization is required. type PayoutReverseParams struct { Params `form:"*"` + // Set of [key-value pairs](https://stripe.com/docs/api/metadata) that you can attach to an object. This can be useful for storing additional information about the object in a structured format. Individual keys can be unset by posting an empty value to them. All keys can be unset by posting an empty value to `metadata`. + Metadata map[string]string `form:"metadata"` +} + +// AddMetadata adds a new key-value pair to the Metadata. +func (p *PayoutReverseParams) AddMetadata(key string, value string) { + if p.Metadata == nil { + p.Metadata = make(map[string]string) + } + + p.Metadata[key] = value } // A `Payout` object is created when you receive funds from Stripe, or when you diff --git a/person.go b/person.go index 7905a3507e..734d8070a6 100644 --- a/person.go +++ b/person.go @@ -232,6 +232,8 @@ type PersonParams struct { LastNameKanji *string `form:"last_name_kanji"` // The person's maiden name. MaidenName *string `form:"maiden_name"` + // Set of [key-value pairs](https://stripe.com/docs/api/metadata) that you can attach to an object. This can be useful for storing additional information about the object in a structured format. Individual keys can be unset by posting an empty value to them. All keys can be unset by posting an empty value to `metadata`. + Metadata map[string]string `form:"metadata"` // The country where the person is a national. Two-letter country code ([ISO 3166-1 alpha-2](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2)), or "XX" if unavailable. Nationality *string `form:"nationality"` // A [person token](https://stripe.com/docs/connect/account-tokens), used to securely provide details to the person. @@ -250,6 +252,15 @@ type PersonParams struct { Verification *PersonVerificationParams `form:"verification"` } +// AddMetadata adds a new key-value pair to the Metadata. +func (p *PersonParams) AddMetadata(key string, value string) { + if p.Metadata == nil { + p.Metadata = make(map[string]string) + } + + p.Metadata[key] = value +} + // The Kana variation of the person's address (Japan only). type PersonAddressKana struct { // City/Ward. diff --git a/plan.go b/plan.go index 094ec198e8..ac2c9a00c0 100644 --- a/plan.go +++ b/plan.go @@ -103,6 +103,15 @@ type PlanProductParams struct { UnitLabel *string `form:"unit_label"` } +// AddMetadata adds a new key-value pair to the Metadata. +func (p *PlanProductParams) AddMetadata(key string, value string) { + if p.Metadata == nil { + p.Metadata = make(map[string]string) + } + + p.Metadata[key] = value +} + // Each element represents a pricing tier. This parameter requires `billing_scheme` to be set to `tiered`. See also the documentation for `billing_scheme`. type PlanTierParams struct { Params `form:"*"` @@ -160,6 +169,8 @@ type PlanParams struct { Interval *string `form:"interval"` // The number of intervals between subscription billings. For example, `interval=month` and `interval_count=3` bills every 3 months. Maximum of one year interval allowed (1 year, 12 months, or 52 weeks). IntervalCount *int64 `form:"interval_count"` + // Set of [key-value pairs](https://stripe.com/docs/api/metadata) that you can attach to an object. This can be useful for storing additional information about the object in a structured format. Individual keys can be unset by posting an empty value to them. All keys can be unset by posting an empty value to `metadata`. + Metadata map[string]string `form:"metadata"` // A brief description of the plan, hidden from customers. Nickname *string `form:"nickname"` Product *PlanProductParams `form:"product"` @@ -175,6 +186,15 @@ type PlanParams struct { UsageType *string `form:"usage_type"` } +// AddMetadata adds a new key-value pair to the Metadata. +func (p *PlanParams) AddMetadata(key string, value string) { + if p.Metadata == nil { + p.Metadata = make(map[string]string) + } + + p.Metadata[key] = value +} + // Each element represents a pricing tier. This parameter requires `billing_scheme` to be set to `tiered`. See also the documentation for `billing_scheme`. type PlanTier struct { // Price for the entire tier. diff --git a/price.go b/price.go index 229c2326c7..b14561fbe0 100644 --- a/price.go +++ b/price.go @@ -217,6 +217,15 @@ type PriceProductDataParams struct { UnitLabel *string `form:"unit_label"` } +// AddMetadata adds a new key-value pair to the Metadata. +func (p *PriceProductDataParams) AddMetadata(key string, value string) { + if p.Metadata == nil { + p.Metadata = make(map[string]string) + } + + p.Metadata[key] = value +} + // The recurring components of a price such as `interval` and `usage_type`. type PriceRecurringParams struct { // Specifies a usage aggregation strategy for prices of `usage_type=metered`. Allowed values are `sum` for summing up all usage during a period, `last_during_period` for using the last usage record reported within a period, `last_ever` for using the last usage record ever (across period bounds) or `max` which uses the usage record with the maximum reported usage during a period. Defaults to `sum`. @@ -276,6 +285,8 @@ type PriceParams struct { CustomUnitAmount *PriceCustomUnitAmountParams `form:"custom_unit_amount"` // A lookup key used to retrieve prices dynamically from a static string. This may be up to 200 characters. LookupKey *string `form:"lookup_key"` + // Set of [key-value pairs](https://stripe.com/docs/api/metadata) that you can attach to an object. This can be useful for storing additional information about the object in a structured format. Individual keys can be unset by posting an empty value to them. All keys can be unset by posting an empty value to `metadata`. + Metadata map[string]string `form:"metadata"` // A brief description of the price, hidden from customers. Nickname *string `form:"nickname"` // The ID of the product that this price will belong to. @@ -300,6 +311,15 @@ type PriceParams struct { UnitAmountDecimal *float64 `form:"unit_amount_decimal,high_precision"` } +// AddMetadata adds a new key-value pair to the Metadata. +func (p *PriceParams) AddMetadata(key string, value string) { + if p.Metadata == nil { + p.Metadata = make(map[string]string) + } + + p.Metadata[key] = value +} + // When set, provides configuration for the amount to be adjusted by the customer during Checkout Sessions and Payment Links. type PriceCurrencyOptionsCustomUnitAmount struct { // The maximum unit amount the customer can specify for this item. diff --git a/product.go b/product.go index ed965a363d..544086c40f 100644 --- a/product.go +++ b/product.go @@ -135,6 +135,8 @@ type ProductParams struct { ID *string `form:"id"` // A list of up to 8 URLs of images for this product, meant to be displayable to the customer. Images []*string `form:"images"` + // Set of [key-value pairs](https://stripe.com/docs/api/metadata) that you can attach to an object. This can be useful for storing additional information about the object in a structured format. Individual keys can be unset by posting an empty value to them. All keys can be unset by posting an empty value to `metadata`. + Metadata map[string]string `form:"metadata"` // The product's name, meant to be displayable to the customer. Name *string `form:"name"` // The dimensions of this product for shipping purposes. @@ -156,6 +158,15 @@ type ProductParams struct { URL *string `form:"url"` } +// AddMetadata adds a new key-value pair to the Metadata. +func (p *ProductParams) AddMetadata(key string, value string) { + if p.Metadata == nil { + p.Metadata = make(map[string]string) + } + + p.Metadata[key] = value +} + // Returns a list of your products. The products are returned sorted by creation date, with the most recently created products appearing first. type ProductListParams struct { ListParams `form:"*"` diff --git a/promotioncode.go b/promotioncode.go index 2e26cde6f6..dfeda2de81 100644 --- a/promotioncode.go +++ b/promotioncode.go @@ -23,10 +23,21 @@ type PromotionCodeParams struct { ExpiresAt *int64 `form:"expires_at"` // A positive integer specifying the number of times the promotion code can be redeemed. If the coupon has specified a `max_redemptions`, then this value cannot be greater than the coupon's `max_redemptions`. MaxRedemptions *int64 `form:"max_redemptions"` + // Set of [key-value pairs](https://stripe.com/docs/api/metadata) that you can attach to an object. This can be useful for storing additional information about the object in a structured format. Individual keys can be unset by posting an empty value to them. All keys can be unset by posting an empty value to `metadata`. + Metadata map[string]string `form:"metadata"` // Settings that restrict the redemption of the promotion code. Restrictions *PromotionCodeRestrictionsParams `form:"restrictions"` } +// AddMetadata adds a new key-value pair to the Metadata. +func (p *PromotionCodeParams) AddMetadata(key string, value string) { + if p.Metadata == nil { + p.Metadata = make(map[string]string) + } + + p.Metadata[key] = value +} + // Promotion codes defined in each available currency option. Each key must be a three-letter [ISO currency code](https://www.iso.org/iso-4217-currency-codes.html) and a [supported currency](https://stripe.com/docs/currencies). type PromotionCodeRestrictionsCurrencyOptionsParams struct { // Minimum amount required to redeem this Promotion Code into a Coupon (e.g., a purchase must be $100 or more to work). diff --git a/quote.go b/quote.go index 40d6da290c..f766dc3441 100644 --- a/quote.go +++ b/quote.go @@ -158,6 +158,8 @@ type QuoteParams struct { InvoiceSettings *QuoteInvoiceSettingsParams `form:"invoice_settings"` // A list of line items the customer is being quoted for. Each line item includes information about the product, the quantity, and the resulting cost. LineItems []*QuoteLineItemParams `form:"line_items"` + // Set of [key-value pairs](https://stripe.com/docs/api/metadata) that you can attach to an object. This can be useful for storing additional information about the object in a structured format. Individual keys can be unset by posting an empty value to them. All keys can be unset by posting an empty value to `metadata`. + Metadata map[string]string `form:"metadata"` // The account on behalf of which to charge. OnBehalfOf *string `form:"on_behalf_of"` // When creating a subscription or subscription schedule, the specified configuration data will be used. There must be at least one line item with a recurring price for a subscription or subscription schedule to be created. A subscription schedule is created if `subscription_data[effective_date]` is present and in the future, otherwise a subscription is created. @@ -168,6 +170,15 @@ type QuoteParams struct { TransferData *QuoteTransferDataParams `form:"transfer_data"` } +// AddMetadata adds a new key-value pair to the Metadata. +func (p *QuoteParams) AddMetadata(key string, value string) { + if p.Metadata == nil { + p.Metadata = make(map[string]string) + } + + p.Metadata[key] = value +} + // Settings for automatic tax lookup for this quote and resulting invoices and subscriptions. type QuoteAutomaticTaxParams struct { // Controls whether Stripe will automatically compute tax on the resulting invoices or subscriptions as well as the quote itself. @@ -238,8 +249,8 @@ type QuoteSubscriptionDataParams struct { } // AppendTo implements custom encoding logic for QuoteSubscriptionDataParams. -func (q *QuoteSubscriptionDataParams) AppendTo(body *form.Values, keyParts []string) { - if BoolValue(q.EffectiveDateCurrentPeriodEnd) { +func (p *QuoteSubscriptionDataParams) AppendTo(body *form.Values, keyParts []string) { + if BoolValue(p.EffectiveDateCurrentPeriodEnd) { body.Add(form.FormatKey(append(keyParts, "effective_date")), "current_period_end") } } diff --git a/radar_valuelist.go b/radar_valuelist.go index 4521fba97d..50379efc5a 100644 --- a/radar_valuelist.go +++ b/radar_valuelist.go @@ -41,10 +41,21 @@ type RadarValueListParams struct { Alias *string `form:"alias"` // Type of the items in the value list. One of `card_fingerprint`, `us_bank_account_fingerprint`, `sepa_debit_fingerprint`, `card_bin`, `email`, `ip_address`, `country`, `string`, `case_sensitive_string`, or `customer_id`. Use `string` if the item type is unknown or mixed. ItemType *string `form:"item_type"` + // Set of [key-value pairs](https://stripe.com/docs/api/metadata) that you can attach to an object. This can be useful for storing additional information about the object in a structured format. Individual keys can be unset by posting an empty value to them. All keys can be unset by posting an empty value to `metadata`. + Metadata map[string]string `form:"metadata"` // The human-readable name of the value list. Name *string `form:"name"` } +// AddMetadata adds a new key-value pair to the Metadata. +func (p *RadarValueListParams) AddMetadata(key string, value string) { + if p.Metadata == nil { + p.Metadata = make(map[string]string) + } + + p.Metadata[key] = value +} + // Value lists allow you to group values together which can then be referenced in rules. // // Related guide: [Default Stripe lists](https://stripe.com/docs/radar/lists#managing-list-items) diff --git a/refund.go b/refund.go index ed02050d1f..8d2a39c629 100644 --- a/refund.go +++ b/refund.go @@ -64,6 +64,8 @@ type RefundParams struct { Customer *string `form:"customer"` // For payment methods without native refund support (e.g., Konbini, PromptPay), use this email from the customer to receive refund instructions. InstructionsEmail *string `form:"instructions_email"` + // Set of [key-value pairs](https://stripe.com/docs/api/metadata) that you can attach to an object. This can be useful for storing additional information about the object in a structured format. Individual keys can be unset by posting an empty value to them. All keys can be unset by posting an empty value to `metadata`. + Metadata map[string]string `form:"metadata"` // Origin of the refund Origin *string `form:"origin"` PaymentIntent *string `form:"payment_intent"` @@ -72,6 +74,15 @@ type RefundParams struct { ReverseTransfer *bool `form:"reverse_transfer"` } +// AddMetadata adds a new key-value pair to the Metadata. +func (p *RefundParams) AddMetadata(key string, value string) { + if p.Metadata == nil { + p.Metadata = make(map[string]string) + } + + p.Metadata[key] = value +} + // Cancels a refund with a status of requires_action. // // Refunds in other states cannot be canceled, and only refunds for payment methods that require customer action will enter the requires_action state. diff --git a/setupintent.go b/setupintent.go index 03cdc8b829..193cf9c58c 100644 --- a/setupintent.go +++ b/setupintent.go @@ -519,6 +519,15 @@ type SetupIntentPaymentMethodDataParams struct { Zip *SetupIntentPaymentMethodDataZipParams `form:"zip"` } +// AddMetadata adds a new key-value pair to the Metadata. +func (p *SetupIntentPaymentMethodDataParams) AddMetadata(key string, value string) { + if p.Metadata == nil { + p.Metadata = make(map[string]string) + } + + p.Metadata[key] = value +} + // Additional fields for Mandate creation type SetupIntentPaymentMethodOptionsACSSDebitMandateOptionsParams struct { // A URL for custom mandate text to render during confirmation step. @@ -688,6 +697,8 @@ type SetupIntentParams struct { FlowDirections []*string `form:"flow_directions"` // This hash contains details about the Mandate to create. This parameter can only be used with [`confirm=true`](https://stripe.com/docs/api/setup_intents/create#create_setup_intent-confirm). MandateData *SetupIntentMandateDataParams `form:"mandate_data"` + // Set of [key-value pairs](https://stripe.com/docs/api/metadata) that you can attach to an object. This can be useful for storing additional information about the object in a structured format. Individual keys can be unset by posting an empty value to them. All keys can be unset by posting an empty value to `metadata`. + Metadata map[string]string `form:"metadata"` // The Stripe account ID for which this SetupIntent is created. OnBehalfOf *string `form:"on_behalf_of"` // ID of the payment method (a PaymentMethod, Card, or saved Source object) to attach to this SetupIntent. @@ -709,6 +720,15 @@ type SetupIntentParams struct { UseStripeSDK *bool `form:"use_stripe_sdk"` } +// AddMetadata adds a new key-value pair to the Metadata. +func (p *SetupIntentParams) AddMetadata(key string, value string) { + if p.Metadata == nil { + p.Metadata = make(map[string]string) + } + + p.Metadata[key] = value +} + // Returns a list of SetupIntents. type SetupIntentListParams struct { ListParams `form:"*"` @@ -976,6 +996,15 @@ type SetupIntentConfirmPaymentMethodDataParams struct { Zip *SetupIntentConfirmPaymentMethodDataZipParams `form:"zip"` } +// AddMetadata adds a new key-value pair to the Metadata. +func (p *SetupIntentConfirmPaymentMethodDataParams) AddMetadata(key string, value string) { + if p.Metadata == nil { + p.Metadata = make(map[string]string) + } + + p.Metadata[key] = value +} + // Confirm that your customer intends to set up the current or // provided payment method. For example, you would confirm a SetupIntent // when a customer hits the “Save” button on a payment method management diff --git a/shippingrate.go b/shippingrate.go index 31ae48251d..68574f6d30 100644 --- a/shippingrate.go +++ b/shippingrate.go @@ -126,6 +126,8 @@ type ShippingRateParams struct { DisplayName *string `form:"display_name"` // Describes a fixed amount to charge for shipping. Must be present if type is `fixed_amount`. FixedAmount *ShippingRateFixedAmountParams `form:"fixed_amount"` + // Set of [key-value pairs](https://stripe.com/docs/api/metadata) that you can attach to an object. This can be useful for storing additional information about the object in a structured format. Individual keys can be unset by posting an empty value to them. All keys can be unset by posting an empty value to `metadata`. + Metadata map[string]string `form:"metadata"` // Specifies whether the rate is considered inclusive of taxes or exclusive of taxes. One of `inclusive`, `exclusive`, or `unspecified`. TaxBehavior *string `form:"tax_behavior"` // A [tax code](https://stripe.com/docs/tax/tax-categories) ID. The Shipping tax code is `txcd_92010001`. @@ -134,6 +136,15 @@ type ShippingRateParams struct { Type *string `form:"type"` } +// AddMetadata adds a new key-value pair to the Metadata. +func (p *ShippingRateParams) AddMetadata(key string, value string) { + if p.Metadata == nil { + p.Metadata = make(map[string]string) + } + + p.Metadata[key] = value +} + // The upper bound of the estimated range. If empty, represents no upper bound i.e., infinite. type ShippingRateDeliveryEstimateMaximum struct { // A unit of time. diff --git a/source.go b/source.go index 0239f2b0be..035dd3e47c 100644 --- a/source.go +++ b/source.go @@ -123,6 +123,8 @@ type SourceParams struct { Flow *string `form:"flow"` // Information about a mandate possibility attached to a source object (generally for bank debits) as well as its acceptance status. Mandate *SourceMandateParams `form:"mandate"` + // Set of [key-value pairs](https://stripe.com/docs/api/metadata) that you can attach to an object. This can be useful for storing additional information about the object in a structured format. Individual keys can be unset by posting an empty value to them. All keys can be unset by posting an empty value to `metadata`. + Metadata map[string]string `form:"metadata"` // The source to share. OriginalSource *string `form:"original_source"` // Information about the owner of the payment instrument that may be used or required by particular source types. @@ -142,6 +144,15 @@ type SourceParams struct { Usage *string `form:"usage"` } +// AddMetadata adds a new key-value pair to the Metadata. +func (p *SourceParams) AddMetadata(key string, value string) { + if p.Metadata == nil { + p.Metadata = make(map[string]string) + } + + p.Metadata[key] = value +} + // The parameters required to store a mandate accepted offline. Should only be set if `mandate[type]` is `offline` type SourceMandateAcceptanceOfflineParams struct { // An email to contact you with if a copy of the mandate is requested, required if `type` is `offline`. diff --git a/stripe.go b/stripe.go index ab7fba2087..d4c6dc27f2 100644 --- a/stripe.go +++ b/stripe.go @@ -275,7 +275,7 @@ type BackendImplementation struct { requestMetricsBuffer chan requestMetrics } -func extractParams(params ParamsContainer) (*form.Values, *Params) { +func extractParams(params ParamsContainer) (*form.Values, *Params, error) { var formValues *form.Values var commonParams *Params @@ -292,23 +292,36 @@ func extractParams(params ParamsContainer) (*form.Values, *Params) { if reflectValue.Kind() == reflect.Ptr && !reflectValue.IsNil() { commonParams = params.GetParams() + + if !reflectValue.Elem().FieldByName("Metadata").IsZero() { + if commonParams.Metadata != nil { + return nil, nil, fmt.Errorf("You cannot specify both the (deprecated) .Params.Metadata and .Metadata in %s", reflectValue.Elem().Type().Name()) + } + } + formValues = &form.Values{} form.AppendTo(formValues, params) } } - return formValues, commonParams + return formValues, commonParams, nil } // Call is the Backend.Call implementation for invoking Stripe APIs. func (s *BackendImplementation) Call(method, path, key string, params ParamsContainer, v LastResponseSetter) error { - body, commonParams := extractParams(params) + body, commonParams, err := extractParams(params) + if err != nil { + return err + } return s.CallRaw(method, path, key, body, commonParams, v) } // CallStreaming is the Backend.Call implementation for invoking Stripe APIs // without buffering the response into memory. func (s *BackendImplementation) CallStreaming(method, path, key string, params ParamsContainer, v StreamingLastResponseSetter) error { - formValues, commonParams := extractParams(params) + formValues, commonParams, err := extractParams(params) + if err != nil { + return err + } var body string if formValues != nil && !formValues.Empty() { diff --git a/stripe_test.go b/stripe_test.go index 29cab87336..d8361316e3 100644 --- a/stripe_test.go +++ b/stripe_test.go @@ -968,6 +968,31 @@ func TestStripeAccount(t *testing.T) { assert.Equal(t, "acct_123", req.Header.Get("Stripe-Account")) } +func TestErrorOnDuplicateMetadata(t *testing.T) { + c := GetBackend(APIBackend).(*BackendImplementation) + type myParams struct { + Params `form:"*"` + Metadata map[string]string `form:"metadata"` + } + + metadata := map[string]string{"foo": "bar"} + resource := APIResource{} + err := c.Call("POST", "/v1/customers", "sk_test_xyz", &myParams{}, &resource) + assert.NoError(t, err) + + err = + c.Call("POST", "/v1/customers", "sk_test_xyz", &myParams{Metadata: metadata}, &resource) + assert.NoError(t, err) + + err = + c.Call("POST", "/v1/customers", "sk_test_xyz", &myParams{Params: Params{Metadata: metadata}}, &resource) + assert.NoError(t, err) + + err = + c.Call("POST", "/v1/customers", "sk_test_xyz", &myParams{Metadata: metadata, Params: Params{Metadata: metadata}}, &resource) + assert.Errorf(t, err, "You cannot specify both the (deprecated) .Params.Metadata and .Metadata in myParams") +} + func TestUnmarshalJSONVerbose(t *testing.T) { type testServerResponse struct { Message string `json:"message"` diff --git a/subscription.go b/subscription.go index 2504e0d6a2..5b1c41a186 100644 --- a/subscription.go +++ b/subscription.go @@ -314,6 +314,15 @@ type SubscriptionItemsParams struct { TaxRates []*string `form:"tax_rates"` } +// AddMetadata adds a new key-value pair to the Metadata. +func (p *SubscriptionItemsParams) AddMetadata(key string, value string) { + if p.Metadata == nil { + p.Metadata = make(map[string]string) + } + + p.Metadata[key] = value +} + // Additional fields for Mandate creation type SubscriptionPaymentSettingsPaymentMethodOptionsACSSDebitMandateOptionsParams struct { // Transaction type of the mandate. @@ -496,6 +505,8 @@ type SubscriptionParams struct { Description *string `form:"description"` // A list of up to 20 subscription items, each with an attached price. Items []*SubscriptionItemsParams `form:"items"` + // Set of [key-value pairs](https://stripe.com/docs/api/metadata) that you can attach to an object. This can be useful for storing additional information about the object in a structured format. Individual keys can be unset by posting an empty value to them. All keys can be unset by posting an empty value to `metadata`. + Metadata map[string]string `form:"metadata"` // Indicates if a customer is on or off-session while an invoice payment is attempted. OffSession *bool `form:"off_session"` // The account on behalf of which to charge, for each of the subscription's invoices. @@ -533,15 +544,24 @@ type SubscriptionParams struct { TrialSettings *SubscriptionTrialSettingsParams `form:"trial_settings"` } +// AddMetadata adds a new key-value pair to the Metadata. +func (p *SubscriptionParams) AddMetadata(key string, value string) { + if p.Metadata == nil { + p.Metadata = make(map[string]string) + } + + p.Metadata[key] = value +} + // AppendTo implements custom encoding logic for SubscriptionParams. -func (s *SubscriptionParams) AppendTo(body *form.Values, keyParts []string) { - if BoolValue(s.BillingCycleAnchorNow) { +func (p *SubscriptionParams) AppendTo(body *form.Values, keyParts []string) { + if BoolValue(p.BillingCycleAnchorNow) { body.Add(form.FormatKey(append(keyParts, "billing_cycle_anchor")), "now") } - if BoolValue(s.BillingCycleAnchorUnchanged) { + if BoolValue(p.BillingCycleAnchorUnchanged) { body.Add(form.FormatKey(append(keyParts, "billing_cycle_anchor")), "unchanged") } - if BoolValue(s.TrialEndNow) { + if BoolValue(p.TrialEndNow) { body.Add(form.FormatKey(append(keyParts, "trial_end")), "now") } } diff --git a/subscriptionitem.go b/subscriptionitem.go index 136c0cfb1b..8436669d47 100644 --- a/subscriptionitem.go +++ b/subscriptionitem.go @@ -50,6 +50,8 @@ type SubscriptionItemParams struct { BillingThresholds *SubscriptionItemBillingThresholdsParams `form:"billing_thresholds"` // Delete all usage for the given subscription item. Allowed only when the current plan's `usage_type` is `metered`. ClearUsage *bool `form:"clear_usage"` + // Set of [key-value pairs](https://stripe.com/docs/api/metadata) that you can attach to an object. This can be useful for storing additional information about the object in a structured format. Individual keys can be unset by posting an empty value to them. All keys can be unset by posting an empty value to `metadata`. + Metadata map[string]string `form:"metadata"` // Only supported on update // Indicates if a customer is on or off-session while an invoice payment is attempted. OffSession *bool `form:"off_session"` @@ -79,6 +81,15 @@ type SubscriptionItemParams struct { TaxRates []*string `form:"tax_rates"` } +// AddMetadata adds a new key-value pair to the Metadata. +func (p *SubscriptionItemParams) AddMetadata(key string, value string) { + if p.Metadata == nil { + p.Metadata = make(map[string]string) + } + + p.Metadata[key] = value +} + // For the specified subscription item, returns a list of summary objects. Each object in the list provides usage information that's been summarized from multiple usage records and over a subscription billing period (e.g., 15 usage records in the month of September). // // The list is sorted in reverse-chronological order (newest first). The first list item represents the most current usage period that hasn't ended yet. Since new usage records can still be added, the returned summary information for the subscription item's ID should be seen as unstable until the subscription billing period ends. diff --git a/subscriptionschedule.go b/subscriptionschedule.go index 385394b1fb..f56a1bb838 100644 --- a/subscriptionschedule.go +++ b/subscriptionschedule.go @@ -160,6 +160,15 @@ type SubscriptionSchedulePhaseItemParams struct { TaxRates []*string `form:"tax_rates"` } +// AddMetadata adds a new key-value pair to the Metadata. +func (p *SubscriptionSchedulePhaseItemParams) AddMetadata(key string, value string) { + if p.Metadata == nil { + p.Metadata = make(map[string]string) + } + + p.Metadata[key] = value +} + // List representing phases of the subscription schedule. Each phase can be customized to have different durations, plans, and coupons. If there are multiple phases, the `end_date` of one phase will always equal the `start_date` of the next phase. type SubscriptionSchedulePhaseParams struct { // A list of prices and quantities that will generate invoice items appended to the next invoice for this phase. You may pass up to 20 items. @@ -211,15 +220,24 @@ type SubscriptionSchedulePhaseParams struct { TrialEndNow *bool `form:"-"` // See custom AppendTo } +// AddMetadata adds a new key-value pair to the Metadata. +func (p *SubscriptionSchedulePhaseParams) AddMetadata(key string, value string) { + if p.Metadata == nil { + p.Metadata = make(map[string]string) + } + + p.Metadata[key] = value +} + // AppendTo implements custom encoding logic for SubscriptionSchedulePhaseParams. -func (s *SubscriptionSchedulePhaseParams) AppendTo(body *form.Values, keyParts []string) { - if BoolValue(s.EndDateNow) { +func (p *SubscriptionSchedulePhaseParams) AppendTo(body *form.Values, keyParts []string) { + if BoolValue(p.EndDateNow) { body.Add(form.FormatKey(append(keyParts, "end_date")), "now") } - if BoolValue(s.TrialEndNow) { + if BoolValue(p.TrialEndNow) { body.Add(form.FormatKey(append(keyParts, "trial_end")), "now") } - if BoolValue(s.StartDateNow) { + if BoolValue(p.StartDateNow) { body.Add(form.FormatKey(append(keyParts, "start_date")), "now") } } @@ -235,6 +253,8 @@ type SubscriptionScheduleParams struct { EndBehavior *string `form:"end_behavior"` // Migrate an existing subscription to be managed by a subscription schedule. If this parameter is set, a subscription schedule will be created using the subscription's item(s), set to auto-renew using the subscription's interval. When using this parameter, other parameters (such as phase values) cannot be set. To create a subscription schedule with other modifications, we recommend making two separate API calls. FromSubscription *string `form:"from_subscription"` + // Set of [key-value pairs](https://stripe.com/docs/api/metadata) that you can attach to an object. This can be useful for storing additional information about the object in a structured format. Individual keys can be unset by posting an empty value to them. All keys can be unset by posting an empty value to `metadata`. + Metadata map[string]string `form:"metadata"` // List representing phases of the subscription schedule. Each phase can be customized to have different durations, plans, and coupons. If there are multiple phases, the `end_date` of one phase will always equal the `start_date` of the next phase. Note that past phases can be omitted. Phases []*SubscriptionSchedulePhaseParams `form:"phases"` // If the update changes the current phase, indicates whether the changes should be prorated. The default value is `create_prorations`. @@ -244,9 +264,18 @@ type SubscriptionScheduleParams struct { StartDateNow *bool `form:"-"` // See custom AppendTo } +// AddMetadata adds a new key-value pair to the Metadata. +func (p *SubscriptionScheduleParams) AddMetadata(key string, value string) { + if p.Metadata == nil { + p.Metadata = make(map[string]string) + } + + p.Metadata[key] = value +} + // AppendTo implements custom encoding logic for SubscriptionScheduleParams. -func (s *SubscriptionScheduleParams) AppendTo(body *form.Values, keyParts []string) { - if BoolValue(s.StartDateNow) { +func (p *SubscriptionScheduleParams) AppendTo(body *form.Values, keyParts []string) { + if BoolValue(p.StartDateNow) { body.Add(form.FormatKey(append(keyParts, "start_date")), "now") } } diff --git a/tax_transaction.go b/tax_transaction.go index 20453ffe77..7a994c788c 100644 --- a/tax_transaction.go +++ b/tax_transaction.go @@ -200,6 +200,15 @@ type TaxTransactionCreateReversalLineItemParams struct { Reference *string `form:"reference"` } +// AddMetadata adds a new key-value pair to the Metadata. +func (p *TaxTransactionCreateReversalLineItemParams) AddMetadata(key string, value string) { + if p.Metadata == nil { + p.Metadata = make(map[string]string) + } + + p.Metadata[key] = value +} + // The shipping cost to reverse. type TaxTransactionCreateReversalShippingCostParams struct { // The amount to reverse, in negative integer cents. @@ -213,6 +222,8 @@ type TaxTransactionCreateReversalParams struct { Params `form:"*"` // The line item amounts to reverse. LineItems []*TaxTransactionCreateReversalLineItemParams `form:"line_items"` + // Set of [key-value pairs](https://stripe.com/docs/api/metadata) that you can attach to an object. This can be useful for storing additional information about the object in a structured format. Individual keys can be unset by posting an empty value to them. All keys can be unset by posting an empty value to `metadata`. + Metadata map[string]string `form:"metadata"` // If `partial`, the provided line item or shipping cost amounts are reversed. If `full`, the original transaction is fully reversed. Mode *string `form:"mode"` // The ID of the Transaction to partially or fully reverse. @@ -223,15 +234,35 @@ type TaxTransactionCreateReversalParams struct { ShippingCost *TaxTransactionCreateReversalShippingCostParams `form:"shipping_cost"` } +// AddMetadata adds a new key-value pair to the Metadata. +func (p *TaxTransactionCreateReversalParams) AddMetadata(key string, value string) { + if p.Metadata == nil { + p.Metadata = make(map[string]string) + } + + p.Metadata[key] = value +} + // Creates a Tax Transaction from a calculation. type TaxTransactionCreateFromCalculationParams struct { Params `form:"*"` // Tax Calculation ID to be used as input when creating the transaction. Calculation *string `form:"calculation"` + // Set of [key-value pairs](https://stripe.com/docs/api/metadata) that you can attach to an object. This can be useful for storing additional information about the object in a structured format. Individual keys can be unset by posting an empty value to them. All keys can be unset by posting an empty value to `metadata`. + Metadata map[string]string `form:"metadata"` // A custom order or sale identifier, such as 'myOrder_123'. Must be unique across all transactions, including reversals. Reference *string `form:"reference"` } +// AddMetadata adds a new key-value pair to the Metadata. +func (p *TaxTransactionCreateFromCalculationParams) AddMetadata(key string, value string) { + if p.Metadata == nil { + p.Metadata = make(map[string]string) + } + + p.Metadata[key] = value +} + // Retrieves the line items of a committed standalone transaction as a collection. type TaxTransactionListLineItemsParams struct { ListParams `form:"*"` diff --git a/taxrate.go b/taxrate.go index 780011d520..0f6a5e459a 100644 --- a/taxrate.go +++ b/taxrate.go @@ -56,6 +56,8 @@ type TaxRateParams struct { Inclusive *bool `form:"inclusive"` // The jurisdiction for the tax rate. You can use this label field for tax reporting purposes. It also appears on your customer's invoice. Jurisdiction *string `form:"jurisdiction"` + // Set of [key-value pairs](https://stripe.com/docs/api/metadata) that you can attach to an object. This can be useful for storing additional information about the object in a structured format. Individual keys can be unset by posting an empty value to them. All keys can be unset by posting an empty value to `metadata`. + Metadata map[string]string `form:"metadata"` // This represents the tax rate percent out of 100. Percentage *float64 `form:"percentage"` // [ISO 3166-2 subdivision code](https://en.wikipedia.org/wiki/ISO_3166-2:US), without country prefix. For example, "NY" for New York, United States. @@ -64,6 +66,15 @@ type TaxRateParams struct { TaxType *string `form:"tax_type"` } +// AddMetadata adds a new key-value pair to the Metadata. +func (p *TaxRateParams) AddMetadata(key string, value string) { + if p.Metadata == nil { + p.Metadata = make(map[string]string) + } + + p.Metadata[key] = value +} + // Tax rates can be applied to [invoices](https://stripe.com/docs/billing/invoices/tax-rates), [subscriptions](https://stripe.com/docs/billing/subscriptions/taxes) and [Checkout Sessions](https://stripe.com/docs/payments/checkout/set-up-a-subscription#tax-rates) to collect tax. // // Related guide: [Tax rates](https://stripe.com/docs/billing/taxes/tax-rates) diff --git a/terminal_location.go b/terminal_location.go index 7fbcd818c5..73d1c52061 100644 --- a/terminal_location.go +++ b/terminal_location.go @@ -17,6 +17,17 @@ type TerminalLocationParams struct { ConfigurationOverrides *string `form:"configuration_overrides"` // A name for the location. DisplayName *string `form:"display_name"` + // Set of [key-value pairs](https://stripe.com/docs/api/metadata) that you can attach to an object. This can be useful for storing additional information about the object in a structured format. Individual keys can be unset by posting an empty value to them. All keys can be unset by posting an empty value to `metadata`. + Metadata map[string]string `form:"metadata"` +} + +// AddMetadata adds a new key-value pair to the Metadata. +func (p *TerminalLocationParams) AddMetadata(key string, value string) { + if p.Metadata == nil { + p.Metadata = make(map[string]string) + } + + p.Metadata[key] = value } // Returns a list of Location objects. diff --git a/terminal_reader.go b/terminal_reader.go index 37627ebd6d..40a8599009 100644 --- a/terminal_reader.go +++ b/terminal_reader.go @@ -65,10 +65,21 @@ type TerminalReaderParams struct { Label *string `form:"label"` // The location to assign the reader to. Location *string `form:"location"` + // Set of [key-value pairs](https://stripe.com/docs/api/metadata) that you can attach to an object. This can be useful for storing additional information about the object in a structured format. Individual keys can be unset by posting an empty value to them. All keys can be unset by posting an empty value to `metadata`. + Metadata map[string]string `form:"metadata"` // A code generated by the reader used for registering to an account. RegistrationCode *string `form:"registration_code"` } +// AddMetadata adds a new key-value pair to the Metadata. +func (p *TerminalReaderParams) AddMetadata(key string, value string) { + if p.Metadata == nil { + p.Metadata = make(map[string]string) + } + + p.Metadata[key] = value +} + // Returns a list of Reader objects. type TerminalReaderListParams struct { ListParams `form:"*"` @@ -155,6 +166,8 @@ type TerminalReaderRefundPaymentParams struct { Amount *int64 `form:"amount"` // ID of the Charge to refund. Charge *string `form:"charge"` + // Set of [key-value pairs](https://stripe.com/docs/api/metadata) that you can attach to an object. This can be useful for storing additional information about the object in a structured format. Individual keys can be unset by posting an empty value to them. All keys can be unset by posting an empty value to `metadata`. + Metadata map[string]string `form:"metadata"` // ID of the PaymentIntent to refund. PaymentIntent *string `form:"payment_intent"` // Boolean indicating whether the application fee should be refunded when refunding this charge. If a full charge refund is given, the full application fee will be refunded. Otherwise, the application fee will be refunded in an amount proportional to the amount of the charge refunded. An application fee can be refunded only by the application that created the charge. @@ -163,6 +176,15 @@ type TerminalReaderRefundPaymentParams struct { ReverseTransfer *bool `form:"reverse_transfer"` } +// AddMetadata adds a new key-value pair to the Metadata. +func (p *TerminalReaderRefundPaymentParams) AddMetadata(key string, value string) { + if p.Metadata == nil { + p.Metadata = make(map[string]string) + } + + p.Metadata[key] = value +} + // Represents a per-transaction tipping configuration type TerminalReaderActionProcessPaymentIntentProcessConfigTipping struct { // Amount used to calculate tip suggestions on tipping selection screen for this transaction. Must be a positive integer in the smallest currency unit (e.g., 100 cents to represent $1.00 or 100 to represent ¥100, a zero-decimal currency). diff --git a/topup.go b/topup.go index 4ab60a4e80..afc3809928 100644 --- a/topup.go +++ b/topup.go @@ -29,6 +29,8 @@ type TopupParams struct { Currency *string `form:"currency"` // An arbitrary string attached to the object. Often useful for displaying to users. Description *string `form:"description"` + // Set of [key-value pairs](https://stripe.com/docs/api/metadata) that you can attach to an object. This can be useful for storing additional information about the object in a structured format. Individual keys can be unset by posting an empty value to them. All keys can be unset by posting an empty value to `metadata`. + Metadata map[string]string `form:"metadata"` // The ID of a source to transfer funds from. For most users, this should be left unspecified which will use the bank account that was set up in the dashboard for the specified currency. In test mode, this can be a test bank token (see [Testing Top-ups](https://stripe.com/docs/connect/testing#testing-top-ups)). Source *string `form:"source"` // Extra information about a top-up for the source's bank statement. Limited to 15 ASCII characters. @@ -37,6 +39,15 @@ type TopupParams struct { TransferGroup *string `form:"transfer_group"` } +// AddMetadata adds a new key-value pair to the Metadata. +func (p *TopupParams) AddMetadata(key string, value string) { + if p.Metadata == nil { + p.Metadata = make(map[string]string) + } + + p.Metadata[key] = value +} + // Returns a list of top-ups. type TopupListParams struct { ListParams `form:"*"` diff --git a/transfer.go b/transfer.go index 7568acc61b..695cf058ea 100644 --- a/transfer.go +++ b/transfer.go @@ -29,6 +29,8 @@ type TransferParams struct { Description *string `form:"description"` // The ID of a connected Stripe account. [See the Connect documentation](https://stripe.com/docs/connect/separate-charges-and-transfers) for details. Destination *string `form:"destination"` + // Set of [key-value pairs](https://stripe.com/docs/api/metadata) that you can attach to an object. This can be useful for storing additional information about the object in a structured format. Individual keys can be unset by posting an empty value to them. All keys can be unset by posting an empty value to `metadata`. + Metadata map[string]string `form:"metadata"` // You can use this parameter to transfer funds from a charge before they are added to your available balance. A pending balance will transfer immediately but the funds will not become available until the original charge becomes available. [See the Connect documentation](https://stripe.com/docs/connect/separate-charges-and-transfers#transfer-availability) for details. SourceTransaction *string `form:"source_transaction"` // The source balance to use for this transfer. One of `bank_account`, `card`, or `fpx`. For most users, this will default to `card`. @@ -37,6 +39,15 @@ type TransferParams struct { TransferGroup *string `form:"transfer_group"` } +// AddMetadata adds a new key-value pair to the Metadata. +func (p *TransferParams) AddMetadata(key string, value string) { + if p.Metadata == nil { + p.Metadata = make(map[string]string) + } + + p.Metadata[key] = value +} + // Returns a list of existing transfers sent to connected accounts. The transfers are returned in sorted order, with the most recently created transfers appearing first. type TransferListParams struct { ListParams `form:"*"` diff --git a/transferreversal.go b/transferreversal.go index 63b3a380b3..82dd918de9 100644 --- a/transferreversal.go +++ b/transferreversal.go @@ -20,10 +20,21 @@ type TransferReversalParams struct { Amount *int64 `form:"amount"` // An arbitrary string which you can attach to a reversal object. It is displayed alongside the reversal in the Dashboard. This will be unset if you POST an empty value. Description *string `form:"description"` + // Set of [key-value pairs](https://stripe.com/docs/api/metadata) that you can attach to an object. This can be useful for storing additional information about the object in a structured format. Individual keys can be unset by posting an empty value to them. All keys can be unset by posting an empty value to `metadata`. + Metadata map[string]string `form:"metadata"` // Boolean indicating whether the application fee should be refunded when reversing this transfer. If a full transfer reversal is given, the full application fee will be refunded. Otherwise, the application fee will be refunded with an amount proportional to the amount of the transfer reversed. RefundApplicationFee *bool `form:"refund_application_fee"` } +// AddMetadata adds a new key-value pair to the Metadata. +func (p *TransferReversalParams) AddMetadata(key string, value string) { + if p.Metadata == nil { + p.Metadata = make(map[string]string) + } + + p.Metadata[key] = value +} + // You can see a list of the reversals belonging to a specific transfer. Note that the 10 most recent reversals are always available by default on the transfer object. If you need more than those 10, you can use this API method and the limit and starting_after parameters to page through additional reversals. type TransferReversalListParams struct { ListParams `form:"*"` diff --git a/treasury_creditreversal.go b/treasury_creditreversal.go index 8ab67bc3e0..be84a51ae1 100644 --- a/treasury_creditreversal.go +++ b/treasury_creditreversal.go @@ -39,9 +39,21 @@ type TreasuryCreditReversalListParams struct { // Reverses a ReceivedCredit and creates a CreditReversal object. type TreasuryCreditReversalParams struct { Params `form:"*"` + // Set of [key-value pairs](https://stripe.com/docs/api/metadata) that you can attach to an object. This can be useful for storing additional information about the object in a structured format. Individual keys can be unset by posting an empty value to them. All keys can be unset by posting an empty value to `metadata`. + Metadata map[string]string `form:"metadata"` // The ReceivedCredit to reverse. ReceivedCredit *string `form:"received_credit"` } + +// AddMetadata adds a new key-value pair to the Metadata. +func (p *TreasuryCreditReversalParams) AddMetadata(key string, value string) { + if p.Metadata == nil { + p.Metadata = make(map[string]string) + } + + p.Metadata[key] = value +} + type TreasuryCreditReversalStatusTransitions struct { // Timestamp describing when the CreditReversal changed status to `posted` PostedAt int64 `json:"posted_at"` diff --git a/treasury_debitreversal.go b/treasury_debitreversal.go index 266f9faea6..ff6e61639d 100644 --- a/treasury_debitreversal.go +++ b/treasury_debitreversal.go @@ -28,10 +28,21 @@ const ( // Reverses a ReceivedDebit and creates a DebitReversal object. type TreasuryDebitReversalParams struct { Params `form:"*"` + // Set of [key-value pairs](https://stripe.com/docs/api/metadata) that you can attach to an object. This can be useful for storing additional information about the object in a structured format. Individual keys can be unset by posting an empty value to them. All keys can be unset by posting an empty value to `metadata`. + Metadata map[string]string `form:"metadata"` // The ReceivedDebit to reverse. ReceivedDebit *string `form:"received_debit"` } +// AddMetadata adds a new key-value pair to the Metadata. +func (p *TreasuryDebitReversalParams) AddMetadata(key string, value string) { + if p.Metadata == nil { + p.Metadata = make(map[string]string) + } + + p.Metadata[key] = value +} + // Returns a list of DebitReversals. type TreasuryDebitReversalListParams struct { ListParams `form:"*"` diff --git a/treasury_financialaccount.go b/treasury_financialaccount.go index b65b986539..152c6095ed 100644 --- a/treasury_financialaccount.go +++ b/treasury_financialaccount.go @@ -224,12 +224,23 @@ type TreasuryFinancialAccountParams struct { Params `form:"*"` // Encodes whether a FinancialAccount has access to a particular feature, with a status enum and associated `status_details`. Stripe or the platform may control features via the requested field. Features *TreasuryFinancialAccountFeaturesParams `form:"features"` + // Set of [key-value pairs](https://stripe.com/docs/api/metadata) that you can attach to an object. This can be useful for storing additional information about the object in a structured format. Individual keys can be unset by posting an empty value to them. All keys can be unset by posting an empty value to `metadata`. + Metadata map[string]string `form:"metadata"` // The set of functionalities that the platform can restrict on the FinancialAccount. PlatformRestrictions *TreasuryFinancialAccountPlatformRestrictionsParams `form:"platform_restrictions"` // The currencies the FinancialAccount can hold a balance in. SupportedCurrencies []*string `form:"supported_currencies"` } +// AddMetadata adds a new key-value pair to the Metadata. +func (p *TreasuryFinancialAccountParams) AddMetadata(key string, value string) { + if p.Metadata == nil { + p.Metadata = make(map[string]string) + } + + p.Metadata[key] = value +} + // Returns a list of FinancialAccounts. type TreasuryFinancialAccountListParams struct { ListParams `form:"*"` diff --git a/treasury_inboundtransfer.go b/treasury_inboundtransfer.go index 1944e06695..aeee324fa8 100644 --- a/treasury_inboundtransfer.go +++ b/treasury_inboundtransfer.go @@ -87,12 +87,23 @@ type TreasuryInboundTransferParams struct { Description *string `form:"description"` // The FinancialAccount to send funds to. FinancialAccount *string `form:"financial_account"` + // Set of [key-value pairs](https://stripe.com/docs/api/metadata) that you can attach to an object. This can be useful for storing additional information about the object in a structured format. Individual keys can be unset by posting an empty value to them. All keys can be unset by posting an empty value to `metadata`. + Metadata map[string]string `form:"metadata"` // The origin payment method to be debited for the InboundTransfer. OriginPaymentMethod *string `form:"origin_payment_method"` // The complete description that appears on your customers' statements. Maximum 10 characters. StatementDescriptor *string `form:"statement_descriptor"` } +// AddMetadata adds a new key-value pair to the Metadata. +func (p *TreasuryInboundTransferParams) AddMetadata(key string, value string) { + if p.Metadata == nil { + p.Metadata = make(map[string]string) + } + + p.Metadata[key] = value +} + // Returns a list of InboundTransfers sent from the specified FinancialAccount. type TreasuryInboundTransferListParams struct { ListParams `form:"*"` diff --git a/treasury_outboundpayment.go b/treasury_outboundpayment.go index 8f929335a1..2c80f638f7 100644 --- a/treasury_outboundpayment.go +++ b/treasury_outboundpayment.go @@ -119,6 +119,15 @@ type TreasuryOutboundPaymentDestinationPaymentMethodDataParams struct { USBankAccount *TreasuryOutboundPaymentDestinationPaymentMethodDataUSBankAccountParams `form:"us_bank_account"` } +// AddMetadata adds a new key-value pair to the Metadata. +func (p *TreasuryOutboundPaymentDestinationPaymentMethodDataParams) AddMetadata(key string, value string) { + if p.Metadata == nil { + p.Metadata = make(map[string]string) + } + + p.Metadata[key] = value +} + // Optional fields for `us_bank_account`. type TreasuryOutboundPaymentDestinationPaymentMethodOptionsUSBankAccountParams struct { // The US bank account network that must be used for this OutboundPayment. If not set, we will default to the PaymentMethod's preferred network. @@ -160,10 +169,21 @@ type TreasuryOutboundPaymentParams struct { EndUserDetails *TreasuryOutboundPaymentEndUserDetailsParams `form:"end_user_details"` // The FinancialAccount to pull funds from. FinancialAccount *string `form:"financial_account"` + // Set of [key-value pairs](https://stripe.com/docs/api/metadata) that you can attach to an object. This can be useful for storing additional information about the object in a structured format. Individual keys can be unset by posting an empty value to them. All keys can be unset by posting an empty value to `metadata`. + Metadata map[string]string `form:"metadata"` // The description that appears on the receiving end for this OutboundPayment (for example, bank statement for external bank transfer). Maximum 10 characters for `ach` payments, 140 characters for `wire` payments, or 500 characters for `stripe` network transfers. The default value is `payment`. StatementDescriptor *string `form:"statement_descriptor"` } +// AddMetadata adds a new key-value pair to the Metadata. +func (p *TreasuryOutboundPaymentParams) AddMetadata(key string, value string) { + if p.Metadata == nil { + p.Metadata = make(map[string]string) + } + + p.Metadata[key] = value +} + // Returns a list of OutboundPayments sent from the specified FinancialAccount. type TreasuryOutboundPaymentListParams struct { ListParams `form:"*"` diff --git a/treasury_outboundtransfer.go b/treasury_outboundtransfer.go index 990892e95f..04c297c36e 100644 --- a/treasury_outboundtransfer.go +++ b/treasury_outboundtransfer.go @@ -97,10 +97,21 @@ type TreasuryOutboundTransferParams struct { DestinationPaymentMethodOptions *TreasuryOutboundTransferDestinationPaymentMethodOptionsParams `form:"destination_payment_method_options"` // The FinancialAccount to pull funds from. FinancialAccount *string `form:"financial_account"` + // Set of [key-value pairs](https://stripe.com/docs/api/metadata) that you can attach to an object. This can be useful for storing additional information about the object in a structured format. Individual keys can be unset by posting an empty value to them. All keys can be unset by posting an empty value to `metadata`. + Metadata map[string]string `form:"metadata"` // Statement descriptor to be shown on the receiving end of an OutboundTransfer. Maximum 10 characters for `ach` transfers or 140 characters for `wire` transfers. The default value is `transfer`. StatementDescriptor *string `form:"statement_descriptor"` } +// AddMetadata adds a new key-value pair to the Metadata. +func (p *TreasuryOutboundTransferParams) AddMetadata(key string, value string) { + if p.Metadata == nil { + p.Metadata = make(map[string]string) + } + + p.Metadata[key] = value +} + // Returns a list of OutboundTransfers sent from the specified FinancialAccount. type TreasuryOutboundTransferListParams struct { ListParams `form:"*"` diff --git a/usagerecord.go b/usagerecord.go index 6870187a05..542854c893 100644 --- a/usagerecord.go +++ b/usagerecord.go @@ -34,8 +34,8 @@ type UsageRecordParams struct { } // AppendTo implements custom encoding logic for UsageRecordParams. -func (u *UsageRecordParams) AppendTo(body *form.Values, keyParts []string) { - if BoolValue(u.TimestampNow) { +func (p *UsageRecordParams) AppendTo(body *form.Values, keyParts []string) { + if BoolValue(p.TimestampNow) { body.Add(form.FormatKey(append(keyParts, "timestamp")), "now") } } diff --git a/webhookendpoint.go b/webhookendpoint.go index 1ce5519ab1..9d4cc1b756 100644 --- a/webhookendpoint.go +++ b/webhookendpoint.go @@ -22,6 +22,8 @@ type WebhookEndpointParams struct { Disabled *bool `form:"disabled"` // The list of events to enable for this endpoint. You may specify `['*']` to enable all events, except those that require explicit selection. EnabledEvents []*string `form:"enabled_events"` + // Set of [key-value pairs](https://stripe.com/docs/api/metadata) that you can attach to an object. This can be useful for storing additional information about the object in a structured format. Individual keys can be unset by posting an empty value to them. All keys can be unset by posting an empty value to `metadata`. + Metadata map[string]string `form:"metadata"` // The URL of the webhook endpoint. URL *string `form:"url"` // This parameter is only available on creation. @@ -30,6 +32,15 @@ type WebhookEndpointParams struct { APIVersion *string `form:"api_version"` } +// AddMetadata adds a new key-value pair to the Metadata. +func (p *WebhookEndpointParams) AddMetadata(key string, value string) { + if p.Metadata == nil { + p.Metadata = make(map[string]string) + } + + p.Metadata[key] = value +} + // You can configure [webhook endpoints](https://stripe.com/docs/webhooks/) via the API to be // notified about events that happen in your Stripe account or connected // accounts.