2

Im building a new SaaS app and am wanting to follow the DDD principles.

Im at the stage where Im sketching ideas out and I came across this problem. Im hoping people can give me some thoughts. I dont think there's necessarily a right or wrong with this. But Id love to hear your thoughts...

Essentially Im not sure where Billing belongs and how to best implement it.

I dont know if the user should be aware of the billing interface. Is it the user entities responsibility to carry out billing??

I think its fair for the user entity to know whether they have a subscription, but not how its been implemented.

At this stage Im thinking that the domain layer would specify the BillingInterace, and the implementation would live in the Infrastructure layer. (Ill be using Stripe to begin with)

Would you create a billing service and pass the user entity in to create the customer account on stripe and carry out the billing functionality?

Or would you code a trait which gets dropped onto the user entity so the user can bill themselves ($user->charge() - or whatever).

Hope that makes sense. Im just looking to throw around some ideas as I cant find any decent guidance online with this stuff.

Thanks!! Lee

Lee Overy
  • 437
  • 5
  • 13

1 Answers1

3

Is it the user entities responsibility to carry out billing?

I don't think so.

At this stage Im thinking that the domain layer would specify the BillingInterace, and the implementation would live in the Infrastructure layer.

Is the billing part of the domain (business)? If yes, then it should be there.

Maybe the billing could be an aggregate root or a domain service. Take a look in this post in which the PurchaseOrder (an aggregate) could be your Billing. And at this, that explains domain services.

fabriciorissetto
  • 9,475
  • 5
  • 65
  • 73
  • 1
    Thanks for the answer! Yea I agree its not the users job to bill. They should have some awareness of their subscription status, but not how this works behind the scenes. The business is concerned with billing, only in so far as a non-paying user doesnt get the services offered. But its not the domains job to worry about how this is done, only that it can be done. – Lee Overy Jan 19 '16 at 12:01