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

Interfaces for polymorphic API resources (external accounts and payment sources) #1320

Conversation

ob-stripe
Copy link
Contributor

@ob-stripe ob-stripe commented Oct 4, 2018

Done:

  • IExternalAccount
  • IPaymentSource

Todo (in followup PRs):

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.

one minor confusion but otherwise this looks great and much cleaner

@@ -6,7 +6,7 @@ namespace Stripe
using Newtonsoft.Json;
using Stripe.Infrastructure;

public class Account : StripeEntity, IHasId, IHasObject
public class Account : StripeEntity, IHasId, IHasObject, IPaymentSource
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we implement IPaymentSource on Account? Forgot Account is a source now, damn that is confusing lol

{
Account Account { get; set; }

string AccountId { get; set; }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand why we have properties in this interface. I thought maybe you wanted to be smart and use this for the nested service but it does not seem to be the case. Can you clarify?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having the properties declared in the interface lets you access those properties without casting, e.g.:

var payout = payoutService.Get("po_123");
var account = payout.Destination.AccountId;

vs.

var payout = payoutService.Get("po_123");
var destination = payout.Destination;
var account = null;
if (destination is BankAccount)
{
    account = ((BankAccount)destination).AccountId;
}
else if (destination is Card) {
    account = ((Card)destination).AccountId;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also wanted to do something similar with IPaymentSource and Customer / CustomerId, but Account is an IPaymentSource that can never be attached to a customer :(

I could add an additional ICustomerPaymentSource interface to do this, but not sure if worth the trouble.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why would you access the Account id on an external account? You already know which account it's on since you retrieved the Payout on that account right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think "why" matters. Conceptually, an external account is a payment destination that is attached to a (Stripe) account, so it makes sense that the interface reflects this. It also costs us literally nothing to add this since the two concrete classes that implement this interface already fulfill that contract.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I disagree though. I think it matters to be consistent though and the fact that it does not happen on IPaymentSource feels confusing to me and not useful. If you were using it explicitly for the service I would say maybe but here I don't see the benefits. Like you could also say the same about Last4 which is on card and bank account and really useful to access without a cast right?

This is my personal opinion and I am fine to merge as is though as I agree it ultimately works and I don't want to block.

@remi-stripe
Copy link
Contributor

Approving!

@ob-stripe ob-stripe force-pushed the ob-polymorphic-resource-interfaces-2 branch from fa3b5cf to d8e2539 Compare October 4, 2018 21:02
@ob-stripe ob-stripe force-pushed the ob-polymorphic-resource-interfaces-2 branch from d8e2539 to 23c58a2 Compare October 4, 2018 21:05
@ob-stripe ob-stripe changed the title [wip] Interfaces for polymorphic API resources Interfaces for polymorphic API resources (external accounts and payment sources) Oct 4, 2018
@ob-stripe ob-stripe mentioned this pull request Oct 4, 2018
32 tasks
@ob-stripe ob-stripe merged commit ac541ee into integration-next-major-version Oct 4, 2018
@ob-stripe ob-stripe deleted the ob-polymorphic-resource-interfaces-2 branch October 4, 2018 21:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants