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

feat: added endpoint for product details #20

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

vickywane
Copy link
Contributor

This pull request closes this issue.

This PR introduces a GET operation into the /notification endpoint to fetch the email notification product created on Stripe. This operation would be further used by the Premium services feature within the Ambianic PWA.

@commit-lint
Copy link

commit-lint bot commented Jun 14, 2021

Features

  • added endpoint for product details (d9ea887)

Update

  • renamed GET /notification to /product (83c257b)
  • adjusted /product documentation (b908eb4)

Bug Fixes

  • fixed merge conflicts from previous branch (4e14a81)

Contributors

vickywane

Commit-Lint commands

You can trigger Commit-Lint actions by commenting on this PR:

  • @Commit-Lint merge patch will merge dependabot PR on "patch" versions (X.X.Y - Y change)
  • @Commit-Lint merge minor will merge dependabot PR on "minor" versions (X.Y.Y - Y change)
  • @Commit-Lint merge major will merge dependabot PR on "major" versions (Y.Y.Y - Y change)
  • @Commit-Lint merge disable will desactivate merge dependabot PR
  • @Commit-Lint review will approve dependabot PR
  • @Commit-Lint stop review will stop approve dependabot PR

@netlify
Copy link

netlify bot commented Jun 14, 2021

✔️ Deploy Preview for hopeful-bell-0b6f9f ready!

🔨 Explore the source changes: b908eb4

🔍 Inspect the deploy log: https://app.netlify.com/sites/hopeful-bell-0b6f9f/deploys/60d07480f84f1d00070a01d9

😎 Browse the preview: https://deploy-preview-20--hopeful-bell-0b6f9f.netlify.app

@vickywane vickywane self-assigned this Jun 14, 2021
@vickywane vickywane requested a review from ivelin June 14, 2021 10:33
Copy link
Contributor

@ivelin ivelin left a comment

Choose a reason for hiding this comment

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

@vickywane should the name of the endpoint be /product to better represent the intended use. It is confusing to think of POST /notification as a way to send an individual notification message and at the same time GET /notification fetches metadata about the notification product.

A more intuitive use for GET /notification would be to fetch the latest sent notification if we ever needed that historical data access.

@vickywane
Copy link
Contributor Author

A more intuitive use for GET /notification would be to fetch the latest sent notification if we ever needed that historical data access.

@ivelin Good catch!

This same thought ran through my mind while creating the endpoint today. I however wanted to know your thoughts on it also. I would make the change and push back.

@lgtm-com
Copy link

lgtm-com bot commented Jun 14, 2021

This pull request fixes 1 alert when merging 83c257b into 6067d3d - view on LGTM.com

fixed alerts:

  • 1 for Unused variable, import, function or class

Copy link
Contributor

@ivelin ivelin left a comment

Choose a reason for hiding this comment

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

@vickywane a few semantic naming comments.

README.md Outdated Show resolved Hide resolved
docs/index.html Outdated
<a href="#operation--product-get">GET</a>
</td>
<td>
<p>Retrieve notification product</p>
Copy link
Contributor

Choose a reason for hiding this comment

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

@vickywane This doesn't need to be tied to notifications. Let's just say that it:

"Retrieve product and pricing information associated with a premium customer subscription."

In Stripe nomenclature, a subscription is the unique pairing of a customer account with a product entity. Products have a pricing attached to them which can be one time, recurring or some combination.

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This text adjustment has been made.

Copy link
Contributor

Choose a reason for hiding this comment

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

Still reads
"

Retrieve notification product

"

docs/index.html Outdated
<span id="path--product"></span>
<div id="operation--product-get" class="swagger--panel-operation-get panel">
<div class="panel-heading">
<div class="operation-summary">Retrieve notification product</div>
Copy link
Contributor

Choose a reason for hiding this comment

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

@vickywane similar comment here. It does not have to be tied to notifications. We may add other products in the future and this API should still return the product information given a customer subscription.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

An adjustment has been made to the summary field in the openapi spec to correct this.

Copy link
Contributor

Choose a reason for hiding this comment

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

Strange. This index.html file still shows <div class="operation-summary">Retrieve notification product</div>

