Skip to content

Conversation

@magni-
Copy link
Contributor

@magni- magni- commented Feb 20, 2025

Type of Change

  • Add RBI for a new gem
  • Modify RBI for an existing gem
  • Other:

Changes

Per the docs, metadata values are always strings (there is no nesting). I opted to not change the signature of #metadata= because you can technically pass in non-strings to the method and either the values will be stringified (e.g. 1 becomes "1") or the keys ignored (e.g. a key with a nil value).

Technically, you could have junk in there until you refresh the data, but I'm not sure supporting that is desirable?

charge = Stripe::Charge.retrieve(...)

charge.metadata = { int: 1, true: true, false: false, nil: nil, obj: User.first, nested: {outer: {inner: [1, 2, 3]}} }
charge.metadata
=> {:int=>1,
 :true=>true,
 :false=>false,
 :nil=>nil,
 :obj=>
  #<User:0x0000000110435f10 ...>,
 :nested=>{:outer=>{:inner=>[1, 2, 3]}}}

Stripe::Charge.update(charge.id)
charge.metadata
=> #<Stripe::StripeObject:0x1b490> JSON: {
  "int": 1,
  "true": true,
  "false": false,
  "nil": null,
  "obj": "#<User:0x0000000121a34ec8>",
  "nested": {"outer":{"inner":[1,2,3]}}
}

charge.refresh.metadata
=> #<Stripe::StripeObject:0x1b4b8> JSON: {
  "false": "false",
  "int": "1",
  "obj": "#<User:0x00000001198346d0>",
  "true": "true"
}

@magni- magni- requested a review from a team as a code owner February 20, 2025 01:12
Per the docs, values are always strings (there is no nesting). I opted to not change the signature of `#metadata=` because you can technically pass in non-strings to the method and either the values will be stringified (e.g. `1` becomes `"1"`) or the keys ignored (e.g. a key with a `nil` value).

https://docs.stripe.com/metadata
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant