Parse Unknown Payment Methods in Link#6248
Conversation
| /// | ||
| /// Modeled after Android's `ApiEnum<E>`. | ||
| /// :nodoc: | ||
| @_spi(STP) public struct ParsedEnum<E: SafeParsedEnumCodable>: Hashable { |
There was a problem hiding this comment.
I'd love feedback about the naming of this type and its usage shapes. Is it clear to the reader what it's goal is?
There was a problem hiding this comment.
There's already a SafeEnumDecodable. Could we extend that and add a rawValue there?
There was a problem hiding this comment.
I wanted to add a separate type here since existing conformers to SafeEnumDecodable don't have to deal with the wrapper type right now (see this file, where we have to add the generic wrapper and parse with .value). I think this adds overhead to types that currently conform to SafeEnumDecodable that don't need the knowledge of the unknown value.
| return .bankAccount | ||
| } | ||
| extension ParsedEnum where E == LinkSettings.FundingSource { | ||
| var detailsType: ParsedEnum<ConsumerPaymentDetails.DetailsType> { |
There was a problem hiding this comment.
We can map unknown funding sources to unknown payment detail types. Which is necessary for comparing them before calling payment_details/list
|
🚨 New dead code detected in this PR: PayWithLinkViewController-WalletViewModel.swift:37 warning: Unused property 'supportedPaymentMethodTypes'Please remove the dead code before merging. If this is intentional, you can bypass this check by adding the label ℹ️ If this comment appears to be left in error, double check that the flagged code is actually used and/or make sure your branch is up-to-date with [find-dead-code] |
226b5ba to
eb9494c
Compare
|
|
||
| // MARK: - Unknown payment method type filtering | ||
|
|
||
| func test_unknownPaymentMethodType_isNotInSupportedTypes() throws { |
There was a problem hiding this comment.
This test exemplifies the inclusion of unknown funding sources in parsing without including them in rendering (and breaking existing functionality before we're ready to render and pay with them). Curious if folks have other ideas for contexts I'm missing coverage for in the tests in this PR.
mats-stripe
left a comment
There was a problem hiding this comment.
This seems like a good approach, nicely done with the documentation and testing 👍
| /// Known values: ``value`` is non-nil, ``rawValue`` matches the enum's raw value. | ||
| /// Unknown values: ``value`` is nil, ``rawValue`` contains the unrecognized API string. |
There was a problem hiding this comment.
Not sure if this was intentional or not:
| /// Known values: ``value`` is non-nil, ``rawValue`` matches the enum's raw value. | |
| /// Unknown values: ``value`` is nil, ``rawValue`` contains the unrecognized API string. | |
| /// Known values: `value` is non-nil, `rawValue` matches the enum's raw value. | |
| /// Unknown values: `value` is nil, `rawValue` contains the unrecognized API string. |
|
|
||
| /// A protocol for enums whose raw API string values should be preserved | ||
| /// even when the value is unknown to the SDK. | ||
| /// Unlike SafeEnumCodable, the raw string is never lost — use with ``ParsedEnum``. |
There was a problem hiding this comment.
Same here - maybe this is intentional syntax!
| /// Unlike SafeEnumCodable, the raw string is never lost — use with ``ParsedEnum``. | |
| /// Unlike SafeEnumCodable, the raw string is never lost — use with `ParsedEnum`. |
eb9494c to
7fdef06
Compare
StripeCorePublic API+public protocol SafeParsedEnumCodable : Swift.CaseIterable, Swift.Hashable, Swift.RawRepresentable where Self.RawValue == Swift.String {
+}If you are adding a new public API consider the following:
If you are modifying or removing a public API:
If you confirm these APIs need to be added/updated and have undergone necessary review, add the label ℹ️ If this comment appears to be left in error, make sure your branch is up-to-date with |
7fdef06 to
f6ecd89
Compare
Summary
Enables forward compatible parsing of unknown payment method types in native Link.
/v1/consumers/sessions/lookupand/v1/elements/sessionspayment methods / funding sources and stores unknown typespayment_details/listquery param list as payment methodtypes(although they are not in this PR to maintain existing functionality).Motivation
We'd like forward compatibility for Link payment methods. When backend adds PMs, they should be able to be rendered and used for payment in prior versions of the SDK. This PR is a first step towards this goal. This proposal provides more context.
Testing
Included a few new tests here to ensure the parsing logic is accurate.