Skip to content
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

Merged

Conversation

ob-stripe
Copy link
Contributor

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 the object attribute). Instead, we need to look at the value of the type attribute that's at the same nesting level as value, 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 entire NextSourceAction attribute will be set to null (like in the API).

Copy link
Contributor

@remi-stripe remi-stripe left a 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());
Copy link
Contributor

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?

Copy link
Contributor Author

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),
Copy link
Contributor

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?

Copy link
Contributor Author

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);
Copy link
Contributor

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?

Copy link
Contributor Author

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.

@ob-stripe ob-stripe force-pushed the ob-interface-next-source-action branch from 9d1e517 to dc4d5f1 Compare October 9, 2018 21:23
@ob-stripe ob-stripe mentioned this pull request Oct 10, 2018
32 tasks
@ob-stripe ob-stripe merged commit f4e23ae into integration-next-major-version Oct 10, 2018
@ob-stripe ob-stripe deleted the ob-interface-next-source-action branch October 10, 2018 10:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants