-
Notifications
You must be signed in to change notification settings - Fork 938
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
Flexible pricing endpoints #1301
Conversation
c328f9a
to
7b969dc
Compare
3568533
to
2dbfd96
Compare
7b969dc
to
8697593
Compare
bb6d32f
to
f775b1f
Compare
1c9b3ba
to
21dc9cc
Compare
f775b1f
to
ce1e71f
Compare
21dc9cc
to
62ab1be
Compare
6307625
to
d97155c
Compare
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.
I had couple of comments but in general, this looks good! I also tested this in my branches and it seemed to work as expected.
listingPromise | ||
.then(apiResponse => { | ||
const listing = apiResponse.data.data; | ||
const lineItems = transactionLineItems(listing, bookingData); |
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.
Because we are using this endpoint directly in FTW I added the lineItem validation here in estimated transaction branch (b9ba586) but now I noticed that this is also used in the other endpoints internally so I'm thinking should we add some flag (e.g. validateLineItems true/false) to the API call or do something else. Anyway, I think it might be clearer to move these changes to this PR.
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.
Hmm, is there any harm in always validating the line items? Then it could be inside the transactionLineItems
helper.
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.
I don't think there should be any harm but it's just extra step that is not always needed. If I understood correctly Marketplace API should anyway calculate the lineTotal even if the total is already passed in the API request and check that these values match.
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.
Ok, now I understand. It doesn't make sense to add the totals if the line items are sent to the Marketplace API that also adds them. It would be just confusing. But the UI needs those for the line items endpoint.
I think a separate function is cleaner than an option, so your changes in the commit you linked seem good IMO. The other places that use line items are sending those to the Marketplace API, and shouldn't add the line totals. Or am I missing something?
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.
Now I checked the code again and realized that I got little confused. Somehow I thought that we are calling the transaction line items endpoint in initiate transaction endpoint too but obviously we are just using the transactionLineItems helper function there. So my bad... (but makes me wonder if we should think about the name of the function again).
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 understand the confusion. Maybe you were confused as the API helper name for the endpoint is the same as the line item util function? I wouldn't rename the functions, most customizers will only have to deal with the util function...
}); | ||
}; | ||
|
||
export const transactionLineItems = body => { |
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.
It would be nice if it was more visible what params these functions are expecting. body
doesn't tell much so now we need to go to server side to check. If we don't want to change the body to more specific params I think adding a comment (or docstring) would be already very helpful.
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.
I went back and forth with this earlier, but didn't want to list the params here. They are already in the place where this function is called, and in the backend endpoint itself. Listing them here as well would just make customization harder.
I added a comment on where to look for the body params. Ok?
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.
Skimmed through the code. Nothing special to say. Didn't have enough guts to remove the pending review label.
bc59157
to
b9a1805
Compare
b9a1805
to
3f1e1c2
Compare
Local API endpoint for privileged transitions
This PR sets up the local API with endpoints to fetch transaction line items, and to initiate or transition a transaction with a privileged transition.
Privileged transitions are transitions that need to be done from a secure context, i.e. from the backend where the application client secret can be stored safely.
This enables doing fully flexible pricing safely by just customizing the
server/api-util/lineItems.js
file. This assumes that the given transition has theaction/privileged-set-line-items
action that accepts the passed line items./api/transaction-line-items
Constructs the line items in the backend using the given booking data. This is used to show an estimated booking breakdown without an actual transaction.
/api/initiate-privileged
Initiates a transaction using a privileged transition. Constructs the line items in the backend using the given booking data.
/api/transition-privileged
Transitions a transaction using a privileged transition. Constructs the line items in the backend using the given booking data.