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

Flexible pricing endpoints #1301

Merged
merged 13 commits into from
Jun 16, 2020
Merged

Flexible pricing endpoints #1301

merged 13 commits into from
Jun 16, 2020

Conversation

kpuputti
Copy link
Contributor

@kpuputti kpuputti commented Jun 2, 2020

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 the action/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.

@kpuputti kpuputti changed the base branch from master to line-item-util-functions June 2, 2020 09:37
@kpuputti kpuputti force-pushed the flexible-pricing-endpoints branch 4 times, most recently from c328f9a to 7b969dc Compare June 2, 2020 11:39
@OtterleyW OtterleyW force-pushed the line-item-util-functions branch from 3568533 to 2dbfd96 Compare June 3, 2020 08:24
@kpuputti kpuputti force-pushed the flexible-pricing-endpoints branch from 7b969dc to 8697593 Compare June 4, 2020 07:09
@OtterleyW OtterleyW force-pushed the line-item-util-functions branch from bb6d32f to f775b1f Compare June 4, 2020 07:44
@kpuputti kpuputti force-pushed the flexible-pricing-endpoints branch 2 times, most recently from 1c9b3ba to 21dc9cc Compare June 4, 2020 11:05
@OtterleyW OtterleyW force-pushed the line-item-util-functions branch from f775b1f to ce1e71f Compare June 5, 2020 06:54
@kpuputti kpuputti force-pushed the flexible-pricing-endpoints branch from 21dc9cc to 62ab1be Compare June 5, 2020 08:53
@kpuputti kpuputti changed the base branch from line-item-util-functions to master June 5, 2020 08:53
@kpuputti kpuputti force-pushed the flexible-pricing-endpoints branch from 6307625 to d97155c Compare June 10, 2020 11:55
@kpuputti kpuputti marked this pull request as ready for review June 10, 2020 12:02
@kpuputti kpuputti requested review from OtterleyW, ovan and rap1ds June 10, 2020 12:13
Copy link
Contributor

@OtterleyW OtterleyW left a 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.

server/api-util/sdk.js Show resolved Hide resolved
listingPromise
.then(apiResponse => {
const listing = apiResponse.data.data;
const lineItems = transactionLineItems(listing, bookingData);
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

@OtterleyW OtterleyW Jun 11, 2020

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.

Copy link
Contributor Author

@kpuputti kpuputti Jun 11, 2020

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?

Copy link
Contributor

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).

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 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...

src/util/api.js Outdated Show resolved Hide resolved
});
};

export const transactionLineItems = body => {
Copy link
Contributor

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.

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 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?

Copy link
Member

@rap1ds rap1ds left a 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.

@kpuputti kpuputti force-pushed the flexible-pricing-endpoints branch from bc59157 to b9a1805 Compare June 11, 2020 11:30
@kpuputti kpuputti force-pushed the flexible-pricing-endpoints branch from b9a1805 to 3f1e1c2 Compare June 11, 2020 12:25
@kpuputti kpuputti merged commit e7f89a6 into master Jun 16, 2020
@kpuputti kpuputti deleted the flexible-pricing-endpoints branch June 16, 2020 11:52
@kpuputti kpuputti mentioned this pull request Jun 18, 2020
7 tasks
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.

3 participants