stripe / stripe-ios

Stripe iOS SDK
https://stripe.com
MIT License
2.09k stars 976 forks source link

Codable support for STPAPIResponseDecodable #1398

Open Gujci opened 4 years ago

Gujci commented 4 years ago

Summary

Codable support for StripePaymentMethod

Code to reproduce

StripePaymentMethod now conforms to a custom STPAPIResponseDecodable to enable basic parsing from a serialized network response.

decodedObject(fromAPIResponse: try JSONSerialization.jsonObject(with: data, options: []) as? [AnyHashable: Any])

However, this provides no conformance to the actual Decodable protocol, introduced in Swift 4. Since some of the developers may rely on generic wrappers around network calls, to reduce boilerplate, thus achieve cleaner code, Decodable conformance would be needed.

With the current interface a Codable (or just Decodable) wrapper has to be introduced around StripePaymentMethod.

as far as I know, this is the only solution, please correct me if I'm wrong

iOS version

iOS 13

Installation method

Manual

SDK version

17.0.1

Other

Please flag as feature request if approved

davidme-stripe commented 4 years ago

Hey @Gujci, thanks for the request. We'll add this to our list for a future release, though it may have to wait until we work out our story for shipping Swift code as part of the SDK.

torgeiou commented 4 years ago

How would you make a struct implementing Decodable to manually decode this using decodedObject?