How to query price items for a customer, in stripe? - stripe-payments

I am trying the following :
stripe.Product.list(limit=3)
however this is quite generic and I dont find any parameter to limit the query to a certain customer.
I apreciate any hint.

Products and Prices are designed to be reusable and aren't restricted to a single user, therefore it doesn't really make sense to list either of them by Customer ID.
If instead you're looking for a specific transaction that is linked to a Customer, you'll want to list either Subscriptions or PaymentIntents by Customer ID.

Related

Reuse same database tables in different repositories (repositories overlap on the data they access)

Suppose I have database tables Customer, Order, Item. I have OrderRepository that accesses, directly with SQL/my ORM, both the Order and Items table. E.g. I could have a method, getItems on the OrderRespositry that returns all items of that order.
Suppose I now also create ItemRepository. Given I now have 2 repositories accessing the same database table, is that generally considered poor design? My thinking is, sometimes a user wants to update the details about an Item (e.g. name), but when using the OrdersRepository, it doesn't really make sense to not be able to access the items directly (you want to know about all the items in an order)
Of course, the OrderRepository could internally create* an ItemRepository and call methods like getItemsById(ids: string[]). However, consider the case that I want to get all orders and items ever purchased by a Customer. Assuming you had the orderIds for a customer, you could have a getOrders(ids: string[]) on the OrderRepository to fetch all the orders and then do a second query to fetch all the Items. I feel you make your life harder (and less efficient) in the sense you have to do the join to match items with orders in the app code rather than doing a join in SQL.
If it's not considered bad practice, is there some kind of limit to how much overlap Repositories should have with each other. I've spent a while trying to search for this on the web, but it seems all the tutorials/blogs/vdieos really don't go further than 1 table per entity (which may be an anti-pattern).
Or am I missing a trick?
Thanks
FYI: using express with TypeScript (not C#)
is a repository creating another repository considered acceptable. shouldn't only the service layer do that?
It's difficult to separate the Database Model from the DDD design but you have to.
In your example:
GetItems should have this signature - OrderRepostiory.GetItems(Ids: int[]) : ItemEntity. Note that this method returns an Entity (not a DAO from your ORM). To get the ItemEntity, the method might pull information from several DAOs (tables, through your ORM) but it should only pull what it needs for the entity's hydration.
Say you want to update an item's name using the ItemRepository, your signature for that could look like ItemRepository.rename(Id: int, name: string) : void. When this method does it's work, it could change the same table as the GetItems above but note that it could also change other tables as well (For example, it could add an audit of the change to an AuditTable).
DDD gives you the ability to use different tables for different Contexts if you want. It gives you enough flexibility to make really bold choices when it comes the infrastructure that surrounds your domain. So ultimately, it's a matter of what makes sense for your specific situation and team. Some teams would apply CQRS and the GETOrder and Rename methods will look completely different under the covers.

DDD: how to do when I need information from another root entity?

There are another questions that seems to ask the same, but it is not still clear for me some aspects when I have to work with one aggregate root (AR) that need information from another AG.
One similiar question is this, DDD: aggregate root needs information from another aggregate root, but it is still not clear some things.
My doubt is this. Supose that I have Order and Buyer. I guess both are AG (if some guess is incorrect, correct me). Suponse that the order needs information of the buyer, for example if the buyer is allows to make orders or not.
One of the rules in DDD is that an AG can't have a reference to the object to another AG, only the ID, so my Order AG would be like this:
Order
{
long Id,
BuyerId,
....
}
In the question that I linked above, it is said: "If the domain logic for Screening requires gender and birth date, then you are going to need to get copies of those values into the aggregate".
It tells it is needed to have the values into the aggregate. Does this mean that in this case, could I have a reference to the object of the buyer instead of the ID?
Or perhaps I could have another option, to use a factory to create an order, that receive the ID of the buyer, then the factory request the information to the BuyerRepository, do the check and if the buyer can make orders, then assign the ID to the order.
This in the creation. But another case is for example when I need to show the information in the UI to the user. do I need to do two queries for that? One to get the information of the order aggregate and another query to get the information of the related aggregate entities, and compiste the information in the UI?
Thanks.

PayPal Orders purchase_units: reference_id vs custom_id?

I am working to set up orders and am a bit confused by the documentation, specifically these two seperate id's given to the purchase_units.
The documentation lists:
reference_id string
The API caller-provided external ID for the purchase unit. Required for multiple purchase units when you must update the order through PATCH. If you omit this value and the order contains only one purchase unit, PayPal sets this value to default.
and
custom_id string
The API caller-provided external ID. Used to reconcile client transactions with PayPal transactions. Appears in transaction and settlement reports but is not visible to the payer.
Both of them having the same The API caller-provided external ID bit confuses the two for me. It seems like one of these is meant to be the id I want to pass through to keep track of the order on the other side, and custom_id sounds more like that, but what is the reference_id supposed to be? It sounds like mostly the same thing, just the id I'd like to give it so I can keep track of it later.
If all of my orders will only have a single purchase_item is there any reason to use the reference_id?
The purpose of reference_id is to distinguish between multiple purchase_units in a single order. Since all yours will have a single one, there is no reason to use it.
Use custom_id for any reconciliation needs, as it will be stored as part of the PayPal transaction.

MongoDB, how to manage user related records

I'm currently trying to learn Node.js and Mongoodb by building the server side of a web application which should manage insurance documents for the insurance agent.
So let's say i'm the user, I sign in, then I start to add my customers and their insurances.
So I have 2 collection related, Customers and Insurances.
I have one more collection to store the users login data, let's call it Users.
I don't want the new users to see and modify the customers and the insurances of other users.
How can I "divide" every user related record, so that each user can work only with his data?
I figured out I can actually add to every record, the _id of the one user who created the record.
For example I login as myself, I got my Id "001", I could add one field with this value in every customer and insurance.
In that way I could filter every query with this code.
Would it be a good idea? In my opinion this filtering is a waste of processing power for mongoDB.
If someone has any idea of a solution, or even a link to an article about it, it would be helpful.
Thank you.
This is more a general permissions problem than just a MongoDB question. Also, without knowing more about your schemas it's hard to give specific advice.
However, here are some approaches:
1) Embed sub-documents
Since MongoDB is a document store allowing you to store arbitrary JSON-like objects, you could simply store the customers and licenses wholly inside each user object. That way querying for a user would return their customers and licenses as well.
2) Denormalise
Common practice for NoSQL databases is to denormalise related data (ie. duplicate the data). This might include embedding a sub-document that is a partial representation of your customers/licenses/whatever inside your user document. This has the similar benefit to the above solution in that it eliminates additional queries for sub-documents. It also has the same drawbacks of requiring more care to be taken for preserving data integrity.
3) Reference with foreign key
This is a more traditionally relational approach, and is basically what you're suggesting in your question. Depending on whether you want the reference to be bi-directional (both documents reference each other) or uni-directional (one document references the other) you can either store the user's ID as a foreign user_id field, or store an array of customer_ids and insurance_ids in the user document. In relational parlance this is sometimes described to as "has many" or "belongs to" (the user has many customers, the customer belongs to a user).

How to design order schema for multiple products?

I have to design a schema in such a way that I can store user id and their order which can be multiple products like bread, butter plus in addition to that I want to store the quantity of product ordered, please guide.
It is difficult to provide you with a real solution to your problem as designing a NoSQL DB structure depends on how you want to access your data. You can keep orders as nested/embedded documents in the User model or store them in a separate collection. In the first case, you will have all the data in one requests, but you will not be able to query and receive orders, that match certain criteria as you will get all orders including those that match. And then you would need to filter them out. Or you could use aggregation to get exactly what you need.
However, there is a limitation to keep in mind. MongoDB document has a size limitation - 16 megabytes. Since users may have very many orders, you can reach the document size limit for some users for sure. Aggregation also has a limitation - Pipeline stages have a limit of 100 megabytes of RAMe but you can override it.
Having orders in a separate collection would require you to separately load them for users. While it is one more request, it will give you more flexibility in terms of how you query them.
Then, of course, create/update operations are also done differently for both cases.
My advice would be that you carefully design your application first - what data you need and where you will show it, how you create/update it. It will give you a better idea and chances are that relational DB will be a better choice for what you need (though absolutely not necessary).

Resources