vapor-community / stripe

Stripe library for Vapor

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add metadata protocol to encode custom structs as part of requests.

Andrewangeta opened this issue · comments

Quoting @anthonycastelli

"One thought I had regarding metadata for Stripe is why don't we create a basic protocol, i.e.

protocol StripeMetadata: Content { }

then we can be more explicit with metadata. Right now I have a bunch of integers and optionals that I have to convert for my metadata into a string dictionary, it'd be nice to just create a struct, then populate that.

struct ChargeMetadata: StripeMetadata {
    var userName: String
    var userId: UUID
}
return charge.create(..., metadata: ChargeMetadata(userName: user.name, userId: user.id"))

At this point we could then serialize the data as part of the body data, right?"

I think this is possible to do. And would be a good approach going forward.

I think it'll be good to still allow just [String: String] for now until we get a lot of demand for it.