netlify/functions/notification.js Outdated Show resolved Hide resolved
} else if (event.httpMethod === "GET") {

try {
const product = await stripe.products.retrieve(process.env.EMAIL_PRODUCT_ID);
Copy link
Contributor

Choose a reason for hiding this comment

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

@vickywane instead of hardcoding the email product id in the deployment environment, let's just retrieve all information about user's subscription options along with product and price id. For now it's only email notifications, but we plan for that list of options to expand.

Copy link
Contributor Author

@vickywane vickywane Jun 17, 2021

Choose a reason for hiding this comment

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

As explained in this comment, the renamed email-product-id has no direct relation with end-users. The product is created by the organization either through the Stripe API or Stripe dashboard.

It is used to identify the product that a user is subscribed to. The product being retrieved is what stores the data.

To handle multiple product-IDs, they can be stored as environment variables with respective names. However, product IDs are currently not stored in a user's meta_data.

Copy link
Contributor

Choose a reason for hiding this comment

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

Then this method should take a generic product ID argument and return product information details.

EMAIL_PRODUCT_ID should not be hardcoded in the method implementation, but instead passed in as a productId argument from the client using this getProductInfo method.

@@ -127,17 +127,21 @@ Class | Method | HTTP request | Description
------------ | ------------- | ------------- | -------------
*AmbianicCloudApiCollection.DefaultApi* | [**createSubscription**](docs/DefaultApi.md#createSubscription) | **POST** /subscription | Subscribe a user to Ambianic&#39;s Premium Services
*AmbianicCloudApiCollection.DefaultApi* | [**deleteSubscription**](docs/DefaultApi.md#deleteSubscription) | **DELETE** /subscription | Delete an Ambianic&#39;s user subscription
*AmbianicCloudApiCollection.DefaultApi* | [**getNotificationProduct**](docs/DefaultApi.md#getNotificationProduct) | **GET** /product | Retrieve notification product
Copy link
Contributor

Choose a reason for hiding this comment

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

@vickywane in line with previous comments, this function name should be probably renamed to getProductInformation()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

An adjustment has been made to the operationId field in the openapi spec to correct this.

Copy link
Contributor

Choose a reason for hiding this comment

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

@vickywane the change has not been reflected in the README.md file.
The path still links to docs/DefaultApi.md#getNotificationProduct instead of docs/DefaultApi.md#getProductInfo.

@vickywane vickywane requested a review from ivelin June 17, 2021 04:44
@lgtm-com
Copy link

lgtm-com bot commented Jun 17, 2021

This pull request fixes 1 alert when merging 6f40ab2 into a31218f - view on LGTM.com

fixed alerts:

  • 1 for Unused variable, import, function or class

docs/index.html Outdated
<a href="#operation--product-get">GET</a>
</td>
<td>
<p>Retrieve notification product</p>
Copy link
Contributor

Choose a reason for hiding this comment

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

Still reads
"

Retrieve notification product

"

docs/index.html Outdated
<span id="path--product"></span>
<div id="operation--product-get" class="swagger--panel-operation-get panel">
<div class="panel-heading">
<div class="operation-summary">Retrieve notification product</div>
Copy link
Contributor

Choose a reason for hiding this comment

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

Strange. This index.html file still shows <div class="operation-summary">Retrieve notification product</div>

} else if (event.httpMethod === "GET") {

try {
const product = await stripe.products.retrieve(process.env.EMAIL_PRODUCT_ID);
Copy link
Contributor

Choose a reason for hiding this comment

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

Then this method should take a generic product ID argument and return product information details.

EMAIL_PRODUCT_ID should not be hardcoded in the method implementation, but instead passed in as a productId argument from the client using this getProductInfo method.

@vickywane
Copy link
Contributor Author

@vickywane In my most recent commit, i updated the bootprint docs alongside the /product route to receive a productId parameter and use it in fetching a specific product.

@lgtm-com
Copy link

lgtm-com bot commented Jun 18, 2021

This pull request fixes 1 alert when merging 11d303f into a31218f - view on LGTM.com

fixed alerts:

  • 1 for Unused variable, import, function or class

@vickywane vickywane requested a review from ivelin June 18, 2021 14:38
Copy link
Contributor

@ivelin ivelin left a comment

Choose a reason for hiding this comment

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

Needs clean up.

@@ -23,7 +23,7 @@ STRIPE_KEY=STRIPE_KEY

# The ID of the email price product used in billing subscribers.
EMAIL_PRODUCT_PRICE_ID=EMAIL_PRODUCT_PRICE_ID
Copy link
Contributor

Choose a reason for hiding this comment

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

@vickywane is this doc line still necessary? We do not hardcode product ID in the API.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For now, yes it is.

The EMAIL_PRODUCT_PRICE_ID that is used to retrieve only the pricing entity is different from the EMAIL_PRODUCT_ID.

The EMAIL_PRODUCT_PRICE_ID is used in the /subscription function when creating a subscription. The product ID response retrieved using the /product function does not include the ID of the pricing entity.

See subscription and price docs.

I would further rephrase the description of the EMAIL_PRODUCT_PRICE_ID to better reflect it's use

docs/index.html Show resolved Hide resolved
docs/index.html Outdated
<a href="#operation--product-get">GET</a>
</td>
<td>
<p>Retrieve product and pricing information associated with a premium customer subscription.</p>
Copy link
Contributor

Choose a reason for hiding this comment

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

@vickywane this description is misleading. If the method returns information associated with a subscription, then the arguments to the method should be user id or subscription id. Needs clean up.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Alright.

You however requested me to use that description here.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, I thought at the time that we would pass user subscription ID as an argument, but later I realized your intention is to pass product ID as an argument to this GET /product method.

docs/index.html Show resolved Hide resolved
docs/index.html Outdated
<a href="#operation--product-get">GET</a>
</td>
<td>
<p>Retrieve product and pricing information associated with a premium customer subscription.</p>
Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, I thought at the time that we would pass user subscription ID as an argument, but later I realized your intention is to pass product ID as an argument to this GET /product method.

docs/index.html Outdated
</div>
<div class="panel-body">
<section class="sw-operation-description">
<p>An endpoint to retrieve details about Ambianic product.</p>
Copy link
Contributor

Choose a reason for hiding this comment

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

@vickywane let's clarify here:
"An endpoint to retrieve details about an Ambianic premium subscription product."

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Alright. I made this adjustment

@@ -127,17 +127,21 @@ Class | Method | HTTP request | Description
------------ | ------------- | ------------- | -------------
*AmbianicCloudApiCollection.DefaultApi* | [**createSubscription**](docs/DefaultApi.md#createSubscription) | **POST** /subscription | Subscribe a user to Ambianic&#39;s Premium Services
*AmbianicCloudApiCollection.DefaultApi* | [**deleteSubscription**](docs/DefaultApi.md#deleteSubscription) | **DELETE** /subscription | Delete an Ambianic&#39;s user subscription
*AmbianicCloudApiCollection.DefaultApi* | [**getNotificationProduct**](docs/DefaultApi.md#getNotificationProduct) | **GET** /product | Retrieve notification product
Copy link
Contributor

Choose a reason for hiding this comment

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

@vickywane the change has not been reflected in the README.md file.
The path still links to docs/DefaultApi.md#getNotificationProduct instead of docs/DefaultApi.md#getProductInfo.

@@ -6,6 +6,7 @@ Method | HTTP request | Description
------------- | ------------- | -------------
[**createSubscription**](DefaultApi.md#createSubscription) | **POST** /subscription | Subscribe a user to Ambianic&#39;s Premium Services
[**deleteSubscription**](DefaultApi.md#deleteSubscription) | **DELETE** /subscription | Delete an Ambianic&#39;s user subscription
[**getNotificationProduct**](DefaultApi.md#getNotificationProduct) | **GET** /product | Retrieve notification product
Copy link
Contributor

Choose a reason for hiding this comment

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

@vickywane another line that needs cleanup getNotificationProduct.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This would be reflected in the new operation-id

@@ -117,6 +118,55 @@ No authorization required
- **Accept**: application/json


## getNotificationProduct
Copy link
Contributor

Choose a reason for hiding this comment

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

@vickywane I see a lot of references to getNotificationProduct. Is the intention to have a method hardwired to getting notification product information or is the goal to have a more generic getProductInfo method?

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 was yet to push the new updates from my local repository at the time of your review. I only called your attention to this comment.

"Content-Type": "application/json",
};

exports.handler = async ({ httpMethod, queryStringParameters }, context, callback) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

@vickywane I see that the implementation is now generic and works for any valid Product ID. Therefore the JS function name should match that behavior and be named getProductInfo as opposed to the more narrow getNotificationProduct naming.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Alright.

I have adjusted the operation-id to effect this change.

@@ -6,6 +6,7 @@ Method | HTTP request | Description
------------- | ------------- | -------------
[**createSubscription**](DefaultApi.md#createSubscription) | **POST** /subscription | Subscribe a user to Ambianic&#39;s Premium Services
[**deleteSubscription**](DefaultApi.md#deleteSubscription) | **DELETE** /subscription | Delete an Ambianic&#39;s user subscription
[**getNotificationProduct**](DefaultApi.md#getNotificationProduct) | **GET** /product | Retrieve notification product
Copy link
Contributor

Choose a reason for hiding this comment

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

@vickywane DefaultApi.md still reads Retrieve notification product for GET /product.

@lgtm-com
Copy link

lgtm-com bot commented Jun 21, 2021

This pull request fixes 1 alert when merging b908eb4 into a31218f - view on LGTM.com

fixed alerts:

  • 1 for Unused variable, import, function or class

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants