-
Notifications
You must be signed in to change notification settings - Fork 573
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use an interface for PaymentIntentSourceAction #1329
Use an interface for PaymentIntentSourceAction #1329
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks mostly good to me, though I have some questions but it's more for my own education so approving
else | ||
{ | ||
sourceAction.Type = PaymentIntentSourceActionType.Unknown; | ||
sourceAction.Value = Mapper<PaymentIntentSourceActionAuthorizeWithUrl>.MapFromJson(incoming.SelectToken("value")?.ToString()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OOC can't you do the same logic as the other one where you map based on type
but use value
for the deserialization? Or is it just that we have one example so it's cleaner this way for now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I think if we wanted to have an abstract version of this converter, we'd need to add 3 additional interfaces (for the type attribute, the value attribute, and the encompassing class). Seems overkill for now.
I did rework the converter to make it more similar to the existing ones for objects though.
var sourceAction = new PaymentIntentSourceAction() | ||
{ | ||
Type = PaymentIntentSourceActionType.Unknown, | ||
Value = default(IPaymentIntentSourceActionValue), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does default
mean here? Shouldn't Value
be null
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
default
would return null
here, but in any case this was unnecessary and I removed it.
Assert.Equal("https://stripe.com", intent.NextSourceAction.AuthorizeWithUrl.Url); | ||
var authorizeWithUrl = intent.NextSourceAction.Value as PaymentIntentSourceActionAuthorizeWithUrl; | ||
Assert.NotNull(authorizeWithUrl); | ||
Assert.Equal("https://stripe.com", authorizeWithUrl.Url); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we test with None
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep! Added two more tests, one where next_source_action
is null
and one where it's a type that the converter cannot handle.
9d1e517
to
dc4d5f1
Compare
r? @remi-stripe
cc @stripe/api-libraries
Similar to #1320 but for
PaymentIntentSourceAction
. The logic is slightly different because we can't deserialize the polymorphic attribute (value
) based on its contents (like we can for Stripe objects, by looking at theobject
attribute). Instead, we need to look at the value of thetype
attribute that's at the same nesting level asvalue
, so the converter has to be associated with the class that encompasses both attributes.I've also removed
None
as a possible value in the enum -- instead, the entireNextSourceAction
attribute will be set tonull
(like in the API).