stripe-ios icon indicating copy to clipboard operation
stripe-ios copied to clipboard

Codable support for STPAPIResponseDecodable

Open Gujci opened this issue 4 years ago • 2 comments

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

Gujci avatar Sep 30 '19 10:09 Gujci

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.

davidme-stripe avatar Sep 30 '19 22:09 davidme-stripe

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

torgeiou avatar Oct 17 '19 12:10 torgeiou